Input and output (pyrad.io)

Functions to read and write data and configuration files.

Reading configuration files

read_config(fname[, cfg]) Read a pyrad config file.

Reading radar data

get_data(voltime, datatypesdescr, cfg) Reads pyrad input data.

Reading cosmo data

cosmo2radar_data(radar, cosmo_coord, cosmo_data) get the COSMO value corresponding to each radar gate using nearest neighbour interpolation
cosmo2radar_coord(radar, cosmo_coord[, …]) Given the radar coordinates find the nearest COSMO model pixel
hzt2radar_data(radar, hzt_coord, hzt_data[, …]) get the HZT value corresponding to each radar gate using nearest neighbour interpolation
hzt2radar_coord(radar, hzt_coord[, …]) Given the radar coordinates find the nearest HZT pixel
get_cosmo_fields(cosmo_data, cosmo_ind[, …]) Get the COSMO data corresponding to each radar gate using a precomputed look up table of the nearest neighbour
get_iso0_field(hzt_data, hzt_ind, z_radar[, …]) Get the height over iso0 data corresponding to each radar gate using a precomputed look up table of the nearest neighbour
read_cosmo_data(fname[, field_names, celsius]) Reads COSMO data from a netcdf file
read_cosmo_coord(fname[, zmin]) Reads COSMO coordinates from a netcdf file
read_hzt_data(fname[, chy0, chx0, read_lib]) Reads iso-0 degree data from an HZT file

Reading DEM data

dem2radar_data
dem2radar_coord
read_idrisi_data(fname, field_name[, fill_value]) Reads DEM data from an IDRISI .rst file
read_idrisi_metadata(fname) Reads DEM metadata from a IDRISI .rdc file

Reading other data

read_proc_periods(fname) Reads a file containing the start and stop times of periods to process
read_last_state(fname) Reads a file containing the date of acquisition of the last volume processed
read_status(voltime, cfg[, ind_rad]) Reads rad4alp xml status file.
read_rad4alp_cosmo(fname, datatype[, ngates]) Reads rad4alp COSMO data binary file.
read_rad4alp_vis(fname, datatype) Reads rad4alp visibility data binary file.
read_excess_gates(fname) Reads a csv files containing the position of gates exceeding a given percentile of frequency of occurrence
read_colocated_gates(fname) Reads a csv files containing the position of colocated gates
read_colocated_data(fname) Reads a csv files containing colocated data
read_timeseries(fname) Reads a time series contained in a csv file
read_ts_cum(fname) Reads a time series of precipitation accumulation contained in a csv file
read_monitoring_ts(fname[, sort_by_date]) Reads a monitoring time series contained in a csv file
read_intercomp_scores_ts(fname[, sort_by_date]) Reads a radar intercomparison scores csv file
get_sensor_data(date, datatype, cfg) Gets data from a point measurement sensor (rain gauge or disdrometer)
read_smn(fname) Reads SwissMetNet data contained in a csv file
read_smn2(fname) Reads SwissMetNet data contained in a csv file with format station,time,value
read_disdro_scattering(fname) Reads scattering parameters computed from disdrometer data contained in a text file
read_sun_hits(fname) Reads sun hits data contained in a csv file
read_sun_hits_multiple_days(cfg, time_ref[, …]) Reads sun hits data from multiple file sources
read_sun_retrieval(fname) Reads sun retrieval data contained in a csv file
read_solar_flux(fname) Reads solar flux data from the DRAO observatory in Canada
read_selfconsistency(fname) Reads a self-consistency table with Zdr, Kdp/Zh columns
read_antenna_pattern(fname[, linear, twoway]) Read antenna pattern from file
read_meteorage(fname) Reads METEORAGE lightning data contained in a text file.
read_lightning(fname[, filter_data]) Reads lightning data contained in a text file.
read_lightning_traj(fname) Reads lightning trajectory data contained in a csv file.
read_lightning_all(fname[, labels]) Reads a file containing lightning data and co-located polarimetric data.
read_trt_scores(fname) Reads the TRT scores contained in a text file.
read_trt_data(fname) Reads the TRT data contained in a text file.
read_trt_traj_data(fname) Reads the TRT cell data contained in a text file.
read_trt_thundertracking_traj_data(fname) Reads the TRT cell data contained in a text file.
read_trt_cell_lightning(fname) Reads the lightning data of a TRT cell.
read_trt_info_all(info_path) Reads all the TRT info files
read_trt_info_all2(info_path) Reads all the TRT info files
read_trt_info(fname) Reads the TRT info used for thundertracking and contained in a text file.
read_trt_info2(fname) Reads the TRT info used for thundertracking and contained in a text file.
read_thundertracking_info(fname) Reads the TRT info used for thundertracking
read_rhi_profile(fname[, labels]) Reads a monitoring time series contained in a csv file
read_histogram(fname) Reads a histogram contained in a csv file
read_quantiles(fname) Reads quantiles contained in a csv file
read_profile_ts(fname_list, labels[, hres, …]) Reads a colection of profile data file and creates a time series
read_histogram_ts(fname_list, datatype[, t_res]) Reads a colection of histogram data file and creates a time series
read_quantiles_ts(fname_list[, step, qmin, …]) Reads a colection of quantiles data file and creates a time series
read_ml_ts(fname) Reads a melting layer time series contained in a csv file
read_windmills_data(fname) Read the wind mills data csv file

Writing data

write_proc_periods(start_times, end_times, fname) writes an output file containing start and stop times of periods to process
write_ts_lightning(flashnr, time_data, …) writes the LMA sources data and the value of the colocated polarimetric variables
send_msg(sender, receiver_list, subject, fname) sends the content of a text file by email
write_alarm_msg(radar_name, param_name_unit, …) writes an alarm file
write_last_state(datetime_last, fname) writes SwissMetNet data in format datetime,avg_value, std_value
write_smn(datetime_vec, value_avg_vec, …) writes SwissMetNet data in format datetime,avg_value, std_value
write_trt_info(ids, max_rank, nscans, …) writes TRT info of the thundertracking
write_trt_thundertracking_data(traj_ID, …) writes TRT cell data of the thundertracking scan
write_trt_cell_data(traj_ID, yyyymmddHHMM, …) writes TRT cell data
write_trt_cell_scores(traj_ID, …) writes TRT cells scores
write_trt_cell_lightning(cell_ID, cell_time, …) writes the lightning data for each TRT cell
write_trt_rpc(cell_ID, cell_time, lon, lat, …) writes the rimed particles column data for a TRT cell
write_rhi_profile(hvec, data, nvalid_vec, …) writes the values of an RHI profile in a text file
write_field_coverage(quantiles, values, …) writes the quantiles of the coverage on a particular sector
write_cdf(quantiles, values, ntot, nnan, …) writes a cumulative distribution function
write_histogram(bin_edges, values, fname[, …]) writes a histogram
write_quantiles(quantiles, values, fname[, …]) writes quantiles
write_ts_polar_data(dataset, fname) writes time series of data
write_ts_grid_data(dataset, fname) writes time series of data
write_ts_cum(dataset, fname) writes time series accumulation of data
write_ts_stats(dt, value, fname[, stat]) writes time series of statistics
write_monitoring_ts(start_time, np_t, …[, …]) writes time series of data
write_excess_gates(excess_dict, fname) Writes the position and values of gates that have a frequency of occurrence higher than a particular threshold
write_intercomp_scores_ts(start_time, stats, …) writes time series of radar intercomparison scores
write_colocated_gates(coloc_gates, fname) Writes the position of gates colocated with two radars
write_colocated_data(coloc_data, fname) Writes the data of gates colocated with two radars
write_colocated_data_time_avg(coloc_data, fname) Writes the time averaged data of gates colocated with two radars
write_sun_hits(sun_hits, fname) Writes sun hits data.
write_sun_retrieval(sun_retrieval, fname) Writes sun retrieval data.
write_fixed_angle(time_data, fixed_angle, …) writes an output file with the fixed angle data

Auxiliary functions

get_rad4alp_prod_fname(datatype) Given a datatype find the corresponding start and termination of the METRANET product file name
map_hydro(hydro_data_op) maps the operational hydrometeor classification identifiers to the ones used by Py-ART
map_Doppler(Doppler_data_bin, Nyquist_vel) maps the binary METRANET Doppler data to actual Doppler velocity
get_save_dir(basepath, procname, dsname, prdname) obtains the path to a product directory and eventually creates it
make_filename(prdtype, dstype, dsname, ext_list) creates a product file name
generate_field_name_str(datatype) Generates a field name in a nice to read format.
get_fieldname_pyart(datatype) maps the config file radar data type name into the corresponding rainbow Py-ART field name
get_fieldname_cosmo(field_name) maps the Py-ART field name into the corresponding COSMO variable name
get_field_unit(datatype) Return unit of datatype.
get_file_list(datadescriptor, starttimes, …) gets the list of files with a time period
get_rad4alp_dir(basepath, voltime[, …]) gets the directory where rad4alp data is stored
get_rad4alp_grid_dir(basepath, voltime, …) gets the directory where rad4alp grid data is stored
get_trtfile_list(basepath, starttime, endtime) gets the list of TRT files with a time period
get_new_rainbow_file_name(master_fname, …) get the rainbow file name containing datatype from a master file name and data type
get_datatype_fields(datadescriptor) splits the data type descriptor and provides each individual member
get_dataset_fields(datasetdescr) splits the dataset type descriptor and provides each individual member
get_datetime(fname, datadescriptor) Given a data descriptor gets date and time from file name
find_raw_cosmo_file(voltime, datatype, cfg) Search a COSMO file in netcdf format
find_hzt_file(voltime, cfg[, ind_rad]) Search an ISO-0 degree file in HZT format
_get_datetime(fname, datagroup[, ftime_format]) Given a data group gets date and time from file name

Trajectory

Trajectory(filename[, starttime, endtime, …]) A class for reading and handling trajectory data from a file.

TimeSeries

TimeSeries(desc[, timevec, timeformat, …]) Holding timeseries data and metadata.
class pyrad.io.TimeSeries(desc, timevec=None, timeformat=None, maxlength=None, datatype='')[source]

Bases: object

Holding timeseries data and metadata.

Attributes:
description : array of str

Description of the data of the time series.

time_vector : array of datetime objects
timeformat : how to print the time (default:

‘Date, UTC [seconds since midnight]’

dataseries : List of _dataSeries object holding the

data

Methods

add_dataseries(label, unit_name, unit[, …]) Add a new data series to the timeseries object.
add_timesample(dt, values) Add a new sample to the time series.
plot(fname[, ymin, ymax]) Make a figure of a time series
plot_hist(fname[, step]) Make histograms of time series
write(fname) Write time series output
__class__

alias of builtins.type

__delattr__(name, /)

Implement delattr(self, name).

__dict__ = mappingproxy({'__module__': 'pyrad.io.timeseries', '__doc__': "\n Holding timeseries data and metadata.\n\n Attributes\n ----------\n description : array of str\n Description of the data of the time series.\n time_vector : array of datetime objects\n timeformat : how to print the time (default:\n 'Date, UTC [seconds since midnight]'\n dataseries : List of _dataSeries object holding the\n data\n\n Methods:\n --------\n add_dataseries : Add a data series to the object\n write : Write time series to a file\n plot : Plot a figure of a time series\n\n ", '__init__': <function TimeSeries.__init__>, 'add_dataseries': <function TimeSeries.add_dataseries>, 'add_timesample': <function TimeSeries.add_timesample>, 'write': <function TimeSeries.write>, 'plot': <function TimeSeries.plot>, 'plot_hist': <function TimeSeries.plot_hist>, '__dict__': <attribute '__dict__' of 'TimeSeries' objects>, '__weakref__': <attribute '__weakref__' of 'TimeSeries' objects>})
__dir__(/)

Default dir() implementation.

__eq__(value, /)

Return self==value.

__format__(format_spec, /)

Default object formatter.

__ge__(value, /)

Return self>=value.

__getattribute__(name, /)

Return getattr(self, name).

__gt__(value, /)

Return self>value.

__hash__(/)

Return hash(self).

__init__(desc, timevec=None, timeformat=None, maxlength=None, datatype='')[source]

Initalize the object.

Parameters:
desc : array of str
timevec : array of datetime
timeformat : specifies time format
maxlength : Maximal length of the time series
num_el : Number of values in the time series
__init_subclass__()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

__le__(value, /)

Return self<=value.

__lt__(value, /)

Return self<value.

__module__ = 'pyrad.io.timeseries'
__ne__(value, /)

Return self!=value.

__new__(*args, **kwargs)

Create and return a new object. See help(type) for accurate signature.

__reduce__(/)

Helper for pickle.

__reduce_ex__(protocol, /)

Helper for pickle.

__repr__(/)

Return repr(self).

__setattr__(name, value, /)

Implement setattr(self, name, value).

__sizeof__(/)

Size of object in memory, in bytes.

__str__(/)

Return str(self).

__subclasshook__()

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

__weakref__

list of weak references to the object (if defined)

add_dataseries(label, unit_name, unit, dataseries=None, plot=True, color=None, linestyle=None)[source]

Add a new data series to the timeseries object. The length of the data vector must be the same as the length of the time vector.

add_timesample(dt, values)[source]

Add a new sample to the time series.

plot(fname, ymin=None, ymax=None)[source]

Make a figure of a time series

plot_hist(fname, step=None)[source]

Make histograms of time series

write(fname)[source]

Write time series output

class pyrad.io.Trajectory(filename, starttime=None, endtime=None, trajtype='plane', flashnr=0)[source]

Bases: object

A class for reading and handling trajectory data from a file.

Attributes:
filename : str

Path and name of the trajectory definition file

starttime : datetime

Start time of trajectory processing.

endtime : datetime

End time of trajectory processing.

trajtype : str
Type of trajectory. Can be ‘plane’ or ‘lightning’
time_vector : Array of datetime objects

Array containing the trajectory time samples

wgs84_lat_deg : Array of floats

WGS84 latitude samples in radian

wgs84_lon_deg : Array of floats

WGS84 longitude samples in radian

wgs84_alt_m : Array of floats

WGS84 altitude samples in m

nsamples : int
Number of samples in the trajectory
_swiss_grid_done : Bool

Indicates that convertion to Swiss coordinates has been performed

swiss_chy, swiss_chx, swiss_chh : Array of floats

Swiss coordinates in m

radar_list : list

List of radars for which trajectories are going to be computed

flashnr : int

For ‘lightning’ only. Number of flash for which trajectory data is going to be computed. If 0 all all flashes are going to be considered.

time_in_flash : array of floats

For ‘lightning’ only. Time within flash (sec)

flashnr_vec : array of ints

For ‘lightning’ only. Flash number of each data sample

dBm : array of floats

For ‘lightning’ only. Lightning power (dBm)

Methods

add_radar(radar) Add the coordinates (WGS84 longitude, latitude and non WGS84 altitude) of a radar to the radar_list.
calculate_velocities(radar) Calculate velocities.
get_end_time() Get time of last trajectory sample.
get_samples_in_period([start, end])
get_start_time() Get time of first trajectory sample.
__class__

alias of builtins.type

__delattr__(name, /)

Implement delattr(self, name).

__dict__ = mappingproxy({'__module__': 'pyrad.io.trajectory', '__doc__': "\n A class for reading and handling trajectory data from a file.\n\n Attributes\n ----------\n filename : str\n Path and name of the trajectory definition file\n starttime : datetime\n Start time of trajectory processing.\n endtime : datetime\n End time of trajectory processing.\n trajtype : str\n Type of trajectory. Can be 'plane' or 'lightning'\n time_vector : Array of datetime objects\n Array containing the trajectory time samples\n wgs84_lat_deg : Array of floats\n WGS84 latitude samples in radian\n wgs84_lon_deg : Array of floats\n WGS84 longitude samples in radian\n wgs84_alt_m : Array of floats\n WGS84 altitude samples in m\n nsamples : int\n Number of samples in the trajectory\n _swiss_grid_done : Bool\n Indicates that convertion to Swiss coordinates has been performed\n swiss_chy, swiss_chx, swiss_chh : Array of floats\n Swiss coordinates in m\n radar_list : list\n List of radars for which trajectories are going to be computed\n flashnr : int\n For 'lightning' only. Number of flash for which trajectory data\n is going to be computed. If 0 all all flashes are going to be\n considered.\n time_in_flash : array of floats\n For 'lightning' only. Time within flash (sec)\n flashnr_vec : array of ints\n For 'lightning' only. Flash number of each data sample\n dBm : array of floats\n For 'lightning' only. Lightning power (dBm)\n\n\n Methods:\n --------\n add_radar : Add a radar\n calculate_velocities : Computes velocities\n get_start_time : Return time of first trajectory sample\n get_end_time : Return time of last trajectory sample\n get_samples_in_period : Get indices of samples within period\n _convert_traj_to_swissgrid : convert data from WGS84 to Swiss coordinates\n _read_traj : Read plane trajectory from file\n _read_traj_trt : Read TRT trajectory from file\n _read_traj_lightning : Read lightning trajectory from file\n _get_total_seconds : Get the total time of the trajectory in seconds\n\n ", '__init__': <function Trajectory.__init__>, 'add_radar': <function Trajectory.add_radar>, 'calculate_velocities': <function Trajectory.calculate_velocities>, 'get_samples_in_period': <function Trajectory.get_samples_in_period>, 'get_start_time': <function Trajectory.get_start_time>, 'get_end_time': <function Trajectory.get_end_time>, '_convert_traj_to_swissgrid': <function Trajectory._convert_traj_to_swissgrid>, '_read_traj': <function Trajectory._read_traj>, '_read_traj_lightning': <function Trajectory._read_traj_lightning>, '_read_traj_trt': <function Trajectory._read_traj_trt>, '_get_total_seconds': <function Trajectory._get_total_seconds>, '__dict__': <attribute '__dict__' of 'Trajectory' objects>, '__weakref__': <attribute '__weakref__' of 'Trajectory' objects>})
__dir__(/)

Default dir() implementation.

__eq__(value, /)

Return self==value.

__format__(format_spec, /)

Default object formatter.

__ge__(value, /)

Return self>=value.

__getattribute__(name, /)

Return getattr(self, name).

__gt__(value, /)

Return self>value.

__hash__(/)

Return hash(self).

__init__(filename, starttime=None, endtime=None, trajtype='plane', flashnr=0)[source]

Initalize the object.

Parameters:
filename : str

Filename containing the trajectory samples.

starttime : datetime

Start time of trajectory processing. If not given, use the time of the first trajectory sample.

endtime : datetime

End time of trajectory processing. If not given, use the time of the last trajectory sample.

trajtype : str

type of trajectory. Can be plane or lightning

flashnr : int

If type of trajectory is lightning, the flash number to check the trajectory. 0 means all flash numbers included

__init_subclass__()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

__le__(value, /)

Return self<=value.

__lt__(value, /)

Return self<value.

__module__ = 'pyrad.io.trajectory'
__ne__(value, /)

Return self!=value.

__new__(*args, **kwargs)

Create and return a new object. See help(type) for accurate signature.

__reduce__(/)

Helper for pickle.

__reduce_ex__(protocol, /)

Helper for pickle.

__repr__(/)

Return repr(self).

__setattr__(name, value, /)

Implement setattr(self, name, value).

__sizeof__(/)

Size of object in memory, in bytes.

__str__(/)

Return str(self).

__subclasshook__()

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

__weakref__

list of weak references to the object (if defined)

_convert_traj_to_swissgrid()[source]

Convert trajectory samples from WGS84 to Swiss CH1903 coordinates

_get_total_seconds(x)[source]

Return total seconds of timedelta object

_read_traj()[source]

Read trajectory from file

_read_traj_lightning(flashnr=0)[source]

Read trajectory from lightning file

Parameters:
flashnr : int

the flash number to keep. If 0 data from all flashes will be kept

_read_traj_trt()[source]

Read trajectory from TRT file

add_radar(radar)[source]

Add the coordinates (WGS84 longitude, latitude and non WGS84 altitude) of a radar to the radar_list.

Parameters:
radar : pyart radar object

containing the radar coordinates

calculate_velocities(radar)[source]

Calculate velocities.

get_end_time()[source]

Get time of last trajectory sample.

get_samples_in_period(start=None, end=None)[source]

” Get indices of samples of the trajectory within given time period.

get_start_time()[source]

Get time of first trajectory sample.

pyrad.io.add_field(radar_dest, radar_orig)[source]

adds the fields from orig radar into dest radar. If they are not in the same grid, interpolates them to dest grid

Parameters:
radar_dest : radar object

the destination radar

radar_orig : radar object

the radar object containing the original field

Returns:
field_dest : dict

interpolated field and metadata

pyrad.io.cosmo2radar_coord(radar, cosmo_coord, slice_xy=True, slice_z=False, field_name=None)[source]

Given the radar coordinates find the nearest COSMO model pixel

Parameters:
radar : Radar

the radar object containing the information on the position of the radar gates

cosmo_coord : dict

dictionary containing the COSMO coordinates

slice_xy : boolean

if true the horizontal plane of the COSMO field is cut to the dimensions of the radar field

slice_z : boolean

if true the vertical plane of the COSMO field is cut to the dimensions of the radar field

field_name : str

name of the field

Returns:
cosmo_ind_field : dict

dictionary containing a field of COSMO indices and metadata

pyrad.io.cosmo2radar_data(radar, cosmo_coord, cosmo_data, time_index=0, slice_xy=True, slice_z=False, field_names=['temperature'], dtype=<class 'numpy.float32'>)[source]

get the COSMO value corresponding to each radar gate using nearest neighbour interpolation

Parameters:
radar : Radar

the radar object containing the information on the position of the radar gates

cosmo_coord : dict

dictionary containing the COSMO coordinates

cosmo_data : dict

dictionary containing the COSMO data

time_index : int

index of the forecasted data

slice_xy : boolean

if true the horizontal plane of the COSMO field is cut to the dimensions of the radar field

slice_z : boolean

if true the vertical plane of the COSMO field is cut to the dimensions of the radar field

field_names : str

names of COSMO fields to convert (default temperature)

dtype : numpy data type object

the data type of the output data

Returns:
cosmo_fields : list of dict

list of dictionary with the COSMO fields and metadata

pyrad.io.find_hzt_file(voltime, cfg, ind_rad=0)[source]

Search an ISO-0 degree file in HZT format

Parameters:
voltime : datetime object

volume scan time

cfg : dictionary of dictionaries

configuration info to figure out where the data is

ind_rad : int

radar index

Returns:
fname : str

Name of HZT file if it exists. None otherwise

pyrad.io.find_raw_cosmo_file(voltime, datatype, cfg, ind_rad=0)[source]

Search a COSMO file in netcdf format

Parameters:
voltime : datetime object

volume scan time

datatype : str

type of COSMO data to look for

cfg : dictionary of dictionaries

configuration info to figure out where the data is

ind_rad : int

radar index

Returns:
fname : str

Name of COSMO file if it exists. None otherwise

pyrad.io.generate_field_name_str(datatype)[source]

Generates a field name in a nice to read format.

Parameters:
datatype : str

The data type

Returns:
field_str : str

The field name

pyrad.io.get_cosmo_fields(cosmo_data, cosmo_ind, time_index=0, field_names=['temperature'])[source]

Get the COSMO data corresponding to each radar gate using a precomputed look up table of the nearest neighbour

Parameters:
cosmo_data : dict

dictionary containing the COSMO data and metadata

cosmo_ind : dict

dictionary containing a field of COSMO indices and metadata

time_index : int

index of the forecasted data

field_names : str

names of COSMO parameters (default temperature)

Returns:
cosmo_fields : list of dict

dictionary with the COSMO fields and metadata

pyrad.io.get_data(voltime, datatypesdescr, cfg)[source]

Reads pyrad input data.

Parameters:
voltime : datetime object

volume scan time

datatypesdescr : list

list of radar field types to read. Format : [radarnr]:[datagroup]:[datatype],[dataset],[product] ‘dataset’ is only specified for data groups ‘ODIM’, ‘CFRADIAL’, ‘CFRADIAL2’, ‘CF1’, ‘ODIMPYRAD’ ‘PYRADGRID’ and ‘NETCDFSPECTRA’. ‘product’ is only specified for data groups ‘CFRADIAL’, ‘ODIMPYRAD’, ‘PYRADGRID’ and ‘NETCDFSPECTRA’ The data group specifies the type file from which data is extracted. It can be:

‘RAINBOW’: Propietary Leonardo format ‘COSMO’: COSMO model data saved in Rainbow file format ‘DEM’: Visibility data saved in Rainbow file format ‘PSR’: Reads PSR data file to extract range gate information

(Noise and transmitted power)

‘RAD4ALP’: METRANET format used for the operational MeteoSwiss

data. To find out which datatype to use to match a particular METRANET field name check the function ‘get_datatype_metranet’ in pyrad/io/io_aux.py

‘RAD4ALPCOSMO’: COSMO model data saved in a binary file format.

Used by operational MeteoSwiss radars

‘RAD4ALPDEM’: Visibility data saved in a binary format used by

operational MeteoSwiss radars

‘RAD4ALPHYDRO’: Used to read the MeteoSwiss operational

hydrometeor classification

‘RAD4ALPDOPPLER’: Used to read the MeteoSwiss operational

dealiased Doppler velocity

‘ODIM’: Generic ODIM file format. For such types ‘dataset’

specifies the directory and file name date convention. Example: ODIM:dBZ,D{%Y-%m-%d}-F{%Y%m%d%H%M%S}. To find out which datatype to use to match a particular ODIM field name check the function ‘get_datatype_odim’ in pyrad/io/io_aux.py

‘NEXRADII’: Nexrad-level II file format.

‘CFRADIAL2’: CFRADIAL2 file format. For such types ‘dataset’

specifies the directory and file name date convention. Example: ODIM:dBZ,D{%Y-%m-%d}-F{%Y%m%d%H%M%S}. To find out which datatype to use to match a particular ODIM field name check the function ‘get_datatype_odim’ in pyrad/io/io_aux.py

‘CF1’: CF1 file format. For such types ‘dataset’

specifies the directory and file name date convention. Example: ODIM:dBZ,D{%Y-%m-%d}-F{%Y%m%d%H%M%S}. To find out which datatype to use to match a particular ODIM field name check the function ‘get_datatype_odim’ in pyrad/io/io_aux.py

‘MXPOL’: MXPOL (EPFL) data written in a netcdf file

‘CFRADIAL’: CFRadial format with the naming convention and

directory structure in which Pyrad saves the data. For such datatypes ‘dataset’ specifies the directory where the dataset is stored and ‘product’ specifies the directroy where the product is stored. Example: CFRADIAL:dBZc,Att_ZPhi,SAVEVOL_dBZc

‘CFRADIALCOSMO’: COSMO data in radar coordinates in a CFRadial

file format.

‘ODIMPYRAD’: ODIM file format with the naming convention and

directory structure in which Pyrad saves the data. For such datatypes ‘dataset’ specifies the directory where the dataset is stored and ‘product’ specifies the directroy where the product is stored. Example: ODIMPYRAD:dBZc,Att_ZPhi,SAVEVOL_dBZc

‘RAD4ALPGRID’: METRANET format used for the operational MeteoSwiss

Cartesian products.

‘RAD4ALPGIF’: Format used for operational MeteoSwiss Cartesian

products stored as gif files

‘PYRADGRID’: Pyrad generated Cartesian grid products. For such

datatypes ‘dataset’ specifies the directory where the dataset is stored and ‘product’ specifies the directroy where the product is stored. Example: ODIMPYRAD:RR,RZC,SAVEVOL

‘SATGRID’: CF Netcdf from used for the MeteoSat satellite data

in the CCS4 (Radar composite) grid.

‘PSRSPECTRA’: Format used to store Rainbow power spectra

recordings.

‘NETCDFSPECTRA’: Format analogous to CFRadial and used to store

Doppler spectral

‘RAD4ALPIQ’: Format used to store rad4alp IQ data

‘RAINBOW’, ‘RAD4ALP’, ‘ODIM’ ‘CFRADIAL2’, ‘CF1’ and ‘MXPOL’ are primary data file sources and they cannot be mixed for the same radar. It is also the case for their complementary data files, i.e. ‘COSMO’ and ‘RAD4ALPCOSMO’, etc. ‘CFRADIAL’ and ‘ODIMPYRAD’ are secondary data file sources and they can be combined with any other datagroup type. For a list of accepted datatypes and how they map to the Py-ART name convention check function ‘get_field_name_pyart’ in pyrad/io/io_aux.py

cfg: dictionary of dictionaries

configuration info to figure out where the data is

Returns:
radar : Radar

radar object

pyrad.io.get_dataset_fields(datasetdescr)[source]

splits the dataset type descriptor and provides each individual member

Parameters:
datasetdescr : str

dataset type. Format : [processing level]:[dataset type]

Returns:
proclevel : str

dataset processing level

dataset : str

dataset type, i.e. dBZ, ZDR, ISO0, …

pyrad.io.get_datatype_fields(datadescriptor)[source]

splits the data type descriptor and provides each individual member

Parameters:
datadescriptor : str

radar field type. Format : [radar file type]:[datatype]

Returns:
radarnr : str

radar number, i.e. RADAR1, RADAR2, …

datagroup : str

data type group, i.e. RAINBOW, RAD4ALP, ODIM, CFRADIAL, COSMO, MXPOL …

datatype : str

data type, i.e. dBZ, ZDR, ISO0, …

dataset : str

dataset type (for saved data only)

product : str

product type (for saved data only)

pyrad.io.get_datetime(fname, datadescriptor)[source]

Given a data descriptor gets date and time from file name

Parameters:
fname : str

file name

datadescriptor : str

radar field type. Format : [radar file type]:[datatype]

Returns:
fdatetime : datetime object

date and time in file name

pyrad.io.get_field_unit(datatype)[source]

Return unit of datatype.

Parameters:
datatype : str

The data type

Returns:
unit : str

The unit

pyrad.io.get_fieldname_cosmo(field_name)[source]

maps the Py-ART field name into the corresponding COSMO variable name

Parameters:
field_name : str

Py-ART field name

Returns:
cosmo_name : str

Py-ART variable name

pyrad.io.get_fieldname_pyart(datatype)[source]

maps the config file radar data type name into the corresponding rainbow Py-ART field name

Parameters:
datatype : str

config file radar data type name

Returns:
field_name : str

Py-ART field name

pyrad.io.get_file_list(datadescriptor, starttimes, endtimes, cfg, scan=None)[source]

gets the list of files with a time period

Parameters:
datadescriptor : str

radar field type. Format : [radar file type]:[datatype]

startimes : array of datetime objects

start of time periods

endtimes : array of datetime object

end of time periods

cfg: dictionary of dictionaries

configuration info to figure out where the data is

scan : str

scan name

Returns:
filelist : list of strings

list of files within the time period

pyrad.io.get_iso0_field(hzt_data, hzt_ind, z_radar, field_name='height_over_iso0')[source]

Get the height over iso0 data corresponding to each radar gate using a precomputed look up table of the nearest neighbour

Parameters:
hzt_data : dict

dictionary containing the HZT data and metadata

hzt_ind : dict

dictionary containing a field of HZT indices and metadata

z_radar : ndarray

gates altitude [m MSL]

field_name : str

names of HZT parameters (default height_over_iso0)

Returns:
iso0_field : list of dict

dictionary with the height over iso0 field and metadata

pyrad.io.get_new_rainbow_file_name(master_fname, master_datadescriptor, datatype)[source]

get the rainbow file name containing datatype from a master file name and data type

Parameters:
master_fname : str

the master file name

master_datadescriptor : str

the master data type descriptor

datatype : str

the data type of the new file name to be created

Returns:
new_fname : str

the new file name

pyrad.io.get_rad4alp_dir(basepath, voltime, radar_name='A', radar_res='L', scan='001', path_convention='MCH')[source]

gets the directory where rad4alp data is stored

Parameters:
basepath : str

base path

voltime : datetime object

nominal time

radar_name : str

radar name (A, D, L, P, W)

radar_res : str

radar resolution (H, L)

scan : str

scan

path_convention : str

The path convention. Can be ‘LTE’, ‘MCH’ or ‘RT’

Returns:
datapath : str

The data path

basename : str

The base name. ex: PHA17213

pyrad.io.get_rad4alp_grid_dir(basepath, voltime, datatype, acronym, path_convention='MCH')[source]

gets the directory where rad4alp grid data is stored

Parameters:
basepath : str

base path

voltime : datetime object

nominal time

datatype : str

data type

acronym : str

acronym identifying the data type

path_convention : str

The path convention. Can be ‘LTE’, ‘MCH’ or ‘RT’

Returns:
datapath : str

The data path

pyrad.io.get_rad4alp_prod_fname(datatype)[source]

Given a datatype find the corresponding start and termination of the METRANET product file name

Parameters:
datatype : str

the data type

Returns:
acronym : str

The start of the METRANET file name

termination : str

The end of the METRANET file name

pyrad.io.get_save_dir(basepath, procname, dsname, prdname, timeinfo=None, timeformat='%Y-%m-%d', create_dir=True)[source]

obtains the path to a product directory and eventually creates it

Parameters:
basepath : str

product base path

procname : str

name of processing space

dsname : str

data set name

prdname : str

product name

timeinfo : datetime

time info to generate the date directory. If None there is no time format in the path

timeformat : str

Optional. The time format.

create_dir : boolean

If True creates the directory

Returns:
savedir : str

path to product

pyrad.io.get_sensor_data(date, datatype, cfg)[source]

Gets data from a point measurement sensor (rain gauge or disdrometer)

Parameters:
date : datetime object

measurement date

datatype : str

name of the data type to read

cfg : dictionary

dictionary containing sensor information

Returns:
sensordate , sensorvalue, label, period : tupple

date, value, type of sensor and measurement period

pyrad.io.get_trtfile_list(basepath, starttime, endtime)[source]

gets the list of TRT files with a time period

Parameters:
datapath : str

directory where to look for data

startime : datetime object

start of time period

endtime : datetime object

end of time period

Returns:
filelist : list of strings

list of files within the time period

pyrad.io.hzt2radar_coord(radar, hzt_coord, slice_xy=True, field_name=None)[source]

Given the radar coordinates find the nearest HZT pixel

Parameters:
radar : Radar

the radar object containing the information on the position of the radar gates

hzt_coord : dict

dictionary containing the HZT coordinates

slice_xy : boolean

if true the horizontal plane of the HZT field is cut to the dimensions of the radar field

field_name : str

name of the field

Returns:
hzt_ind_field : dict

dictionary containing a field of HZT indices and metadata

pyrad.io.hzt2radar_data(radar, hzt_coord, hzt_data, slice_xy=True, field_name='height_over_iso0')[source]

get the HZT value corresponding to each radar gate using nearest neighbour interpolation

Parameters:
radar : Radar

the radar object containing the information on the position of the radar gates

hzt_coord : dict

dictionary containing the HZT coordinates

hzt_data : dict

dictionary containing the HZT data

slice_xy : boolean

if true the horizontal plane of the COSMO field is cut to the dimensions of the radar field

field_name : str

name of HZT fields to convert (default height_over_iso0)

Returns:
hzt_fields : list of dict

list of dictionary with the HZT fields and metadata

pyrad.io.interpol_field(radar_dest, radar_orig, field_name, fill_value=None, ang_tol=0.5)[source]

interpolates field field_name contained in radar_orig to the grid in radar_dest

Parameters:
radar_dest : radar object

the destination radar

radar_orig : radar object

the radar object containing the original field

field_name: str

name of the field to interpolate

fill_value: float

The fill value

ang_tol : float

angle tolerance to determine whether the radar origin sweep is the radar destination sweep

Returns:
field_dest : dict

interpolated field and metadata

pyrad.io.make_filename(prdtype, dstype, dsname, ext_list, prdcfginfo=None, timeinfo=None, timeformat='%Y%m%d%H%M%S', runinfo=None)[source]

creates a product file name

Parameters:
timeinfo : datetime

time info to generate the date directory

prdtype : str

product type, i.e. ‘ppi’, etc.

dstype : str

data set type, i.e. ‘raw’, etc.

dsname : str

data set name

ext_list : list of str

file name extensions, i.e. ‘png’

prdcfginfo : str

Optional. string to add product configuration information, i.e. ‘el0.4’

timeformat : str

Optional. The time format

runinfo : str

Optional. Additional information about the test (e.g. ‘RUN01’, ‘TS011’)

Returns:
fname_list : list of str

list of file names (as many as extensions)

pyrad.io.map_Doppler(Doppler_data_bin, Nyquist_vel)[source]

maps the binary METRANET Doppler data to actual Doppler velocity

Parameters:
Doppler_data_bin : numpy array

The binary METRANET data

Returns:
Doppler_data : numpy array

The Doppler veloctiy in [m/s]

pyrad.io.map_hydro(hydro_data_op)[source]

maps the operational hydrometeor classification identifiers to the ones used by Py-ART

Parameters:
hydro_data_op : numpy array

The operational hydrometeor classification data

Returns:
hydro_data_py : numpy array

The pyart hydrometeor classification data

pyrad.io.read_antenna_pattern(fname, linear=False, twoway=False)[source]

Read antenna pattern from file

Parameters:
fname : str

path of the antenna pattern file

linear : boolean

if true the antenna pattern is given in linear units

twoway : boolean

if true the attenuation is two-way

Returns:
pattern : dict

dictionary with the fields angle and attenuation

pyrad.io.read_colocated_data(fname)[source]

Reads a csv files containing colocated data

Parameters:
fname : str

path of time series file

Returns:
rad1_time, rad1_ray_ind, rad1_rng_ind, rad1_ele, rad1_azi, rad1_rng,
rad1_val, rad2_time, rad2_ray_ind, rad2_rng_ind, rad2_ele, rad2_azi,
rad2_rng, rad2_val : tupple

A tupple with the data read. None otherwise

pyrad.io.read_colocated_gates(fname)[source]

Reads a csv files containing the position of colocated gates

Parameters:
fname : str

path of time series file

Returns:
rad1_ray_ind, rad1_rng_ind, rad1_ele, rad1_azi, rad1_rng,
rad2_ray_ind, rad2_rng_ind, rad2_ele, rad2_azi, rad2_rng : tupple

A tupple with the data read. None otherwise

pyrad.io.read_config(fname, cfg=None)[source]

Read a pyrad config file.

Parameters:
fname : str

Name of the configuration file to read.

cfg : dict of dicts, optional

dictionary of dictionaries containing configuration parameters where the new parameters will be placed

Returns:
cfg : dict of dicts

dictionary of dictionaries containing the configuration parameters

pyrad.io.read_cosmo_coord(fname, zmin=None)[source]

Reads COSMO coordinates from a netcdf file

Parameters:
fname : str

name of the file to read

Returns:
cosmo_coord : dictionary

dictionary with the data and metadata

pyrad.io.read_cosmo_data(fname, field_names=['temperature'], celsius=True)[source]

Reads COSMO data from a netcdf file

Parameters:
fname : str

name of the file to read

field_names : str

name of the variable to read

celsius : Boolean

if True and variable temperature converts data from Kelvin to Centigrade

Returns:
cosmo_data : dictionary

dictionary with the data and metadata

pyrad.io.read_disdro_scattering(fname)[source]

Reads scattering parameters computed from disdrometer data contained in a text file

Parameters:
fname : str

path of time series file

Returns:
date, preciptype, lwc, rr, zh, zv, zdr, ldr, ah, av, adiff, kdp, deltaco,
rhohv : tupple

The read values

pyrad.io.read_excess_gates(fname)[source]

Reads a csv files containing the position of gates exceeding a given percentile of frequency of occurrence

Parameters:
fname : str

path of time series file

Returns:
rad1_ray_ind, rad1_rng_ind, rad1_ele, rad1_azi, rad1_rng,
rad2_ray_ind, rad2_rng_ind, rad2_ele, rad2_azi, rad2_rng : tupple

A tupple with the data read. None otherwise

pyrad.io.read_histogram(fname)[source]

Reads a histogram contained in a csv file

Parameters:
fname : str

path of time series file

Returns:
hist , bin_edges : tupple

The read data. None otherwise

pyrad.io.read_histogram_ts(fname_list, datatype, t_res=300.0)[source]

Reads a colection of histogram data file and creates a time series

Parameters:
fname_list : str

list of files to read

datatype : str

The data type (dBZ, ZDR, etc.)

t_res : float

time resolution [s]. If None the time resolution is taken as the median

Returns:
tbin_edges, bin_edges, data_ma, datetime_arr : tupple

The read data. None otherwise

pyrad.io.read_hzt_data(fname, chy0=255.0, chx0=-160.0, read_lib='C')[source]

Reads iso-0 degree data from an HZT file

Parameters:
fname : str

name of the file to read

chy0, chx0: float

south west point of grid in Swiss coordinates [km]

read_lib : str

Type of METRANET read library used. Can be ‘C’ or ‘python’

Returns:
hzt_data : dictionary

dictionary with the data and metadata

pyrad.io.read_idrisi_data(fname, field_name, fill_value=-99.0)[source]

Reads DEM data from an IDRISI .rst file

Parameters:
fname : str

name of the file to read

field_name : str

name of the readed variable

fill_value : float

The fill value

Returns:
dem_data : dictionary

dictionary with the data and metadata

pyrad.io.read_idrisi_metadata(fname)[source]

Reads DEM metadata from a IDRISI .rdc file

Parameters:
fname : str

name of the file to read

Returns:
metadata : dictionary

dictionary with the metadata

pyrad.io.read_intercomp_scores_ts(fname, sort_by_date=False)[source]

Reads a radar intercomparison scores csv file

Parameters:
fname : str

path of time series file

sort_by_date : bool

if True, the read data is sorted by date prior to exit

Returns:
date_vec, np_vec, meanbias_vec, medianbias_vec, quant25bias_vec,
quant75bias_vec, modebias_vec, corr_vec, slope_vec, intercep_vec,
intercep_slope1_vec : tupple

The read data. None otherwise

pyrad.io.read_last_state(fname)[source]

Reads a file containing the date of acquisition of the last volume processed

Parameters:
fname : str

name of the file to read

Returns:
last_state : datetime object

the date

pyrad.io.read_lightning(fname, filter_data=True)[source]

Reads lightning data contained in a text file. The file has the following fields:

flashnr: (0 is for noise) UTC seconds of the day Time within flash (in seconds) Latitude (decimal degrees) Longitude (decimal degrees) Altitude (m MSL) Power (dBm)
Parameters:
fname : str

path of time series file

filter_data : Boolean

if True filter noise (flashnr = 0)

Returns:
flashnr, time_data, time_in_flash, lat, lon, alt, dBm : tupple

A tupple containing the read values. None otherwise

pyrad.io.read_lightning_all(fname, labels=['hydro [-]', 'KDPc [deg/Km]', 'dBZc [dBZ]', 'RhoHVc [-]', 'TEMP [deg C]', 'ZDRc [dB]'])[source]

Reads a file containing lightning data and co-located polarimetric data. fields:

flashnr time data Time within flash (in seconds) Latitude (decimal degrees) Longitude (decimal degrees) Altitude (m MSL) Power (dBm) Polarimetric values at flash position
Parameters:
fname : str

path of time series file

labels : list of str

The polarimetric variables labels

Returns:
flashnr, time_data, time_in_flash, lat, lon, alt, dBm,
pol_vals_dict : tupple

A tupple containing the read values. None otherwise

pyrad.io.read_lightning_traj(fname)[source]

Reads lightning trajectory data contained in a csv file. The file has the following fields:

Date UTC [seconds since midnight] # Flash Flash Power (dBm) Value at flash Mean value in a 3x3x3 polar box Min value in a 3x3x3 polar box Max value in a 3x3x3 polar box # valid values in the polar box
Parameters:
fname : str

path of time series file

Returns:
time_flash, flashnr, dBm, val_at_flash, val_mean, val_min, val_max,
nval : tupple

A tupple containing the read values. None otherwise

pyrad.io.read_meteorage(fname)[source]

Reads METEORAGE lightning data contained in a text file. The file has the following fields:

date: date + time + time zone lon: longitude [degree] lat: latitude [degree] intens: amplitude [kilo amperes] ns: number of strokes of the flash mode: kind of localization [0,15] intra: 1 = intra-cloud , 0 = cloud-to-ground ax: length of the semi-major axis of the ellipse [km] ki2: standard deviation on the localization computation (Ki^2) ecc: eccentricity (major-axis / minor-axis) incl: ellipse inclination (angle with respect to the North, +90° is

East) [degrees]

sind: stroke index within the flash

Parameters:
fname : str

path of time series file

Returns:
stroke_time, lon, lat, intens, ns, mode, intra, ax, ki2, ecc, incl,
sind : tupple

A tupple containing the read values. None otherwise

pyrad.io.read_ml_ts(fname)[source]

Reads a melting layer time series contained in a csv file

Parameters:
fname : str

path of time series file

Returns:
dt_ml, ml_top_avg, ml_top_std, thick_avg, thick_std, nrays_valid,
nrays_total : tupple

The read data. None otherwise

pyrad.io.read_monitoring_ts(fname, sort_by_date=False)[source]

Reads a monitoring time series contained in a csv file

Parameters:
fname : str

path of time series file

sort_by_date : bool

if True, the read data is sorted by date prior to exit

Returns:
date , np_t, central_quantile, low_quantile, high_quantile : tupple

The read data. None otherwise

pyrad.io.read_proc_periods(fname)[source]

Reads a file containing the start and stop times of periods to process

Parameters:
fname : str

name of the file to read

Returns:
starttimes, endtimes : array of datetime objects or None

The start and end times of the periods to process if the reading has been successful

pyrad.io.read_profile_ts(fname_list, labels, hres=None, label_nr=0, t_res=300.0)[source]

Reads a colection of profile data file and creates a time series

Parameters:
fname_list : str

list of files to read

labels : list of str

The data labels

hres : float

Height resolution

label_nr : int

the label nr of the data that will be used in the time series

t_res : float

time resolution [s]. If None the time resolution is taken as the median

Returns:
tbin_edges, hbin_edges, np_ma, data_ma, datetime_arr : tupple

The read data. None otherwise

pyrad.io.read_quantiles(fname)[source]

Reads quantiles contained in a csv file

Parameters:
fname : str

path of time series file

Returns:
quantiles, values : tupple

The read data. None otherwise

pyrad.io.read_quantiles_ts(fname_list, step=5.0, qmin=0.0, qmax=100.0, t_res=300.0)[source]

Reads a colection of quantiles data file and creates a time series

Parameters:
fname_list : str

list of files to read

step, qmin, qmax : float

The minimum, maximum and step quantiles

t_res : float

time resolution [s]. If None the time resolution is taken as the median

Returns:
tbin_edges, qbin_edges, data_ma, datetime_arr : tupple

The read data. None otherwise

pyrad.io.read_rad4alp_cosmo(fname, datatype, ngates=0)[source]

Reads rad4alp COSMO data binary file.

Parameters:
fname : str

name of the file to read

datatype : str

name of the data type

ngates : int

maximum number of range gates per ray. If larger than 0 the radar field will be cut accordingly.

Returns:
field : dictionary

The data field

pyrad.io.read_rad4alp_vis(fname, datatype)[source]

Reads rad4alp visibility data binary file.

Parameters:
fname : str

name of the file to read

datatype : str

name of the data type

Returns:
field_list : list of dictionaries

A data field. Each element of the list corresponds to one elevation

pyrad.io.read_rhi_profile(fname, labels=['50.0-percentile', '25.0-percentile', '75.0-percentile'])[source]

Reads a monitoring time series contained in a csv file

Parameters:
fname : str

path of time series file

labels : list of str

The data labels

Returns:
height, np_t, vals : tupple

The read data. None otherwise

pyrad.io.read_selfconsistency(fname)[source]

Reads a self-consistency table with Zdr, Kdp/Zh columns

Parameters:
fname : str

path of time series file

Returns:
zdr, kdpzh : arrays

The read values

pyrad.io.read_smn(fname)[source]

Reads SwissMetNet data contained in a csv file

Parameters:
fname : str

path of time series file

Returns:
smn_id, date , pressure, temp, rh, precip, wspeed, wdir : tupple

The read values

pyrad.io.read_smn2(fname)[source]

Reads SwissMetNet data contained in a csv file with format station,time,value

Parameters:
fname : str

path of time series file

Returns:
smn_id, date , value : tupple

The read values

pyrad.io.read_solar_flux(fname)[source]

Reads solar flux data from the DRAO observatory in Canada

Parameters:
fname : str

path of time series file

Returns:
flux_datetime : datetime array

the date and time of the solar flux retrievals

flux_value : array

the observed solar flux

pyrad.io.read_status(voltime, cfg, ind_rad=0)[source]

Reads rad4alp xml status file.

Parameters:
voltime : datetime object

volume scan time

cfg: dictionary of dictionaries

configuration info to figure out where the data is

ind_rad: int

radar index

Returns:
root : root element object

The information contained in the status file

pyrad.io.read_sun_hits(fname)[source]

Reads sun hits data contained in a csv file

Parameters:
fname : str

path of time series file

Returns:
date, ray, nrng, rad_el, rad_az, sun_el, sun_az, ph, ph_std, nph, nvalh,
pv, pv_std, npv, nvalv, zdr, zdr_std, nzdr, nvalzdr : tupple

Each parameter is an array containing a time series of information on a variable

pyrad.io.read_sun_hits_multiple_days(cfg, time_ref, nfiles=1)[source]

Reads sun hits data from multiple file sources

Parameters:
cfg : dict

dictionary with configuration data to find out the right file

time_ref : datetime object

reference time

nfiles : int

number of files to read

Returns:
date, ray, nrng, rad_el, rad_az, sun_el, sun_az, ph, ph_std, nph, nvalh,
pv, pv_std, npv, nvalv, zdr, zdr_std, nzdr, nvalzdr : tupple

Each parameter is an array containing a time series of information on a variable

pyrad.io.read_sun_retrieval(fname)[source]

Reads sun retrieval data contained in a csv file

Parameters:
fname : str

path of time series file

Returns:
first_hit_time, last_hit_time, nhits_h, el_width_h, az_width_h, el_bias_h,
az_bias_h, dBm_sun_est, std_dBm_sun_est, sf_h,
nhits_v, el_width_v, az_width_v, el_bias_v, az_bias_v, dBmv_sun_est,
std_dBmv_sun_est, sf_v,
nhits_zdr, zdr_sun_est, std_zdr_sun_est,
sf_ref, ref_time : tupple

Each parameter is an array containing a time series of information on a variable

pyrad.io.read_thundertracking_info(fname)[source]

Reads the TRT info used for thundertracking

Parameters:
fname : str

Name of the file containing the info

Returns:
A tupple containing the read values. None otherwise. The read values are
id, max_rank, nscans_Xband, time_start, time_end
pyrad.io.read_timeseries(fname)[source]

Reads a time series contained in a csv file

Parameters:
fname : str

path of time series file

Returns:
date , value : tupple

A datetime object array containing the time and a numpy masked array containing the value. None otherwise

pyrad.io.read_trt_cell_lightning(fname)[source]

Reads the lightning data of a TRT cell. The file has the following fields:

traj_ID yyyymmddHHMM lon lat area RANKr nflashes flash_dens
Parameters:
fname : str

path of the TRT data file

Returns:
A tupple containing the read values. None otherwise
pyrad.io.read_trt_data(fname)[source]

Reads the TRT data contained in a text file. The file has the following fields:

traj_ID yyyymmddHHMM

Description of ellipsis: lon [deg] lat [deg] ell_L [km] long ell_S [km] short ell_or [deg] orientation area [km2]

Cell speed: vel_x [km/h] vel_y [km/h] det [dBZ]: detection threshold RANKr from 0 to 40 (int)

Lightning information: CG- number (int) CG+ number (int) CG number (int) %CG+ [%]

Echo top information: ET45 [km] echotop 45 max ET45m [km] echotop 45 median ET15 [km] echotop 15 max ET15m [km] echotop 15 median

VIL and max echo: VIL [kg/m2] vertical integrated liquid content maxH [km] height of maximum reflectivity (maximum on the cell) maxHm [km] height of maximum reflectivity (median per cell)

POH [%] RANK (deprecated)

standard deviation of the current time step cell velocity respect to the previous time: Dvel_x [km/h] Dvel_y [km/h]

cell_contour_lon-lat

Parameters:
fname : str

path of the TRT data file

Returns:
A tupple containing the read values. None otherwise
pyrad.io.read_trt_info(fname)[source]

Reads the TRT info used for thundertracking and contained in a text file.

Parameters:
fname : str

path of the TRT info file

Returns:
A tupple containing the read values. None otherwise. The read values are
trt_time, id, rank, nscans, azi, rng, lat, lon, ell_l, ell_s, ell_or,
vel_x, vel_y, det
pyrad.io.read_trt_info2(fname)[source]

Reads the TRT info used for thundertracking and contained in a text file.

Parameters:
fname : str

path of the TRT info file

Returns:
A tupple containing the read values. None otherwise. The read values are
trt_time, id, rank, scan_time, azi, rng, lat, lon, ell_l, ell_s, ell_or,
vel_x, vel_y, det
pyrad.io.read_trt_info_all(info_path)[source]

Reads all the TRT info files

Parameters:
info_path : str

directory where the files are stored

Returns:
A tupple containing the read values. None otherwise. The read values are
trt_time, id, rank, nscans, azi, rng, lat, lon, ell_l, ell_s, ell_or,
vel_x, vel_y, det
pyrad.io.read_trt_info_all2(info_path)[source]

Reads all the TRT info files

Parameters:
info_path : str

directory where the files are stored

Returns:
A tupple containing the read values. None otherwise. The read values are
trt_time, id, rank, scan_time, azi, rng, lat, lon, ell_l, ell_s, ell_or,
vel_x, vel_y, det
pyrad.io.read_trt_scores(fname)[source]

Reads the TRT scores contained in a text file. The file has the following fields:

traj ID max flash density time max flash density rank max flash density max rank time max rank
Parameters:
fname : str

path of the TRT data file

Returns:
A tupple containing the read values. None otherwise
pyrad.io.read_trt_thundertracking_traj_data(fname)[source]

Reads the TRT cell data contained in a text file. The file has the following fields:

traj_ID scan_ordered_time scan_time azi rng yyyymmddHHMM

lon [deg] lat [deg] ell_L [km] long ell_S [km] short ell_or [deg] orientation area [km2]

vel_x [km/h] cell speed vel_y [km/h] det [dBZ] detection threshold RANKr from 0 to 40 (int)

CG- number (int) CG+ number (int) CG number (int) %CG+ [%]

ET45 [km] echotop 45 max ET45m [km] echotop 45 median ET15 [km] echotop 15 max ET15m [km] echotop 15 median VIL [kg/m2] vertical integrated liquid content maxH [km] height of maximum reflectivity (maximum on the cell) maxHm [km] height of maximum reflectivity (median per cell) POH [%] RANK (deprecated)

Standard deviation of the current time step cell velocity respect to the previous time: Dvel_x [km/h] Dvel_y [km/h]

cell_contour_lon-lat

Parameters:
fname : str

path of the TRT data file

Returns:
A tupple containing the read values. None otherwise
pyrad.io.read_trt_traj_data(fname)[source]

Reads the TRT cell data contained in a text file. The file has the following fields:

traj_ID yyyymmddHHMM

lon [deg] lat [deg] ell_L [km] long ell_S [km] short ell_or [deg] orientation area [km2]

vel_x [km/h] cell speed vel_y [km/h] det [dBZ] detection threshold RANKr from 0 to 40 (int)

CG- number (int) CG+ number (int) CG number (int) %CG+ [%]

ET45 [km] echotop 45 max ET45m [km] echotop 45 median ET15 [km] echotop 15 max ET15m [km] echotop 15 median VIL [kg/m2] vertical integrated liquid content maxH [km] height of maximum reflectivity (maximum on the cell) maxHm [km] height of maximum reflectivity (median per cell) POH [%] RANK (deprecated)

Standard deviation of the current time step cell velocity respect to the previous time: Dvel_x [km/h] Dvel_y [km/h]

cell_contour_lon-lat

Parameters:
fname : str

path of the TRT data file

Returns:
A tupple containing the read values. None otherwise
pyrad.io.read_ts_cum(fname)[source]

Reads a time series of precipitation accumulation contained in a csv file

Parameters:
fname : str

path of time series file

Returns:
date, np_radar, radar_value, np_sensor, sensor_value : tupple

The data read

pyrad.io.read_windmills_data(fname)[source]

Read the wind mills data csv file

Parameters:
fname : str

path of the windmill data file

Returns:
windmill_dict : dict

A dictionary containing all the parameters or None

pyrad.io.send_msg(sender, receiver_list, subject, fname)[source]

sends the content of a text file by email

Parameters:
sender : str

the email address of the sender

receiver_list : list of string

list with the email addresses of the receiver

subject : str

the subject of the email

fname : str

name of the file containing the content of the email message

Returns:
fname : str

the name of the file containing the content

pyrad.io.write_alarm_msg(radar_name, param_name_unit, date_last, target, tol_abs, np_trend, value_trend, tol_trend, nevents, np_last, value_last, fname)[source]

writes an alarm file

Parameters:
radar_name : str

Name of the radar being controlled

param_name_unit : str

Parameter and units

date_last : datetime object

date of the current event

target, tol_abs : float

Target value and tolerance

np_trend : int

Total number of points in trend

value_trend, tol_trend : float

Trend value and tolerance

nevents: int

Number of events in trend

np_last : int

Number of points in the current event

value_last : float

Value of the current event

fname : str

Name of file where to store the alarm information

Returns:
fname : str

the name of the file where data has written

pyrad.io.write_cdf(quantiles, values, ntot, nnan, nclut, nblocked, nprec_filter, noutliers, ncdf, fname, use_nans=False, nan_value=0.0, filterprec=[], vismin=None, sector=None, datatype=None, timeinfo=None)[source]

writes a cumulative distribution function

Parameters:
quantiles : datetime array

array containing the measurement time

values : float array

array containing the average value

fname : float array

array containing the standard deviation

sector : str

file name where to store the data

Returns:
fname : str

the name of the file where data has written

pyrad.io.write_colocated_data(coloc_data, fname)[source]

Writes the data of gates colocated with two radars

Parameters:
coloc_data : dict

dictionary containing the colocated data parameters

fname : str

file name where to store the data

Returns:
fname : str

the name of the file where data has written

pyrad.io.write_colocated_data_time_avg(coloc_data, fname)[source]

Writes the time averaged data of gates colocated with two radars

Parameters:
coloc_data : dict

dictionary containing the colocated data parameters

fname : str

file name where to store the data

Returns:
fname : str

the name of the file where data has written

pyrad.io.write_colocated_gates(coloc_gates, fname)[source]

Writes the position of gates colocated with two radars

Parameters:
coloc_gates : dict

dictionary containing the colocated gates parameters

fname : str

file name where to store the data

Returns:
fname : str

the name of the file where data has written

pyrad.io.write_excess_gates(excess_dict, fname)[source]

Writes the position and values of gates that have a frequency of occurrence higher than a particular threshold

Parameters:
excess_dict : dict

dictionary containing the gates parameters

fname : str

file name where to store the data

Returns:
fname : str

the name of the file where data has written

pyrad.io.write_field_coverage(quantiles, values, ele_start, ele_stop, azi_start, azi_stop, threshold, nvalid_min, datatype, timeinfo, fname)[source]

writes the quantiles of the coverage on a particular sector

Parameters:
quantiles : datetime array

array containing the quantiles computed

values : float array

quantile value

ele_start, ele_stop, azi_start, azi_stop : float

The limits of the sector

threshold : float

The minimum value to consider the data valid

nvalid_min : int

the minimum number of points to consider that there are values in a ray

datatype : str

data type and units

timeinfo : datetime object

the time stamp of the data

fname : str

name of the file where to write the data

Returns:
fname : str

the name of the file where data has written

pyrad.io.write_fixed_angle(time_data, fixed_angle, rad_lat, rad_lon, rad_alt, fname)[source]

writes an output file with the fixed angle data

Parameters:
time_data : datetime object

The scan time

fixed_angle : float

The first fixed angle in the scan

rad_lat, rad_lon, rad_alt : float

Latitude, longitude [deg] and altitude [m MSL] of the radar

fname : str

The name of the file where to write

Returns:
fname : str

the name of the file containing the content

pyrad.io.write_histogram(bin_edges, values, fname, datatype='undefined', step=0)[source]

writes a histogram

Parameters:
bin_edges : float array

array containing the histogram bin edges

values : int array

array containing the number of points in each bin

fname : str

file name

datatype :str

The data type

step : str

The bin step

Returns:
fname : str

the name of the file where data has written

pyrad.io.write_intercomp_scores_ts(start_time, stats, field_name, fname, rad1_name='RADAR001', rad2_name='RADAR002', rewrite=False)[source]

writes time series of radar intercomparison scores

Parameters:
start_time : datetime object or array of date time objects

the time of the intercomparison

stats : dict

dictionary containing the statistics

field_name : str

The name of the field

fname : str

file name where to store the data

rad1_name, rad2_name : str

Name of the radars intercompared

rewrite : bool

if True a new file is created

Returns:
fname : str

the name of the file where data has written

pyrad.io.write_last_state(datetime_last, fname)[source]

writes SwissMetNet data in format datetime,avg_value, std_value

Parameters:
datetime_last : datetime object

date and time of the last state

fname : str

file name where to store the data

Returns:
fname : str

the name of the file where data has written

pyrad.io.write_monitoring_ts(start_time, np_t, values, quantiles, datatype, fname, rewrite=False)[source]

writes time series of data

Parameters:
start_time : datetime object or array of date time objects

the time of the monitoring

np_t : int or array of ints

the total number of points

values: float array with 3 elements of array of arrays

the values at certain quantiles

quantiles: float array with 3 elements

the quantiles computed

datatype : str

The data type

fname : str

file name where to store the data

rewrite : bool

if True a new file is created

Returns:
fname : str

the name of the file where data has written

pyrad.io.write_proc_periods(start_times, end_times, fname)[source]

writes an output file containing start and stop times of periods to process

Parameters:
start_times, end_times : datetime object

The starting and ending times of the periods

fname : str

The name of the file where to write

Returns:
fname : str

the name of the file containing the content

pyrad.io.write_quantiles(quantiles, values, fname, datatype='undefined')[source]

writes quantiles

Parameters:
quantiles : float array

array containing the quantiles to write

values : float array

array containing the value of each quantile

fname : str

file name

datatype :str

The data type

Returns:
fname : str

the name of the file where data has written

pyrad.io.write_rhi_profile(hvec, data, nvalid_vec, labels, fname, datatype=None, timeinfo=None, sector=None)[source]

writes the values of an RHI profile in a text file

Parameters:
hvec : float array

array containing the alitude in m MSL

data : list of float array

the quantities at each altitude

nvalid_vec : int array

number of valid data points used to compute the quantiles

labels : list of strings

label specifying the quantitites in data

fname : str

file name where to store the data

datatype : str

the data type

timeinfo : datetime object

time of the rhi profile

sector : dict

dictionary specying the sector limits

Returns:
fname : str

the name of the file where data has been written

pyrad.io.write_smn(datetime_vec, value_avg_vec, value_std_vec, fname)[source]

writes SwissMetNet data in format datetime,avg_value, std_value

Parameters:
datetime_vec : datetime array

array containing the measurement time

value_avg_vec : float array

array containing the average value

value_std_vec : float array

array containing the standard deviation

fname : str

file name where to store the data

Returns:
fname : str

the name of the file where data has written

pyrad.io.write_sun_hits(sun_hits, fname)[source]

Writes sun hits data.

Parameters:
sun_hits : dict

dictionary containing the sun hits parameters

fname : str

file name where to store the data

Returns:
fname : str

the name of the file where data has written

pyrad.io.write_sun_retrieval(sun_retrieval, fname)[source]

Writes sun retrieval data.

Parameters:
sun_retrieval : dict

dictionary containing the sun retrieval parameters

fname : str

file name where to store the data

Returns:
fname : str

the name of the file where data has written

pyrad.io.write_trt_cell_data(traj_ID, yyyymmddHHMM, lon, lat, ell_L, ell_S, ell_or, area, vel_x, vel_y, det, RANKr, CG_n, CG_p, CG, CG_percent_p, ET45, ET45m, ET15, ET15m, VIL, maxH, maxHm, POH, RANK, Dvel_x, Dvel_y, cell_contour, fname)[source]

writes TRT cell data

Parameters:
traj_ID, yyyymmddHHMM, lon, lat, ell_L, ell_S, ell_or, area,
vel_x, vel_y, det, RANKr, CG_n, CG_p, CG, CG_percent_p, ET45,
ET45m, ET15, ET15m, VIL, maxH, maxHm, POH, RANK, Dvel_x,
Dvel_y, cell_contour:

the cell parameters

fname : str

file name where to store the data

Returns:
fname : str

the name of the file where data has written

pyrad.io.write_trt_cell_lightning(cell_ID, cell_time, lon, lat, area, rank, nflash, flash_density, fname, timeformat='%Y%m%d%H%M')[source]

writes the lightning data for each TRT cell

Parameters:
cell_ID : array of ints

the cell ID

cell_time : array of datetime

the time step

lon, lat : array of floats

the latitude and longitude of the center of the cell

area : array of floats

the area of the cell

rank : array of floats

the rank of the cell

nflash : array of ints

the number of flashes/sources within the cell

flash_density : array of floats

the flash/source density

fname : str

file name where to store the data

Returns:
fname : str

the name of the file where data has written

pyrad.io.write_trt_cell_scores(traj_ID, flash_density_max_time, flash_density_max_rank, nflashes_max_list, area_flash_max_list, flash_density_max, rank_max_time, rank_max, fname)[source]

writes TRT cells scores

Parameters:
traj_ID : array of ints

The ID of the cells

flash_density_max_time : array of date times

The time at which the maximum flash density was reached for each cell

flash_density_max_rank : array of floats

The rank when the maximum flash density was reached for each cell

nflashes_max_list : array of ints

the number of flashes when the max flash density was reached

area_flash_max_list : array of floats

The area when the max flash density was reached

flash_density_max : array of floats

The maximum flash density for each cell

rank_max_time : array of datetime

the time at wich the maximum rank of each cell was reached

rank_max : array of float

the rank when the maximum rank of each cell was reached

fname : str

file name where to store the data

Returns:
fname : str

the name of the file where data has written

pyrad.io.write_trt_info(ids, max_rank, nscans, time_start, time_end, fname)[source]

writes TRT info of the thundertracking

Parameters:
ids, max_rank, nscans, time_start, time_end: array

the cell parameters

fname : str

file name where to store the data

Returns:
fname : str

the name of the file where data has written

pyrad.io.write_trt_rpc(cell_ID, cell_time, lon, lat, area, rank, hmin, hmax, freq, fname, timeformat='%Y%m%d%H%M')[source]

writes the rimed particles column data for a TRT cell

Parameters:
cell_ID : array of ints

the cell ID

cell_time : array of datetime

the time step

lon, lat : array of floats

the latitude and longitude of the center of the cell

area : array of floats

the area of the cell

rank : array of floats

the rank of the cell

hmin, hmax : array of floats

Minimum and maximum altitude of the rimed particle column

freq : array of floats

Frequency of the species constituting the rime particle column within the limits of it

fname : str

file name where to store the data

Returns:
fname : str

the name of the file where data has written

pyrad.io.write_trt_thundertracking_data(traj_ID, scan_ordered_time, scan_time, azi, rng, yyyymmddHHMM, lon, lat, ell_L, ell_S, ell_or, area, vel_x, vel_y, det, RANKr, CG_n, CG_p, CG, CG_percent_p, ET45, ET45m, ET15, ET15m, VIL, maxH, maxHm, POH, RANK, Dvel_x, Dvel_y, cell_contour, fname)[source]

writes TRT cell data of the thundertracking scan

Parameters:
traj_ID, scan_ordered_time, scan_time, azi, rng, yyyymmddHHMM, lon, lat,
ell_L, ell_S, ell_or, area, vel_x, vel_y, det, RANKr, CG_n, CG_p, CG,
CG_percent_p, ET45, ET45m, ET15, ET15m, VIL, maxH, maxHm, POH, RANK,
Dvel_x, Dvel_y, cell_contour:

the cell parameters

fname : str

file name where to store the data

Returns:
fname : str

the name of the file where data has written

pyrad.io.write_ts_cum(dataset, fname)[source]

writes time series accumulation of data

Parameters:
dataset : dict

dictionary containing the time series parameters

fname : str

file name where to store the data

Returns:
fname : str

the name of the file where data has written

pyrad.io.write_ts_grid_data(dataset, fname)[source]

writes time series of data

Parameters:
dataset : dict

dictionary containing the time series parameters

fname : str

file name where to store the data

Returns:
fname : str

the name of the file where data has written

pyrad.io.write_ts_lightning(flashnr, time_data, time_in_flash, lat, lon, alt, dBm, vals_list, fname, pol_vals_labels)[source]

writes the LMA sources data and the value of the colocated polarimetric variables

Parameters:
flashnr : int

flash number

time_data : datetime object

flash source time

time_in_flash : float

seconds since start of flash

lat, lon, alt : float

latitude, longitude [deg] and altitude [m MSL] of the flash source

dBm : float

flash power

vals_list : list of arrays

List containing the data for each polarimetric variable

fname : str

the name of the file containing the content

pol_values_labels : list of strings

List containing strings identifying each polarimetric variable

Returns:
fname : str

the name of the file containing the content

pyrad.io.write_ts_polar_data(dataset, fname)[source]

writes time series of data

Parameters:
dataset : dict

dictionary containing the time series parameters

fname : str

file name where to store the data

Returns:
fname : str

the name of the file where data has written

pyrad.io.write_ts_stats(dt, value, fname, stat='mean')[source]

writes time series of statistics

Parameters:
dt : date time array

array of time steps

value: float arrays

the average and the standard deviation of the melting layer top height

fname : str

file name where to store the data

stat : str

Statistic that is written

Returns:
fname : str

the name of the file where data has written