Your name
Haipeng Lin
Your affiliation
NCAR
What happened? What did you expect to happen?
A few bugs in Regrid_A2A_Mod, particularly with regional grids.
Some background. It looks like xmap (in the E-W direction) in A2A is more "technologically advanced" than ymap (in the N-S direction), so to speak. xmap appears to handle regional sources better but ymap fell out of sync with it. You can see xmap has notes on "reduce input grid" and "ghosting" but ymap still retains this
|
! sin1 (1) = -1 must be south pole; sin1(jm+1)=1 must be N pole. |
so I think the N-S regridding is slightly buggy for regional source inventories.
AI disclosure: after noticing this asymmetry between xmap and ymap, AI was used to write reproducers for the bugs with synthetic data so I can demonstrate the issues clearly. There are a total of 3 bugs. I think the use of AI is warranted here to clearly demonstrate the problem.
The below demos are one-dimensional since they either affect xmap or ymap:
-
ymap southern edge is incorrectly missval. ymap assigns an output cell only if its southern edge sin2(j) lands inside some source cell [sin1(m), sin1(m+1)] but not if it is straddling. The northern edge is handled correctly.
-
xmap dilutes west/east-straddle cells when missval /= 0. The ghosting regions are initialized to 0 and should be missval; if missval /= 0 then the ghost zeros get averaged into the boundary cells halving the values on the edges.
-
Pole averaging problems. Two issues here: observe ymap_r8r8's
|
if ( nlon > 0.0d0 ) sum = sum / DBLE( im ) |
compared with the other variants
|
if ( nlon > 0.0d0 ) sum = sum / nlon |
|
if ( nlon > 0.0 ) sum = sum / nlon |
I think this DBLE(im) is intended to be nlon. No idea how it got here.
The second issue is that the nlon>0 guard should cover both the sum calculation and the assignment...
|
if ( nlon > 0.0 ) sum = sum / nlon |
|
do i=1,im |
|
q2(i,jn) = sum |
|
enddo |
What are the steps to reproduce the bug?
I attach three reproducers that show this problem. The reproducers were written with the assistance of AI after providing the buggy code.
For problem 1:
https://gist.github.com/jimmielin/a5d83fa6e0a331cf1d8a1120820eea6e
driver_ymap_south.F90: source regional in latitude [10N,50N] (=100), global
target. Cell [0,20] straddles the south edge; cell [40,90] the north edge.
| target cell |
unpatched |
patched |
correct |
[-90,-30] |
0 (bug 3) |
-999 (MISS) |
MISS |
[-30,0] |
-999 (MISS) |
-999 (MISS) |
MISS |
[0,20] south straddle |
-999 (MISS) ❌ |
100 ✅ |
100 |
[20,40] |
100 |
100 |
100 |
[40,90] north straddle |
100 |
100 |
100 |
(The [-90,-30] south-pole row is all-missing; unpatched it was clobbered to 0
by bug 3, patched it stays -999.)
For problem 2:
https://gist.github.com/jimmielin/32c6557609e78f4c3b3f932b19535d75
driver_xmap_west.F90: source regional in longitude [100,120] (=100). Cell
[95,105] straddles the west edge; cell [115,125] the east edge.
| target cell |
unpatched (miss=0) |
unpatched (miss=-999) |
patched |
correct |
[95,105] west straddle |
100 |
50 ❌ |
100 ✅ |
100 |
[105,115] |
100 |
100 |
100 |
100 |
[115,125] east straddle |
100 |
50 ❌ |
100 ✅ |
100 |
For problem 3:
https://gist.github.com/jimmielin/aa54ae5483b78ba8feae50ea6846868c
driver_pole_partial.F90: identical longitudes, global lat regrid so ymap's
pole block runs.
| scenario |
unpatched |
patched |
correct |
partial north ring (2 of 4 valid, missval=0) |
50 ❌ |
100 ✅ |
100 |
all-missing north ring (missval=-999) |
0 ❌ (clobbers) |
-999 ✅ |
MISS |
Outputs when running these against HEMCO upstream:
======================== driver_ymap_south ========================
target lat cell q2(1,j) expected
cell -90.0 -30.0 0.000 MISS (south of source)
cell -30.0 0.0 -999.000 MISS (south of source)
cell 0.0 20.0 -999.000 100.0 <-- SOUTH straddle (overlaps [10,20])
cell 20.0 40.0 100.000 100.0 (fully inside source)
cell 40.0 90.0 100.000 100.0 <-- NORTH straddle (overlaps [40,50])
======================== driver_xmap_west ========================
=== missval = 0.0
cell 95.0 105.0 100.0000 expected 100.0 <-- WEST straddle (overlaps [100,105])
cell 105.0 115.0 100.0000 expected 100.0 (fully inside source)
cell 115.0 125.0 100.0000 expected 100.0 <-- EAST straddle (overlaps [115,120])
=== missval = -999.0
cell 95.0 105.0 50.0000 expected 100.0 <-- WEST straddle (overlaps [100,105])
cell 105.0 115.0 100.0000 expected 100.0 (fully inside source)
cell 115.0 125.0 50.0000 expected 100.0 <-- EAST straddle (overlaps [115,120])
======================== driver_pole_partial ========================
Scenario A (partial north pole, missval=0)
north pole row q2(:,jn) = 50.00 50.00 50.00 50.00
(unpatched -> 50.0 ; patched -> 100.0 ; correct = 100.0)
Scenario B (all-missing north pole, missval=-999)
north pole row q2(:,jn) = 0.00 0.00 0.00 0.00
(unpatched -> 0.0 clobbers missval ; patched -> -999.0 preserved)
Outputs when running these after patching:
======================== driver_ymap_south ========================
target lat cell q2(1,j) expected
cell -90.0 -30.0 -999.000 MISS (south of source)
cell -30.0 0.0 -999.000 MISS (south of source)
cell 0.0 20.0 100.000 100.0 <-- SOUTH straddle (overlaps [10,20])
cell 20.0 40.0 100.000 100.0 (fully inside source)
cell 40.0 90.0 100.000 100.0 <-- NORTH straddle (overlaps [40,50])
======================== driver_xmap_west ========================
=== missval = 0.0
cell 95.0 105.0 100.0000 expected 100.0 <-- WEST straddle (overlaps [100,105])
cell 105.0 115.0 100.0000 expected 100.0 (fully inside source)
cell 115.0 125.0 100.0000 expected 100.0 <-- EAST straddle (overlaps [115,120])
=== missval = -999.0
cell 95.0 105.0 100.0000 expected 100.0 <-- WEST straddle (overlaps [100,105])
cell 105.0 115.0 100.0000 expected 100.0 (fully inside source)
cell 115.0 125.0 100.0000 expected 100.0 <-- EAST straddle (overlaps [115,120])
======================== driver_pole_partial ========================
Scenario A (partial north pole, missval=0)
north pole row q2(:,jn) = 100.00 100.00 100.00 100.00
(unpatched -> 50.0 ; patched -> 100.0 ; correct = 100.0)
Scenario B (all-missing north pole, missval=-999)
north pole row q2(:,jn) = -999.00 -999.00 -999.00 -999.00
(unpatched -> 0.0 clobbers missval ; patched -> -999.0 preserved)
Please attach any relevant configuration and log files.
No response
What HEMCO version were you using?
dev/3.13.0
What environment were you running HEMCO on?
Personal computer
What compiler and version were you using?
gfortran 16.1.1
Will you be addressing this bug yourself?
Yes
In what configuration were you running HEMCO?
Other (please explain in additional information section below)
As what resolution were you running HEMCO?
Standalone reproducers for bugs.
What meterology fields did you use?
Other (please explain in additional information section below)
Additional information
No response
Your name
Haipeng Lin
Your affiliation
NCAR
What happened? What did you expect to happen?
A few bugs in Regrid_A2A_Mod, particularly with regional grids.
Some background. It looks like
xmap(in the E-W direction) in A2A is more "technologically advanced" thanymap(in the N-S direction), so to speak.xmapappears to handle regional sources better butymapfell out of sync with it. You can seexmaphas notes on "reduce input grid" and "ghosting" butymapstill retains thisHEMCO/src/Shared/GeosUtil/hco_regrid_a2a_mod.F90
Line 681 in 07da3c2
so I think the N-S regridding is slightly buggy for regional source inventories.
AI disclosure: after noticing this asymmetry between
xmapandymap, AI was used to write reproducers for the bugs with synthetic data so I can demonstrate the issues clearly. There are a total of 3 bugs. I think the use of AI is warranted here to clearly demonstrate the problem.The below demos are one-dimensional since they either affect xmap or ymap:
ymapsouthern edge is incorrectlymissval.ymapassigns an output cell only if its southern edgesin2(j)lands inside some source cell[sin1(m), sin1(m+1)]but not if it is straddling. The northern edge is handled correctly.xmapdilutes west/east-straddle cells whenmissval /= 0. The ghosting regions are initialized to0and should bemissval; ifmissval /= 0then the ghost zeros get averaged into the boundary cells halving the values on the edges.Pole averaging problems. Two issues here: observe
ymap_r8r8'sHEMCO/src/Shared/GeosUtil/hco_regrid_a2a_mod.F90
Line 813 in 07da3c2
compared with the other variants
HEMCO/src/Shared/GeosUtil/hco_regrid_a2a_mod.F90
Line 1012 in 07da3c2
HEMCO/src/Shared/GeosUtil/hco_regrid_a2a_mod.F90
Line 1212 in 07da3c2
I think this
DBLE(im)is intended to benlon. No idea how it got here.The second issue is that the
nlon>0guard should cover both thesumcalculation and the assignment...HEMCO/src/Shared/GeosUtil/hco_regrid_a2a_mod.F90
Lines 1212 to 1215 in 07da3c2
What are the steps to reproduce the bug?
I attach three reproducers that show this problem. The reproducers were written with the assistance of AI after providing the buggy code.
For problem 1:
https://gist.github.com/jimmielin/a5d83fa6e0a331cf1d8a1120820eea6e
driver_ymap_south.F90: source regional in latitude[10N,50N](=100), globaltarget. Cell
[0,20]straddles the south edge; cell[40,90]the north edge.[-90,-30][-30,0][0,20]south straddle[20,40][40,90]north straddle(The
[-90,-30]south-pole row is all-missing; unpatched it was clobbered to0by bug 3, patched it stays
-999.)For problem 2:
https://gist.github.com/jimmielin/32c6557609e78f4c3b3f932b19535d75
driver_xmap_west.F90: source regional in longitude[100,120](=100). Cell[95,105]straddles the west edge; cell[115,125]the east edge.[95,105]west straddle[105,115][115,125]east straddleFor problem 3:
https://gist.github.com/jimmielin/aa54ae5483b78ba8feae50ea6846868c
driver_pole_partial.F90: identical longitudes, global lat regrid soymap'spole block runs.
missval=0)missval=-999)Outputs when running these against HEMCO upstream:
Outputs when running these after patching:
Please attach any relevant configuration and log files.
No response
What HEMCO version were you using?
dev/3.13.0
What environment were you running HEMCO on?
Personal computer
What compiler and version were you using?
gfortran 16.1.1
Will you be addressing this bug yourself?
Yes
In what configuration were you running HEMCO?
Other (please explain in additional information section below)
As what resolution were you running HEMCO?
Standalone reproducers for bugs.
What meterology fields did you use?
Other (please explain in additional information section below)
Additional information
No response