Data container and transformations

Data container format

The connector provides the data loaded from the netcdf file as a data contianer (plain python dict with a specific set of keys). As a rule of thumb the pyLARDA.NcReader() returns the variable in linear units, the time as unix timestamp and the range in m. Following keys are currently specified:

Key

Example

ts

numpy.array containing unix timestamps

rg

numpy.array containing ranges (optional)

vel

velocity (of Doppler spectrum, optional)

dimlabel

eg ['time'], ['time', 'range'], ['time', 'range', 'vel']

var

the actual data as numpy.array

mask

a bool mask numpy.array for the data

paraminfo

the info dict derived for the parameter config file (do not mutate)

filename

the source file

rg_unit

unit for the range

var_unit

unit for the variable

var_lims

limits for the plot

colormap

colormap to use

plot_varconverter

meta

dict of meta data read with the meta.* tags

var_definition

(opt) dict definition of the variable (e.g. cloudnet class flags)

Transformations

Transformations operate on a single or several data container(s).

Hint

As a rule of thumb, transformations either return a data container or a plot.

Interpolation

# get a data_container
MIRA_Zg = larda.read("MIRA","Zg", [dt_begin, dt_end], [0, 4000])
# plot it
fig, ax = pyLARDA.Transformations.plot_timeheight(
    MIRA_Zg, range_interval=[500, 3000], z_converter='lin2z')
fig.savefig('MIRA_Z.png', dpi=250)

# or for interpolation
interpolated_container = pyLARDA.Transformations.interpolate2d(MIRA_Zg, new_time=array)
interpolated_container = pyLARDA.Transformations.interpolate2d(MIRA_Zg, new_range=array)

h.pprint(MIRA_Zg)

Calculations

The arrays of a data container can either be modified directly

# copy to not overwrite the values
data_new = {**data}
data_new['var'] = data['var']/15.3*20.6
# 'mask' is also just a numpy array, though with boolean values
data_new['mask'] = np.logical_or(data_new['mask'], data_new['var'] > 7)

It is recommended to use the pyLARDA.Transformations.combine() functionality, to not loose the meta-information:

def correct_Z_bias(data):
    var = data['var'] + h.z2lin(8.)
    return var, data['mask']

Z_corrected = pyLARDA.Transformations.combine(correct_Z_bias, Z, {})

Attention

Several plotting functions were refactored, consider using the new functions: pyLARDA.Transformations.plot_timeseries2(), pyLARDA.Transformations.plot_timeheight2(), pyLARDA.Transformations.plot_scatter2()

Slicing

Subsetting of a data containter is facilitated with the pyLARDA.Transformations.slice_container() function.

Conversion and output

Data containers can be easily converted into and xarray.DataArray with pyLARDA.Transformations.container2DataArray() or stored into a netcdf with pyLARDA.NcWrite.write_simple_nc().

function list

pyLARDA.Transformations.join(datadict1, datadict2)[source]

join two data containers in time domain

when you want to join more than two data containers use reduce as done in the connector

they have to be in the correct time order

Parameters:
  • datadict1 – left data container

  • datadict2 – right data container

Returns:

merged data container

pyLARDA.Transformations.interpolate1d(data, mask_thres=0.0, **kwargs)[source]

same as interpolate2d but for 1d containers (time or range dimension must be len 1)

Parameters:
  • data – larda data container to be interpolated in its 1d-dimension

  • **kwargs

  • new_time (for interpolation in time dimension) – new time vector to which data should be interpolated

  • new_range (for interpolation in range dimension) – new range vector to which data should be interpolated

Returns:

data_container

pyLARDA.Transformations.interpolate2d(data, mask_thres=0.1, **kwargs)[source]

interpolate timeheight data container

Parameters:
  • mask_thres (float, optional) – threshold for the interpolated mask

  • **new_time (np.array) – new time axis

  • **new_range (np.array) – new range axis

  • **method (str) – if not given, use scipy.interpolate.RectBivariateSpline

  • arguments (valid method) – ‘linear’ - scipy.interpolate.interp2d ‘nearest’ - scipy.interpolate.NearestNDInterpolator ‘rectbivar’ (default) - scipy.interpolate.RectBivariateSpline

Returns:

data_container

pyLARDA.Transformations.combine(func, datalist, keys_to_update, **kwargs)[source]

apply a func to the variable

Parameters:
  • func – a function that takes [datacontainer1, datacontainer2, ..] as given input (order as given in datalist) and returns var, mask

  • datalist – list of data containers or single data container

  • keys_to_update – dictionary of keys to update

Returns:

new data container

pyLARDA.Transformations.slice_container(data, value={}, index={})[source]

slice a data_container either by values or indices (or combination of both)

using on pyLARDA.helpers.argnearest()

slice_container(data, value={'time': [timestamp1], 'range': [4000, 5000]})
# or
slice_container(data, value={'time': [timestamp1, timestamp2], 'range': [4000, 5000]})
# or
slice_container(data, index={'time': [10, 20], 'range': [5, 25]})
#or
slice_container(data, value={'time': [timestamp1, timestamp2]},
                      index={'range': [5, 25]})
Parameters:
  • value (dict) – slice by value of coordinate axis

  • index (dict) – slice by index of axis

Returns:

a sliced container

pyLARDA.Transformations.select_closest(data, ts)[source]

Select closest time steps from larda container to given time steps and replaces original time steps with given ones Useful when plotting flag data, as interpolation does not work with categorical data

Parameters:
  • data – larda container

  • ts (ndarray) – array with unix time steps

Returns:

larda container with time steps closest to the given ones

pyLARDA.Transformations.plot_timeseries(data, **kwargs)[source]

plot a timeseries data container

Parameters:
  • data (dict) – data container

  • **time_interval (list dt) – constrain plot to this dt

  • **z_converter (string) – convert var before plotting use eg ‘lin2z’ or ‘log’

  • **var_converter (string) – alternate name for the z_converter

  • **figsize (list) – size of figure, default is [10, 5.7]

  • **linewidth (float) – controls the line width

  • **alpha (float) – controls transparency between [0, 1]

  • **label (string, Bool) – True, label the data automatically, otherwise use string

  • **time_diff_jumps

pyLARDA.Transformations.plot_profile(data, **kwargs)[source]

plot a profile data container

Parameters:
  • data (dict) – data container

  • **range_interval (list) – constrain plot to this ranges

  • **z_converter (string) – convert var before plotting use eg ‘lin2z’ or ‘log’

  • **var_converter (string) – alternate name for the z_converter

  • **figsize (list) – size of figure, default is [4, 5.7]

Returns:

tuple with

  • fig: matplotlib figure

  • ax: axis

pyLARDA.Transformations.plot_timeheight(data, fig=None, ax=None, **kwargs)[source]

plot a timeheight data container

Parameters:
  • data (dict) – data container

  • **time_interval (list dt) – constrain plot to this dt

  • **range_interval (list float) – constrain plot to this ranges

  • **z_converter (string) – convert var before plotting use eg ‘lin2z’ or ‘log’

  • **var_converter (string) – alternate name for the z_converter

  • **contour – add a countour

  • **figsize (list) – size of figure, default is [10, 5.7]

  • **zlim (list) – set vmin and vmax of color axis

  • **title – True/False or string, True will auto-generate title

  • **rg_converter – True/false, True will convert from “m” to “km”

  • **time_diff_jumps – default is 60

  • **fig – add to an existing figure

  • **ax – add to an existing axis

  • **cbar – removes cbar if False

  • **mask

Returns:

tuple with

  • fig: matplotlib figure

  • ax: axis

pyLARDA.Transformations.plot_barbs_timeheight(u_wind, v_wind, *args, **kwargs)[source]

barb plot for plotting of horizontal wind vector

Parameters:
  • u_wind (dict) – u component of horizontal wind, m/s

  • v_wind (dict) – v component of horizontal wind, m/s

  • args

  • *sounding_data – data container (dict) Wyoming radiosounding, m/s

  • **range_interval – range interval to be plotted

  • **figsize – size of png (default is [10, 5.7])

  • **all_data – True/False, default is False (plot only every third height bin)

  • **z_lim – min/max velocity for plot (default is 0, 25 m/s)

  • **labelsize – size of the axis labels (default 12)

  • **barb_length – length of the barb (default 5)

  • **flip_barb – bool to flip the barb for the SH (default is false (=NH))

  • **fig – existing matplotlib figure

  • **ax – existing matplotlib axis

Returns:

tuple with

  • fig: matplotlib figure

  • ax: axis

pyLARDA.Transformations.plot_scatter(data_container1, data_container2, identity_line=True, **kwargs)[source]

scatter plot for variable comparison between two devices or variables

Parameters:
  • data_container1 (dict) – container 1st device

  • data_container2 (dict) – container 2nd device

  • x_lim (list) – limits of var used for x axis

  • y_lim (list) – limits of var used for y axis

  • c_lim (list) – limits of var used for color axis

  • **identity_line (bool) – plot 1:1 line if True

  • **z_converter (string) – convert var before plotting use eg ‘lin2z’

  • **var_converter (string) – alternate name for the z_converter

  • **custom_offset_lines (float) – plot 4 extra lines for given distance

  • **info (bool) – print slope, interception point and R^2 value

  • **figsize (list) – size of the figure in inches

  • **font_size (int) – default: 15

  • **font_weight (int) – default: semibold

  • **colorbar (bool) – if True, add a colorbar to the scatterplot

  • **color_by (dict) – data container 3rd device

  • **scale (string) – ‘lin’ or ‘log’ –> if you get a ValueError from matplotlib.colors try setting scale to lin, log does not work for negative values!

  • **cmap (string) – colormap

  • **formstring (string) – format string to use as key word argument to fig.colorbar, overwrites the default values for ‘lin’ or ‘log’ scale. E.g. use “%.2f” for displaying two digits

  • **Nbins (int) – number of bins for histograms

