Skip to content

Commit d065d58

Browse files
authored
[semver:patch] Compatibility fixes for psy-simple v1.4.1 (#42)
Fix projection issues Fixed ----- - `false_easting` and `false_northing` are now expected to be optional arguments for most projections (see #41) Changed ------- - we now use the `convert_coordinate` method that has been introduced in psyplot/psyplot#39 and psyplot/psy-simple#30. See #41
1 parent aa2de37 commit d065d58

File tree

6 files changed

+103
-24
lines changed

6 files changed

+103
-24
lines changed

.appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ after_test:
4343
deploy_script:
4444
- cmd: "
4545
IF NOT DEFINED APPVEYOR_REPO_TAG_NAME (
46-
deploy-conda-recipe -l %APPVEYOR_REPO_BRANCH% -py %PYTHON_VERSION% ci/conda-recipe
46+
deploy-conda-recipe -l %APPVEYOR_REPO_BRANCH:/=-% -py %PYTHON_VERSION% ci/conda-recipe
4747
) ELSE (
4848
deploy-conda-recipe -py %PYTHON_VERSION% ci/conda-recipe
4949
)"

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: 2.1
22

33
orbs:
4-
psyplot: psyplot/psyplot-ci-orb@1.5.24
4+
psyplot: psyplot/psyplot-ci-orb@1.5.31
55
mattermost-plugin-notify: nathanaelhoun/mattermost-plugin-notify@1.2.0
66

77
executors:

CHANGELOG.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
v1.4.1
2+
======
3+
Fix projection issues
4+
5+
Fixed
6+
-----
7+
- ``false_easting`` and ``false_northing`` are now expected to be optional
8+
arguments for most projections (see
9+
`#41 <https://github.com/psyplot/psy-maps/pull/41>`__)
10+
11+
Changed
12+
-------
13+
- we now use the ``convert_coordinate`` method that has been introduced in
14+
`psyplot/psyplot#39 <https://github.com/psyplot/psyplot/pull/39>`__ and
15+
`psyplot/psy-simple#30 <https://github.com/psyplot/psy-simple/pull/30>`__.
16+
See `#41 <https://github.com/psyplot/psy-maps/pull/41>`__
17+
18+
119
v1.4.0
220
======
321
Compatibility fixes and LGPL license

docs/environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: psyplot_docs
22
channels:
33
- local
4+
- psyplot/label/__CURRENTBRANCH__
45
- psyplot/label/master
56
- conda-forge
67
dependencies:

psy_maps/plotters.py

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,9 @@ def albers_conical_equal_area_from_cf(self, crs):
319319
iter(kwargs['standard_parallels'])
320320
except TypeError:
321321
kwargs['standard_parallels'] = [kwargs['standard_parallels']]
322-
if getattr(crs, 'false_easting'):
322+
if getattr(crs, 'false_easting', None):
323323
kwargs['false_easting'] = crs.false_easting
324-
if getattr(crs, 'false_northing'):
324+
if getattr(crs, 'false_northing', None):
325325
kwargs['false_northing'] = crs.false_northing
326326
return ccrs.AlbersEqualArea(**kwargs)
327327

@@ -330,9 +330,9 @@ def azimuthal_equidistant_from_cf(self, crs):
330330
central_longitude=crs.longitude_of_projection_origin,
331331
central_latitude=crs.latitude_of_projection_origin,
332332
)
333-
if getattr(crs, 'false_easting'):
333+
if getattr(crs, 'false_easting', None):
334334
kwargs['false_easting'] = crs.false_easting
335-
if getattr(crs, 'false_northing'):
335+
if getattr(crs, 'false_northing', None):
336336
kwargs['false_northing'] = crs.false_northing
337337
return ccrs.AzimuthalEquidistant(**kwargs)
338338

@@ -342,9 +342,9 @@ def geostationary_from_cf(self, crs):
342342
satellite_height=crs.perspective_point_height,
343343
sweep_axis=crs.sweep_angle_axis,
344344
)
345-
if getattr(crs, 'false_easting'):
345+
if getattr(crs, 'false_easting', None):
346346
kwargs['false_easting'] = crs.false_easting
347-
if getattr(crs, 'false_northing'):
347+
if getattr(crs, 'false_northing', None):
348348
kwargs['false_northing'] = crs.false_northing
349349
return ccrs.Geostationary(**kwargs)
350350

@@ -353,9 +353,9 @@ def lambert_azimuthal_equal_area_from_cf(self, crs):
353353
central_longitude=crs.longitude_of_projection_origin,
354354
central_latitude=crs.latitude_of_projection_origin,
355355
)
356-
if getattr(crs, 'false_easting'):
356+
if getattr(crs, 'false_easting', None):
357357
kwargs['false_easting'] = crs.false_easting
358-
if getattr(crs, 'false_northing'):
358+
if getattr(crs, 'false_northing', None):
359359
kwargs['false_northing'] = crs.false_northing
360360
return ccrs.LambertAzimuthalEqualArea(**kwargs)
361361

@@ -369,9 +369,9 @@ def lambert_conformal_conic_from_cf(self, crs):
369369
iter(kwargs['standard_parallels'])
370370
except TypeError:
371371
kwargs['standard_parallels'] = [kwargs['standard_parallels']]
372-
if getattr(crs, 'false_easting'):
372+
if getattr(crs, 'false_easting', None):
373373
kwargs['false_easting'] = crs.false_easting
374-
if getattr(crs, 'false_northing'):
374+
if getattr(crs, 'false_northing', None):
375375
kwargs['false_northing'] = crs.false_northing
376376
return ccrs.LambertConformal(**kwargs)
377377

@@ -390,9 +390,9 @@ def mercator_from_cf(self, crs):
390390
)
391391
if hasattr(crs, 'scale_factor_at_projection_origin'):
392392
kwargs['scale_factor'] = crs.scale_factor_at_projection_origin
393-
if getattr(crs, 'false_easting'):
393+
if getattr(crs, 'false_easting', None):
394394
kwargs['false_easting'] = crs.false_easting
395-
if getattr(crs, 'false_northing'):
395+
if getattr(crs, 'false_northing', None):
396396
kwargs['false_northing'] = crs.false_northing
397397
return ccrs.Mercator(**kwargs)
398398

@@ -427,9 +427,9 @@ def sinusoidal_from_cf(self, crs):
427427
kwargs = dict(
428428
central_longitude=crs.longitude_of_central_meridian,
429429
)
430-
if getattr(crs, 'false_easting'):
430+
if getattr(crs, 'false_easting', None):
431431
kwargs['false_easting'] = crs.false_easting
432-
if getattr(crs, 'false_northing'):
432+
if getattr(crs, 'false_northing', None):
433433
kwargs['false_northing'] = crs.false_northing
434434
return ccrs.Sinusoidal(**kwargs)
435435

@@ -439,9 +439,9 @@ def stereographic_from_cf(self, crs):
439439
central_longitude=crs.longitude_of_projection_origin,
440440
scale_factor=crs.scale_factor_at_projection_origin
441441
)
442-
if getattr(crs, 'false_easting'):
442+
if getattr(crs, 'false_easting', None):
443443
kwargs['false_easting'] = crs.false_easting
444-
if getattr(crs, 'false_northing'):
444+
if getattr(crs, 'false_northing', None):
445445
kwargs['false_northing'] = crs.false_northing
446446
return ccrs.Stereographic(**kwargs)
447447

@@ -451,9 +451,9 @@ def transverse_mercator_from_cf(self, crs):
451451
central_latitude=crs.latitude_of_projection_origin,
452452
scale_factor=crs.scale_factor_at_central_meridian,
453453
)
454-
if getattr(crs, 'false_easting'):
454+
if getattr(crs, 'false_easting', None):
455455
kwargs['false_easting'] = crs.false_easting
456-
if getattr(crs, 'false_northing'):
456+
if getattr(crs, 'false_northing', None):
457457
kwargs['false_northing'] = crs.false_northing
458458
return ccrs.TransverseMercator(**kwargs)
459459

