This tools aims at generating regions mask in netcdf format in a way that it can be ported to any configuration and / or any model, to allow for simple comparisons when dealing with regional studies from larger models.
The script run_create_regions.py provides a simple example of all the steps and functions.
There are two options to define a region:
- by hand: provide a region name and a list of [lon, lat] points that define a polygon
- via a kmz file: these are file that can be easily edited via Google Maps or (better Google Earth). The kmz file has to include a list of Polygons that defines the area of the region requested. Regions defined are stored into a dictionary called "regions_dict" that can be modified and saved to netcdf and kmz format.
Python 3 and the following librairies:
- xarray : http://xarray.pydata.org/en/stable/index.html
- regionmask : https://regionmask.readthedocs.io/en/stable/
- Add create_regions.py to a directory in your PYTHONPATH (or current directory)
- open a python console
- Import create_regions and define your configuration (cf. example in run_create_regions.py)
- Start define your regions
- Save your regions to kmz and / or netcdf files
Check examples in run_create_regions.py create_region function takes 3 arguments :
- name of the region
- abbreviated name (in the netcdf file, mask will be named "tmaskxxxx" xxxx begin the abbreviated name
- list of [lon,lat] points defining a closed polygon that will define the area of the region
Use the function create_regions_from_kmz('my_kmz_file.kmz')
In Google Earth:
- Right-click on "My Places" -> Add -> Folder
- Right-click on the new Folder -> Add -> Polygon Repeat 2) for every new region
- Right-click on the new Folder -> Save Place As
Right-click on the Polygon -> Properties -> Right-click on points of the Polygon to suppress them / Left-click to add a new point
Use the function get_list_regions()
I've defined some regions, but I'm not totaly happy with one that I'd like to modify. What should I do ?
This can be done in 3 simple steps:
- store the Polygon of the region you want to modify using the function get_polygon
- do the modification on this Polygon
- update the region definition with the new polygon using update_region. This will also update the mask of the region.
Use the function create_nc('my_nc_file.nc')
Use the function create_kmz('my_kmz_file.kmz')
I have a nice kmz file that I already used to generate regions, and I want to use it to generate the same region masks for my brand new configuration. How should I do ?
Use the function create_nc_from_kmz('my_kmz_file.kmz','my_nc_file.nc')