Returns:

tuple with

  • fig: matplotlib figure

  • ax: axis

pyLARDA.Transformations.plot_frequency_of_occurrence(data, legend=True, **kwargs)[source]

Frequency of occurrence diagram of a variable (number of occurrence for each range bin). x-axis is separated into n bins, default value for n = 100.

Parameters:
  • data (dict) – container of Ze values

  • **n_bins (integer) – number of bins for reflectivity values (x-axis), default 100

  • **x_lim (list) – limits of x-axis, default: data[‘var_lims’]

  • **y_lim (list) – limits of y-axis, default: minimum and maximum of data[‘rg’]

  • **z_converter (string) – convert var before plotting use eg ‘lin2z’

  • **var_converter (string) – alternate name for the z_converter

  • **range_offset (list) – range values where chirp shift occurs

  • **sensitivity_limit (np.array) – 1-Dim array containing the minimum sensitivity values for each range

  • **title (string) – plot title string if given, otherwise not title

  • **legend (bool) – prints legend, default True

Returns:

tuple with

  • fig: matplotlib figure

  • ax: axis

pyLARDA.Transformations.plot_foo_general(data_1, data_2, legend=True, **kwargs)[source]

Frequency of occurrence diagram of a variable (number of occurrence binned by another variable). x-axis is separated into n bins, default value for n = 100.

Parameters:
  • data_1 (dict) – container of e.g. Ze values

  • data_2 (dict) – container of e.g. velocity values

  • **x_bins (integer) – number of bins for dataset 2 values (x-axis), default 100

  • **y_bins (integer) – number of bins for dataset 1 values (y-axis), default 100

  • **x_lim (list) – limits of x-axis, default: data_2[‘var_lims’]

  • **y_lim (list) – limits of y-axis, default: data_1[‘var_lims’]

  • **z_converter (string) – convert var before plotting use eg ‘lin2z’

  • **var_converter (string) – alternate name for the z_converter

  • **range_offset (list) – range values where chirp shift occurs

  • **sensitivity_limit (np.array) – 1-Dim array containing the minimum sensitivity values for each range

  • **title (string) – plot title string if given, otherwise not title

  • **legend (bool) – prints legend, default True

Returns:

tuple with

  • fig: matplotlib figure

  • ax: axis

pyLARDA.Transformations.plot_spectra(data, *args, **kwargs)[source]

Finds the closest match to a given point in time and height and plot Doppler spectra.

Notes

