-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error plotting countries spanning both eastern and western hemispheres #70
Comments
Thanks for the report! Indeed I haven't looked much how salem behaves across hemispheres. I'll try to have a look soon. Is your data defined on [0, 360] or [-180, 180]? |
Thanks for looking into this! The shapefile is define on -180 to 180 (and so is the data). The shapefile is here: https://www.dropbox.com/sh/yp22wdue7ri63z9/AADqm4zPwKNkykcneMwthm8Fa?dl=0 |
OK, so there are a couple of things going on. If everything is in the -180 180 range, roi and subset work fine, as long as one uses no margin: import xarray as xr
import numpy as np
import salem
from salem import get_demo_file, open_wrf_dataset
import matplotlib.pyplot as plt
borders = salem.read_shapefile(get_demo_file('world_borders.shp'), cached=True)
borders = borders.loc[borders['CNTRY_NAME'].isin(['Russia'])]
# make dummy dataset
lon = np.linspace(1, 359, 180) - 180
lat = np.linspace(1, 89, 45)
data = lon * np.ones((len(lat), 1))
da = xr.DataArray(data, dims=['lat', 'lon'], coords={'lat': lat, 'lon':lon})
# plot
f = plt.figure(figsize=(12, 4))
roi = da.salem.roi(shape=borders)
roi.salem.quick_map(countries=False)
With The easiest way to make Russia "continuous" is to shift the data prior analysis:
But then, the shapefile also has to be converted too :-( def trafo_360(x, y, z=None):
return np.where(x < 0, x+360, x), y
from shapely.ops import transform
sborders = borders.copy()
sborders['geometry'] = borders.geometry.apply(lambda geom: transform(trafo_360, geom))
# finally!
f = plt.figure(figsize=(12, 4))
roi = sda.salem.roi(shape=sborders)
s = roi.salem.subset(shape=sborders, margin=2)
s.salem.quick_map(countries=False) I guess that salem could take over the last step (the shapefile transformation), and could provide automatic tools to shift datasets (I've needed this several times). |
thank you so much! this is a very comprehensive answer and works for me. |
Thanks for an excellent package! I found that trying to use salem to plot a map for an individual country fails for a country like Russia which wraps around to exist in both western and eastern hemispheres.
The text was updated successfully, but these errors were encountered: