Package: wavebreaking
WaveBreaking - Detection, Classification and Tracking of Rossby Wave BreakingWaveBreaking is a Python package that provides detection, classification and tracking of Rossby Wave Breaking (RWB) in weather and climate data. The detection of RWB is based on analyzing the dynamical tropopause represented by a closed contour line encircling the pole as for example the 2 Potential Vorticity Units (PVU) contour line in Potential Vorticity (PV) fields. By applying three different breaking indices, regions of RWB are identified and different characteristics of the events such as area and intensity are calculated. The event tracking provides information about the temporal evolution of the RWB events. Finally, the implemented plotting methods allow for a first visualization. This tool was developed during my master studies at the University of Bern.The detection of RWB is based on applying a RWB index to the dynamical tropopause. The WaveBreaking package provides three different RWB indices:Streamer Index:The streamer index is based on work byWernli and Sprenger (2007)(andSprenger et al. 2017). Streamers are elongated structures present on the contour line that represents the dynamical tropopause. They can be described by a pair of contour points that are close together considering their geographical distance but far apart considering their distance connecting the points on the contour. Further description can be found in mymaster thesis.Overturning Index:The overturning index is based on work byBarnes and Hartmann (2012). This index identifies overturning structures of the contour line. An overturning of the contour line is present if the contour intersects at least three times with the same longitude. Further description can be found in mymaster thesis.Cutoff Index:The Cutoff Index provides information about the decaying of a wave breaking event. From a Potential Vorticity perspective, a wave breaking event is formed by an elongation of the 2 PVU contour line. These so-called streamers can elongate further until they separate from the main stratospheric or tropospheric body. The separated structure is referred to as a cutoff (Wernli and Sprenger (2007).The tool is designed to analyze gridded data provided as anxarray.DataArray. Output is provided either in ageopandas.GeoDataFrameor in anxarray.DataArray.Parts of the data setup functions and of the tracking function are based on theConTrack - Contour Trackingtool developed byDaniel Steinfeld.Important information:Free software: MIT licenseFurther documentation about the implemented methods can be found in mymaster thesis.Referencing:Please cite WaveBreaking in your publication: Kaderli, S., 2023. WaveBreaking - Detection, Classification and Tracking of Rossby Wave Breaking.https://doi.org/10.5281/zenodo.8123188If you are using the Streamer Index, please citeWernli and Sprenger (2007)(andSprenger et al. 2017).If you are using the Overturning INdex, please citeBarnes and Hartmann (2012).InstallationStable releaseTo install WaveBreaking, run this command in your terminal:pip install wavebreakingThis is the preferred method to install WaveBreaking, as it will always install the most recent stable release.
Your virtual environment is automatically checked for the necessary dependencies.
After the installation, you can start calculating RWB events by following the tutorial below.From sourcesThe sources for WaveBreaking can be downloaded in two different ways. You can either install WaveBreaking directly from the GitHub repository:pip install git+https://github.com/skaderli/WaveBreakingOr you can clone the GitHub repository first and then install WaveBreaking locally. For that, start with setting the working directory and cloning the repository.git clone https://github.com/skaderli/WaveBreaking.git
cd /path/to/local/WaveBreakingSecond, set up the conda environment and install the necessary dependencies (this may take some time):conda create -y -n wb_env
conda env update -f environment.yml -n wb_envNow activate the environment and install the WaveBreaking package locally by using the developer mode “-e”:conda activate wb_env
pip install -e .To check if the installation was successful, perform some tests:python -m unittest tests.test_wavebreakingTutorialThis tutorial shows how to calculate RWB events step by step. After successfully installing WaveBreaking, the module needs to be imported. Make sure that the Python kernel with the correct virtual environment (where WaveBreaking is installed) is running.importwavebreakingaswbMore information about the functions presented below can be found in thedocumentation.Please note that the algorithm depends on the order of the spatial dimensions. Both the longitude and latitude dimensions should be in ascending order. Although the WaveBreaking tool identifies and adjusts descending coordinates, the dataset should be checked and adapted before starting the calculation to get the best performance.Data pre-processing:Optionally, the variable intended for the RWB calculations can be smoothed. The smoothing routine applies by default a 5-point smoothing (not diagonally) with a double-weighted center and an adjustable number of smoothing passes. Since the smoothing is based on the scipy.ndimage.convolve function, array-like weights and the mode for handling boundary values can be passed as an argument. This routine returns a xarray.DataArray with the variable “smooth_<variable>”.# read dataimportxarrayasxrdemo_data=xr.open_dataset("tests/data/demo_data.nc")# smooth variable with 5 passesimportnumpyasnpsmoothed=wb.calculate_smoothed_field(data=demo_data.PV,passes=5,weights=np.array([[0,1,0],[1,2,1],[0,1,0]]),# optionalmode="wrap")# optionalThe wavebreaking module calculates the intensity for each identified event, if an intensity field is provided. In my master thesis, the intensity is represented by the momentum flux derived from the product of the (daily) zonal deviations of both wind components. The routine creates a xarray.DataArray with the variable “mflux”. More information can be found in mymaster thesis.# calculate momentum fluxmflux=wb.calculate_momentum_flux(u=demo_data.U,v=demo_data.V)Contour calculation:All RWB indices are based on a contour line representing the dynamical tropopause. The “calculate_contours()” function calculates the dynamical tropopause on the desired contour levels (commonly the 2 PVU level for Potential Vorticity). The function supports several contour levels at a time which allows for processing data of both hemispheres at the same time (e.g., contour levels -2 and 2). The contour calculation is also included in the RWB index functions and doesn’t need to be performed beforehand. However, you can also pass the contours directly to the index functions. This is especially useful if you want to perform the calculation of several indices at once.If the input field is periodic, the parameter “periodic_add” can be used to extend the field in the longitudinal direction (default 120 degrees) to correctly extract the contour at the date border. With “original_coordinates = False”, array indices are returned (used for the index calculations) instead of original coordinates. The routine returns a geopandas.GeoDataFrame with a geometry column and some properties for each contour.# calculate contourscontours=wb.calculate_contours(data=smoothed,contour_levels=[-2,2],periodic_add=120,# optionaloriginal_coordinates=True)# optionalIndex calculation:All three RWB indices perform the contour calculation before identifying the RWB events. If you pass the separately calculated contours, the contour calcultion is skipped. For the streamer index, the default parameters are taken fromWernli and Sprenger (2007)(andSprenger et al. 2017) and for the overturning index fromBarnes and Hartmann (2012). If the intensity is provided (momentum flux, see data pre-processing), it is calculated for each event. All index functions create a geopandas.GeoDataFrame with a geometry column and some properties for each event.# calculate streamersstreamers=wb.calculate_streamers(data=smoothed,contour_levels=[-2,2],contours=contours,#optionalgeo_dis=800,# optionalcont_dis=1200,# optionalintensity=mflux,# optionalperiodic_add=120)# optional# calculate overturningsoverturnings=wb.calculate_overturnings(data=smoothed,contour_levels=[-2,2],contours=contours,#optionalrange_group=5,# optionalmin_exp=5,# optionalintensity=mflux,# optionalperiodic_add=120)# optional# calculate cutoffscutoffs=wb.calculate_cutoffs(data=smoothed,contour_levels=[-2,2],contours=contours,#optionalmin_exp=5,# optionalintensity=mflux,# optionalperiodic_add=120)# optionalEvent classification:The event classification is based on selecting the events of interest from the geopandas.GeoDataFrame provided by the index calculation functions.Some suggested classifications:# stratospheric and tropospheric (only for streamers and cutoffs)stratospheric=events[events.mean_var>=contour_level]tropospheric=events[events.mean_var<contour_level]# anticyclonic and cyclonic by intensity for the Northern Hemisphereanticyclonic=events[events.intensity>=0]cyclonic=events[events.intensity<0]# anticyclonic and cyclonic by intensity for the Southern Hemisphereanticyclonic=events[events.intensity<=0]cyclonic=events[events.intensity>0]# anticyclonic and cyclonic by orientation (only for overturning events)anticyclonic=events[events.orientation=="anticyclonic"]cyclonic=events[events.orientation=="cyclonic"]In addition, a subset of events with certain characteristics can be selected, e.g. the 10% largest events:# 10 percent largest eventslarge=events[events.event_area>=events.event_area.quantile(0.9)]Transform to DataArray:To calculate and visualize the occurrence of RWB events, it comes in handy to transform the coordinates of the events into a xarray.DataArray. The “to_xarray” function flags every grid cell where an event is present with the value 1. Before the transformation, it is suggested to classify the events first and only use for example stratospheric events.# classify eventsstratospheric=streamers[streamers.mean_var.abs()>=2]# transform to xarray.DataArrayflag_array=wb.to_xarray(data=smoothed,events=stratospheric)Visualization:WaveBreaking provides two options to do a first visual analysis of the output. Both options are based on the xarray.DataArray with the flagged grid cells from the “to_xarray” function.To analyze a specific large scale situation, the RWB events on a single time steps can be plotted:# import cartopy for projectionimportcartopy.crsasccrswb.plot_step(flag_data=flag_array,step="1959-06-05T06",#index or datedata=smoothed,# optionalcontour_level=[-2,2],# optionalproj=ccrs.PlateCarree(),# optionalsize=(12,8),# optionalperiodic=True,# optionallabels=True,# optionallevels=None,# optionalcmap="Blues",# optionalcolor_events="gold",# optionaltitle="")# optionalThe analyze Rossby wave breaking from a climatological perspective, the occurrence (for specific seasons) can be plotted:wb.plot_clim(flag_data=flag_array,seasons=None,# optionalproj=ccrs.PlateCarree(),# optionalsize=(12,8),# optionalsmooth_passes=0,# optionalperiodic=True,# optionallabels=True,# optionallevels=None,# optionalcmap=None,# optionaltitle="")# optionalEvent tracking:Last but not least, WaveBreaking provides a routine to track events over time. Beside the time range of the temporal tracking, two methods for defining the spatial coherence are available. Events receive the same label if they either spatially overlap (method “by_overlapping”) or if the centre of mass lies in a certain radius (method “by_radius”). Again, it is suggested to classify the events first and only use for example stratospheric events. This routine adds a column “label” to the events geopandas.GeoDataFrame.# classify eventsanticyclonic=overturnings[overturnings.orientation=="anticyclonic"]# track eventstracked=wb.event_tracking(events=anticyclonic,time_range=6,#time range for temporal tracking in hoursmethod="by_overlap",#method for tracking ["by_overlap", "by_distance"], optionalbuffer=0,# buffer in degrees for polygons overlapping, optionaloverlap=0,# minimum overlap percentage, optinaldistance=1000)# distance in km for method "by_distance"The result can be visualized by plotting the paths of the tracked events:wb.plot_tracks(data=smoothed,events=tracked,proj=ccrs.PlateCarree(),# optionalsize=(12,8),# optionalmin_path=0,# optionalplot_events=True,# optionallabels=True,# optionaltitle="")# optionalCreditsThe installation guide is to some extend based on theConTrack - Contour Trackingtool developed byDaniel Steinfeld.This package was created withCookiecutterand theaudreyr/cookiecutter-pypackageproject template.History0.3.0 (2023-05-08)Update coordinate transformation to geometry intersectionsUpdate date handling from string to numpy.datetime64Fix problem related to parameters in degrees east/northAdd new tracking method (by_radius)Add check for too many dimensionsUpdate smoothing from wrf-python to ndimage.convolveMinor fixes0.2.0 (2023-04-27)2nd pre-releaseadd support of several contour levelsadd support for both hemispheresminor fixes0.1.0 (2023-04-24)Pre-release on GitHub.