From 98afc1c5b8806cd4037503e03e84c4417c358ed3 Mon Sep 17 00:00:00 2001 From: Ben Koziol Date: Wed, 15 Oct 2014 15:15:48 -0600 Subject: [PATCH] interpolation incorrect over poles #335 Fixed row and column creation so interpolation over poles with spherical coordinate systems now work as expected. --- src/ocgis/regrid/base.py | 16 ++-- .../test/test_ocgis/test_api/test_subset.py | 15 +-- .../test/test_ocgis/test_regrid/test_base.py | 93 ++++++++++--------- 3 files changed, 62 insertions(+), 62 deletions(-) diff --git a/src/ocgis/regrid/base.py b/src/ocgis/regrid/base.py index 9dc613bad..f2adbdf06 100644 --- a/src/ocgis/regrid/base.py +++ b/src/ocgis/regrid/base.py @@ -24,8 +24,8 @@ def get_sdim_from_esmf_grid(egrid): dtype_coords = coords[0].dtype # construct the ocgis grid array and fill grid_value = np.zeros([2] + shape_coords_list, dtype=dtype_coords) - grid_value[0, ...] = coords[0] - grid_value[1, ...] = coords[1] + grid_value[0, ...] = coords[1] + grid_value[1, ...] = coords[0] # check for corners on the esmf grid if all(egrid.coords_done[ESMF.StaggerLoc.CORNER]): @@ -37,8 +37,8 @@ def get_sdim_from_esmf_grid(egrid): for ii, jj in iter_array(coords[0], use_mask=False): row_slice = slice(ii, ii+2) col_slice = slice(jj, jj+2) - row_corners = corner[0][row_slice, col_slice] - col_corners = corner[1][row_slice, col_slice] + row_corners = corner[1][row_slice, col_slice] + col_corners = corner[0][row_slice, col_slice] for kk, slc in enumerate(slices): grid_corners[:, ii, jj, kk] = row_corners[slc], col_corners[slc] else: @@ -89,9 +89,9 @@ def get_esmf_grid_from_sdim(sdim, with_corners=True, value_mask=None): ogrid = sdim.grid egrid = ESMF.Grid(max_index=np.array(ogrid.value.shape[1:]), staggerloc=ESMF.StaggerLoc.CENTER, coord_sys=ESMF.CoordSys.SPH_DEG) - row = egrid.get_coords(0, staggerloc=ESMF.StaggerLoc.CENTER) + row = egrid.get_coords(1, staggerloc=ESMF.StaggerLoc.CENTER) row[:] = ogrid.value[0, ...] - col = egrid.get_coords(1, staggerloc=ESMF.StaggerLoc.CENTER) + col = egrid.get_coords(0, staggerloc=ESMF.StaggerLoc.CENTER) col[:] = ogrid.value[1, ...] # use a logical or operation to merge with value_mask if present @@ -115,8 +115,8 @@ def get_esmf_grid_from_sdim(sdim, with_corners=True, value_mask=None): egrid.add_coords(staggerloc=[ESMF.StaggerLoc.CORNER]) # get the coordinate pointers and set the coordinates grid_corner = egrid.coords[ESMF.StaggerLoc.CORNER] - grid_corner[0][:] = corners_esmf[0] - grid_corner[1][:] = corners_esmf[1] + grid_corner[1][:] = corners_esmf[0] + grid_corner[0][:] = corners_esmf[1] except CornersUnavailable: pass diff --git a/src/ocgis/test/test_ocgis/test_api/test_subset.py b/src/ocgis/test/test_ocgis/test_api/test_subset.py index cab2e3112..c4fcff7cb 100644 --- a/src/ocgis/test/test_ocgis/test_api/test_subset.py +++ b/src/ocgis/test/test_ocgis/test_api/test_subset.py @@ -55,7 +55,7 @@ def test_bounding_box_wrapped(self): self.assertEqual(field.shape, (1, 1, 1, 64, 72)) self.assertEqual(field.spatial.grid.value.mean(), -29.75) self.assertIsNotNone(field.spatial.grid.corners) - self.assertAlmostEqual(field.variables.first().value.mean(), 262.07747395833331) + self.assertAlmostEqual(field.variables.first().value.mean(), 262.08338758680554) def test_geometry_dictionary(self): """Test geometry dictionaries come out properly as collections.""" @@ -118,15 +118,6 @@ def test_regridding_same_field(self): field.spatial.grid.corners, field.spatial.geom.polygon.value]: self.assertIsNotNone(to_check) - def test_regridding_same_field_bad_bounds_raises(self): - """Test a regridding error is raised with bad bounds.""" - - rd1 = self.test_data.get_rd('cancm4_tas') - ops = ocgis.OcgOperations(dataset=rd1, regrid_destination=rd1, snippet=True) - subset = SubsetOperation(ops) - with self.assertRaises(ValueError): - list(subset) - def test_regridding_same_field_bad_bounds_without_corners(self): """Test bad bounds may be regridded with_corners as False.""" @@ -252,7 +243,7 @@ def test_regridding_update_crs(self): rd1 = self.test_data.get_rd('cancm4_tas') rd2 = self.test_data.get_rd('narccap_lambert_conformal') - actual = np.ma.array([[[[[0.0, 0.0, 0.0, 0.0, 289.3017883300781, 288.7024230957031, 287.9030456542969, 287.1700439453125, 286.50152587890625, 285.89556884765625, 0.0, 0.0, 0.0], [0.0, 288.76837158203125, 288.6125793457031, 288.323486328125, 287.90484619140625, 287.3174743652344, 286.6184387207031, 285.9873046875, 285.422119140625, 284.9210510253906, 284.4820861816406, 0.0, 0.0], [288.41796875, 288.18145751953125, 287.804443359375, 287.2906799316406, 286.6439514160156, 285.8691101074219, 285.2718505859375, 284.7440185546875, 284.2837219238281, 283.88897705078125, 283.557861328125, 0.0, 0.0], [288.1981506347656, 287.7408142089844, 287.1394348144531, 286.3978271484375, 285.5198669433594, 284.5093994140625, 283.86285400390625, 283.4398193359375, 283.08587646484375, 282.79901123046875, 282.5773010253906, 0.0, 0.0], [288.0224914550781, 287.44732666015625, 286.61846923828125, 285.6458435058594, 284.5333557128906, 283.2848815917969, 282.39093017578125, 282.0742492675781, 281.82818603515625, 281.6507568359375, 281.5400390625, 0.0, 0.0], [287.8061218261719, 287.3020935058594, 286.2425231933594, 285.0356140136719, 283.6852722167969, 282.1954345703125, 280.85565185546875, 280.6468200683594, 280.51019287109375, 280.4438171386719, 280.4490966796875, 280.4698181152344, 0.0], [287.58941650390625, 287.3061218261719, 286.0126037597656, 284.5680847167969, 282.9765319824219, 281.241943359375, 279.4717102050781, 279.3304443359375, 279.31854248046875, 279.322509765625, 279.3420715332031, 279.3770751953125, 0.0], [287.37237548828125, 287.3219299316406, 285.88140869140625, 284.1074523925781, 282.3339538574219, 280.56085205078125, 278.7880554199219, 278.173095703125, 278.17498779296875, 278.1929016113281, 278.2267150878906, 278.27618408203125, 0.0], [286.8515319824219, 286.482421875, 285.2543640136719, 283.4666442871094, 281.67938232421875, 279.8925476074219, 278.1060791015625, 277.00677490234375, 277.0225830078125, 277.0546875, 277.1029052734375, 277.1670227050781, 0.0], [286.04193115234375, 285.54132080078125, 284.6296691894531, 282.8280029296875, 281.0268249511719, 279.2261047363281, 277.4257507324219, 275.83135986328125, 275.86126708984375, 275.9077453613281, 275.9705505371094, 276.04949951171875, 0.0], [285.3255920410156, 284.691650390625, 283.970458984375, 282.1915588378906, 280.3763122558594, 278.5615234375, 276.74713134765625, 274.93310546875, 274.6908874511719, 274.75189208984375, 274.8294677734375, 274.9234619140625, 275.03363037109375], [284.70318603515625, 283.93414306640625, 283.0754699707031, 281.557373046875, 279.72784423828125, 277.8988037109375, 276.0702209472656, 274.2420349121094, 273.51129150390625, 273.5870056152344, 273.6817626953125, 273.9592590332031, 274.23809814453125], [284.17547607421875, 283.2694396972656, 282.2713928222656, 280.92547607421875, 279.08148193359375, 277.2380065917969, 275.3950500488281, 273.7021484375, 272.6849060058594, 272.9571533203125, 273.23040771484375, 273.5047607421875, 273.7804260253906], [283.7431945800781, 282.69830322265625, 281.5589904785156, 280.3041687011719, 278.539306640625, 276.8466491699219, 275.2239685058594, 273.6691589355469, 272.2420654296875, 272.5112609863281, 272.7813720703125, 273.05255126953125, 273.324951171875], [283.3773498535156, 282.1432189941406, 280.9111328125, 279.6810607910156, 278.1356201171875, 276.5419006347656, 275.0201110839844, 273.5680236816406, 272.1833801269531, 272.0677185058594, 272.33465576171875, 272.6025695800781, 272.8716735839844], [282.7506408691406, 281.5077209472656, 280.2668762207031, 279.028076171875, 277.65899658203125, 276.1656799316406, 274.7462158203125, 273.3983459472656, 272.1197814941406, 271.6265563964844, 271.8902282714844, 272.15484619140625, 272.4205627441406], [282.1257629394531, 280.8739318847656, 279.62420654296875, 278.3765563964844, 277.1088562011719, 275.7173767089844, 274.40167236328125, 273.1595458984375, 271.9886474609375, 271.187744140625, 271.4480895996094, 271.7093505859375, 271.97161865234375], [281.5027160644531, 280.2418518066406, 278.9831237792969, 277.7264709472656, 276.4718933105469, 275.1964111328125, 273.98602294921875, 272.85113525390625, 271.7894592285156, 270.7986145019531, 271.00823974609375, 271.2593688964844, 271.4490966796875], [280.8815612792969, 279.61151123046875, 278.3436279296875, 277.077880859375, 275.8142395019531, 274.6021423339844, 273.4985656738281, 272.4725036621094, 271.57916259765625, 270.69873046875, 270.55328369140625, 270.6933898925781, 270.78143310546875], [280.2622985839844, 278.98291015625, 277.7057800292969, 276.4308166503906, 275.1949768066406, 274.1751708984375, 273.2945556640625, 272.4111633300781, 271.5249938964844, 270.635986328125, 270.1463928222656, 270.1847839355469, 270.1696472167969], [0.0, 278.40582275390625, 277.3563232421875, 276.3005676269531, 275.2385559082031, 274.17022705078125, 273.26031494140625, 272.3682861328125, 271.4734802246094, 270.5758056640625, 269.7988586425781, 269.7340087890625, 269.6141357421875], [0.0, 278.4913024902344, 277.4296569824219, 276.3616943359375, 275.2873840332031, 274.2066955566406, 273.2289733886719, 272.3282165527344, 271.4246520996094, 270.5182189941406, 269.6088562011719, 269.341552734375, 269.1153259277344], [0.0, 278.5826110839844, 277.5086975097656, 276.4283447265625, 275.3415832519531, 274.2483825683594, 273.2006530761719, 272.2910461425781, 271.37860107421875, 270.4632568359375, 269.54498291015625, 269.00787353515625, 268.6737365722656], [0.0, 0.0, 277.593505859375, 276.5006408691406, 275.4012451171875, 274.29534912109375, 273.1828918457031, 272.25677490234375, 271.3353271484375, 270.4109802246094, 269.48370361328125, 268.7335205078125, 0.0]]]]], + actual = np.ma.array([[[[[0.0, 0.0, 0.0, 0.0, 289.309326171875, 288.7110290527344, 287.92108154296875, 287.1899108886719, 286.51715087890625, 285.9024658203125, 0.0, 0.0, 0.0], [0.0, 288.77825927734375, 288.62823486328125, 288.3404541015625, 287.9151611328125, 287.32000732421875, 286.633544921875, 286.0067138671875, 285.43914794921875, 284.93060302734375, 284.48077392578125, 0.0, 0.0], [288.4192199707031, 288.18804931640625, 287.8165588378906, 287.30499267578125, 286.65362548828125, 285.86676025390625, 285.28515625, 284.7640686035156, 284.30316162109375, 283.90216064453125, 283.560791015625, 0.0, 0.0], [288.19488525390625, 287.74169921875, 287.14593505859375, 286.4078063964844, 285.52752685546875, 284.5051574707031, 283.87457275390625, 283.4606628417969, 283.1078186035156, 282.8158264160156, 282.58441162109375, 0.0, 0.0], [288.023193359375, 287.4422607421875, 286.6193542480469, 285.65179443359375, 284.5396728515625, 283.2830505371094, 282.4002685546875, 282.09503173828125, 281.8517761230469, 281.6702575683594, 281.55029296875, 0.0, 0.0], [287.8075866699219, 287.2928771972656, 286.2398986816406, 285.0399475097656, 283.6930236816406, 282.19915771484375, 280.86077880859375, 280.66571044921875, 280.5335388183594, 280.4640808105469, 280.4613952636719, 280.4708251953125, 0.0], [287.591552734375, 287.296875, 286.0108337402344, 284.5754089355469, 282.99066162109375, 281.2564392089844, 279.47003173828125, 279.34307861328125, 279.3382263183594, 279.3432922363281, 279.3581848144531, 279.3829040527344, 0.0], [287.3750305175781, 287.322265625, 285.8916931152344, 284.12139892578125, 282.3462829589844, 280.566162109375, 278.7807922363281, 278.1846618652344, 278.1950988769531, 278.2154846191406, 278.24578857421875, 278.2860107421875, 0.0], [286.864013671875, 286.48724365234375, 285.2509460449219, 283.4699401855469, 281.6840515136719, 279.8930358886719, 278.0966796875, 277.01617431640625, 277.0421142578125, 277.07806396484375, 277.1240234375, 277.1799621582031, 0.0], [286.0535583496094, 285.5471496582031, 284.6158752441406, 282.8240661621094, 281.0272521972656, 279.2252197265625, 277.4177551269531, 275.8373107910156, 275.8789367675781, 275.9306945800781, 275.9925231933594, 276.0644226074219, 0.0], [285.3349609375, 284.69732666015625, 283.9648132324219, 282.183837890625, 280.3759765625, 278.56280517578125, 276.74407958984375, 274.91961669921875, 274.7053527832031, 274.77313232421875, 274.85107421875, 274.9391784667969, 275.0374450683594], [284.7100830078125, 283.93963623046875, 283.07275390625, 281.54925537109375, 279.730224609375, 277.90576171875, 276.07568359375, 274.2397155761719, 273.5210266113281, 273.6050720214844, 273.69940185546875, 273.9654235839844, 274.24139404296875], [284.1809387207031, 283.27606201171875, 282.2731018066406, 280.9204406738281, 279.090087890625, 277.25421142578125, 275.41259765625, 273.7033996582031, 272.687744140625, 272.9641418457031, 273.2394104003906, 273.5135498046875, 273.78662109375], [283.7496337890625, 282.70855712890625, 281.56787109375, 280.3042907714844, 278.54541015625, 276.8524169921875, 275.22515869140625, 273.6634826660156, 272.24554443359375, 272.5191955566406, 272.7915954589844, 273.0628662109375, 273.3330078125], [283.39312744140625, 282.1578369140625, 280.91937255859375, 279.67755126953125, 278.1316223144531, 276.5411071777344, 275.017333984375, 273.56024169921875, 272.16973876953125, 272.07550048828125, 272.3450622558594, 272.6134338378906, 272.8805847167969], [282.7581481933594, 281.516845703125, 280.27227783203125, 279.0242614746094, 277.64892578125, 276.16229248046875, 274.743408203125, 273.3922424316406, 272.1087646484375, 271.63311767578125, 271.8998107910156, 272.1651916503906, 272.4293518066406], [282.1268615722656, 280.87945556640625, 279.6286926269531, 278.3744201660156, 277.095703125, 275.7143249511719, 274.4017639160156, 273.157958984375, 271.98297119140625, 271.1920471191406, 271.4557800292969, 271.71820068359375, 271.97930908203125], [281.499267578125, 280.24566650390625, 278.9886779785156, 277.7280578613281, 276.4637145996094, 275.19561767578125, 273.9908142089844, 272.85589599609375, 271.7908630371094, 270.79583740234375, 271.0130615234375, 271.26873779296875, 271.4607238769531], [280.8753662109375, 279.6155090332031, 278.3522033691406, 277.085205078125, 275.81439208984375, 274.6044921875, 273.50897216796875, 272.4844055175781, 271.58203125, 270.6971130371094, 270.5581359863281, 270.7032165527344, 270.7939453125], [280.25518798828125, 278.989013671875, 277.71929931640625, 276.4458312988281, 275.1974182128906, 274.173828125, 273.29473876953125, 272.4113464355469, 271.5235290527344, 270.63116455078125, 270.1499938964844, 270.1932678222656, 270.1813049316406], [0.0, 278.4078063964844, 277.3578186035156, 276.3003234863281, 275.2351379394531, 274.162109375, 273.2556457519531, 272.36480712890625, 271.4695129394531, 270.569580078125, 269.8001403808594, 269.7401428222656, 269.6240234375], [0.0, 278.4853820800781, 277.42474365234375, 276.3564758300781, 275.2804260253906, 274.1964416503906, 273.2213134765625, 272.3229675292969, 271.4200744628906, 270.5124816894531, 269.6001281738281, 269.3451232910156, 269.1233825683594], [0.0, 278.5711669921875, 277.49969482421875, 276.4205017089844, 275.33343505859375, 274.23834228515625, 273.1918640136719, 272.2858581542969, 271.3752746582031, 270.4599304199219, 269.53973388671875, 269.00958251953125, 268.6806335449219], [0.0, 0.0, 277.5827941894531, 276.4925537109375, 275.3943176269531, 274.2879638671875, 273.1732482910156, 272.25360107421875, 271.335205078125, 270.4120178222656, 269.48388671875, 268.73492431640625, 0.0]]]]], mask=[[[[[True, True, True, True, True, True, True, True, True, False, False, False, True], [True, True, True, True, True, True, True, False, False, False, False, False, True], [True, True, True, True, True, True, True, False, False, False, False, False, True], [True, True, True, True, True, True, False, False, False, False, False, False, False], [True, True, True, True, True, False, False, False, False, False, False, False, False], [True, True, True, True, False, False, False, False, False, False, False, False, True], [True, True, False, False, False, False, False, False, False, False, False, False, True], [True, True, False, False, False, False, False, False, False, False, False, True, True], [True, True, False, False, False, False, False, False, False, False, True, True, True], [True, True, False, False, False, False, False, False, False, False, True, True, True], [True, False, False, False, False, False, False, False, False, True, True, True, True], [True, False, False, False, False, False, False, False, True, True, True, True, True], [True, False, False, False, False, False, False, False, True, True, True, True, True], [True, False, False, False, False, False, False, True, True, True, True, True, True], [True, False, False, False, False, False, False, True, True, True, True, True, True], [False, False, False, False, False, False, True, True, True, True, True, True, True], [False, False, False, False, False, False, True, True, True, True, True, True, True], [False, False, False, False, False, False, True, True, True, True, True, True, True], [False, False, False, False, False, False, False, True, True, True, True, True, True], [False, False, False, False, False, False, False, True, True, True, True, True, True], [False, False, False, False, False, False, False, True, True, True, True, True, True], [False, False, False, False, False, False, False, False, True, True, True, True, True], [True, False, False, False, False, False, True, True, True, True, True, True, True], [True, False, False, True, True, True, True, True, True, True, True, True, True]]]]], dtype=np.float32, fill_value=np.float32(1e20)) @@ -270,7 +261,7 @@ def test_regridding_update_crs(self): self.assertEqual(field.spatial.crs, rd1.crs) to_test = field.variables.first().value self.assertEqual(to_test.shape, (1, 1, 1, 24, 13)) - self.assertNumpyAll(to_test,actual) + self.assertNumpyAll(to_test, actual) def test_regridding_with_output_crs(self): """Test with an output coordinate system.""" diff --git a/src/ocgis/test/test_ocgis/test_regrid/test_base.py b/src/ocgis/test/test_ocgis/test_regrid/test_base.py index f986a7ca4..212f868c9 100644 --- a/src/ocgis/test/test_ocgis/test_regrid/test_base.py +++ b/src/ocgis/test/test_ocgis/test_regrid/test_base.py @@ -216,7 +216,7 @@ def test_iter_regridded_fields_different_grid_shapes(self): for regridded in iter_regridded_fields([downscaled], gcm): self.assertEqual(regridded.shape, (1, 28, 1, 3, 5)) self.assertEqual(regridded.variables.keys(), ['tas']) - self.assertAlmostEqual(regridded.variables['tas'].value.data.mean(), 0.058454717908586772) + self.assertAlmostEqual(regridded.variables['tas'].value.data.mean(), 0.057409391) self.assertNumpyAll(gcm.spatial.get_mask(), mask) for variable in regridded.variables.itervalues(): vmask = variable.value.mask @@ -240,24 +240,16 @@ def test_iter_regridded_fields_problem_bounds(self): ret = list(iter_esmf_fields(src)) self.assertEqual(len(ret), 1) tidx, variable_alias, efield = ret[0] - self.assertNumpyAll(efield.grid.coords[0][0], dst.spatial.grid.value.data[0]) - self.assertNumpyAll(efield.grid.coords[0][1], dst.spatial.grid.value.data[1]) - - #todo: uncomment when output errors understood - # # this should fail as the bounds are strange - # with self.assertRaises(ValueError): - # list(iter_regridded_fields([src], dst)) + self.assertNumpyAll(efield.grid.coords[0][0], dst.spatial.grid.value.data[1]) + self.assertNumpyAll(efield.grid.coords[0][1], dst.spatial.grid.value.data[0]) ret = list(iter_regridded_fields([src], dst, with_corners=False))[0] actual = dst[0, 0, 0, :, :].variables.first().value to_test = ret.variables.first().value self.assertFalse(to_test.mask.any()) - x = np.abs(ret.variables.first().value - actual) - select = x > 0 - - #todo: appears to be a systematic error in the output... - self.assertNumpyAllClose(to_test, actual) + self.assertNumpyAllClose(to_test.data, actual.data) + self.assertNumpyAll(to_test.mask, actual.mask) def test_iter_regridded_fields(self): """Test with equivalent input and output expectations. The shapes of the grids are equal.""" @@ -488,19 +480,26 @@ def test_get_esmf_grid_from_sdim(self): egrid = get_esmf_grid_from_sdim(sdim) - for idx in [0, 1]: - coords = egrid.coords[ESMF.StaggerLoc.CENTER][idx] - self.assertNumpyAll(coords, field.spatial.grid.value[idx, ...].data) + # ocgis is row major with esmf being column major (i.e. in ocgis rows are stored in the zero index) + for idx_esmf, idx_ocgis in zip([0, 1], [1, 0]): + coords = egrid.coords[ESMF.StaggerLoc.CENTER][idx_esmf] + self.assertNumpyAll(coords, field.spatial.grid.value[idx_ocgis, ...].data) corner = egrid.coords[ESMF.StaggerLoc.CORNER] if h: - corner_row = corner[0] - corner_row_actual = np.array([[36.5, 36.5, 36.5, 36.5, 36.5], [37.5, 37.5, 37.5, 37.5, 37.5], [38.5, 38.5, 38.5, 38.5, 38.5], [39.5, 39.5, 39.5, 39.5, 39.5], [40.5, 40.5, 40.5, 40.5, 40.5]], dtype=field.spatial.grid.value.dtype) + corner_row = corner[1] + corner_row_actual = np.array( + [[36.5, 36.5, 36.5, 36.5, 36.5], [37.5, 37.5, 37.5, 37.5, 37.5], [38.5, 38.5, 38.5, 38.5, 38.5], + [39.5, 39.5, 39.5, 39.5, 39.5], [40.5, 40.5, 40.5, 40.5, 40.5]], + dtype=field.spatial.grid.value.dtype) self.assertNumpyAll(corner_row, corner_row_actual) corner = egrid.coords[ESMF.StaggerLoc.CORNER] - corner_col = corner[1] - corner_col_actual = np.array([[-105.5, -104.5, -103.5, -102.5, -101.5], [-105.5, -104.5, -103.5, -102.5, -101.5], [-105.5, -104.5, -103.5, -102.5, -101.5], [-105.5, -104.5, -103.5, -102.5, -101.5], [-105.5, -104.5, -103.5, -102.5, -101.5]], dtype=field.spatial.grid.value.dtype) + corner_col = corner[0] + corner_col_actual = np.array( + [[-105.5, -104.5, -103.5, -102.5, -101.5], [-105.5, -104.5, -103.5, -102.5, -101.5], + [-105.5, -104.5, -103.5, -102.5, -101.5], [-105.5, -104.5, -103.5, -102.5, -101.5], + [-105.5, -104.5, -103.5, -102.5, -101.5]], dtype=field.spatial.grid.value.dtype) self.assertNumpyAll(corner_col, corner_col_actual) else: for idx in [0, 1]: @@ -513,9 +512,9 @@ def test_get_esmf_grid_from_sdim_real_data(self): field = rd.get() egrid = get_esmf_grid_from_sdim(field.spatial) - for idx in [0, 1]: - coords = egrid.coords[ESMF.StaggerLoc.CENTER][idx] - self.assertNumpyAll(coords, field.spatial.grid.value[idx, ...].data) + for idx_esmf, idx_ocgis in zip([0, 1], [1, 0]): + coords = egrid.coords[ESMF.StaggerLoc.CENTER][idx_esmf] + self.assertNumpyAll(coords, field.spatial.grid.value[idx_ocgis, ...].data) def test_get_esmf_grid_from_sdim_change_origin_row(self): """Test with different row grid origin.""" @@ -528,18 +527,23 @@ def test_get_esmf_grid_from_sdim_change_origin_row(self): egrid = get_esmf_grid_from_sdim(field.spatial) - for idx in [0, 1]: - coords = egrid.coords[ESMF.StaggerLoc.CENTER][idx] - self.assertNumpyAll(coords, field.spatial.grid.value[idx, ...].data) + for idx_esmf, idx_ocgis in zip([0, 1], [1, 0]): + coords = egrid.coords[ESMF.StaggerLoc.CENTER][idx_esmf] + self.assertNumpyAll(coords, field.spatial.grid.value[idx_ocgis, ...].data) corner = egrid.coords[ESMF.StaggerLoc.CORNER] - corner_row = corner[0] - corner_row_actual = np.array([[40.5, 40.5, 40.5, 40.5, 40.5], [39.5, 39.5, 39.5, 39.5, 39.5], [38.5, 38.5, 38.5, 38.5, 38.5], [37.5, 37.5, 37.5, 37.5, 37.5], [36.5, 36.5, 36.5, 36.5, 36.5]], dtype=field.spatial.grid.value.dtype) + corner_row = corner[1] + corner_row_actual = np.array( + [[40.5, 40.5, 40.5, 40.5, 40.5], [39.5, 39.5, 39.5, 39.5, 39.5], [38.5, 38.5, 38.5, 38.5, 38.5], + [37.5, 37.5, 37.5, 37.5, 37.5], [36.5, 36.5, 36.5, 36.5, 36.5]], dtype=field.spatial.grid.value.dtype) self.assertNumpyAll(corner_row, corner_row_actual) corner = egrid.coords[ESMF.StaggerLoc.CORNER] - corner_col = corner[1] - corner_col_actual = np.array([[-105.5, -104.5, -103.5, -102.5, -101.5], [-105.5, -104.5, -103.5, -102.5, -101.5], [-105.5, -104.5, -103.5, -102.5, -101.5], [-105.5, -104.5, -103.5, -102.5, -101.5], [-105.5, -104.5, -103.5, -102.5, -101.5]], dtype=field.spatial.grid.value.dtype) + corner_col = corner[0] + corner_col_actual = np.array( + [[-105.5, -104.5, -103.5, -102.5, -101.5], [-105.5, -104.5, -103.5, -102.5, -101.5], + [-105.5, -104.5, -103.5, -102.5, -101.5], [-105.5, -104.5, -103.5, -102.5, -101.5], + [-105.5, -104.5, -103.5, -102.5, -101.5]], dtype=field.spatial.grid.value.dtype) self.assertNumpyAll(corner_col, corner_col_actual) def test_get_esmf_grid_from_sdim_change_origin_col(self): @@ -553,18 +557,23 @@ def test_get_esmf_grid_from_sdim_change_origin_col(self): egrid = get_esmf_grid_from_sdim(field.spatial) - for idx in [0, 1]: - coords = egrid.coords[ESMF.StaggerLoc.CENTER][idx] - self.assertNumpyAll(coords, field.spatial.grid.value[idx, ...].data) + for idx_esmf, idx_ocgis in zip([0, 1], [1, 0]): + coords = egrid.coords[ESMF.StaggerLoc.CENTER][idx_esmf] + self.assertNumpyAll(coords, field.spatial.grid.value[idx_ocgis, ...].data) corner = egrid.coords[ESMF.StaggerLoc.CORNER] - corner_row = corner[0] - corner_row_actual = np.array([[36.5, 36.5, 36.5, 36.5, 36.5], [37.5, 37.5, 37.5, 37.5, 37.5], [38.5, 38.5, 38.5, 38.5, 38.5], [39.5, 39.5, 39.5, 39.5, 39.5], [40.5, 40.5, 40.5, 40.5, 40.5]], dtype=field.spatial.grid.value.dtype) + corner_row = corner[1] + corner_row_actual = np.array( + [[36.5, 36.5, 36.5, 36.5, 36.5], [37.5, 37.5, 37.5, 37.5, 37.5], [38.5, 38.5, 38.5, 38.5, 38.5], + [39.5, 39.5, 39.5, 39.5, 39.5], [40.5, 40.5, 40.5, 40.5, 40.5]], dtype=field.spatial.grid.value.dtype) self.assertNumpyAll(corner_row, corner_row_actual) corner = egrid.coords[ESMF.StaggerLoc.CORNER] - corner_col = corner[1] - corner_col_actual = np.array([[-101.5, -102.5, -103.5, -104.5, -105.5], [-101.5, -102.5, -103.5, -104.5, -105.5], [-101.5, -102.5, -103.5, -104.5, -105.5], [-101.5, -102.5, -103.5, -104.5, -105.5], [-101.5, -102.5, -103.5, -104.5, -105.5]], dtype=field.spatial.grid.value.dtype) + corner_col = corner[0] + corner_col_actual = np.array( + [[-101.5, -102.5, -103.5, -104.5, -105.5], [-101.5, -102.5, -103.5, -104.5, -105.5], + [-101.5, -102.5, -103.5, -104.5, -105.5], [-101.5, -102.5, -103.5, -104.5, -105.5], + [-101.5, -102.5, -103.5, -104.5, -105.5]], dtype=field.spatial.grid.value.dtype) self.assertNumpyAll(corner_col, corner_col_actual) def test_get_esmf_grid_from_sdim_change_origin_row_and_col(self): @@ -580,17 +589,17 @@ def test_get_esmf_grid_from_sdim_change_origin_row_and_col(self): egrid = get_esmf_grid_from_sdim(field.spatial) - for idx in [0, 1]: - coords = egrid.coords[ESMF.StaggerLoc.CENTER][idx] - self.assertNumpyAll(coords, field.spatial.grid.value[idx, ...].data) + for idx_esmf, idx_ocgis in zip([0, 1], [1, 0]): + coords = egrid.coords[ESMF.StaggerLoc.CENTER][idx_esmf] + self.assertNumpyAll(coords, field.spatial.grid.value[idx_ocgis, ...].data) corner = egrid.coords[ESMF.StaggerLoc.CORNER] - corner_row = corner[0] + corner_row = corner[1] corner_row_actual = np.array([[40.5, 40.5, 40.5, 40.5, 40.5], [39.5, 39.5, 39.5, 39.5, 39.5], [38.5, 38.5, 38.5, 38.5, 38.5], [37.5, 37.5, 37.5, 37.5, 37.5], [36.5, 36.5, 36.5, 36.5, 36.5]], dtype=field.spatial.grid.value.dtype) self.assertNumpyAll(corner_row, corner_row_actual) corner = egrid.coords[ESMF.StaggerLoc.CORNER] - corner_col = corner[1] + corner_col = corner[0] corner_col_actual = np.array([[-101.5, -102.5, -103.5, -104.5, -105.5], [-101.5, -102.5, -103.5, -104.5, -105.5], [-101.5, -102.5, -103.5, -104.5, -105.5], [-101.5, -102.5, -103.5, -104.5, -105.5], [-101.5, -102.5, -103.5, -104.5, -105.5]], dtype=field.spatial.grid.value.dtype) self.assertNumpyAll(corner_col, corner_col_actual)