Comments (4)
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]?
from salem.
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
from salem.
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)
f = plt.figure(figsize=(12, 4))
s = roi.salem.subset(shape=borders)
s.salem.quick_map(countries=False)
With margin=2
we have an issue, as you noticed. I am not sure what to do in this case, though. The subset (with or without margin) isn't very useful...
The easiest way to make Russia "continuous" is to shift the data prior analysis:
sdata = np.roll(data, 90, axis=1)
slon = np.roll(lon, 90)
slon = np.where(slon < 0, slon + 360, slon)
sda = xr.DataArray(sdata, dims=['lat', 'lon'], coords={'lat': lat, 'lon':slon})
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).
from salem.
thank you so much! this is a very comprehensive answer and works for me.
from salem.
Related Issues (20)
- Custom .salem_cache location (if any) HOT 4
- Cylindrical Equidistant WRF projection not supported HOT 8
- salem.subset and salem.roi wrong result HOT 4
- [Feature] Add Dask integration HOT 17
- pip install --no-binary fails with salem 0.3.5 HOT 3
- Descartes is in a bad shape
- Can geogrid simulator add 'd01','d02' labels to it? HOT 2
- Simplify descartes vendored code
- Opening multiple wrfout files as a single dataset HOT 1
- Concatenating and ValueError: 'PRCP' is not present in all datasets. HOT 2
- RuntimeError salem.wrf_zlevel HOT 2
- Salem should not fail when `description` attribute is not present
- support relative humidity and dewpoint temperature HOT 1
- Error: Map() takes 0 positional arguments but 1 was given HOT 1
- Iterating through a shapefile in a loop HOT 1
- reproject grid data for rasterio / gdal HOT 3
- Size of subset files too large (`salem.roi`) HOT 3
- Reproject WRF out file to WGS84 to match ERA5 data HOT 10
- Why we need to set dask to single tread? HOT 4
- Issue overlapping model data to Google map background
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from salem.