lib_delay_model module

Library for calculating delays using polynomial models.

Known issues

(!) Delays currently computed w.r.t. the first station, they should computed w.r.t. the center of the Earth instead.

TO DO

Compute absolute delays instead of relative to reference station.
lib_delay_model.apply_offset_coefficients_poly(poly_found, seconds_from_ref)[source]
Apply offset to polynomial, i.e. given a list of polynomial coefficients [p0,p1,p2,...]

from low to high order for f(x), obtain coefficientes for f(x+s) where s is an offset:

q(x)=p(x+s)=p0+p1(x+s)+p2(x+s)^2+p3(x+s)^3+...

The functions returns the list of polynomial coefficients [q0,q1,q2,...] for q(x).

poly_found : list of float
list of polynomial coefficients [p0,p1,p2,...] (LIMIT_POLY_EVAL coefficients).
seconds_from_ref : float
offset in seconds.
poly_found : list of int
list of polynomial coefficients [q0,q1,p2,...] (LIMIT_POLY_FOUND coefficients).
seconds_from_ref : 0
(since this offset has been applied to the polynomial).

Configuration:

LIMIT_POLY_EVAL: maximum order coefficient in input. (e.g.: 5).
LIMIT_POLY_FOUND: maximum order coefficient in output (e.g.: 2).
lib_delay_model.compute_initial_delays(params_array_delay_model, params_array_stations, s_st, s_so, s_delay, mjd_start, seconds_ref_in, tot_steps, step_seconds, seconds_offset=0, v=1, file_ini='')[source]

Main script for computing the initial delays and delay polynomials.

params_array_delay_model : list
information from delay model ini file (see lib_ini_files.py).
params_array_stations : list
information from stations ini file (see lib_ini_files.py).
s_st
configparser handler for stations ini.
s_so
configparser handler for sources ini.
s_delay
configparser handler for delays ini.
mjd_start
MJD for the start of the scan.
seconds_ref_in
seconds for the start of the scan.
tot_steps
number of accumulation periods.
step_seconds
accumulation period duration [s].
seconds_offset
[should be 0, consider removing]
v
verbose if 1.
file_ini
delays.ini output filename.
s_delay
configparser handler to delays.ini output filename.

TO DO:

Check seconds_offset, remove.
lib_delay_model.create_sections_config_delays(s_delay, s_st, s_so)[source]

Add sections to the delay ini file handler.

s_delay
configparser handler for the delays ini file.
s_st
configparser handler for the station ini file.
s_so
configparser handler for the sources ini file.
s_delay : configparserhandler
updated version of input.
pairs_vv : list of str
list with headers, to be accessed using the station and source ids.
lib_delay_model.filter_roots(roots)[source]

Return the real positive smallest delay from a list of complex. To be called after np_roots(pol).

roots : list of complex
roots of a delay polynomial.
min_val : float
result.
lib_delay_model.get_all_polynomials(params_array_delay_model, params_array_stations, s_st, s_so, mjd_start, seconds_ref, seconds_offset, tot_steps, step_seconds, v=0)[source]

Read and pre-process the delay polynomials from the models in the ini files.

params_array_delay_model : list
list with configuration of delay_mode.ini.
params_array_stations : list
list with configuration of stations.ini.
s_st : configparser handler
configparser handler for the station ini file.
s_so : configparser handler
configparser handler for the sources ini file.
mjd_start
MJD for the start of the scan.
seconds_ref
seconds for the start of the scan.
seconds_offset
offset seconds from the start of the scan.
tot_steps
number of accumulation periods.
step_seconds
accumulation period duration.
v
verbose if 1.
seconds_inc_v : 3D list (tot_steps x sources x stations)
offset in seconds since scan start.
max_saved : 2D list (tot_steps x sources)
maximum delay for all stations.
min_saved : 2D list (tot_steps x sources)
minimum delay for all stations.
v_delays : 3D list (tot_steps x sources x stations)
delays in seconds.
v_delay_rates : 3D list (tot_steps x sources x stations)
lists with [poly_delay,seconds_from_ref,poly_station_clock, seconds_diff_clock,result_dr,result_cr,section_in_model] from get_polynomials_interval().
no_offset_total : int
number of times that manual offsets have been applied (based on .ini).

TO DO:

Check seconds_offset.
lib_delay_model.get_delay_shift_frac(delay, fs, data_type=0)[source]

Compute integer and fractional shift.

delay : float
value for the delay [s].
fs : float
sampling frequency [Hz].
data_type : int
0 for real, 1 for complex.
shift_int : int
offset in number of samples.
fractional_sample_delay : float
fractional sample.
Data type is for being used with complex samples unpacked as a list of integers (in msvf),
otherwise it should be left as zero.
lib_delay_model.get_delay_val(clock_diff, poly_diff, seconds_ref_clock, seconds_ref_poly, seconds, seconds_offset, v=0, diff_pol=1)[source]

Compute delays at seconds_offset+seconds, considering the offsets for each polynomial (seconds_ref_clock and seconds_ref_poly).

clock_diff : list of float
polynomial for station clock delay.
poly_diff : list of float
polynomial for geometric model delay.
seconds_ref_clock : float
offset for the station clock polynomial.
seconds_ref_poly : float
offset for the geometric model polynomial.
seconds : float 1D np.array
seconds (for evaluating polys).
seconds_offset : float
offset to be applied to seconds.
v : int
verbose if 1.
diff_pol : int
1 if using differential polynomials.
r_recalc : float 1D np.array
delays in seconds (model+clock)
m_delay : float 1D np.array
delays in seconds (model)
c_delay : float 1D np.array
delays in seconds (clock)
rate_mc : list of int
[0]
acce_mc : list of int
[0]

Assumptions:

If the four first elements of poly_diff are zero the resulting model delay is zero to avoid calling polyval.


Notes:

simple offset reduces the computation of the offset to only the first value in the timescale provided in seconds.
No correction for retarded baselines.


TO DO:

This needs further work.
Remove rate_mc and acce_mc, no longer used.
Check diff_pol, different behavior ini_exper and lib_fx...
lib_delay_model.get_full_frac_val(r_recalc, fs, diff_frac=0, bypass_correction=0)[source]

Compute total offset in number of samples, and also fractional sample correction.

r_recalc : float
delay.
fs : float
sampling frequency.
diff_frac : 0
[unused] 0 by default.
bypass_correction : int
if 0: corrects the fractional sample correction to be between -0.5 and +0.5.
if 1: returns the fractional sample correction between 0 and 1.
full_fractional_recalc : float
total offset in number of samples, including fractional part.
fractional_recalc : float
fractional sample correction.
Bypass correction used in get_frac_over for simplicity.
lib_delay_model.get_initial_abe(poly_delay, seconds_ref_poly, seconds_offset=0)[source]

Compute delay due to aberration.

lib_delay_model.get_poly_clock(params_array, section_str)[source]

Get list with poly from params array and section string. Clock correction.

params_array : list
information from delay model ini file (see lib_ini_files.py).
section_str : str
section of the ini file associated with a certain station, source and time (see const_ini_files.py)
poly_model : list of float
list of [m-th coeff] with polynomial coefficients for the station clock model with m from zero to max_order-1, in seconds.
lib_delay_model.get_poly_list(params_array, section_str)[source]

Get list with poly from params array and section string.

params_array : list
information from delay model ini file (see lib_ini_files.py).
section_str : str
section of the ini file associated with a certain station, source and time (see const_ini_files.py)
poly_model : list of float
list of [n-th coeff] with polynomial coefficients for the delay model with n from zero to max_order, in seconds.

Configuration (constants):

LIMIT_POLY_EVAL: [2 by default] maximum order coefficient of the polynomial.


Notes:

Coefficients in the delay model ini file are in microseconds, output polynomials in seconds.
lib_delay_model.get_polynomials_interval(params_array_delay_model, params_array_stations, mjd, seconds_ref, seconds_from_ref, source_id, station_id, v, current_offset=0)[source]
Get the polynomials for the delay and clock models for a given station, source and time:
-day: MJD. -seconds: seconds_ref+seconds_from_ref.
params_array_delay_model : list
information from delay model ini file (see lib_ini_files.py).
params_array_stations : list
information from stations ini file (see lib_ini_files.py).
mjd : int
MJD for the start of the scan.
seconds_ref : int or float
seconds for the start of the scan.
seconds_from_ref : int or float
offset seconds from the start of the scan.
source_id : int
source id.
station_id : int
station id.
v : int
verbose if 1.
result : float
delay [s].
poly_found
polynomial (see get_poly_list() for format).
seconds_from_ref
[check this]
poly_station_clock
polynomial for the station clock.
seconds_diff_clock
seconds between the epoch and the start of the clock.
result_dr
geometric delay [s].
result_cr
station clock delay [s].
error_model : { 0, None}
0 if success, None if error.
section_in_model : str
section in the delay model .ini file (for debugging).
no_offset : int
0 if no offset applied from .ini file [default], 1 otherwise.

Limitations:

Currently single source source_id=0.


Notes:

It returns delay from model ini file.
If no model is available returns None.
Clock polynomial always zero offset with respect to start time, thus no need to offset (unless delta from start).


TO DO:

Organize.
Further testing on precision.
lib_delay_model.get_str_scf(val, tot_dec_pos=16)[source]

Get string representation of float, used for normalization.

lib_delay_model.np_polyder(pol, x, o)[source]

Get derivative of order o at x. Numpy polyval, changing order of polynomial (numpy is decreasing order).

See np_polyval() for more info.

lib_delay_model.np_polyval(pol, x)[source]

Evaluate a polynomial at x. Numpy polyval, changing order of polynomial (numpy is decreasing order).

pol : list of floats
polynomial, leftmost term is zero order.
x : float
value to be evaluated.
out : float
result.
-For numpy polyval the rightmost term is zero order.
(!) –Excerpt from the reference– “Notes:Horner’s scheme [R65] is used to evaluate the polynomial.
Even so, for polynomials of high degree the values may be inaccurate due to rounding errors.
Use carefully.”
lib_delay_model.np_roots(pol)[source]

Get roots of a polynomial. Numpy roots, changing order.

pol : list of floats
polynomial, leftmost term is zero order.
out : list of complex
roots of the polynomial.
lib_delay_model.print_delays(sti, poly_total, poly_clock, t0, t_display=None, v=1)[source]

Print delay information in [us] for debugging.

sti : int
station id.
poly_total : list of floats
polynomial for total delay (leftmost is zero order).
poly_clock : list of floats
polynomial for clock (leftmost is zero order).
t0 : float
time to evaluate polynomials at.
t_display : float
time to be displayed.
v : int
verbose mode if 1.
str_out : str
line with delay information.
lib_delay_model.print_delays_header(v=1)[source]

Print header for summary of delay information.

v : int
verbose mode if 1.
str_out : str
line with header.
lib_delay_model.set_config_delay(s_delay, st_so, seconds_i, a_delay, r_delay, f_delay, poly_diff, clock_diff, clock_abs, seconds_from_ref, seconds_diff_clock, m_delay, c_delay, delta_reference_delay, section_in_model)[source]

Save configuration parameters to delay ini file handler.

s_delay : configparser handler
configparser handler for the delays ini file (to be written).
st_so : str
station - source.
seconds_i : int or float
seconds for the start of this interval since the start of the scan.
a_delay : float
absolute delay [s].
r_delay : float
relative delay (w.r.t. reference station) [s]
f_delay : float
[unused?]
poly_diff : list of float
polynomial for geometric delay.
clock_diff : list of float
polynomial for station clock delay.
clock_abs : float
[unused?] initially for ref station clock.
seconds_from_ref : float
[same as seconds_i ?]
seconds_diff_clock : float
seconds from epoch for the clock (zero if offset).
m_delay : float
geometric-model-only delay.
c_delay : float
clock-only delay.
delta_reference_delay
[unused?]
section_in_model : str
section in delay model (for debugging).
s_delay : configparser handler
updated version of input with added information.