This python library downloads downscaled climate change scenarios from NASA NEX-GDDP-CMIP6 (https://ds.nccs.nasa.gov/thredds/catalog/AMES/NEX/GDDP-CMIP6/catalog.html).
To use this library install the requirements:
- wget
- csv
- numpy
- pandas
- xarray
- beautifulsoup4
If you are using windows, wget needs to be downloaded and added to your paths If you don't want to get the .csv summary you do not need xarray, but it is highly recommended for post-processing.
Recommended Way:
pip install git+https://github.com/jonathanqv/cmip6d.git@main
Deprecated:
pip install cmip6d
To import the library:
from cmip6d import cmip6d
Define the main variables. Until
out_path = 'test' # Defines your output folder, choose a new empty folder
coords = [-75,-69.5,-17.5,-14] # xmin,xmax,ymin,ymax
models = [] # If empty, downloads everything, if not, downloads specified packages
ssp=['ssp245','ssp585'] # DEFAULT VARIABLE. Target scenarios from the NASA server
variables = ['pr','tasmax','tasmin'] # DEFAULT VARIABLE. Target variables from the NASA server
To create the main Python object:
cc = cmip6d(out_path,coords,models,variables=variables,ssp=ssp)
First, it creates the folder structure based on the MODELS, then it generates a "link.txt" file with the links to be downloaded. The "check_links" argument allows you to not re-create the "link.txt" file if it already exists.
cc.get_links(out_path,check_links=True)
To download the links you need to specify a number of workers "nworker", which speeds up the download. Once completed these step you will have all the netcdf files for your climate change model, these can be loaded with xarray or whatever other method you prefer.
cc.download_links(nworker=4)
If you want to merge the yearly individual ".nc" files into one for each variable use:
cc.merge_files(cont)
Note: There are some climate change models that do not contain all variables. For instance, if you want to download "CESM2" "ssp245" and you specify the variables ["pr","tasmax","tasmin"], It'll crash because there are no datasets "tasmax" and "tasmin" in this scenario, but it has "pr", so you would need to specify variables equal to only ["pr"]
If you would like to get 2 ".csv" files with coordinates of the following structure:
ID | Latitude | Longitude |
---|---|---|
P_0_0 | .... | ..... |
P_0_1 | .... | ..... |
... | .... | ..... |
and
Date | P_0_0 | P_0_1 | ... |
---|---|---|---|
2015-01-01 | .... | ..... | ... |
2015-01-02 | .... | ..... | ... |
... | .... | ..... | ... |
You can use the following function after running "merge_files", where "cont=True" does not process the data if the files already exist. This function returns a dictionary of the climate change models and dates that were not processed because of missing dates in the timeserie from 2015-01-01 to 2100-12-31.
todel = cc.get_csv(cont)