@@ -2047,10 +2047,6 @@ class MapPlotter(psyps.Base2D):
20472047
"""Base plotter for visualizing data on a map
20482048
"""
20492049

2050-
#: Boolean that is True if coordinates with units in radian should be
2051-
#: converted to degrees
2052-
convert_radian = True
2053-
20542050
_rcparams_string = ['plotter.maps.']
20552051

20562052
background = MapBackground('background')
@@ -2093,6 +2089,37 @@ def ax(self):
20932089
def ax(self, value):
20942090
self._ax = value
20952091

2092+
@docstrings.dedent
2093+
def convert_coordinate(self, coord, *variables):
2094+
"""Convert a coordinate from radian to degree.
2095+
2096+
This method checks if the coordinate or one of the given variables has
2097+
units in radian. If yes, the given `coord` is converted to degree.
2098+
2099+
Parameters
2100+
----------
2101+
%(Formatoption.convert_coordinate.parameters)s
2102+
2103+
Returns
2104+
-------
2105+
%(Formatoption.convert_coordinate.returns)s
2106+
"""
2107+
2108+
def in_rad(var):
2109+
return var.attrs.get('units', '').startswith('radian')
2110+
2111+
def in_km(var):
2112+
return var.attrs.get('units', '') == "km"
2113+
2114+
if any(map(in_rad, chain([coord], variables))):
2115+
coord = coord.copy(data=coord * 180. / np.pi)
2116+
coord.attrs["units"] = "degrees"
2117+
elif any(map(in_km, chain([coord], variables))):
2118+
coord = coord.copy(data=coord * 1000)
2119+
coord.attrs["units"] = "m"
2120+
2121+
return coord
2122+
20962123

20972124
class FieldPlotter(psyps.Simple2DBase, MapPlotter, psyps.BasePlotter):
20982125
"""Plotter for 2D scalar fields on a map

tests/test_projections.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,36 @@ def test_rotated_pole_extent(open_grid_ds):
123123
assert isinstance(plotter.ax.projection, ccrs.RotatedPole)
124124
lonmin, lonmax = plotter.ax.get_extent()[:2]
125125
assert lonmax - lonmin < 200
126+
127+
128+
def test_false_easting(open_grid_ds, grid, grid_projection):
129+
grid_ds = open_grid_ds(grid)
130+
grid_var = grid_ds["Band1"].grid_mapping
131+
if "false_easting" not in grid_ds[grid_var].attrs:
132+
pytest.skip(f"No false_easting parameter for {grid_var} grid.")
133+
return
134+
del grid_ds[grid_var].attrs["false_easting"]
135+
with grid_ds.psy.plot.mapplot() as sp:
136+
assert len(sp) == 1
137+
plotter = sp.plotters[0]
138+
assert isinstance(plotter.transform.projection, grid_projection)
139+
assert plotter.plot._kwargs.get('transform') is \
140+
plotter.transform.projection
141+
assert isinstance(plotter.projection.projection, grid_projection)
142+
143+
144+
def test_false_northing(open_grid_ds, grid, grid_projection):
145+
grid_ds = open_grid_ds(grid)
146+
grid_var = grid_ds["Band1"].grid_mapping
147+
if "false_northing" not in grid_ds[grid_var].attrs:
148+
pytest.skip(f"No false_northing parameter for {grid_var} grid.")
149+
return
150+
del grid_ds[grid_var].attrs["false_northing"]
151+
with grid_ds.psy.plot.mapplot() as sp:
152+
assert len(sp) == 1
153+
plotter = sp.plotters[0]
154+
assert isinstance(plotter.transform.projection, grid_projection)
155+
assert plotter.plot._kwargs.get('transform') is \
156+
plotter.transform.projection
157+
assert isinstance(plotter.projection.projection, grid_projection)
158+

0 commit comments

Comments
 (0)