The user is able to provide sliced containers, e.g.

  • one spectrum: data['dimlabel'] = ['vel']

  • range spectrogram: data['dimlabel'] = ['range', 'vel']

  • time spectrogram: data['dimlabel'] = ['time, 'vel']

  • time-range spectrogram: data['dimlabel'] = ['time, 'range', 'vel']

Parameters:
  • data (dict) – data container

  • *data2 (dict or numpy.ndarray) – data container of a second device

  • **z_converter (string) – convert var before plotting use eg ‘lin2z’

  • **var_converter (string) – alternate name for the z_converter

  • **velmin (float) – minimum x axis value

  • **velmax (float) – maximum x axis value

  • **vmin (float) – minimum y axis value

  • **vmax (float) – maximum y axis value

  • **save (string) – location where to save the pngs

  • **figsize (list) – size of png, default is [10, 5.7]

  • **mean (float) – numpy array dimensions (time, height, 2) containing mean noise level for each spectra in linear units [mm6/m3]

  • **thresh (float) – numpy array dimensions (time, height, 2) containing noise threshold for each spectra in linear units [mm6/m3]

  • **text (Bool) – should time/height info be added as text into plot?

  • **title (str or bool)

  • **smooth (bool) – if True, regular pyplot plot function is used (default is step)

  • **alpha (float) – triggers transparency of the line plot (not the bar plot), 0 <= alpha <= 1

Returns:

tuple with

  • fig (pyplot figure): contains the figure of the plot (for multiple spectra, the last fig is returned)

  • ax (pyplot axis): contains the axis of the plot (for multiple spectra, the last ax is returned)

pyLARDA.Transformations.plot_spectrogram(data, **kwargs)[source]

Plot a time or height spectrogram

The user is able to provide sliced containers, e.g.

  • range spectrogram: data['dimlabel'] = ['range', 'vel']

  • time spectrogram: data['dimlabel'] = ['time, 'vel']

  • time-range spectrogram: data['dimlabel'] = ['time, 'range', 'vel']

In the latter case, a height or time (value or index) must be provided at which the time / height spectrogram should be drawn

Parameters:
  • data – data container

  • **index (dict) – either {‘time’: time index} or {‘range’: range index}

  • **z_converter (string) – convert var before plotting use eg ‘lin2z’

  • **var_converter (string) – alternate name for the z_converter

  • **figsize (list) – size of png, default is [10, 5.7]

  • **v_lims (list) – limits of Doppler velocity to be plotted

Returns:

tuple with

  • fig (pyplot figure): contains the figure of the plot

  • ax (pyplot axis): contains the axis of the plot

pyLARDA.Transformations.concat_images(imga, imgb)[source]

Combines two color image ndarrays side-by-side.

pyLARDA.Transformations.concat_n_images(image_path_list)[source]

Combines N color images from a list of image path.

pyLARDA.Transformations.plot_ppi(data, azimuth, **kwargs)[source]

plot a mira plan-position-indicator scan

Parameters:
  • data (dict) – data_container holding the variable of the scan (Z, v, ..)

  • azimuth (dict) – data_container with the azimuth data

  • **z_converter (string) – convert var before plotting use eg ‘lin2z’

  • **var_converter (string) – alternate name for the z_converter

  • **elv (float) – elevation other than 75 deg

  • **figsize (list) – size of png, default is [10, 5.7]

Returns:

tuple with

  • fig: matplotlib figure

  • ax: axis

pyLARDA.Transformations.plot_rhi(data, elv, **kwargs)[source]

plot a mira range-height-indicator scan

Parameters:
  • data (dict) – data_container holding the variable of the scan (Z, LDR, ..)

  • elv (dict) – data_container with the elevation data

  • **z_converter (string) – convert var before plotting use eg ‘lin2z’

  • **var_converter (string) – alternate name for the z_converter

  • **figsize (list) – size of png, default is [10, 5.7]

  • **title (str or bool)

Returns:

tuple with

  • fig: matplotlib figure

  • ax: axis

pyLARDA.Transformations.remsens_limrad_quicklooks(container_dict, **kwargs)[source]

plot the daily overview for the standard radar moments

Content of container_dict: Ze, VEL, sw, ldr, LWP, rr optional: SurfTemp, SurfWS

Parameters:
  • container_dict (dict) – data container

  • **plot_range (list) – plot base and top in m

  • **timespan (str) – 24h for daily plot

  • **mask_jumps (bool) – mask gaps due to scans

Returns:

tuple with

  • fig: matplotlib figure

  • ax: axis

pyLARDA.Transformations.remsens_limrad_polarimetry_quicklooks(container_dict, **kwargs)[source]

plot the daily overview for the polarimetric variables

Content of container_dict: Ze, ldr, ZDR, RHV, LWP, rr optional: SurfTemp, SurfWS

Parameters:
  • container_dict (dict) – data container

  • **plot_range (list) – plot base and top in m

  • **timespan (str) – 24h for daily plot

  • **mask_jumps (bool) – mask gaps due to scans

Returns:

tuple with

  • fig: matplotlib figure

  • ax: axis

pyLARDA.Transformations.container2DataArray(container)[source]

convert the data_container to a xarray Dataset

time dimension (named ts) is converted to datatime.datetime and to datetime64

Parameters:

data (dict) – data_container

Returns:

xarray.DataArray

pyLARDA.Transformations.roll_mean_2D(matrix, windowsize, dim)[source]

Calculate a rolling mean over a given axis of a 2D (time x range) array :param matrix: 2D (time x range) matrix :type matrix: ndarray :param windowsize: size of the moving window :type windowsize: int :param dim: over which dimension to apply the mean, ‘time’ or ‘range’ :type dim: str

Returns: 2D matrix of averaged values

pyLARDA.Transformations.plot_timeheight2(data: dict, **kwargs: dict) -> (<function figure at 0x7ff2fe36c220>, <function axis at 0x7ff2fe36ed40>)[source]

Plot a timeheight larda container or xarray Dataset

Parameters:
  • data – data container

  • **figure (optional) – already open matplotlib figure

  • **axis (optional) – already open matplotlib axis

  • **colormp (optional) – string key from matplotlib colormaps

  • **mask (optional) – additional variable mask (invalid/missing data)

  • **rg_converter (optional) – if True converting from m to km for 2D plots

  • **time_interval (optional) – restricts the xaxis for time series and 2D data

  • **range_interval (optional) – restricts the yaxis for 2D data

  • **var_lims (optional) – new data limits, default: var_lims of data

  • **fontsize (optional) – figure font size

  • **labelsize (optional) – colorbar label size

  • **fontweight (optional) – axis label font weight

  • **cbar (optional) – if False, hides the colorbar from the plot

  • **linewidth (optional) – width of time series data line plot

  • **alpha (optional) – alpha of time series data line plot

  • **zlim (optional) – if provided, these colorbar limits will get passed through

  • **var_converter (optional) – other name for variable converter string

  • **z_converter (optional) – variable converter string

  • **contour (optional) – dictionary with keys ‘data’ and ‘levels’ (optional), where data is an xarray or larda dict

  • **contour_col (optional) – string defining the color of the contour, default is ‘black’

  • **label (optional) – label name if string or autogenerated label if True, else no label

  • **clim (optional) – colorbar limits

  • **title (optional) – title string

  • **title_loc (optional) – location string for title (‘center’, ‘left’, ‘right’)

Returns:

tuple with

  • fig: matplotlib figure

  • ax: axis

pyLARDA.Transformations.plot_binaryflag(data: dict, **kwargs: dict) -> (<function figure at 0x7ff2fe36c220>, <function axis at 0x7ff2fe36ed40>)[source]

Plot a timeheight larda container or xarray Dataset

Parameters:
  • data – data container

  • **figure (optional) – already open matplotlib figure

  • **axis (optional) – already open matplotlib axis

  • **mask (optional) – additional variable mask (invalid/missing data)

  • **time_interval (optional) – restricts the xaxis for time series and 2D data

  • **var_lims (optional) – new data limits, default: var_lims of data

  • **fontsize (optional) – figure font size

  • **labelsize (optional) – colorbar label size

  • **fontweight (optional) – axis label font weight

  • **cbar (optional) – if False, hides the colorbar from the plot

  • **linewidth (optional) – width of time series data line plot

  • **alpha (optional) – alpha of time series data line plot

  • **var_converter (optional) – other name for variable converter string

  • **z_converter (optional) – variable converter string

  • **label (optional) – label name if string or autogenerated label if True, else no label

  • **clim (optional) – colorbar limits

  • **title (optional) – title string

  • **title_loc (optional) – location string for title (‘center’, ‘left’, ‘right’)

Returns:

tuple with

  • fig: matplotlib figure

  • ax: axis

pyLARDA.Transformations.plot_timeseries2(data: dict, **kwargs: dict) -> (<function figure at 0x7ff2fe36c220>, <function axis at 0x7ff2fe36ed40>)[source]

Plot a timeseries data container or xarray dataset.

Parameters:
  • data – data container

  • **figure (optional) – already open matplotlib figure

  • **axis (optional) – already open matplotlib axis

  • **colormp (optional) – string key from matplotlib colormaps

  • **mask (optional) – additional variable mask (invalid/missing data)

  • **time_interval (optional) – restricts the xaxis for time series and 2D data

  • **var_lims (optional) – new data limits, default: var_lims of data

  • **figsize (optional) – size of the figure in inches

  • **fontsize (optional) – figure font size

  • **labelsize (optional) – colorbar label size

  • **fontweight (optional) – axis label font weight

  • **cbar (optional) – if False, hides the colorbar from the plot

  • **linewidth (optional) – width of time series data line plot

  • **alpha (optional) – alpha of time series data line plot

  • **zlim (optional) – if provided, these colorbar limits will get passed through

  • **var_converter (optional) – other name for variable converter string

  • **z_converter (optional) – variable converter string

  • **contour (optional) – dictionary with keys ‘data’ and ‘levels’ (optional), where data is an xarray or larda dict

  • **label (optional) – label name if string or autogenerated label if True, else no label

  • **clim (optional) – colorbar limits

  • **title (optional) – title string

  • **title_loc (optional) – location string for title (‘center’, ‘left’, ‘right’)

  • **x_lim (optional) – x axis limit

  • **y_lim (optional) – y axis limit

Returns:

tuple with

  • fig: matplotlib figure

  • ax: axis

pyLARDA.Transformations.plot_scatter2(data1: dict, data2: dict, identity_line: bool = False, figsize: ~typing.List[float] = None, color_by: dict = None, scale: str = 'lin', Nbins: int = None, **kwargs) -> (<function figure at 0x7ff2fe36c220>, <function axis at 0x7ff2fe36ed40>)[source]

Scatter plot for variable comparison between two devices or variables.

Parameters:
  • data1 – container 1st device

  • data2 – container 2nd device

  • identity_line (optional) – plot 1:1 line if True

  • figsize (optional) – size of the figure in inches

  • color_by (optional) – data container 3rd device

  • scale (optional) – ‘lin’ or ‘log’ –> if you get a ValueError from matplotlib.colors try setting scale to lin, log does not work for negative values!

  • Nbins (optional) – number of bins for histogram

  • **figure (optional) – already open matplotlib figure

  • **axis (optional) – already open matplotlib axis

  • **colormp (optional) – string key from matplotlib colormaps

  • **mask (optional) – additional variable mask (invalid/missing data)

  • **var_lims (optional) – new data limits, default: var_lims of data

  • **fontsize (optional) – figure font size

  • **labelsize (optional) – colorbar label size

  • **fontweight (optional) – axis label font weight

  • **cbar (optional) – if False, hides the colorbar from the plot

  • **linewidth (optional) – width of time series data line plot

  • **alpha (optional) – alpha of time series data line plot

  • **zlim (optional) – if provided, these colorbar limits will get passed through

  • **var_converter (optional) – other name for variable converter string

  • **z_converter (optional) – variable converter string

  • **contour (optional) – dictionary with keys ‘data’ and ‘levels’ (optional), where data is an xarray or larda dict

  • **label (optional) – label name if string or autogenerated label if True, else no label

  • **clim (optional) – colorbar limits

  • **title (optional) – title string

  • **title_loc (optional) – location string for title (‘center’, ‘left’, ‘right’)

  • **x_lim (optional) – x axis limit

  • **y_lim (optional) – y axis limit

Returns:

tuple with

  • fig: matplotlib figure

  • ax: axis

pyLARDA.Transformations.delete_non_monotonic_elements(container)[source]

Delete non-monotonic timestamp elements from data-dict container

For some instruments (i.e. pollyxt, hatpro) there is sometimes a non-monotonic behaviour within the timestamps. This function creates a mask for all elements, where the diff of element n+1 and element n is smaller or same as Zero by using the functionality of the cumulative maximum. This mask is used to delete those elements in the array of container[‘ts’], container[‘var’] and container[‘mask’] and returns a corrected container. This ensures for example the usage of the xarray resampling function for converted pylarda dictionaries (Transformations.container2DataArray).

Parameters:

data (dict) – data_container

Returns:

corrected_data_container

private functions

pyLARDA.Transformations._add_identity(axes, *line_args, **line_kwargs)[source]

helper function for the scatter plot

Returns:

axes

pyLARDA.Transformations._new_fig(figsize: ~typing.List[float] = None, figure: ~matplotlib.pyplot.figure = None, axis: ~matplotlib.pyplot.axis = None, **kwargs) -> (<function figure at 0x7ff2fe36c220>, <function axis at 0x7ff2fe36ed40>)[source]

Opens or parses a matplotlib figure and axis.

Parameters:
  • figsize (optional) – list of figure height and width

  • figure (optional) – already open matplotlib figure

  • axis (optional) – already open matplotlib axis

Returns:

tuple with

  • fig: matplotlib figure

  • axis: axis

pyLARDA.Transformations._copy_data(data: dict, colormp: str = None, mask: array = None, rg_converter: bool = False, time_interval: List[datetime] = None, range_interval: List[float] = None, var_lims: List[float] = None, fontsize: int = 12, labelsize: int = 12, figsize: List[float] = None, fontweight: str = 'normal', cbar: bool = True, clim: List[float] = None, linewidth: int = 1.5, alpha: float = 0.95, **kwargs) dict[source]

Copy data from an xarray or larda dict to the plot data structure ‘pdata’.

Parameters:
  • data – xarray or larda dict

  • colormp (optional) – string key from matplotlib colormaps

  • mask (optional) – additional variable mask (invalid/missing data)

  • rg_converter (optional) – if True converting from m to km for 2D plots

  • time_interval (optional) – restricts the xaxis for time series and 2D data

  • range_interval (optional) – restricts the yaxis for 2D data

  • var_lims (optional) – new data limits, default: var_lims of data

  • fontsize (optional) – figure font size

  • labelsize (optional) – colorbar label size

  • figsize (optional) – figure size list of height and width

  • fontweight (optional) – axis label font weight

  • cbar (optional) – if False, hides the colorbar from the plot

  • cmap (optional) – string according to matplotlib colormap lists

  • linewidth (optional) – width of time series data line plot

  • alpha (optional) – alpha of time series data line plot

Returns:

pdata (plot data structure)

pyLARDA.Transformations._masked_jumps(pdata: dict, tdel_jumps: float = 60, tres: float = 5.0, **kwargs) -> (<class 'list'>, <function array at 0x7ff2ff80fce0>)[source]

Fills data gaps with fill_values and masks them.

Parameters:
  • pdata – plot data structure

  • tdel_jumps (optional) – time jump threshold in seconds

  • tres (optional) – target time resolution in seconds

Returns:

tuple with data corrected for gaps

  • dt (list): datetimes

  • var (np.ma.ndarray): var

pyLARDA.Transformations._get_cbar_limits(pdata: dict, is_class: bool = False, cbar_fraciton: float = 0.13, zlim: ~typing.List[float] = None, **kwargs) -> (<class 'float'>, <class 'float'>)[source]

Returns the minimum and maximum value for the colorbar.

Parameters:
  • pdata

  • is_class (optional) – if True increas colorbar portion for larger labels

  • cbar_fraciton (optional) – colorbar fraction

  • zlim (optional) – if provided, these colorbar limits will get passed through

Returns:

zlim - color bar axis limits

pyLARDA.Transformations._apply_2Dvar_converter(pdata: dict, var_converter: str = None, z_converter: str = None, **kwargs) -> (<function array at 0x7ff2ff80fce0>, <class 'matplotlib.colors.LogNorm'>)[source]

Converts a 2D numpy array for a given valid string.

Parameters:
  • pdata

  • var_converter (optional) – other name for variable converter string

  • z_converter (optional) – variable converter string

Returns:

tuple with

  • var: converted variable

  • norm: matplotlib log norm

pyLARDA.Transformations._apply_1Dvar_converter(var: array, var_converter: str = None, z_converter: str = None, **kwargs) array[source]

Converts a 1D numpy array for a given valid string.

Parameters:
  • var – 1D numpy array data

  • var_converter (optional) – other name for variable converter string

  • z_converter (optional) – variable converter string

Returns:

va - converted array

pyLARDA.Transformations._apply_log_scaling(axis: axis, var_converter: str = None, z_converter: str = None, **kwargs) array[source]

Converts the yaxis scale to log iff z_converter = ‘log’

Parameters:
  • axis – matplotlib axis

  • var_converter (optional) – other name for variable converter string

  • z_converter (optional) – variable converter string

Returns:

va - converted array

pyLARDA.Transformations._get_colormap(pdata: dict, name: str = 'colormap_name') str[source]

Parse colormap string or check for additional color maps.

Parameters:
  • pdata – plot data

  • name – key of the colormap string

Returns:

cmap - colormap string

pyLARDA.Transformations._add_contour(axis: axis, contour: dict = None, rg_converter: bool = False, fontsize: int = 12, label=True, **kwargs) axis[source]

Plots contour lines with label ontop of an existing matplotlib axis.

Parameters:
  • axis – plot axis

  • contour (optional) – dictionary with keys ‘data’ and ‘levels’ (optional), where data is an xarray or larda dict

  • rg_converter (optional) – if True convert range from meter to kilometer

  • fontsize (optional) – size of contour labels

Returns:

tuple with

  • ax: axis

  • pcont:

pyLARDA.Transformations._format_timexaxis(axis: axis, pdata: dict, **kwargs) axis[source]

Zoom to a specific time interval and format xaxis.

Parameters:
  • axis – plot axis

  • pdata – plot structure data

Returns:

axis - plot axis

pyLARDA.Transformations._set_xticks_and_xlabels(axis: axis, time_extend: timedelta) axis[source]

This function sets the ticks and labels of the x-axis (only when the x-axis is time in UTC).

Options:
  • time_extend > 7 days: major ticks every 2 day, minor ticks every 12 hours

  • 7 days > time_extend > 2 days: major ticks every day, minor ticks every 6 hours

  • 2 days > time_extend > 1 days: major ticks every 12 hours, minor ticks every 3 hours

  • 1 days > time_extend > 6 hours: major ticks every 3 hours, minor ticks every 30 minutes

  • 6 hours > time_extend > 1 hour: major ticks every hour, minor ticks every 15 minutes

  • else: major ticks every 15 minutes, minor ticks every 5 minutes

Parameters:
  • axis – axis in which the x-ticks and labels have to be set

  • time_extend – time difference of t_end - t_start (format datetime.timedelta)

Returns:

axis - axis with new ticks and labels

pyLARDA.Transformations._format_rangeyaxis(axis: axis, pdata: dict, rg_converter: bool = False, **kwargs) axis[source]

Zoom to a specific range interval and format yaxis.

Parameters:
  • axis – plot axis

  • pdata – plot structure data

  • rg_converter – if True convert range from meter to kilometer

Returns:

axis - plot axis

pyLARDA.Transformations._format_xaxis(axis: axis, pdata: dict, fontsize: int = 12, fontweight: str = 'normal', label: str = None, **kwargs) axis[source]

More general x axis formatting.

Parameters:
  • axis – plot axis

  • pdata – plot data structure

  • fontsize (optional) – size of labels

  • fontweight (optional) – weight of labels

  • label – label for xaxis

Returns:

axis - plot axis

pyLARDA.Transformations._format_yaxis(axis: axis, pdata: dict, fontsize: int = 12, fontweight: str = 'normal', label: str = None, **kwargs) axis[source]

More general y axis formatting.

Parameters:
  • axis – plot axis

  • pdata – plot data structure

  • fontsize (optional) – size of labels

  • fontweight (optional) – weight of labels

  • label – label for xaxis

Returns:

axis - plot axis

pyLARDA.Transformations._plot_line(axis: ~matplotlib.pyplot.axis, pdata: dict, label_str: str, step: bool = False, **kwargs) -> (<function axis at 0x7ff2fe36ed40>, <class 'matplotlib.lines.Line2D'>)[source]

plot a line or step

Parameters:
  • axis – plot axis

  • pdata – plot data structure

  • label_str – label of line

  • step (bool or str) – ‘pre’, ‘mid’, ‘post’, default False

Returns:

tuple with

  • ax: plot axis

  • line: Line2D

pyLARDA.Transformations._format_cbaraxis(figure: ~matplotlib.pyplot.figure, axis: ~matplotlib.pyplot.axis, pcmesh: ~matplotlib.pyplot.pcolormesh, pdata: dict, color_by: dict = None, is_scatter: bool = False, is_class: bool = False, remove: bool = False, clim: ~typing.List[float] = None, **kwargs) -> (<function axis at 0x7ff2fe36ed40>, <function colorbar at 0x7ff2fe36dc60>)[source]

Formates the colorbar.

Parameters:
  • figure – plot figure

  • axis – plot axis

  • pcmesh – colormesh plot

  • pdata – plot data structure

  • color_by (optional) – larda container

  • is_scatter (optional) – if True adapt colorbar for scatter plot

  • is_class (optional) – if True adapt colorbar with discrete labels

  • remove (optional) – if True remove colorbar

  • clim (optional) – colorbar limits

Returns:

tuple with

  • ax: plot axis

  • cbar: colorbar

pyLARDA.Transformations._axis_label_from_meta(pdata: dict, **kwargs) str[source]

Generates an automated axis label from data using system name, variable name and variable unit.

Parameters:

pdata – plot data structure

Returns:

str - axis label

pyLARDA.Transformations._format_axis(figure: ~matplotlib.pyplot.figure, axis: ~matplotlib.pyplot.axis, pcmesh: ~matplotlib.pyplot.pcolormesh, pdata: dict, pdatai: dict = None, color_by: dict = None, **kwargs) -> (<function axis at 0x7ff2fe36ed40>, <function colorbar at 0x7ff2fe36dc60>)[source]

Format all axis.

Parameters:
  • figure – plot figure

  • axis – plot axis

  • pcmesh – colormesh plot

  • pdata – plot data structure

  • pdatai (optional) – additional plot data structure, formatting scatter plots

Returns:

tuple with

  • ax: axis

  • cbar: colorbar

  • var_lims: y axis limits

pyLARDA.Transformations._set_title(axis: axis, pdata: dict, title: str = None, **kwargs) axis[source]

Set/remove or auto generate a title.

Parameters:
  • axis – plot axis

  • pdata – plot data structure

  • title (optional) – title string

  • **title_loc (optional) – where to position title (‘center’, ‘left’, ‘right’)

Returns:

axis - plot axis

pyLARDA.Transformations._get_line_label(pdata: dict, label: str = '', **kwargs) str[source]

Parse or auto generate a line label.

Parameters:
  • pdata – plot data structure

  • label (optional) – label name if string or autogenerated label if True, else no label

Returns:

string

pyLARDA.Transformations._Freedman_Diaconis(var: array, name: str = 'unknown variable', Nbins: int = None, **kwargs)[source]

Parse or calculate the optimum number of bins for a scatter plot.

Parameters:
  • var – array

  • name – variable name

  • Nbins (optional) – given number of bins

Returns:

Nbins - number of bins

References

Freedman-Diaconis rule: h=2×IQR×n−1/3. number of bins is (max−min)/h, where n is the number of observations https://stats.stackexchange.com/questions/798/calculating-optimal-number-of-bins-in-a-histogram

pyLARDA.Transformations._create_histogram(var1: array, var2: array, Nbins: int = 100, x_lim: List[float] = None, y_lim: List[float] = None, **kwargs) dict[source]

Calculates a histogram from two given arrays with same size

Parameters:
  • var1 – array xdata

  • var2 – array ydata

  • Nbins (optional) – number of bin in histogram

  • x_lim (optional) – x axis limit

  • y_lim (optional) – y axis limit

Returns:

hist - dictionary with histogram, x and y edges

pyLARDA.Transformations._color_by_3rd_variable(var1: array, var2: array, var3: array, H: dict, Nbins: int = 100, **kwargs) array[source]

Recalculates a given histogram for a given 3rd variable.

Parameters:
  • var1 – array xdata

  • var2 – array ydata

  • var3 – array zdata

  • H – given histogram dict keys = H, xedges, yedges

  • Nbins – number of bin in histogram

Returns:

hist - new histogram array

pyLARDA.Transformations._get_pcmesh_kwargs(H: array, clim: int = None, scale: str = None, cmap: str = 'viridis', **kwargs) dict[source]

Returns a dict with vmin, vmax and norm for pcolormesh plot.

Parameters:
  • H – histogram

  • clim – given limits

  • scale – scaling strategy

  • cmap – colormap

Returns:

dict - pcmesh

pyLARDA.Transformations._add_regression_info(axis: axis, pdata1: dict, pdata2: dict, info: bool = False, **kwargs) axis[source]

Add textbox with y axis intersetion, slope and r^2.

Parameters:
  • axis – plot axis

  • pdata1 – plot data structure

  • pdata2 – plot data structure

  • info

Returns:

axis - plot axis