peakTree extension

peakTree Setup

Optionally, for faster reading (building the trees from the netcdf file) a cython extension can be used. This extension has to be complied:

python3 setup.py build_ext --inplace

Load and plot

Loading the data works similar to the standard larda, only the third dimension of the data_container is a dict of nodes instead a further array dimension. To plot these data into a time height crosssection, a parameter (reflectivity, velocity, width, …) and a node index have to be choosen.

larda=pyLARDA.LARDA().connect('lacros_dacapo')

begin_dt = datetime.datetime(2019, 2, 19, 4, 0)
end_dt = datetime.datetime(2019, 2, 19, 5, 30)
trees=larda.read("peakTree", "tree", [begin_dt, end_dt], [0, 10000])

# the tree_to_timeheight selects a 2d array from the ['time', 'range', 'dict'] data container
# here just the total number of nodes is returned
no_nodes = pyLARDA.peakTree.tree_to_timeheight(trees, 'no_nodes')
no_nodes['name'] = 'no. nodes'
no_nodes['var_unit'] = ''
# plot_no_nodes provides a wrapper with special colormaps
fig, ax = pyLARDA.peakTree.plot_no_nodes(no_nodes, fig_size=[13, 5.7])
fig.savefig("{}_no_nodes.png".format(begin_dt.strftime("%Y%m%d-%H%M")), dpi=250)

# plot Reflectivity of node 0
z_node0 = pyLARDA.peakTree.tree_to_timeheight(trees, 'z', sel_node=0)
z_node0['name'] = 'Reflectivity'
z_node0['var_unit'] = 'dBZ'
fig, ax = Transf.plot_timeheight(z_node0, fig_size=[13, 5.7])
fig.savefig("{}_Z_node0.png".format(begin_dt.strftime("%Y%m%d-%H%M")), dpi=250)

select nodes based on rule

Special features can easily be detected by selection rules. An example is already provided with pyLARDA.peakTree.select_liquid_node(). The found index is returned as a 2d array inside a data container.

# select the indices by a rule
# here: node['z'] < -20 and abs(node['v']) < 0.3
selected_index = pyLARDA.peakTree.select_liquid_node(trees)

# plot the selected index
fig, ax = pyLARDA.peakTree.plot_sel_index(selected_index, fig_size=[13, 5.7])
fig.savefig("{}_ind_node_liq_wide.png".format(begin_dt.strftime("%Y%m%d-%H%M")), dpi=250)

# extract a 2d array of the parameters
liquid_z = pyLARDA.peakTree.tree_to_timeheight(trees, 'z', sel_node=selected_index['var'])
liquid_z['name'] = 'Reflectivity'
liquid_z['var_unit'] = 'dBZ'

# and plot
fig, ax = Transf.plot_timeheight(liquid_z, fig_size=[13, 5.7])
fig.savefig("{}_Z_liq_wide.png".format(begin_dt.strftime("%Y%m%d-%H%M")), dpi=250)

Standalone

The pyLARDA.peakTree module can be used without the main part of pyLARDA, when loading the file manually. For convenience one might add the pyLARDA.Transformations.

import pyLARDA.peakTree
import pyLARDA.helpers as h
import pyLARDA.Transformations as Transf

# configuration which is normally provided by the
# connector/toml file
paraminfo = {'time_variable': "timestamp",
            'range_variable': 'range',
            'time_conversion': "unix",
            'range_conversion': "none",
            'var_conversion': 'none',
            'system': "peaktree_peako",
            'var_unit': "tree",
            'rg_unit': "m",
            'paramkey': "trees",
            'colormap': "gist",
            'var_lims': [-99, -99],
            'altitude': 181,
            'ncreader': 'peakTree'}

rdr = pyLARDA.peakTree.peakTree_reader(paraminfo)
filename = "../20140202_1600_kazrbaeccpeako_peakTree.nc4"

trees = rdr(filename, [begin_dt, end_dt], [200, 3000])
# trees is then the standard data_container of dim ['time', 'range', 'dict']

doc-strings

pyLARDA.peakTree.build_tree_py(data, ldr_avail)[source]

pure python/numpy version of the build tree function (slower than the compiled cython version)

