Download ERA5 data with julia
This Julia script from George Datseris works in a similar way as the Python script. First, you have to install the PyCall.jl library, which allows calling Python packages directly from Julia (no wrappers). Remember to add the `.cdsapirc` file to your home directory (must be done for python as well), as instructed here: https://cds.climate.copernicus.eu/api-how-to .
Now, do the following:
- installCDS.jl
using Pkg # access package manager ENV["PYTHON"] = "" # Ensure dedicated Python installation for Julia Pkg.add(["Conda", "PyCall"]) using Conda; Conda.add("cdsapi"; channel = "conda-forge") # install cdsapi
Once this is done, you can use the API within Julia. What I like to do is go to the website to order data, do a dummy selection, and then at the end click “Show API Request”. This gives you the Python version of the code. You transform it to Julia by doing three trivial changes (by global search+replace in your favorite editor):
- Replace `{ … }` with `Dict( … )`.
- Replace all `'` with `“`, as in Julia strings are within double quotes.
- Replace the syntax `”something“: “entries…“` with `”something” ⇒ “entries…“` because in Julia `⇒` defines dictionaries.
And that is it. Here is an example:
- download_CDS.jl
using PyCall cdsapi = pyimport("cdsapi") c = cdsapi.Client() year = "2019" savename = "ERA5/T_W_F_$year.nc" mkpath(dirname(savename)) c.retrieve( "reanalysis-era5-pressure-levels-monthly-means", Dict( "product_type" => "monthly_averaged_reanalysis", "variable" => [ "fraction_of_cloud_cover", "temperature", "vertical_velocity", ], "pressure_level" => [ "2", "5", "10", "30", "70", "125", "175", "225", "300", "400", "500", "600", "700", "775", "825", "875", "925", "975", ], "year" => year, "month" => [ "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", ], "time" => "00:00", "format" => "netcdf", ), savename # file to save the data. )