-
Notifications
You must be signed in to change notification settings - Fork 4
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
Slicing EURO-CORDEX model outputs #195
Comments
Hi @Murk89, thanks for the question. Since you are referring to shapefiles, i guess you want to mask a certain region for analysis, right? That's not really the scope of py-cordex since there are other great packages do achieve this. However, since this a popular task with regional climate model datasets, there is actually an example in the docs here. The example is based on regionmask. If you want to use shapefiles, i can recommend the excellent documentation on how to work with geopandas and regionmask. I hope that helps! |
Hi @larsbuntemeyer I have previously tried to clip the REMO2015 dataset to my study area using a shapefile and using geopandas. For that to work I need to change the projection of the shapefile to the EURO-CORDEX rotated latitude longitude. That didn't work because cartopy doesn't recognize the wkt of EURO-CORDEX grid. I think that might be a separate issue on it's own. |
Yes, the coordinates of the dataset (rlon/rlat) are defined in the rotated coordinate reference system (CRS), but since you have the projected lon/lat coordinates in the dataset, you can use them for masking with where, e.g., you could do something like: ds.where((ds.lon > min_lon) & (ds.lon < max_lon) & (ds.lat > min_lat) & (ds.lat < max_lat)) and using an example: import cordex as cx
min_lon = 24.344
min_lat = 43.609
max_lon = 25.739
max_lat = 45.672
ds = cx.tutorial.open_dataset("tas_EUR-11_ECMWF-ERAINT_evaluation_r1i1p1_GERICS-REMO2015_v1_mon_197902-198012")
subset = ds.where((ds.lon > min_lon) & (ds.lon < max_lon) & (ds.lat > min_lat) & (ds.lat < max_lat), drop=True)
subset.tas.isel(time=0).plot() subset = ds.where((ds.lon > min_lon) & (ds.lon < max_lon) & (ds.lat > min_lat) & (ds.lat < max_lat))
subset.tas.isel(time=0).plot() |
If you want to plot CORDEX datasets in their native rotated coordinates, i did some example for this in a notebook some time ago. You should also check out the cartopy documentation on that topic which really helped me to understand it! |
Thanks for the code. The .where method is a good idea. I was also able to do something similar with python-cdo.
So looking at the notebook you mention, it is not changing the crs of the actual dataset ? It is for plotting purposes only, right? |
Exactly! cartopy only needs to know the CRS of your data (the transform keyword). It then does the projection itself using pyproj. For xarray and cdo, you need the projected coordinates in the dataset, e.g, the lon/lat coordinates if you want to work with those coordinates (e.g. masking, etc...). The |
Hi, This is the xarray Dataset:
and these are my lines:
The problem is on the very last line. This is the message that I receive:
Any comment or suggestion would be very much appreciated. Many thanks in advance. Karla |
hi @kzarate and thanks for joining! Could you please give some more details about your dataset (maybe one example file that you downloaded from ESGF?) and maybe where to find your shapefile. A first guess might be that it fails because you make a mean on the whole dataset and that might fail for variables like the xr_database.huss.weighted(mask_cordex * weights).mean(dim={'rlat', 'rlon'}) # weighted mean only on huss |
Hi @larsbuntemeyer thanks for your reply!
and I got this message:
My attempt to solve this was to reinstall it by conda but I still got the same result. Do you have any idea or suggestion? |
@kzarate glad to hear you could do the plotting! I don't really see the usage of import cordex as cx
cx.cordex_domain("EUR-11", cell_area=True) Please also ensure you have the latest version installed: import cordex as cx
cx.__version__ |
Is there a way to slice/subset EURO-CORDEX model outputs using py-cordex? I am working with REMO2015 model output and have tried using xarrays to slice the output for my area of study. It doesn't work and I am guessing it is due to the rotated lat lon grid. The code I have is as follows.
A solution could be if py-cordex offers a function to clip the EURO-CORDEX outputs based on shapefiles? And would the shapefiles need to be in the rotated lat lon projection?
The text was updated successfully, but these errors were encountered: