From ea056c8636a5f4a4cc1b2010ddd5ab571673fc93 Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Thu, 26 Nov 2020 12:56:04 +0000 Subject: [PATCH 1/2] Rerturn nan if the delta is nan --- gwcs/coordinate_frames.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gwcs/coordinate_frames.py b/gwcs/coordinate_frames.py index b15f32ff..2e768b1f 100644 --- a/gwcs/coordinate_frames.py +++ b/gwcs/coordinate_frames.py @@ -531,6 +531,9 @@ def _convert_to_time(self, dt, *, unit, **kwargs): if not hasattr(dt, 'unit'): dt = dt * unit + if np.isnan(dt): + return np.zeros_like(dt) * np.nan + return self.reference_frame + dt def coordinate_to_quantity(self, *coords): From 92d7a66d35f58d368a8e75c3a47116eed06725cd Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Thu, 26 Nov 2020 13:12:29 +0000 Subject: [PATCH 2/2] Handle some elements of the array being NaN --- gwcs/coordinate_frames.py | 8 ++++++-- gwcs/tests/test_coordinate_systems.py | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/gwcs/coordinate_frames.py b/gwcs/coordinate_frames.py index 2e768b1f..fd43363d 100644 --- a/gwcs/coordinate_frames.py +++ b/gwcs/coordinate_frames.py @@ -531,8 +531,12 @@ def _convert_to_time(self, dt, *, unit, **kwargs): if not hasattr(dt, 'unit'): dt = dt * unit - if np.isnan(dt): - return np.zeros_like(dt) * np.nan + is_nan = np.isnan(dt) + if is_nan.any(): + dt[is_nan] = 0 + out = self.reference_frame + dt + out[is_nan] = np.nan + return out return self.reference_frame + dt diff --git a/gwcs/tests/test_coordinate_systems.py b/gwcs/tests/test_coordinate_systems.py index 056aea1b..05fe8ffb 100644 --- a/gwcs/tests/test_coordinate_systems.py +++ b/gwcs/tests/test_coordinate_systems.py @@ -200,6 +200,13 @@ def test_temporal_absolute(): assert t.coordinates("2018-01-01T00:00:00") == Time("2018-01-01T00:00:00", scale='tai') +def test_temporal_nan(): + t = cf.TemporalFrame(reference_frame=Time("2018-01-01T00:00:00"), unit=u.s) + + ret = t._convert_to_time([0, np.nan]*u.s, unit=u.s) + assert np.allclose(ret.mask, [False, True]) + + @pytest.mark.parametrize('inp', [ (10 * u.deg, 20 * u.deg), ((10 * u.deg, 20 * u.deg),),