Indices in the stacked data array:

0: 'parent', 1: 'Z', 2: 'v',
3: 'width', 4: 'skew', 5: 'threshold',
6: 'prominence', 7: 'bound_l', 8: 'bound_r',
optional
9: 'LDR', 10: 'ldrmax'
pyLARDA.peakTree.array_to_tree_py(data, ldr_avail)[source]

convert the array from the netcdf to var of data container pure python/numpy version (slower than the compiled cython version)

pyLARDA.peakTree.peakTree_reader(paraminfo)[source]

build a function for reading the peakTree data (setup by connector)

pyLARDA.peakTree.tree_to_timeheight(data_cont, param, sel_node=0, **kwargs)[source]

convert the tree data container to a normal time-height data container by extracting a node and a parameter

Parameters:
  • data_cont (dict) – data container

  • param (str) – parameter to select, eg z, v

  • sel_node (np.array or int, optional) – integer or array of index to select

  • **kwargs

Returns:

data container of dimension ['time', 'range']

pyLARDA.peakTree.select_rimed_node(data_cont)[source]

select the rimed nodes from a peaktree data container The nodes are filtered by the rule: abs(n['v'][0]-n['v'][-1]) > 1.5

Parameters:

data_cont – peakTree data container

Returns:

data_container with selected indices in var of shape (time, range)

pyLARDA.peakTree.select_liquid_node(data_cont, **kwargs)[source]

select the liquid nodes from a peaktree data container

The nodes are filtered by the rule: n['z'] < -20 and abs(n['v']) < 0.3

Parameters:

data_cont – peakTree data container

Key word arguments:

Z_thresh, maximum Z of liquid peak (default is -20) LDR_thresh, maximum LDR of liquid peaks (LDR ignored if not given)

Returns:

data_container with selected indices in var of shape (time, range)

pyLARDA.peakTree.select_columnar_ice(data_cont, **kwargs)[source]

select columnar ice nodes from a peaktree data container

The nodes are filtered by the rule: n['z'] < -10 and n['ldr'] >= -20

Parameters:

data_cont – peakTree data container

Key word arguments:

Z_thresh, maximum Z of columnar ice peak (default is -10) LDR_thresh, minimum LDR of columnar ice peaks

Returns:

data_container with selected indices in var of shape (time, range)

pyLARDA.peakTree.select_frozen_drops(data_cont, vel=-1.8, prom=2)[source]

select the fastest-falling ice nodes from a peaktree data container node index = 1 or 3 minimum prominence: 2 dB velocity >= 1.8 m/s

Parameters:

data_cont – peakTree data container

Returns:

data_container with selected indices in var of shape (time, range)

pyLARDA.peakTree.select_fastest_node(data_cont)[source]

select the fastest-falling nodes from a peaktree data container

Parameters:

data_cont – peakTree data container

Returns:

data_container with selected indices in var of shape (time, range)

pyLARDA.peakTree.select_large_ice(data_cont, **kwargs)[source]

select the large ice-nodes from a peaktree data container if they have high reflectivity and low LDR ! Rain must be excluded !

Parameters:

data_cont – peakTree data container

Key word arguments:

Z_thresh, minimum Z of large ice peak (default is -10) LDR_thresh, maximum LDR of large ice peaks

Returns:

data_container with selected indices in var of shape (time, range)

pyLARDA.peakTree.plot_no_nodes(data_cont, **kwargs)[source]

wrapper for pyLARDA.Transformations.plot_timeheight2 to plot the no of nodes

Parameters:
  • data (dict) – data container

  • no_peaks (bool) – no_nodes or no_peaks

  • **kwargs – piped to plot_timeheight2 function

Returns:

fig, ax

pyLARDA.peakTree.plot_sel_index(data_cont, **kwargs)[source]

wrapper for pyLARDA.Transformations.plot_timeheight2 to plot the index of selected node

Parameters:
  • data (dict) – data container

  • **kwargs – piped to plot_timeheight2 function

Returns:

fig, ax

pyLARDA.peakTree.to_text(data_cont)[source]

represent the tree as a multiline string

pyLARDA.peakTree.print_tree(data_cont)[source]

print the tree as a multi line string