Skip to content
Snippets Groups Projects
Commit dcee9cab authored by Michael Blaschek's avatar Michael Blaschek :bicyclist:
Browse files

added mars requests and era5 plotting

parent f05cf0de
No related branches found
No related tags found
No related merge requests found
# Data at ECMWF
## MARS
ECMWF's Meteorological Archival and Retrieval System (MARS) enables you to explore and retrieve meteorological data in GRIB or NetCDF format. GRIB (General Regularly distributed Information in Binary form) is the WMO's format for binary gridded data and is designed for storing and distributing weather data. GRIB files are widely used in meteorological applications. NetCDF (Network Common Data Form) is a set of software libraries and self-describing, machine-independent data formats that support the creation, access, and sharing of array-oriented scientific data.
## Meteorological Archival and Retrieval System (MARS)
![MARS request tree](../mkdocs/img/MARS-tree.png)
How to make a MARS request?
How to make a mars request
What ECMWF says: [here](https://www.ecmwf.int/en/forecasts/access-forecasts/access-archive-datasets)
- using ECMWF's servers
- using [MARS web api](../Python/QA-012-Mars-Requests.ipynb) in Python
- [using ECMWF mars web interface](https://apps.ecmwf.int/archive-catalogue/?class=od) using the archive catalogue.
## GRIB
How to handle grib files.
## General Regularly distributed Information in Binary form (GRIB)
Example using Python and Fortran90.
\ No newline at end of file
GRIB is a binary format, and the data is packed to increase storage efficiency. GRIB messages are often concatenated together to form a GRIB file. GRIB files usually have the extension .grib, .grb or .gb.
Currently there are two different coding standards: GRIB edition 1 (commonly referred to as GRIB1) and GRIB edition 2 (GRIB2). The major differences are in the structure of the messages; in GRIB2, several variables are defined with more precision (e.g. in GRIB1, latitudes and longitudes are in milli-degrees while in GRIB2, they are in micro-degrees). Also in GRIB2, longitude values must lie between 0 and 360 degrees), the encoding of the parameter is very different, and in GRIB2 the description of the data is template/table based. Note that a GRIB file can contain a mix of GRIB1 and GRIB2 messages.
### How to read GRIB files?
ECMWF provides and supports ecCodes. This software package has an Application Program Interface which makes ECMWF GRIB1 and GRIB2 files accessible from C, FORTRAN and Python programmes. ecCodes also provides a useful set of command line tools to give quick access to GRIB messages within the files.
Commonly used programs that can handle grib files:
- [Panoply](http://www.giss.nasa.gov/tools/panoply/) by NASA
- [Metview](https://confluence.ecmwf.int/display/METV) by ECMWF
- ecCodes by ECMWF
- magics / metview by ECMWF
- CDO
- NCO
- GrADS
- idl
We have some examples of reading grib files:
- [Reading grib using cfgrib into xarray](../Python/QA-012-Mars-Requests.ipynb)
- [Reading grib using magics](../Python/QA-013-Retrieving-ERA5-Magics.ipynb)
it is also possible to convert grib files into netcdf files:
```sh title="Convert GRIB to NetCDF"
# load eccodes module or make grib_to_netcdf available to our PATH
module load eccodes
# convert to netcdf
grib_to_netcdf input.grb -o output.nc
```
`grib_to_netcdf` only works correctly when a single level coordinate is present in the GRIB file. Often the model output files have fields on multiple level types (ie. hybrid model levels and pressure levels).
```sh title="Split Model level types"
# check the contents of the grib file
grib_ls input.grb
# split by model lvel type
grib_copy input.grb output_[typeOfLevel].grb
```
more information can be found at [ECMWF](https://confluence.ecmwf.int/display/OIFS/How+to+convert+GRIB+to+netCDF)
\ No newline at end of file
%% Cell type:markdown id:7d86c6c1-140e-4c0c-9cbb-98355f11da04 tags:
# Access to MARS
This Service will allow authorised users to retrieve and list MARS data from outside the ECMWF facilities. Users within ECMWF Member and Co-operating States may contact their Computing Representative to obtain access to MARS. All other users may request a username and password, following these [instructions](https://confluence.ecmwf.int/display/WEBAPI/Access+MARS#AccessMARS-downloadmars).
Accessing and retrieving files from MARS got a lot easier, with this package.
We need to install the web client for MARS and get credentials from ECMWf to allow the API to call MARS.
%% Cell type:code id:543bfff5-ce4e-4bcc-af5f-5013a0470f9a tags:
``` python
!pip -q install --user ecmwf-api-client
```
%% Cell type:markdown id:1257ed6b-f5fc-4657-b4b9-43eb28f13d6c tags:
You need an ECMWF account and login to get the login credentials for the web api of MARS.
Go to https://api.ecmwf.int/v1/key ( click login ) and then same the information to a file called `$HOME/.ecmwfapirc`
%% Cell type:code id:0fce3a30-dca5-40e1-94ac-f7189bc92154 tags:
``` python
%%writefile /mnt/users/staff/mmustermann/.ecmwfapirc
{
"url" : "https://api.ecmwf.int/v1",
"key" : "1234567890???????",
"email" : "max.mustermann@univie.ac.at"
}
```
%% Output
Overwriting /mnt/users/staff/mblaschek/.ecmwfapirc
%% Cell type:markdown id:2dddf15a-d542-4e03-9155-2dcb57b9637e tags:
This is an example of a request. If you want to figure more exactly what you need it is best to browse the online catalog of MARS and then get exactly what you want.
Look here: [Mars Catalogue](https://apps.ecmwf.int/mars-catalogue/) or the [Archive Catalogue (freely)](http://apps.ecmwf.int/archive-catalogue/)
%% Cell type:code id:ba4b42e5-5218-4948-ab43-c64c3606734c tags:
``` python
from ecmwfapi import ECMWFService
server = ECMWFService("mars")
server.execute(
{
"class": "od",
"date": "20150101",
"expver": "1",
"levtype": "sfc",
"param": "167.128",
"step": "0/to/240/by/12",
"stream": "oper",
"time": "00",
"type": "fc"
},
"target.grib")
```
%% Output
2024-02-29 15:49:59 ECMWF API python library 1.6.3
2024-02-29 15:49:59 ECMWF API at https://api.ecmwf.int/v1
2024-02-29 15:49:59 Welcome Max Mustermann
2024-02-29 15:50:00 In case of problems, please check https://confluence.ecmwf.int/display/WEBAPI/Web+API+FAQ or contact servicedesk@ecmwf.int
2024-02-29 15:50:00 Request submitted
2024-02-29 15:50:00 Request id: 65e09998778174dbb7b3479f
2024-02-29 15:50:00 Request is submitted
2024-02-29 15:50:01 Request is queued
2024-02-29 15:50:07 Calling 'nice mars /tmp/20240229-1450/ff/tmp-_mars-BMsk2q.req'
2024-02-29 15:50:07 Forcing MIR_CACHE_PATH=/data/ec_coeff
2024-02-29 15:50:07 mars - WARN -
2024-02-29 15:50:07 mars - WARN -
2024-02-29 15:50:07 MIR environment variables:
2024-02-29 15:50:07 MIR_CACHE_PATH=/data/ec_coeff
2024-02-29 15:50:07 MIR_LSM_NAMED=1km.climate.v013
2024-02-29 15:50:07 Using MARS binary: /usr/local/apps/mars/versions/6.33.16.2/bin/mars.bin
2024-02-29 15:50:07 mars - INFO - 20240229.145002 - Welcome to MARS
2024-02-29 15:50:07 mars - INFO - 20240229.145002 - MARS Client build stamp: 20231005152332
2024-02-29 15:50:07 mars - INFO - 20240229.145002 - MARS Client bundle version: 6.33.16.2
2024-02-29 15:50:07 mars - INFO - 20240229.145002 - package mars-client version: 6.33.16
2024-02-29 15:50:07 mars - INFO - 20240229.145002 - package mir version: 1.18.0
2024-02-29 15:50:07 mars - INFO - 20240229.145002 - package odc version: 1.4.6
2024-02-29 15:50:07 mars - INFO - 20240229.145002 - package fdb version: 5.11.23
2024-02-29 15:50:07 mars - INFO - 20240229.145002 - package metkit version: 1.10.15
2024-02-29 15:50:07 mars - INFO - 20240229.145002 - package eckit version: 1.24.4
2024-02-29 15:50:07 mars - INFO - 20240229.145002 - package eccodes version: 2.32.0
2024-02-29 15:50:07 mars - INFO - 20240229.145002 - Maximum retrieval size is 75.00 G
2024-02-29 15:50:07 retrieve,stream=oper,levtype=sfc,param=167.128,padding=0,step=0/to/240/by/12,expver=1,time=00,date=20150101,type=fc,class=odmars - INFO - 20240229.145002 - Automatic split on dates is on
2024-02-29 15:50:07
2024-02-29 15:50:07 mars - INFO - 20240229.145002 - Processing request 1
2024-02-29 15:50:07
2024-02-29 15:50:07 RETRIEVE,
2024-02-29 15:50:07 CLASS = OD,
2024-02-29 15:50:07 TYPE = FC,
2024-02-29 15:50:07 STREAM = OPER,
2024-02-29 15:50:07 EXPVER = 0001,
2024-02-29 15:50:07 REPRES = GG,
2024-02-29 15:50:07 LEVTYPE = SFC,
2024-02-29 15:50:07 PARAM = 167.128,
2024-02-29 15:50:07 TIME = 0000,
2024-02-29 15:50:07 STEP = 0/12/24/36/48/60/72/84/96/108/120/132/144/156/168/180/192/204/216/228/240,
2024-02-29 15:50:07 DOMAIN = G,
2024-02-29 15:50:07 PADDING = 0,
2024-02-29 15:50:07 DATE = 20150101
2024-02-29 15:50:07
2024-02-29 15:50:07 mars - INFO - 20240229.145002 - Web API request id: 65e09998778174dbb7b3479f
2024-02-29 15:50:07 mars - INFO - 20240229.145002 - Requesting 21 fields
2024-02-29 15:50:07 mars - INFO - 20240229.145002 - Setting SO_SNDBUF to 33554432 (32.00 M)
2024-02-29 15:50:07 mars - INFO - 20240229.145002 - Current value is 8192 (8.00 K)
2024-02-29 15:50:07 mars - INFO - 20240229.145002 - Setting SO_RCVBUF to 33554432 (32.00 M)
2024-02-29 15:50:07 mars - INFO - 20240229.145002 - Current value is 43690 (42.67 K)
2024-02-29 15:50:07 mars - INFO - 20240229.145002 - Calling mars on 'fdbprod', local port is 57169
2024-02-29 15:50:07 mars - INFO - 20240229.145002 - Server task is 447 [ATOS FDB]
2024-02-29 15:50:07 mars - INFO - 20240229.145002 - Retrieving from FDB [ATOS FDB]
2024-02-29 15:50:07 mars - INFO - 20240229.145002 - Looking up FDB indexes: 0.00488 second elapsed, 0.003801 second cpu [ATOS FDB]
2024-02-29 15:50:07 mars - INFO - 20240229.145002 - Calling mars on 'marsod-core', local port is 52683
2024-02-29 15:50:07 mars - INFO - 20240229.145002 - Server task is 390 [marsod]
2024-02-29 15:50:07 mars - INFO - 20240229.145002 - Request cost: 21 fields, 85.7978 Mbytes online, nodes: mvr004 mvr006 [marsod]
2024-02-29 15:50:07 mars - INFO - 20240229.145002 - The efficiency of your requests in the last 12 hours is 100% [marsod]
2024-02-29 15:50:07 mars - INFO - 20240229.145002 - Transfering 89965512 bytes
2024-02-29 15:50:07 mars - INFO - 20240229.145004 - 21 fields retrieved from 'marsod'
2024-02-29 15:50:07 mars - INFO - 20240229.145004 - Request time: wall: 2 sec
2024-02-29 15:50:07 mars - INFO - 20240229.145004 - Visiting marsod: wall: 2 sec
2024-02-29 15:50:07 mars - INFO - 20240229.145004 - Read from network: 85.80 Mbyte(s) in 2 sec [53.45 Mbyte/sec]
2024-02-29 15:50:07 mars - INFO - 20240229.145004 - Writing to target file: 85.80 Mbyte(s) in < 1 sec [220.00 Mbyte/sec]
2024-02-29 15:50:07 mars - INFO - 20240229.145004 - Memory used: 40.92 Mbyte(s)
2024-02-29 15:50:07 mars - INFO - 20240229.145004 - No errors reported
2024-02-29 15:50:07 Process '['nice', 'mars', '/tmp/20240229-1450/ff/tmp-_mars-BMsk2q.req']' finished
2024-02-29 15:50:07 Request is complete
2024-02-29 15:50:07 Transfering 85.7978 Mbytes into target.grib
2024-02-29 15:50:07 From https://apps.ecmwf.int/api/streaming/private/blue/02/20240229-1450/d9/_mars-bol-webmars-private-svc-blue-003-4a73a881a8d5eead47db9eff2f9935a4-rDzHit.grib
2024-02-29 15:50:13 Transfer rate 14.1941 Mbytes/s
2024-02-29 15:50:13 Done
%% Cell type:markdown id:25cd62c4-a3da-4411-bec0-c431763571d2 tags:
## Reading the grib file
we can use the [cfgrib](https://github.com/ecmwf/cfgrib) package, which allows xarray to read grib files.
%% Cell type:code id:38ba97fe-3fb8-4c36-a802-0282fcc7c860 tags:
``` python
!pip -q install --user cfgrib
```
%% Cell type:code id:3debef90-b0e0-4ac2-a519-a89323f3652b tags:
``` python
import xarray as xr
ds = xr.open_dataset('target.grib', engine='cfgrib')
```
%% Cell type:code id:8b1bc0e1-3ec3-4e62-b9e4-b9279435b508 tags:
``` python
print(ds)
```
%% Output
<xarray.Dataset>
Dimensions: (step: 21, values: 2140702)
Coordinates:
number int64 ...
time datetime64[ns] ...
* step (step) timedelta64[ns] 0 days 00:00:00 ... 10 days 00:00:00
surface float64 ...
latitude (values) float64 ...
longitude (values) float64 ...
valid_time (step) datetime64[ns] ...
Dimensions without coordinates: values
Data variables:
t2m (step, values) float32 ...
Attributes:
GRIB_edition: 1
GRIB_centre: ecmf
GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts
GRIB_subCentre: 0
Conventions: CF-1.7
institution: European Centre for Medium-Range Weather Forecasts
history: 2024-02-29T15:55 GRIB to CDM+CF via cfgrib-0.9.1...
%% Cell type:code id:a207cddd-ddba-4bc5-a888-33e66b721006 tags:
``` python
```
Source diff could not be displayed: it is too large. Options to address this: view the blob.
......@@ -145,6 +145,15 @@ ECMWF created a python package that helps to read BUFR messages via ECCODES into
ECMWF created a python package that helps to read ODB messages via ODC or pure Python into pandas DataFrame.
## Q: How to retrieve data from MARS in python?
[MARS](QA-012-Mars-Requests.ipynb)
ECMWF has created a package that allows to retrieve data from MARS, easily.
## Q: How to retrieve ERA5 from CDS and plot in Magics?
[Magics](QA-013-Retrieving-ERA5-Magics.ipynb)
It is very easy to download and plot ERA5 data, using cdsapi and Magics.
## Q: How to ignore user site packages?
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment