From 062f39df0d3bfd37a2749ba0b2881f506a91394f Mon Sep 17 00:00:00 2001 From: "Philipp S. Sommer" Date: Mon, 20 Apr 2020 15:18:49 +0200 Subject: [PATCH 1/3] use ccrs.PlateCarree standard_name is longitude for cf decoded projections of the transform formatoption, see https://github.com/psyplot/psy-view/issues/17 --- psy_maps/plotters.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/psy_maps/plotters.py b/psy_maps/plotters.py index d6bb99c..5a72d2f 100755 --- a/psy_maps/plotters.py +++ b/psy_maps/plotters.py @@ -583,12 +583,12 @@ class CenterLon(BoxBase): dependencies = ['lonlatbox'] def update(self, value): - self.lon_mean = np.mean(self.lonlatbox.lonlatbox[:2]) + self.lon_mean = float(np.mean(self.lonlatbox.lonlatbox[:2])) if value is not None: if isinstance(value, six.string_types): box = self.lola_from_pattern(value) if box is not None: - self.clon = np.mean(box[:2]) + self.clon = float(np.mean(box[:2])) else: value = None else: @@ -623,12 +623,12 @@ class CenterLat(BoxBase): dependencies = ['lonlatbox'] def update(self, value): - self.lat_mean = np.mean(self.lonlatbox.lonlatbox[2:]) + self.lat_mean = float(np.mean(self.lonlatbox.lonlatbox[2:])) if value is not None: if isinstance(value, six.string_types): box = self.lola_from_pattern(value) if box is not None: - self.clat = np.mean(box[2:]) + self.clat = float(np.mean(box[2:])) else: value = None else: @@ -1048,6 +1048,14 @@ class Transform(ProjectionBase): connections = ['plot', 'vplot'] + @property + def cf_projection(self): + data = next(self.iter_data) + xcoord = data.psy.get_coord('x') + if xcoord.attrs.get('standard_name') == 'longitude': + return ccrs.PlateCarree() + return super().cf_projection + def update(self, value): if value == 'cf': self.projection = self.cf_projection From 90a5493b7b1ea38471e998b563c2add7987e461c Mon Sep 17 00:00:00 2001 From: "Philipp S. Sommer" Date: Mon, 20 Apr 2020 15:24:03 +0200 Subject: [PATCH 2/3] update changelog --- CHANGELOG.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 6e4448e..c44ee62 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,7 +6,8 @@ Added order of dimensions in the data is ``(x, y)`` rather than ``(y, x)`` * the `transform` and `projection` formatoptions now automatically decode the ``'grid_mappings'`` attribute following the `CF-conventions `__, - see `#5 `__) + see `#5 `__, + `#10 `__) * the ``projection`` and ``transform`` formatoptions now also support a `rotated` value to use a rotated pole projection From 5519e9fd3dc711cecb11e4dffe16033ff9c23e1d Mon Sep 17 00:00:00 2001 From: "Philipp S. Sommer" Date: Mon, 20 Apr 2020 15:26:48 +0200 Subject: [PATCH 3/3] add test for decoding standard_name of longitude --- tests/test_projections.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_projections.py b/tests/test_projections.py index a046cb4..26b3c5f 100644 --- a/tests/test_projections.py +++ b/tests/test_projections.py @@ -77,3 +77,15 @@ def test_clat_centering(open_grid_ds, grid, clat): with grid_ds.psy.plot.mapplot(projection='ortho') as sp: plotter = sp.plotters[0] assert plotter.clat.clat == pytest.approx(clat, abs=1) + + +def test_rotated_pole_transform(open_grid_ds): + """Test if the lon coordinate is correctly interpreted as PlateCarree + + See https://github.com/psyplot/psy-maps/issues/9""" + grid_ds = open_grid_ds('rotated_latitude_longitude') + with grid_ds.psy.plot.mapplot(decoder=dict(x={'lon'}, y={'lat'})) as sp: + plotter = sp.plotters[0] + assert isinstance(plotter.transform.projection, ccrs.PlateCarree) + assert isinstance(plotter.ax.projection, ccrs.RotatedPole) +