From 1c8d989e4c3dab7ebef79d6299d37c4af1721644 Mon Sep 17 00:00:00 2001 From: Bobby Jackson Date: Thu, 13 Apr 2023 14:03:51 -0500 Subject: [PATCH] FIX: GateMapper will now map source field to destination radar even if 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 --- pyart/map/gate_mapper.py | 12 +++++++++--- tests/map/test_gatemapper.py | 16 ++++++++++++---- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/pyart/map/gate_mapper.py b/pyart/map/gate_mapper.py index 7467a6865b..f1bfb6c9bc 100644 --- a/pyart/map/gate_mapper.py +++ b/pyart/map/gate_mapper.py @@ -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"] ) diff --git a/tests/map/test_gatemapper.py b/tests/map/test_gatemapper.py index 719fbb5487..d7ad0a7280 100644 --- a/tests/map/test_gatemapper.py +++ b/tests/map/test_gatemapper.py @@ -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] )