api documentation

main module

peakTree.check_part_not_reproduced(tree, spectrum)[source]

check how good the moments in the tree (only leave nodes) represent the original spectrum (i.e. if there are non-Gaussian peaks)

Parameters:
  • tree – a tree in the traversed (dict) format
  • spectrum – and the corresponding spectrum
Returns:

number of bins, where the reprocduced spectrum differs by more than 7dB

peakTree.saveVar(dataset, varData, dtype=<class 'numpy.float32'>)[source]

save an item to the dataset with data in a dict

Parameters:
  • ( (dataset) – obj:netCDF4.Dataset): netcdf4 Dataset to add to
  • dtype – datatype of the array
  • varData (dict) – data to add, for example:
Key Description
var_name name of the variable
dimension ('time', 'height')
arr data
long_name descriptive long name
optional  
comment description as a sentence
units string with units
units_html units in the html formatting
missing_value define missing value
plot_range tuple of range to plot
plot_scale “linear” or “log”
axis  
peakTree.get_git_hash()[source]
Returns:git describe string
peakTree.time_index(timestamps, sel_ts)[source]

get the index of a timestamp in the list

Parameters:
  • timestamps – array
  • sel_ts – timestamp whose index is required
peakTree.get_time_grid(timestamps, ts_range, time_interval, filter_empty=True)[source]

get the mapping from timestamp indices to gridded times eg for use in interpolation routines

https://gist.github.com/martin-rdz/b7c3b9f06bb41aeb6b2fb6c888275e26

Parameters:
  • timestamps – list of timestamps
  • ts_range – range fo the gridded timestamps
  • time_interval – interval of the gridded timestamps
  • filter_empty (bool, optional) – include the bins that are empty
Returns:

list of (timestamp_begin, timestamp_end, grid_mid, index_begin, index_end, no_indices)

peakTree.get_averaging_boundaries(array, slice_length, zero_index=0)[source]

get the left and right indices each element in an array for a given averaging slice_length

class peakTree.peakTreeBuffer(config_file='instrument_config.toml', system='Lacros')[source]

trees for a time-height chunk

Parameters:
  • config_file (string, optional) – path to the instrument config file (.toml)
  • system (string, optional) – specify the system/campaign

The attribute setting may contain

Key Description
decoupling decoupling of the crosschannel
smooth flag if smoothing should be applied
grid_time time in seconds to average the spectra
max_no_nodes number of nodes to save
thres_factor_co factor between noise_lvl and noise thres in co channel
thres_factor_cx factor between noise_lvl and noise thres in cross ch.
station_altitude height of station above msl
load(filename, load_to_ram=False)[source]

convenience fuction for loader call reads the self.loader (as specified in the instrument_config)

load_spec_file(filename, load_to_ram=False)[source]

load spectra from raw file

Parameters:filename – specify file
load_peakTree_file(filename)[source]

load preprocessed peakTree file

Parameters:filename – specify file
load_kazr_file(filename, load_to_ram=False)[source]

load a kazr file

Parameters:filename – specify file
load_newkazr_file(filename, load_to_ram=False)[source]

load a kazr file

Parameters:filename – specify file
load_rpgbinary_spec(filename, load_to_ram=False)[source]

load the rpg binary (.LV0) file directly; requires rpgpy

Parameters:
  • filename – path to file
  • load_to_ram (optional False) –
2022-07-25: reimplemented the polarimetry based on sldr_bulk_revised-seeding_case.ipynb
and the communication with A. Myagkov

developed with rpgpy version 0.10.2

load_rpgpy_spec(filename, load_to_ram=False)[source]

WIP implementation of the rpgpy spectra format

See https://github.com/actris-cloudnet/rpgpy

preload_averaging_grid()[source]

precalculate the averaging boundaries

get_tree_at(sel_ts, sel_range, temporal_average='fromparams', roll_velocity=False, peak_finding_params={}, tail_filter=False, silent=False)[source]

get a single tree either from the spectrum directly (prior call of load_spec_file()) or from the pre-converted file (prior call of load_peakTree_file())

