Python package to performs meteorological calculations
Project description
metlib
Python package to performs meteorological calculations
Requirements
Usage
See the next jupyter notebook examples where are calculated the relative vorticity, the horizontal divergence of wind and the temperature advection, also are showed how to creates lat-lon plots and vertical profile plots along latitude, longitude or time.
-
Using netCDF4:
- creates lat-lon plots using basemap/cartopy, matplotlib and pcolormesh/contourf (example).
- creates vertical profile plots using matplotlib and pcolormesh/contourf (example).
-
Using xarray:
- creates lat-lon plots using basemap/cartopy, matplotlib and pcolormesh/contourf (example).
- creates vertical profile plots using matplotlib and pcolormesh/contourf (example).
-
Using xarray and xarray.plot:
- creates lat-lon plots using xarray.plot, cartopy, matplotlib and pcolormesh/contourf (example).
- creates vertical profile plots using xarray.plot, matplotlib and pcolormesh/contourf (example).
Reference Guide
Click on the item to see the function and their description.
Central difference finites
cdiff(Field, Dim)
Calculates a centered finite difference of Numpy array or Xarray.DataArray.
Parameters
----------
Field: Numpy array or Xarray.DataArray
Their structure can be:
- 1D [x]
- 2D [y,x]
- 3D [z,y,x]
- 4D [t,z,y,x]
Dim: String (str)
Defines axis of derivative and can be 'X', 'Y', 'Z', 'T'.
Returns
-------
CDIFF: Numpy array or Xarray.DataArray
Centered finite difference in Dim of Field. The shape is the same that input(Field).
Relative vorticity
relative_vorticity(UComp, VComp, Lon=None, Lat=None)
Calculates the relative vorticity of horizontal wind.
Parameters
----------
UComp: Numpy array or Xarray.DataArray
Zonal component of wind. Their structure can be:
- 2D [y,x]
- 3D [z,y,x] or [t,y,x]
- 4D [t,z,y,x]
VComp: Numpy array or Xarray.DataArray
Meridional component of wind. Their structure can be:
- 2D [y,x]
- 3D [z,y,x] or [t,y,x]
- 4D [t,z,y,x]
Lon: Numpy array
2D array with the longitudes of UComp and VComp.
If UComp and VComp are xarray.DataArray is not necessary define this parameter.
Lat: Numpy array
2D array with the latitudes of UComp and VComp.
If UComp and VComp are xarray.DataArray is not necessary define this parameter.
Returns
-------
vor: Numpy array or Xarray.DataArray
Relative vorticity of Ucomp and Vcomp [s**-1]
Absolute vorticity
absolute_vorticity(UComp, VComp, Lon=None, Lat=None)
Calculates the absolute vorticity of horizontal wind.
Parameters
----------
UComp: Numpy array or Xarray.DataArray
Zonal component of wind. Their structure can be:
- 2D [y,x]
- 3D [z,y,x] or [t,y,x]
- 4D [t,z,y,x]
VComp: Numpy array or Xarray.DataArray
Meridional component of wind. Their structure can be:
- 2D [y,x]
- 3D [z,y,x] or [t,y,x]
- 4D [t,z,y,x]
Lon: Numpy array
2D array with the longitudes of UComp and VComp.
If UComp and VComp are xarray.DataArray is not necessary define this parameter.
Lat: Numpy array
2D array with the latitudes of UComp and VComp.
If UComp and VComp are xarray.DataArray is not necessary define this parameter.
Returns
-------
avor: Numpy array or Xarray.DataArray
Absolute relative vorticity of Ucomp and Vcomp [s**-1]
Divergence
divergence(UComp, VComp, Lon=None, Lat=None)
Calculates the divergence of horizontal wind or some vector field.
Parameters
----------
UComp: Numpy array or Xarray.DataArray
Zonal component of wind. Their structure can be:
- 2D [y,x]
- 3D [z,y,x] or [t,y,x]
- 4D [t,z,y,x]
VComp: Numpy array or Xarray.DataArray
Meridional component of wind. Their structure can be:
- 2D [y,x]
- 3D [z,y,x] or [t,y,x]
- 4D [t,z,y,x]
Lon: Numpy array
2D array with the longitudes of UComp and VComp.
If UComp and VComp are xarray.DataArray is not necessary define this parameter.
Lat: Numpy array
2D array with the latitudes of UComp and VComp.
If UComp and VComp are xarray.DataArray is not necessary define this parameter.
Returns
-------
div: Numpy array or Xarray.DataArray
Horizontal divergence of Ucomp and Vcomp [1/s]
Negative divergence is also known as convergence.
Advection
advection(Field, UComp, VComp, Lon=None, Lat=None)
Calculates the horizontal adveccion of Field.
Parameters
----------
Field: Numpy array or Xarray.DataArray
Their structure can be:
- 2D [y,x]
- 3D [z,y,x] or [t,y,x]
- 4D [t,z,y,x]
UComp: Numpy array or Xarray.DataArray
Zonal component of wind. Their structure can be:
- 2D [y,x]
- 3D [z,y,x] or [t,y,x]
- 4D [t,z,y,x]
VComp: Numpy array or Xarray.DataArray
Meridional component of wind. Their structure can be:
- 2D [y,x]
- 3D [z,y,x] or [t,y,x]
- 4D [t,z,y,x]
Lon: Numpy array
2D array with the longitudes of UComp and VComp.
If UComp and VComp are xarray.DataArray is not necessary define this parameter.
Lat: Numpy array
2D array with the latitudes of UComp and VComp.
If UComp and VComp are xarray.DataArray is not necessary define this parameter.
Returns
-------
adv: Numpy array or Xarray.DataArray
Horizontal advection of Field [Field_units/s]
Potential temperature
potential_temperature(Temperature, Levels=None)
Calculates the potential temperature.
Parameters
----------
Temperature: Numpy array or Xarray.DataArray
Temperature field in Kelvin. Their structure can be:
- 2D [y,x]
- 3D [z,y,x] or [t,y,x]
- 4D [t,z,y,x]
Levels: Numpy array
1D array with pressure levels of Temperature.
Returns
-------
PTemp: Numpy array or Xarray.DataArray
Potential temperature [K].
Potential vorticity
potential_vorticity(Temperature, UComp, VComp, Lon=None, Lat=None, Levels=None)
Calculates the baroclinic potential vorticity.
Parameters
----------
Temperature: Numpy array or Xarray.DataArray
Temperature field in Kelvin. Their structure can be:
- 3D [z,y,x]
- 4D [t,z,y,x]
UComp: Numpy array or Xarray.DataArray
Zonal component of wind. Their structure can be:
- 3D [z,y,x]
- 4D [t,z,y,x]
VComp: Numpy array or Xarray.DataArray
Meridional component of wind. Their structure can be:
- 3D [z,y,x]
- 4D [t,z,y,x]
Lon: Numpy array
2D array with the longitudes of UComp and VComp.
If UComp and VComp are xarray.DataArray is not necessary define this parameter.
Lat: Numpy array
2D array with the latitudes of UComp and VComp.
If UComp and VComp are xarray.DataArray is not necessary define this parameter.
Levels: Numpy array
1D array with pressure levels of Temperature.
If UComp and VComp are xarray.DataArray is not necessary define this parameter.
Returns
-------
PVor: Numpy array or Xarray.DataArray
Baroclinic potential voticity [1/s].
Installation
You can install metlib on Python 2 or 3 on Linux, Windows or other using the following commands (I recommend doing it within your favorite Python environment).
From PYPI using pip (recommended method)
pip install metlib
From github
- Download ZIP (metlib-master.zip) and following commands:
unzip metlib-master.zip
cd metlib-master
python setup.py install
cd .. # it is necessary to leave the installation folder
- or also, cloning the github package:
clone https://github.com/joaohenry23/metlib.git
cd metlib
python setup.py install
cd .. # it is necessary to leave the installation folder
Check if package was installed
pip show metlib
Update to the latest version
pip install --upgrade metlib
Support
If you have any questions, do not hesitate to write to:
joaohenry23@gmail.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.