Utilities and tools for working with MAR regional climate model outputs through xarray
Project description
marutils - Utilities for working with MAR RCM outputs
This package contains utilities/tools that make it easier to open MAR RCM outputs.
- Load outputs straight into an xarray Dataset with standard dimensions names
(time, y, x)
. - Provide a path with a wildcard expression (
*
) to automatically load several years of MAR files at once, concatenating them along the time axis. - Plays nicely with Dask - chunking options default to 365-366 days (but can be changed at will).
- Loaded Datasets are automatically "geo-aware" using the rioxarray
.rio
accessor - no more trying to work out MAR's geo-referencing manually! - Helper functions for turning X-hourly variables into continuous time series.
- Helper functions for masking.
QuickStart
import marutils
# Open a time series for the 21st century.
mar_outputs = marutils.open_dataset('MARv3.11.2/MAR*20*.nc')
# Check out the coordinates.
print(mar_outputs.coords)
Coordinates:
* x (x) float32 -760000.0 -740000.0 -720000.0 ... 660000.0 680000.0
* y (y) float32 -1180000.0 -1160000.0 ... 1480000.0 1500000.0
* SECTOR (SECTOR) float32 1.0 2.0
* SECTOR1_1 (SECTOR1_1) float32 1.0
* time (time) datetime64[ns] 2019-01-01T12:00:00 ... 2019-12-31T12:...
* ATMLAY3_3 (ATMLAY3_3) float32 0.99974793
spatial_ref int64 0
# What is proj.4 string for the geo-referencing of this dataset?
print(mar_outputs.rio.crs.to_proj4())
+proj=stere +lat_0=70.5 +lon_0=-40 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs=True
Installation
At the moment, manually:
git clone <repository>
cd <repository>
pip install -e .
Soon to be available via pyPI.
Working with X-hourly outputs
To return an X-hourly variable with a single, continuous hourly time variable:
hourly_air_temperatures = marutils.xhourly.Xhourly_to_time(mar_outputs.TTH)
Useful notes
Pixel corners vs centres
It's useful to remember that netCDF file geo-referencing treats X,Y coordinates as pixel (cell) centres. In contrast, the rasterio/GDAL data model treats X,Y coordinates as pixel upper-left corners.
In the QuickStart section above we loaded a 20 km resolution dataset. The minimum and maximum X coordinates are -760000 and 680000 m respectively. These correspond to the centres of the min/max pixels.
Through the .rio
accessor we can check on the bounds/complete spatial extent of the file:
# What is the centre of the top-left cell? (xmin, ymin, xmax, ymax)
mar_outputs.rio.bounds()
(-770000.0, 1510000.0, 690000.0, -1190000.0)
We can see that these bounds account for the 20 km pixel size of this dataset.
Caveats
The geo-referencing capabilities have so far been tested only for Greenland datasets. If you have problems trying to load other domains, please post an issue on this repository.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file marutils-1.0.0.tar.gz
.
File metadata
- Download URL: marutils-1.0.0.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 614b531112c7974aaec543bfbcbd05a06a35b83c7e380b769829fc19edda38b8 |
|
MD5 | 9f1821f438f9d3738d8a615b9fb02d1e |
|
BLAKE2b-256 | 0621322bfc434ceeb49deaae154fba4141c82a279d2850169277f1b522b70e58 |
File details
Details for the file marutils-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: marutils-1.0.0-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 618d9290e53031b5742476a15527e9aae0d5fb51a5d2f1472b1b77b048724f44 |
|
MD5 | 29797bdb36ae729a1b99729a9b5a211f |
|
BLAKE2b-256 | 0878fb7671fc9076aa0910dc23916134aa94009797238d50e866b9f25996885a |