|
| 1 | +# ecmwf |
| 2 | + |
| 3 | +```julia |
| 4 | +ecmwf(; filename="", cb::Bool=false, dataset="", params::AbstractString="", key::String="", |
| 5 | + url::String="", region="", format="netcdf", dryrun::Bool=false, verbose::Bool=true) |
| 6 | +``` |
| 7 | + |
| 8 | +Retrieves data from the Climate Data Store [CDS](https://cds.climate.copernicus.eu) service. |
| 9 | + |
| 10 | + |
| 11 | +--- |
| 12 | + ecmwf(:forecast; levlist="", kw...) |
| 13 | + |
| 14 | +Download forecast datasets or just some variables from the ECMWF. (see man after that of first mode) |
| 15 | + |
| 16 | + |
| 17 | +--- |
| 18 | +Get ERA5 data from the Copernicus Climate Change Service (C3S) Climate Data Store (CDS) using the CDS API. |
| 19 | + |
| 20 | +- `filename`: The name of the file to save the data to. If not provided, the function will generate a |
| 21 | + name based on the dataset and the data format. |
| 22 | + |
| 23 | +- `cb`: A boolean indicating whether to use the clipboard contents. If true, the function will use the |
| 24 | + ``clipboard()`` to fetch its contents. The clipboard should contain a valid API request code as generated |
| 25 | + by the CDS website. This site provides a ``Show API request`` button at the bottom of the download tab |
| 26 | + of each dataset. After clicking it, the user can copy the request code with a Control-C (or click ``Copy`` |
| 27 | + button) which will and paste it into the clipboard. |
| 28 | + |
| 29 | +- `dataset`: The name of the dataset to retrieve. This option can be skipped if the `dataset` option |
| 30 | + is provided in the `params` argument, or is included clipboard copy (the `cb` option is set to true). |
| 31 | + |
| 32 | +- `params`: A JSON string containing the request parameters. This string should be in the format expected |
| 33 | + by the CDSAPI. When using input via this option the `dataset` option is mandatory. |
| 34 | + If you feel brave, you can create the request parametrs yourself and pass them as a two elements string |
| 35 | + vector with the output of the ``era5vars()`` and ``era5time()`` functions. In this case, a region selection |
| 36 | + and pressure levels, if desired, must be provided via the `region` and `levlist` options. The `region` |
| 37 | + option has the same syntax in all other GMT.jl modules that use it, _e.g._ the ``coast`` function. |
| 38 | + |
| 39 | +- `key`: The API key for the CDSAPI server. Default is the value in the ``.cdsapirc`` file in the home directory. |
| 40 | + but if that file does not exist, the user can provide the `key` and `url` as arguments. Instructions on how |
| 41 | + to create the ``.cdsapirc`` file for your user account can be found at [CDS](https://cds.climate.copernicus.eu/how-to-api) |
| 42 | + |
| 43 | +- `url`: The URL of the CDS API server. Default is https://cds.climate.copernicus.eu/api |
| 44 | + |
| 45 | +- `levlist`: List of pressure levels to retrieve. It can be a string to select a unique level, or a vector |
| 46 | + of strings or Ints to select multiple levels. But it can also be a range of levels, e.g. "1000:-100:500". |
| 47 | + This option is only used when the `params` argument is provided as a string vector. |
| 48 | + |
| 49 | +- `region`: Specify a region of a specific geographic area. It can be provided as a string with form "N/W/S/E" |
| 50 | + or a 4-element vector or tuple with numeric data. This option is only used when the `params` argument is |
| 51 | + provided as a string vector. |
| 52 | + |
| 53 | +- `format`: The format of the data to download. Default is "netcdf". Other options is "grib". |
| 54 | + |
| 55 | +- `dryrun`: A boolean indicating whether to print the `params` from the outputs of the `era5vars()` and |
| 56 | + `era5time()` functions. I this case, we just print the `params` and return without trying to download any file. |
| 57 | + |
| 58 | +- `verbose`: A boolean indicating whether to print the attemps to connect to the CDS server. Default is true. |
| 59 | + |
| 60 | +### Credits |
| 61 | +This function is based in part on bits of CDSAPI.jl but doesn't require any of the dependencies of that package. |
| 62 | + |
| 63 | +Examples |
| 64 | +-------- |
| 65 | + |
| 66 | +```julia |
| 67 | +# Copy the following code by selecting it and pressing Ctrl-C |
| 68 | + |
| 69 | +{"product_type": ["reanalysis"], |
| 70 | + "variable": [ |
| 71 | + "10m_u_component_of_wind", |
| 72 | + "10m_v_component_of_wind" |
| 73 | + ], |
| 74 | + "year": ["2024"], |
| 75 | + "month": ["12"], |
| 76 | + "day": ["06"], |
| 77 | + "time": ["16:00"], |
| 78 | + "data_format": "netcdf", |
| 79 | + "download_format": "unarchived", |
| 80 | + "area": [58, 6, 55, 9] |
| 81 | +} |
| 82 | + |
| 83 | +# Now call the function but WARNING: DO NOT COPY_PASTE it as it would replace the clipboard contents |
| 84 | +ecmwf(dataset="reanalysis-era5-single-levels", cb=true) |
| 85 | +``` |
| 86 | + |
| 87 | +### Let's dare and build the request ourselves |
| 88 | +```julia |
| 89 | +var = era5vars(["t2m", "skt"]) # "t2m" is the 2m temperature and "skt" is the skin temperature |
| 90 | +datetime = era5time(hour=10:14); |
| 91 | +ecmwf(dataset="reanalysis-era5-land", params=[var, datetime], region=(-10, 0, 30, 45)) |
| 92 | +``` |
| 93 | + |
| 94 | + |
| 95 | +--- |
| 96 | + ecmwf(:forecast; levlist="", kw...) |
| 97 | + |
| 98 | +Download forecast data |
| 99 | + |
| 100 | + |
| 101 | +### Kwargs |
| 102 | +- `cube`: If true [the default], when downloading pressure levels variables, save them data as a netCDF 3D cubes instead |
| 103 | + of one file per layer (when `cube=false`). |
| 104 | + |
| 105 | +- `date`: The date to select. It can be a string to select a unique date, a ``DateTime`` object, or a Int. |
| 106 | + Where the Int is the number of days to go back from today. If the Int is greater than 3, an error is raised. |
| 107 | + If the date is a string, it must be in the form YYYYMMDD or YYYY-MM-DD. |
| 108 | + |
| 109 | +- `dryrun`: Print the URL of the requested data and return without trying to download anything. |
| 110 | + |
| 111 | +- `format`: The format in which to save the downloaded data. It can be "grib" or "netcdf". Default is "netcdf". |
| 112 | + |
| 113 | +- `levlist`: The pressure levels to select. It can be a string to select a unique pressure level, |
| 114 | + or a vector of strings or Ints to select multiple pressure levels. |
| 115 | + |
| 116 | +- `model`: A string with the model to select. Either "ifs" or "aifs". Default is "ifs". |
| 117 | + |
| 118 | +- `param, variable, var, vars`: The variable(s) to select. It can be a string to select a unique variable, or a vector |
| 119 | + of strings or Ints to select multiple variables. When variable(s) is requested, we download only those |
| 120 | + variables as separate files. The names of those files are the same as the variable names with the .grib2 extension. |
| 121 | + NOTE: Not specifying a variable will download the entire forecast grib file for each forecast step selected with the `step` option. |
| 122 | + |
| 123 | +\textinput{common_opts/opt_R} |
| 124 | + |
| 125 | +- `root`: The root URL of the CDS ERA5 dataset. Default is "https://data.ecmwf.int/forecasts". |
| 126 | + |
| 127 | +- `step`: An Int with the forecast step to select. |
| 128 | + |
| 129 | +- `stream`: The stream to select. It can be one of: "oper", "enfo", "waef", "wave", "scda", "scwv", "mmsf". Default is "oper". |
| 130 | + |
| 131 | +- `time`: The time in hours to select. It can be a string a ``Time`` object, or a Int. What ever it is, |
| 132 | + it will floored to 0, 6, 12 or 18. The default is the current hour. |
| 133 | + |
| 134 | +- `stream`: A string with the stream to select, it must be one of: "oper", "enfo", "waef", "wave", "scda", "scwv", "mmsf". Default is "oper". |
| 135 | + |
| 136 | +- `type`: A string with the type of forecast to select, it must be one of: "fc", "ef", "ep", "tf". Default is "fc". |
| 137 | + |
| 138 | +Example |
| 139 | +------- |
| 140 | + |
| 141 | +Get the latest 10m wind and 2m temperature forecast for today. |
| 142 | + |
| 143 | +```julia |
| 144 | +ecmwf(:forecast, vars=["10u", "2t"]) |
| 145 | +``` |
| 146 | + |
| 147 | + |
| 148 | +See Also |
| 149 | +-------- |
| 150 | + |
| 151 | +\myreflink{weather}, \myreflink{era5vars}, \myreflink{era5time}, \myreflink{listecmwfvars} |
0 commit comments