Parameters:
  • sel_ts (tuple or float) – either value or (index, value)
  • sel_range (tuple or float) – either value or (index, value)
  • temporal_average (optional) – average over the interval (tuple of bin in time dimension or ‘fromparams’ or False)
  • roll_velocity (optional) – shift the x rightmost bins to the left
  • peak_finding_params (optional) –
  • silent – verbose output

‘vel_smooth’: convolution with given array ‘prom_thres’: prominence threshold in dB

Returns:dictionary with all nodes and the parameters of each node
assemble_time_height(outdir, fname_system=False)[source]

convert a whole spectra file to the peakTree node file

Parameters:outdir – directory for the output

print_tree

output of visualized trees as text, plots and schematic graphs

peakTree.print_tree.coord_pattern_child(p)[source]

the coordinate pattern required for filtering the dictionary for children for use in iterchilds()

Parameters:p – coordinate of parent
Returns:function that thest if a coordinate is a child of p
peakTree.print_tree.iterchilds(travtree, parentcoord)[source]

generator that yields all childs of a parent with given coordinats for use in iternodes()

peakTree.print_tree.iternodes(travtree)[source]

generator that yields a full traversal of the tree

peakTree.print_tree.travtree2text(travtree, show_coordinates=True)[source]

returns a string with the tabular representation of the traversed tree

Parameters:
  • travtree – traversed tree
  • show_coordinates (optional) – include the coordinates
Returns:

string with line breaks

peakTree.print_tree.gen_lines_to_par(travtree)[source]

get all the connection lines between the nodes of travtree

Returns:list of coordinate pairs [(v,z), ..]
peakTree.print_tree.plot_spectrum(travtree, spectrum, savepath)[source]

plot the spectrum together with the traversed tree

Parameters:
  • travtree – traversed tree
  • spectrum – spectrum dict
  • savepath – either None or string
Returns:

fig, ax

peakTree.print_tree.dot_format(travtree, display='table')[source]

generate a string for the graphviz dot format

Parameters:
  • travtree – traversed tree
  • display – either table or bounds
Returns:

a graphvis compatible definition string

peakTree.print_tree.vis_tree(dot)[source]

visualize the dot string

peakTree.print_tree.format_for_json(elem)[source]

json elementwise formatter

peakTree.print_tree.d3_format(travtree)[source]

format the traversed tree in a json compatible manner

helpers

Collection of common helper functions.

peakTree.helpers.list_of_elem(elem, length)[source]

return a list of given length of given elements

peakTree.helpers.epoch_to_timestamp(time_raw)[source]

converts raw time (days since year 0) to unix timestamp

peakTree.helpers.dt_to_ts(dt)[source]

convert a datetime to unix timestamp

peakTree.helpers.ts_to_dt(ts)[source]

convert a unix timestamp to datetime

peakTree.helpers.masked_to_plain(array)[source]

unpack the masked array into plain versions

peakTree.helpers.divide_bounds(bounds)[source]

divide_bounds([[10,20],[20,25],[25,30],[40,50]]) => noise_sep [[10, 30], [40, 50]], internal [20, 25]

peakTree.helpers.lin2z[source]

calculate dB values from a array of linear

peakTree.helpers.z2lin[source]

calculate linear values from a array of dBs

peakTree.helpers.fill_with(array, mask, fill)[source]

fill array with fill value where mask is True

peakTree.helpers.round_odd(f)[source]

round to odd number :param f: float number to be rounded to odd number

peakTree.helpers.flatten(xs)[source]

flatten inhomogeneous deep lists e.g. [[1,2,3],4,5,[6,[7,8],9],10]

peakTree.helpers.filter_none_rec(e)[source]

filter None values from nested list

peakTree.helpers.gauss_func[source]

calculate the gaussian function on a given grid :param x: grid :type x: array :param m: mean :type m: float :param sd: standard deviation :type sd: float

Returns:array
peakTree.helpers.gauss_func_offset[source]

x, H, A, x0, sigma

peakTree.helpers.estimate_noise[source]

Noise estimate based on Hildebrand and Sekhon (1974)

peakTree.helpers.estimate_noise_array(spectra_array)[source]

Wrapper for estimate_noise, to apply to a chunk of Doppler spectra :param spectra_array: 3D array of Doppler spectra :type spectra_array: ndarray

Returns:mean noise for each time-height