Coder Social home page Coder Social logo

meteocat / unimodel Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 369 KB

Lectura i conversió de fitxer grib de model a xarray. Reprojeccions i interpolacions per passar a una malla comuna.

Home Page: https://unimodel.readthedocs.io/en/latest/

Python 99.89% Batchfile 0.05% Shell 0.06%
grib meteorology regridding

unimodel's Introduction

Anaconda-Server Badge Documentation Status

logo

Aquest paquet de Python implementa un seguit de mòduls per llegir i facilitar el processament de les sortides dels models de prediccó numèrica del temps en format grib disponibles al Servei Meteorològic de Catalunya. Els mòduls llegeixen els fitxers grib i els transformen en xarray.DataArray, que inclouen les dades, la projecció i les coordenades en la projecció nativa del grib.

A part, el paquet inclou també un mòdul d'interpolació i reprojecció dels xarray.DataArray. Les metodologies d'interpolació que hi ha implementades són, de moment, nearest i bilinear. La reprojecció es fa mitjançant la llibreria rioxarray. Els mòduls d'interpolació poden incloure també, de forma opcional, una reprojecció.

A més, s'inclou també un mòdul de refinament del camp de temperatura basat en les diferències d'altitud que hi ha entre l'orografia del model i la d'un model digital d'elevació de més resolució espacial.

La sortida per defecte de la lectura dels models és un xarray.DataArray, però s'inclou un mòdul per exportar les dades en format netCDF. L'exportació és d'un únic xarray.DataArray que pot incloure més d'un horitzó de pronòstic i més d'un model.

Instal·lació

El paquet es troba al canal meteocat de conda i es pot instal·lar mitjançant:

conda install -c conda-forge -c meteocat unimodel

També es pot instal·lar de la manera tradicional utilitzant pip. En primer lloc, cal crear un entorn conda amb les llibreries necessàries per executar correctament el paquet. Aquetes es poden trobar dins del fitxer unimodel_environment.yml.

conda env create -f unimodel_environment.yml

Una vegada activat l'entorn conda, la instal·lació del paquet es pot fer a partir de la comanda següent:

pip install [path a la carpeta unimodel]

Coverage

Per avaluar la cobertura dels testos s'ha d'executar la comanda següent:

pytest --cov=./unimodel ./tests --cov-report=xml:cov.xml

unimodel's People

Contributors

ecasellas avatar iciarguerrero avatar jrmiro avatar sotis-am avatar

unimodel's Issues

wrf_tl_ens name file change

The name of the wrf_tl_ens files has been changed, and this change affects how Unimodel reads the realization of each wrf_tl_ens file. The regular expression used to match the file path needs to be adapted.

From:

ens-{member}.{year}{month}{day}{hour}_{lt}.grib

To:

tl_ens-03-{member}.{year}{month}{day}{hour}_{lt}.grib

To accommodate the -03- part, the regular expression in unimodel.io.readers.read_wrf_tl_ens_grib should be r"-(\d{3})\.".

Refactoring NWP readers

Currently, each NWP has a specific reader function; however, most of the functions share some similarities and may be refactored. Unimodel has twelve model readers, and some of them can be merged into different new functions:

read_nwp_grib

Apart from reading the grib, it includes the functionality of renaming longitude/latitude to x/y. This function should include the following models: ICON, ECMWF, UM, NCEP, WW3, SWAN.

_get_nwp_metadata

Retrieves projection CRS from xarray data. It can be used for the following models: ICON, ECMWF, UM, NCEP, WW3, SWAN, Meteofrance, WRF-TL-ENS.

get_meteofrance_grib

Apart from what is included in read_nwp_grib, it should also include rounding coordinate x/y values round(2) for AROME and round(1) for ARPEGE. Merge of read_arome_grib and read_arpege_grib.

get_cnr_isac_grib

Apart from what is included in read_nwp_grib, it should also include the creation of x and y coordinates from geotransform and dropping longitude and latitude coordinates. Function to read MOLOCH and BOLAM model gribs.

_get_cnr_isac_metadata

Merge of _get_bolam_metadata and _get_moloch_metadata.

get_wrf_tl_ens_grib

Leave as is, but change specific metadata by _get_nwp_metadata.

unimodel.io.interface must be changed accordingly.

Add extra filters in the 'backend_kwargs' of the model readers

Every reader function in readers_nwp.py accepts three arguments (grib_file, variable and model) except for the read_ecmwf_ens_grib, which also needs ens_type. This was done because when reading an ECMWF ensemble file you need to specifiy whether it is the perturbed forecast (pf) or the control forecast (cf). The ens_type value is passed in the backend_kwargs as follows:

backend_kwargs={'filter_by_keys': {'shortName': variable, 'dataType': ens_type},
                'indexpath': ''}

Instead, we can add the argument extra_filters to update directly the filter_by_keys dict with a custom dictionary. This will allow us more flexibility when selecting the variable (selecting the levels, for example) and it will solve the potential issue of the same variable having two different type of levels: https://github.com/ecmwf/cfgrib#filter-heterogeneous-grib-files. Apart from that, all the readers will request the same arguments.

We should also control the exceptions to provide user-friendly messages to users.

Wave model reader

Unimodel should read SWAN and WW3 files. Two functions named read_swan_grib and read_ww3_grib can be added to unimodel/io/readers_nwp.py.

ECMWF HINDCAST grib reader

Unimodel should read ECMWF HINDCAST grib files. A function named read_ecmwf_hindcast_grib can be added to unimodel/io/readers_nwp.py. To obtain metadata, _get_ecmwf_metadata may be used.

Catch exception when no file in .tar.gz is found

import_nwp_grib function in importers_nwp.py may copy a compressed file from a directory to a working directory. Then, it extracts a specific file from it. If the file name pattern in the configuration dictionary doesn't match any file of the .tar, an IndexError is raised. However, it should be controlled to provide more user-friendly information to user.

Example: "File {xxxxx} not found in {xxxxx}.tar.gz"

GFS/GEFS reader

Unimodel should read GFS and GEFS grib files. A function named read_ncep_grib can be added to unimodel/io/readers_nwp.py. The interface then should point gfs and gefs to that function.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.