Data¶
This module contains all the functions required for reading and writing to hdf5 data/output files. The two main hdf tables are lookup_tables and output_x. You can read more about them at Lookup Tables.
Lookup Tables¶
- exception nupyprop.data.ModelError(fnm, message='This is either an incorrectly formatted model file or file not found')¶
Exception raised for errors in the input custom model file.
- fnm -- input filename which caused the error
- message -- explanation of the error
- nupyprop.data.add_alpha(ch_lepton, material, alpha_table)¶
adds charged lepton ionization energy loss values to lookup_tables.h5
- Parameters:
ch_lepton (str) – type of charged lepton; can be tau or muon
material (str) – material of propagation for charged lepton
alpha_table (~astropy.table.Table) – ionization energy loss values Each table will need the following columns: -
energy
: Charged lepton energy, in GeV [energy
] -alpha
: Ionization energy loss value in material, in (GeV*cm^2)/g [alpha
]
- Returns:
None
- nupyprop.data.add_attributes(nu_type, ch_lepton, idepth, cross_section_model, pn_model, prop_type, stats, arg=None)¶
adds attributes to output file
- Parameters:
nu_type (str) – type of neutrino particle; can be neutrino or anti_neutrino
ch_lepton (str) – type of charged lepton; can be tau or muon
idepth (int) – depth of water layer, in km
cross_section_model (str) – neutrino cross-section model
pn_model (str) – photonuclear energy loss model
prop_type (str) – type of energy loss mechanism; can be stochastic or continuous
stats (int) – statistics or number of neutrinos injected
arg (str, optional) – additional arguments at the end of the file name. Defaults to None.
- Returns:
None
- nupyprop.data.add_beta(ch_lepton, material, beta_table)¶
adds charged lepton energy loss parameter values to lookup_tables.h5
- Parameters:
ch_lepton (str) – type of charged lepton; can be tau or muon
material (str) – material of propagation for charged lepton
beta_table (~astropy.table.Table) – energy loss parameter values Each table will need the following columns: -
energy
: Charged lepton energy, in GeV [energy
] -beta_brem_cut
: Energy loss parameter value for Bremmstrahlung in material (cut value), in cm^2/g [beta_brem_cut
] -beta_brem_total
: Energy loss parameter value for Bremmstrahlung in material (total value), in cm^2/g [beta_brem_total
] -beta_pair_cut
: Energy loss parameter value for pair-production in material (cut value), in cm^2/g [beta_pair_cut
] -beta_pair_total
: Energy loss parameter value for pair-production in material (total value), in cm^2/g [beta_pair_total
] -beta_pn_x_cut
: Energy loss parameter value in material (cut value), in cm^2/g; x is the name of the photonuclear energy loss model [beta_pn_x_cut
] -beta_pn_x_total
: Energy loss parameter value in material (total value), in cm^2/g; x is the name of the photonuclear energy loss model [beta_pn_x_total
]
- Returns:
None
- nupyprop.data.add_cdf(ch_lepton, energy, eout_list, out_file, htc_mode, bins=None, arg=None)¶
adds outgoing charged lepton energy CDF values to output file
- Parameters:
ch_lepton (str) – type of charged lepton; can be tau or muon
energy (float) – ingoing neutrino (or anti-neutrino) energy, in log_10(E/GeV)
eout_list (float) – final energy of exiting charged leptons
out_file (str) – Filename of h5 file in which the data will be stored
arg (str, optional) – additional arguments at the end of the file name. Defaults to None.
- Returns:
None
- nupyprop.data.add_clep_out(ch_lepton, energy, angle, e_out, out_file, arg=None)¶
adds outgoing charged lepton energy values to output file
- Parameters:
ch_lepton (str) – type of charged lepton; can be tau or muon
energy (float) – ingoing neutrino (or anti-neutrino) energy, in log_10(E/GeV)
angle (float) – earth emergence angle, in degrees
e_out (float) – final energy of exiting charged leptons [
lep_energy
]out_file (str) – Filename of h5 file in which the data will be stored
arg (str, optional) – additional arguments at the end of the file name. Defaults to None.
- Returns:
None
- nupyprop.data.add_ixc(part_type, ixc_table, arg)¶
adds cross-section CDF values to lookup_tables.h5
- Parameters:
part_type (str) – type of particle; can be nu for neutrinos or tau for tau leptons or muon for muons
xc_table (~astropy.table.Table) –
astropy table containing cross-section CDF values Each table will need the following columns: - if part_type=nu:
energy
: Neutrino (or anti-neutrino) energy, in GeV [energy
]y
: Inelasticity, y = (E_init-E_final)/E_initial [y
]cc_cdf_x
: Charged current cross-section CDF values for x model; x is the nameof the model [cc_cdf_x`]
nc_cdf_x
: Neutral current cross-section CDF values for x model; x is the nameof the model [
nc_cdf_x
]
- if part_type=tau or part_type=muon:
energy
: Charged lepton energy, in GeV [energy
]y
: Inelasticity, y = (E_init-E_final)/E_initial [y
]cdf_brem
: Cross-section CDF values for Bremmstrahlung in material, in cm^2 [cdf_brem`]cdf_pair
: Cross-section CDF values for pair-production in material, in cm^2 [cdf_pair`]cdf_pn_x
: Cross-section CDF values for x model in material, in cm^2/g; x is the nameof the photonuclear energy loss model [cdf_pn_x`]
arg (str) – type of neutrino for part_type=nu or the propagation material for part_type=tau and part_type=muon
- Returns:
None
- nupyprop.data.add_pexit(ch_lepton, energy, p_angle, p_noregen, p_regen, out_file, arg=None)¶
adds exit probability values to .h5 formatted output file
- Parameters:
ch_lepton (str) – type of charged lepton; can be tau or muon
energy (float) – ingoing neutrino (or anti-neutrino) energy, in log_10(E/GeV)
p_angle (float) – Earth emergence angle, in degrees [
angle
]p_noregen (float) – Exit probability value without any regeneration [
no_regen
]p_regen (float) – Exit probability value including regeneration (max. of 6 rounds of regen) [
regen
]out_file (str) – Filename of h5 file in which the data will be stored
arg (str, optional) – additional arguments at the end of the file name. Defaults to None.
- Returns:
None
- nupyprop.data.add_polarization(ch_lepton, energy, pola_angle, avg_pola, out_file, arg=None)¶
adds outgoing charged lepton average polarization to output file
- Parameters:
ch_lepton (str) – type of charged lepton; can be tau or muon
energy (float) – ingoing neutrino (or anti-neutrino) energy, in log_10(E/GeV)
pola_angle (float) – the earth emergence angle in degrees [
angle
]avg_polarization (float) – Outgoing charged lepton average polarization about z-axis [
Avg_polarization
]out_file (str) – Filename of h5 file in which the data will be stored
arg (str, optional) – additional arguments at the end of the file name. Defaults to None.
- Returns:
None
- nupyprop.data.add_trajs(type_traj, idepth, traj_table)¶
adds trajectory values to lookup_tables.h5
- Parameters:
type_traj (str) – type of trajectory; can be col (for column depth) or water (for water depth)
idepth (int) – depth of water layer, in km
traj_table (~astropy.table.Table) – astropy table containing the trajectories Each table will need the following columns: -
beta
: Earth emergence angle, in degrees [beta
] -xalong
: Distance in water, in km [xalong`] -cdalong
: Column depth at xalong, in g/cm^2 [cdalong
]
- Returns:
None
- nupyprop.data.add_xc(part_type, xc_table, arg)¶
adds cross-section values to lookup_tables.h5
- Parameters:
part_type (str) – type of particle; can be nu for neutrinos or tau for tau leptons or muon for muons
xc_table (~astropy.table.Table) –
astropy table containing cross-section values Each table will need the following columns: - if part_type=nu:
energy
: Neutrino (or anti-neutrino) energy, in GeV [energy
]sigma_cc_x
: Charged current cross-section for x model, in cm^2; x is the nameof the model [sigma_cc_x`]
sigma_nc_x
: Neutral current cross-section for x model, in cm^2; x is the nameof the model [
sigma_nc_x
]
- if part_type=tau or part_type=muon:
energy
: Charged lepton energy, in GeV [energy
]sigma_brem
: N_A/A * cross-section for bremmstrahlung in material, in cm^2/g [sigma_brem`]sigma_pair
: N_A/A * cross-section for pair production in material, in cm^2/g [sigma_pair
]sigma_pn_x
: N_A/A * cross-section for x model in material, in cm^2/g; x is the name of thephotonuclear energy loss model [
sigma_pn_x
]
arg (str) – type of neutrino for part_type=nu or the propagation material for part_type=tau and part_type=muon
- Returns:
None
- nupyprop.data.cdf_calc(energy, eout_list, bins)¶
calculates the CDF values for the exiting charged lepton
- Parameters:
energy (float) – incoming neutrino (or anti-neutrino) energy, in log_10(E/GeV)
eout_list ([list, float]) – final energy of exiting charged leptons, in log_10(E/GeV)
bins ([array, float]) – bins for computing CDF values, different for each charged lepton
Returns – ndarray of cdf values
- nupyprop.data.get_alpha(ch_lepton, material, out=False)¶
get charged lepton ionization energy loss values
- Parameters:
ch_lepton (str) – type of charged lepton; can be tau or muon
material (str) – material of propagation for charged lepton
out (bool, optional) – saves the data as an ASCII ecsv file if set to True; returns the array value if set to False. Defaults to False.
- Returns:
- None if out=True otherwise otherwise:
1D Fortran array of shape (121,) containing charged lepton ionization energy loss values in material, in (GeV*cm^2)/g
- Return type:
None/ndarray
- nupyprop.data.get_beta(ch_lepton, model, material, arg, out=False)¶
get charged lepton ionization energy loss values; works with custom PN models
- Parameters:
ch_lepton (str) – type of charged lepton; can be tau or muon
material (str) – material of propagation for charged lepton
arg (str) – type of beta parameter; can be cut or total
out (bool, optional) – saves the data as an ASCII ecsv file if set to True; returns the array value if set to False. Defaults to False.
- Returns:
- None if out=True otherwise otherwise:
2D Fortran array of shape (121,3) containing charged lepton energy loss parameter values in material, for Bremmstrahlung, pair-production and photonuclear energy loss model, in cm^2/g
- Return type:
None/ndarray
- nupyprop.data.get_cdf(nu_type, ch_lepton, energy, idepth, cross_section_model, pn_model, prop_type, stats, out=False, arg=None)¶
get charged lepton outgoing energy CDF values
- Parameters:
nu_type (str) – type of neutrino particle; can be neutrino or anti_neutrino
ch_lepton (str) – type of charged lepton; can be tau or muon
energy (float) – ingoing neutrino (or anti-neutrino) energy, in GeV
idepth (int) – depth of water layer, in km
cross_section_model (str) – neutrino cross-section model
pn_model (str) – photonuclear energy loss model
prop_type (str) – type of energy loss mechanism; can be stochastic or continuous
stats (int) – statistics or number of neutrinos injected
out (bool, optional) – saves the data as an ascii ecsv file if set to True; returns the array
False. (value if set to False. Defaults to) –
arg (str) – type of neutrino for part_type=nu or the material for part_type=tau and part_type=muon
- Returns:
- None if out=True otherwise tuple containing:
z_vals (ndarray): 1D array of shape (n,) containing bins from the output file -> CLep_out_cdf table angles (ndarray): 1D array of shape (n,) containing earth emergence angles in the output file cdf_arr (ndarray): 1D array of shape (n,) containing CDF values of outgoing charged lepton energies, binned according to the output file -> CLep_out_cdf table
- Return type:
None/tuple
- nupyprop.data.get_clep_out(nu_type, ch_lepton, energy, angle, idepth, cross_section_model, pn_model, prop_type, stats, out=False, arg=None)¶
get charged lepton outgoing energy values
- Parameters:
nu_type (str) – type of neutrino particle; can be neutrino or anti_neutrino
ch_lepton (str) – type of charged lepton; can be tau or muon
energy (float) – ingoing neutrino (or anti-neutrino) energy, in GeV
angle (float) – earth emergence angle, in degrees
idepth (int) – depth of water layer, in km
cross_section_model (str) – neutrino cross-section model
pn_model (str) – photonuclear energy loss model
prop_type (str) – type of energy loss mechanism; can be stochastic or continuous
stats (int) – statistics or number of neutrinos injected
out (bool, optional) – saves the data as an ascii ecsv file if set to True; returns the array
False. (value if set to False. Defaults to) –
arg (str, optional) – additional arguments at the end of the file name. Defaults to None.
- Returns:
- None if out=True otherwise:
1D numpy array of shape (x,) containing outgoing charged lepton energy values, in GeV; x is the number of outgoing charged leptons
- Return type:
None/ndarray
- nupyprop.data.get_custom_path(data_type, part_type, model, arg)¶
gets the path of the model file to be used for loading data from custom model files
- Parameters:
data_type (str) – type of data; can be xc for cross-section values, ixc for cross-section CDF values and beta for energy loss parameter values
part_type (str) – type of particle; can be nu for neutrinos or tau for tau leptons or muon for muons
model (str) – name of the model
arg (str) – type of neutrino for part_type=nu or the propagation material for part_type=tau and part_type=muon
- Raises:
ModelError – either an incorrectly formatted model file or file not found
ModelError – either an incorrectly formatted model file or file not found
- Returns:
path of the csutom mode file
- Return type:
PosixPath
- nupyprop.data.get_ixc(part_type, model, arg, out=False)¶
get integrated cross-section CDF values; works with custom PN models
- Parameters:
part_type (str) – type of particle; can be nu for neutrinos or tau for tau leptons or muon for muons
model (str) – name of the model
arg (str) – type of neutrino for part_type=nu or the propagation material for part_type=tau and part_type=muon
out (bool, optional) – saves the data as an ASCII ecsv file if set to True; returns the array value if set to False. Defaults to False.
- Returns:
- None if out=True otherwise otherwise:
3D Fortran array of shape (31,91,2) containing integrated charged current and neutral current neutrino (or anti-neutrino) cross-section CDF values, or 3D Fortran array of shape (31,121,3) containing integrated Bremmstrahlung, pair-production and photonuclear cross-section CDF values for charged lepton
- Return type:
None/ndarray
- nupyprop.data.get_pexit(nu_type, ch_lepton, energy, idepth, cross_section_model, pn_model, prop_type, stats, out=False, arg=None)¶
get charged lepton exit probability values
- Parameters:
nu_type (str) – type of neutrino particle; can be neutrino or anti_neutrino
ch_lepton (str) – type of charged lepton; can be tau or muon
energy (float) – ingoing neutrino (or anti-neutrino) energy, in GeV
idepth (int) – depth of water layer, in km
cross_section_model (str) – neutrino cross-section model
pn_model (str) – photonuclear energy loss model
prop_type (str) – type of energy loss mechanism; can be stochastic or continuous
stats (int) – statistics or number of neutrinos injected
out (bool, optional) – saves the data as an ascii ecsv file if set to True; returns the array
False. (value if set to False. Defaults to) –
arg (str, optional) – additional arguments at the end of the file name. Defaults to None.
- Returns:
- None if out=True otherwise otherwise:
2D numpy array of shape (2,x) containing charged lepton exit probability values without regeneration and including regeneration; x is the number of Earth emergence angles.
- Return type:
None/ndarray
- nupyprop.data.get_polarization(nu_type, ch_lepton, energy, idepth, cross_section_model, pn_model, prop_type, stats, out=False, arg=None)¶
gets outgoing charged lepton average polarization values
- Parameters:
nu_type (str) – type of neutrino particle; can be neutrino or anti_neutrino
ch_lepton (str) – type of charged lepton; can be tau or muon
energy (float) – ingoing neutrino (or anti-neutrino) energy, in GeV
angle (float) – earth emergence angle, in degrees
idepth (int) – depth of water layer, in km
cross_section_model (str) – neutrino cross-section model
pn_model (str) – photonuclear energy loss model
prop_type (str) – type of energy loss mechanism; can be stochastic or continuous
stats (int) – statistics or number of neutrinos injected
out (bool, optional) – saves the data as an ascii ecsv file if set to True; returns the array
False. (value if set to False. Defaults to) –
arg (str, optional) – additional arguments at the end of the file name. Defaults to None.
- Returns:
- None if out=True otherwise:
1D numpy array of shape (x,) containing outgoing charged lepton average polarization along z-axis; x is the number of outgoing charged leptons
- Return type:
None/ndarray
- nupyprop.data.get_trajs(type_traj, angle, idepth, out=False)¶
get trajectory values
- Parameters:
type_traj (str) – type of trajectory; can be col (for column depth) or water (for water depth)
angle (float) – earth emergence angle, in degrees
idepth (int) – depth of water layer, in km
out (bool, optional) – saves the data as an ASCII ecsv file if set to True; returns the array value if set to False. Defaults to False.
- Returns:
- None if out=True otherwise tuple containing:
xalong (ndarray): 1D Fortran array of shape (100,) containing distance in water, in km cdalong (ndarray): 1D Fortran array of shape (100,) containing column depth at xalong, in g/cm^2 or chord (float): Chord length, in km water (float): Final water layer distance, in km
- Return type:
None/tuple
- nupyprop.data.get_xc(part_type, model, arg, out=False)¶
get cross-section values; works with custom PN models
- Parameters:
part_type (str) – type of particle; can be nu for neutrinos or tau for tau leptons or muon for muons
model (str) – name of the model
arg (str) – type of neutrino for part_type=nu or the propagation material for part_type=tau and part_type=muon
out (bool, optional) – saves the data as an ASCII ecsv file if set to True; returns the array value if set to False. Defaults to False.
- Returns:
- None if out=True otherwise otherwise:
2D Fortran array of shape (91,2) containing charged current and neutral current neutrino (or anti-neutrino) cross-section values, in cm^2, or 3D Fortran array of shape (121,3) containing Bremmstrahlung, pair-production and photonuclear cross-section values for charged lepton, all multiplied by N_A/A, in cm^2/g
- Return type:
None/ndarray
- nupyprop.data.interp_cdf(nu_type, ch_lepton, energy, angle, idepth, cross_section_model, pn_model, prop_type, stats, z=None, arg=None)¶
interpolates CDF values at given energy, angle and z (bin) value
- Parameters:
nu_type (str) – type of neutrino particle; can be neutrino or anti_neutrino
ch_lepton (str) – type of charged lepton; can be tau or muon
energy (float) – energy to be interpolated at, in GeV
angle (float) – earth emergence angle to be interpolated at, in degrees
idepth (int) – depth of water layer, in km
cross_section_model (str) – neutrino cross-section model
pn_model (str) – photonuclear energy loss model
prop_type (str) – type of energy loss mechanism; can be stochastic or continuous
stats (int) – statistics or number of neutrinos injected
z (float, optional) – z value to be interpolated at; z=E_tau (or E_muon)/E_nu
None (Defaults to) –
CLep_out_cdf (it will be the array in the output file ->) –
None –
arg (str, optional) – additional arguments at the end of the file name. Defaults to None
- Returns:
interpolated cdf value (float) at z if z is provided, or interpolated cdf array (ndarray) of size (len(z_vals)) at z array if z is None
- Return type:
float/ndarray
- nupyprop.data.interp_pexit(nu_type, ch_lepton, energy, angle, idepth, cross_section_model, pn_model, prop_type, stats, method='linear', arg=None)¶
interpolates exit probability value at a given energy & angle
- Parameters:
nu_type (str) – type of neutrino particle; can be neutrino or anti_neutrino
ch_lepton (str) – type of charged lepton; can be tau or muon
energy (float) – energy to be interpolated at, in GeV
angle (float) – earth emergence angle to be interpolated at, in degrees
idepth (int) – depth of water layer, in km
cross_section_model (str) – neutrino cross-section model
pn_model (str) – photonuclear energy loss model
prop_type (str) – type of energy loss mechanism; can be stochastic or continuous
stats (int) – statistics or number of neutrinos injected
method (str, optional) – method for 2D interpolation; can be linear, nearest or splinef2d. Defaults to linear
arg (str, optional) – additional arguments at the end of the file name. Defaults to None
- Returns:
interpolated p_exit value at (energy,angle)
- Return type:
float
- nupyprop.data.output_file(nu_type, ch_lepton, idepth, cross_section_model, pn_model, prop_type, stats, arg=None)¶
gets the name of the output file based on input args
- Parameters:
nu_type (str) – type of neutrino particle; can be neutrino or anti_neutrino
ch_lepton (str) – type of charged lepton; can be tau or muon
idepth (int) – depth of water layer, in km
cross_section_model (str) – neutrino cross-section model
pn_model (str) – photonuclear energy loss model
prop_type (str) – type of energy loss mechanism; can be stochastic or continuous
stats (int) – statistics or number of neutrinos injected
arg (str, optional) – additional arguments at the end of the file name. Defaults to None.
- Returns:
name of the output file
- Return type:
str
- nupyprop.data.patch_for_astropy(arr)¶
makes a patch for astropy to avoid errors with ‘0 len’ arrays
- Parameters:
arr (ndarray) – 1D array containing data
- Returns:
astropy patched array containing the same data
- Return type:
ndarray
- nupyprop.data.process_htc_out(files_path, nu_type, ch_lepton, energy, idepth, cross_section_model, pn_model, prop_type, stats, elep_mode=False, arg=None)¶
processes files created when the code is run with HTC mode on
- Parameters:
nu_type (str) – type of neutrino particle; can be neutrino or anti_neutrino
ch_lepton (str) – type of charged lepton; can be tau or muon
energy (float) – ingoing neutrino (or anti-neutrino) energy, in log_10(E/GeV)
idepth (int) – depth of water layer, in km
cross_section_model (str) – neutrino cross-section model
pn_model (str) – photonuclear energy loss model
prop_type (str) – type of energy loss mechanism; can be stochastic or continuous
stats (int) – statistics or number of neutrinos injected
elep_mode (str) – Option to print exiting charged lepton’s final energy. Can be yes or no. Default is No.
arg (str, optional) – additional arguments at the end of the file name. Defaults to None
- Returns:
None
- nupyprop.data.replace_elements(old_arr, new_arr)¶
replaces repeated array row, based on if the first element of each row is repeated.
Args:¶
- old_arrndarray
previously present data in h5 file
- new_arrndarray
new data to be written in h5 file
- returns:
arr – data comprising of old and new data, and the repeated old data got replaced by new data
- rtype:
ndarray
- nupyprop.data.sci_str(exp_value)¶
converts exponential value to scientific string format
- Parameters:
exp_value (float) – exponential value to be converted
- Returns:
string equivalent of input with some custom formatting
- Return type:
str
- nupyprop.data.sign(avg_pola)¶
changes the sign of the avergae polariation value of charged lepton, because it starts as LH (P=-1)
- Parameters:
avg_pola (float) – Average polarization value of charged lepton
- Returns:
Average polarization with an opposite sign as input