Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/MeteoSwiss/pyart
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfidan committed Feb 29, 2024
2 parents fd30da6 + 95ef2d5 commit 32da5b9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
6 changes: 3 additions & 3 deletions pyart/aux_io/odim_h5.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def read_odim_grid_h5(filename, field_names=None, additional_metadata=None,
2.)

x['data'] = xvec
y['data'] = yvec
y['data'] = yvec[::-1] # conversion img -> map coordinates
z['data'] = np.array([0], dtype='float64')

if odim_object == 'CVOL': # CAPPI case
Expand Down Expand Up @@ -486,7 +486,7 @@ def read_odim_grid_h5(filename, field_names=None, additional_metadata=None,
ny = h_where['ysize']
nx = h_where['xsize']
field_dic['data'] = ma_broadcast_to(
fdata[::-1, :], (1, ny, nx))
fdata, (1, ny, nx))
field_dic['_FillValue'] = nodata
field_dic['undetect'] = undetect

Expand Down Expand Up @@ -547,7 +547,7 @@ def read_odim_grid_h5(filename, field_names=None, additional_metadata=None,
else:
origin_latitude['data'] = np.array([0.])
if 'lon_0' in projection:
origin_longitude['data'] = np.array([projection['lat_0']])
origin_longitude['data'] = np.array([projection['lon_0']])
else:
origin_longitude['data'] = np.array([0.])
origin_altitude['data'] = np.array([0.])
Expand Down
6 changes: 1 addition & 5 deletions pyart/aux_io/odim_h5_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def write_odim_grid_h5(filename, grid, field_names=None, physical=True,

# where - UL, LL, LR, UR, scales, sizes, projdef
x = grid.x['data']
y = grid.y['data']
y = grid.y['data'][::-1] # conversion img -> map coordinates
X, Y = np.meshgrid(x, y)
lon, lat = X, Y

Expand Down Expand Up @@ -319,10 +319,6 @@ def write_odim_grid_h5(filename, grid, field_names=None, physical=True,
grid, i, field_name, physical=physical,
undefined_value=undefined_value)

if data_dict['data'].ndim == 2:
# Switch index to agree with ODIM standard
data_dict['data'] = data_dict['data'][::-1]

# write data
what3_dict[i][j]['gain'] = data_dict['gain']
what3_dict[i][j]['offset'] = data_dict['offset']
Expand Down
2 changes: 2 additions & 0 deletions pyart/io/cfradial.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,8 @@ def _create_ncvar(dic, dataset, name, dimensions):

# set all attributes
for key, value in dic.items():
if isinstance(value, bool): # convert bool to int
value = int(value)
if key in special_keys.keys():
continue
if key in ["data", "long_name", "units"]:
Expand Down
18 changes: 13 additions & 5 deletions tests/aux_io/test_odim_grid_h5.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_y():
assert "units" in grid.y
assert "data" in grid.y
assert grid.y["data"].shape == (640,)
assert_almost_equal(grid.y["data"][0], -159500, 0)
assert_almost_equal(grid.y["data"][0], 479500, 0)

# fields attribute is tested later

Expand All @@ -56,13 +56,21 @@ def test_metadata():
assert "instrument_name" in grid.metadata
assert "radar" in grid.metadata

# origin_longitude attribute
def test_origin_longitude():
assert "data" in grid.origin_longitude
assert "standard_name" in grid.origin_longitude
assert "units" in grid.origin_longitude
assert grid.origin_longitude["data"].shape == (1,)
assert_almost_equal(grid.origin_longitude["data"], 7.43, 0)

# origin_latitude attribute
def test_latitude():
def test_origin_latitude():
assert "data" in grid.origin_latitude
assert "standard_name" in grid.origin_latitude
assert "units" in grid.origin_latitude
assert grid.origin_latitude["data"].shape == (1,)
assert_almost_equal(grid.origin_latitude["data"], 46.95240556, 0)
assert_almost_equal(grid.origin_latitude["data"], 46.952, 0)


# point_longitude attribute
Expand All @@ -79,7 +87,7 @@ def test_point_latitude():
assert "long_name" in grid.point_latitude
assert "units" in grid.point_latitude
assert grid.point_latitude["data"].shape == (1,640,710)
assert_almost_equal(grid.point_latitude["data"][0,0,0],43.63508830, 0)
assert_almost_equal(grid.point_latitude["data"][0,0,0], 49.370, 0)

####################
# fields attribute #
Expand Down Expand Up @@ -152,7 +160,7 @@ def test_field_points(field, field_value):


def check_field_point(field, value):
assert_almost_equal(grid.fields[field]["data"][0,49,501], value, 0)
assert_almost_equal(grid.fields[field]["data"][0,590,501], value, 0)


########################################################################
Expand Down

0 comments on commit 32da5b9

Please sign in to comment.