Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ Changed
see `#4 <https://github.com/psyplot/psy-maps/pull/4>`__
* the default values for the `transform` and `projection` formatoptions are now
``'cf'`` (see `#5 <https://github.com/psyplot/psy-maps/pull/5>`__)
* ``clat`` now always takes the mean latitude of the data if the formatoption
value is None and the data does not span the entire latitudinal range. At the
same time, ``clon`` now takes the mean longitude of the data if the
formatoption value is None and the data does not span the entire longitudinal
range (see `#8 <https://github.com/psyplot/psy-maps/pull/8>`__)

v1.2.0
======
Expand Down
20 changes: 12 additions & 8 deletions psy_maps/plotters.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,10 +593,12 @@ def update(self, value):
value = None
else:
self.clon = value
if value is None and self.lonlatbox.value is not None:
self.clon = self.lon_mean
elif value is None:
self.clon = 0.0
if value is None:
lonmin, lonmax = self.lonlatbox.lonlatbox[:2]
if lonmax - lonmin > 350:
self.clon = 0.0
else:
self.clon = self.lon_mean


class CenterLat(BoxBase):
Expand Down Expand Up @@ -631,10 +633,12 @@ def update(self, value):
value = None
else:
self.clat = value
if value is None and self.lonlatbox.value is not None:
self.clat = self.lat_mean
elif value is None:
self.clat = 0.0
if value is None:
latmin, latmax = self.lonlatbox.lonlatbox[2:]
if latmax - latmin > 170:
self.clat = 0
else:
self.clat = self.lat_mean


@docstrings.get_sectionsf('LonLatBox')
Expand Down
5 changes: 3 additions & 2 deletions tests/test_plotters.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,9 @@ def test_lonlatbox(self):
sp = psy.plot.mapplot(os.path.join(bt.test_dir, 'Stockholm.nc'),
name='Population', transform='moll')
ax = sp.plotters[0].ax
self.assertEqual(np.round(ax.get_extent(), 2).tolist(),
[17.66, 18.39, 59.1, 59.59])
self.assertEqual(
np.round(ax.get_extent(ccrs.PlateCarree()), 2).tolist(),
[17.66, 18.39, 59.1, 59.59])
sp.update(lonlatbox=[17.8, 18.2, 59.2, 59.4])
self.assertEqual(
np.round(ax.get_extent(ccrs.PlateCarree()), 2).tolist(),
Expand Down
35 changes: 31 additions & 4 deletions tests/test_projections.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,47 @@ def grid(request):


@pytest.fixture
def grid_ds(grid):
return psyd.open_dataset(osp.join(bt.test_dir, 'grids', grid + '.nc'))
def open_grid_ds():
open_datasets = []
def _grid_ds(grid):
ds = psyd.open_dataset(osp.join(bt.test_dir, 'grids', grid + '.nc'))
open_datasets.append(ds)
return ds
yield _grid_ds
for ds in open_datasets:
ds.close()


@pytest.fixture
def grid_projection(grid):
return projection_mapping[grid]


def test_grid_plotting(grid_ds, grid, grid_projection):
def test_grid_plotting(open_grid_ds, grid, grid_projection):
grid_ds = open_grid_ds(grid)
with grid_ds.psy.plot.mapplot() as sp:
assert len(sp) == 1
plotter = sp.plotters[0]
assert isinstance(plotter.transform.projection, grid_projection)
assert plotter.plot._kwargs.get('transform') is \
plotter.transform.projection
assert isinstance(plotter.projection.projection, grid_projection)
assert isinstance(plotter.projection.projection, grid_projection)


@pytest.mark.parametrize(
"grid,clon", [("rotated_latitude_longitude", 11),
(osp.join("..", "test-t2m-u-v"), 0)])
def test_clon_centering(open_grid_ds, grid, clon):
grid_ds = open_grid_ds(grid)
with grid_ds.psy.plot.mapplot(projection='ortho') as sp:
plotter = sp.plotters[0]
assert plotter.clon.clon == pytest.approx(clon, abs=1)

@pytest.mark.parametrize(
"grid,clat", [("rotated_latitude_longitude", 51),
(osp.join("..", "test-t2m-u-v"), 0)])
def test_clat_centering(open_grid_ds, grid, clat):
grid_ds = open_grid_ds(grid)
with grid_ds.psy.plot.mapplot(projection='ortho') as sp:
plotter = sp.plotters[0]
assert plotter.clat.clat == pytest.approx(clat, abs=1)