Skip to content

Commit

Permalink
FIX: GateMapper will now map source field to destination radar even i…
Browse files Browse the repository at this point in the history
…f field not in destination radar (#1418)

* FIX: GateMapper will now map source field to destination radar even if field does not exist in destination.

* FIX: Whitespace

---------

Co-authored-by: Robert Jackson <[email protected]>
  • Loading branch information
rcjackson and Robert Jackson authored Apr 13, 2023
1 parent 6c8bc9c commit 1c8d989
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
12 changes: 9 additions & 3 deletions pyart/map/gate_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,15 @@ def mapped_radar(self, field_list):

src_fields = {}
for field in field_list:
mapped_radar.fields[field]["data"] = np.ma.masked_where(
True, mapped_radar.fields[field]["data"]
)
if field in list(mapped_radar.fields.keys()):
mapped_radar.fields[field]["data"] = np.ma.masked_where(
True, mapped_radar.fields[field]["data"]
)
else:
mapped_radar.fields[field] = deepcopy(self.src_radar.fields[field])
mapped_radar.fields[field]["data"] = np.ma.masked_where(
True, np.ma.zeros((mapped_radar.nrays, mapped_radar.ngates))
)
src_fields[field] = np.ma.masked_where(
self.gatefilter_src.gate_excluded, self.src_radar.fields[field]["data"]
)
Expand Down
16 changes: 12 additions & 4 deletions tests/map/test_gatemapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,23 @@ def test_gatemapper():
new_radar = deepcopy(old_radar)
new_radar.latitude["data"] = old_radar.latitude["data"] + 0.001
new_radar.longitude["data"] = old_radar.longitude["data"] + 0.001
gate_mapper = pyart.map.GateMapper(new_radar, old_radar)
old_radar.fields["reflectivity_copy"] = old_radar.fields["reflectivity"]
gate_mapper = pyart.map.GateMapper(old_radar, new_radar)
mapped_radar = gate_mapper.mapped_radar(["reflectivity"])

# Test point outside of 1 min tolerance
assert gate_mapper[20, 20] == (None, None)
assert gate_mapper[4, 4] == (26, 11)
assert gate_mapper[40, 40] == (40, 33)
assert (
mapped_radar.fields["reflectivity"]["data"][40, 33]
== old_radar.fields["reflectivity"]["data"][40, 40]
)

# Check case where source radar has field destination doesn't
mapped_radar = gate_mapper.mapped_radar(["reflectivity_copy"])
assert (
mapped_radar.fields["reflectivity"]["data"][26, 11]
== old_radar.fields["reflectivity"]["data"][4, 4]
mapped_radar.fields["reflectivity_copy"]["data"][40, 33]
== old_radar.fields["reflectivity_copy"]["data"][40, 40]
)


Expand Down

0 comments on commit 1c8d989

Please sign in to comment.