Skip to content
Snippets Groups Projects
Unverified Commit 0479a553 authored by Philipp S. Sommer's avatar Philipp S. Sommer Committed by GitHub
Browse files

[semver:patch] Fix density and lonlatbox in mapvector (#45)

Merge pull request #45 from psyplot/develop
parents d065d589 5e0cec7a
No related branches found
Tags v1.4.2
No related merge requests found
version: 2.1
orbs:
psyplot: psyplot/psyplot-ci-orb@1.5.31
psyplot: psyplot/psyplot-ci-orb@1.5.32
mattermost-plugin-notify: nathanaelhoun/mattermost-plugin-notify@1.2.0
executors:
......
V1.4.2
======
Fix mapvector issue
Fixed
-----
- This PR fixes an issue that arises when using ``density`` together with
``lonlatbox``, see `#43 <https://github.com/psyplot/psy-maps/issues/43>`__
and `#44 <https://github.com/psyplot/psy-maps/pull/44>`__
v1.4.1
======
Fix projection issues
......
......@@ -273,6 +273,20 @@ class ProjectionBase(Formatoption):
#'vertical_perspective', # not available for cartopy
]
def transform_lonlatbox(self, value):
"""Transform a lon-lat-box to the specific projection"""
value = np.asarray(value)
transformed = self.projection.transform_points(
ccrs.PlateCarree(), value[:2], value[2:]
)[..., :2]
value[:2] = transformed[..., 0]
value[2:] = transformed[..., 1]
if value[0] == value[1] and isinstance(
self.projection, ccrs.PlateCarree
):
value[1] += 360
return value
@property
def cf_projection(self):
data = next(self.iter_data)
......@@ -514,12 +528,17 @@ class Projection(ProjectionBase):
dependencies = ['clon', 'clat']
connections = ['transform']
connections = ['transform', 'lonlatbox']
def __init__(self, *args, **kwargs):
super(Projection, self).__init__(*args, **kwargs)
self.projection = None
@property
def lonlatbox_transformed(self):
"""Transform the lonlatbox according to the projection"""
return self.transform_lonlatbox(self.lonlatbox.lonlatbox)
def initialize_plot(self, value, clear=True):
"""Initialize the plot and set the projection for the axes
"""
......@@ -715,15 +734,7 @@ class LonLatBox(BoxBase):
@property
def lonlatbox_transformed(self):
value = np.asarray(self.lonlatbox)
transformed = self.transform.projection.transform_points(
ccrs.PlateCarree(), value[:2], value[2:])[..., :2]
value[:2] = transformed[..., 0]
value[2:] = transformed[..., 1]
if value[0] == value[1] and isinstance(self.transform.projection,
ccrs.PlateCarree):
value[1] += 360
return value
return self.transform.transform_lonlatbox(self.lonlatbox)
def data_dependent(self, data, set_data=True):
if isinstance(data, InteractiveList):
......@@ -1927,9 +1938,12 @@ class MapDensity(psyps.Density):
--------------
%(Density.possible_types)s"""
dependencies = psyps.Density.dependencies + ["projection"]
def _set_quiver_density(self, value):
if all(val == 1.0 for val in value):
self.plot._kwargs.pop('regrid_shape', None)
self.plot._kwargs.pop('target_extent', None)
elif self.decoder.is_unstructured(self.raw_data):
warnings.warn("Quiver plot of unstructered data does not support "
"the density keyword!", RuntimeWarning)
......@@ -1940,6 +1954,8 @@ class MapDensity(psyps.Density):
shape = self.data.shape[-2:]
value = map(int, [value[0]*shape[0], value[1]*shape[1]])
self.plot._kwargs['regrid_shape'] = tuple(value)
lonlatbox = self.projection.lonlatbox_transformed
self.plot._kwargs["target_extent"] = lonlatbox
def _unset_quiver_density(self):
self.plot._kwargs.pop('regrid_shape', None)
......
......@@ -22,6 +22,8 @@
#
# You should have received a copy of the GNU LGPL-3.0 license
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import pytest
import os.path as osp
try:
# make sure we import QtWebEngineWidgets at the start
......@@ -40,3 +42,8 @@ def pytest_configure(config):
if config.getoption('ref'):
import unittest
unittest.TestLoader.testMethodPrefix = 'ref'
@pytest.fixture
def regular_test_file():
return osp.join(osp.dirname(__file__), "test-t2m-u-v.nc")
......@@ -175,5 +175,20 @@ class VectorPlotterTest2D(bt.TestBase2D, VectorPlotterTest):
var = ['u_2d', 'v_2d']
def test_density_with_lonlatbox(regular_test_file):
"""Test that the lonlatbox still works with density.
see https://github.com/psyplot/psy-maps/issues/43
"""
sp = psy.plot.mapvector(
regular_test_file, name=[["u", "v"]], density=0.5, lonlatbox="Europe"
)
ax = sp.plotters[0].ax
xmin, xmax, ymin, ymax = ax.get_extent()
assert xmax - xmin < 180
assert ymax - ymin < 90
if __name__ == '__main__':
unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment