gwsnr.utils
Submodules
Package Contents
Classes
Custom JSON encoder for numpy data types. It converts numpy.ndarray objects (and any nested-list composition |
Functions
|
Save a dictionary as a json file. |
|
Load a json file. |
|
Save a dictionary as a pickle file. |
|
Load a pickle file. |
|
Function to load a specific dataset from an .h5 file |
|
Append (values with corresponding keys) and update a json file with a dictionary. There are four options: |
|
Adds two dictionaries with the same keys together. |
|
Function to get the parameters from json file. |
|
Function to load a specific dataset from an .h5 file within the package |
|
Function to load a specific dataset from a .json file within the package |
|
Function to load a specific dataset from a .pkl file within the package |
|
Function to deal with psds inputs and for creating bilby.gw.detector.PowerSpectralDensity objects. |
|
psd array finder from pycbc |
|
Function for interpolator (snr_partialsacaled) check and generation if not exists. |
|
Function for storing or getting interpolator (snr_partialsacaled) pickle path |
|
|
Probaility of detection of GW for the given sensitivity of the detectors |
|
Probaility of detection of GW for the given sensitivity of the detectors |
|
|
Probaility of detection of GW for the given sensitivity of the detectors |
- class gwsnr.utils.NumpyEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]
Bases:
json.JSONEncoderCustom JSON encoder for numpy data types. It converts numpy.ndarray objects (and any nested-list composition that includes ndarray objects) into regular lists for JSON serialization. This is particularly useful when serializing data structures that include numpy arrays.
- default(obj)[source]
Implement this method in a subclass such that it returns a serializable object for
o, or calls the base implementation (to raise aTypeError).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return super().default(o)
- gwsnr.utils.save_json(file_name, param)[source]
Save a dictionary as a json file.
- Parameters:
- file_namestr
json file name for storing the parameters.
- paramdict
dictionary to be saved as a json file.
- gwsnr.utils.load_json(file_name)[source]
Load a json file.
- Parameters:
- file_namestr
json file name for storing the parameters.
- Returns:
- paramdict
- gwsnr.utils.save_pickle(file_name, param)[source]
Save a dictionary as a pickle file.
- Parameters:
- file_namestr
pickle file name for storing the parameters.
- paramdict
dictionary to be saved as a pickle file.
- gwsnr.utils.load_pickle(file_name)[source]
Load a pickle file.
- Parameters:
- file_namestr
pickle file name for storing the parameters.
- Returns:
- paramdict
- gwsnr.utils.load_ann_h5(filename)[source]
Function to load a specific dataset from an .h5 file
- Parameters:
- filenamestr
name of the .h5 file
- Returns:
- modelkeras.models.Model
Keras model loaded from the .h5 file
- gwsnr.utils.append_json(file_name, new_dictionary, old_dictionary=None, replace=False)[source]
Append (values with corresponding keys) and update a json file with a dictionary. There are four options:
If old_dictionary is provided, the values of the new dictionary will be appended to the old dictionary and save in the ‘file_name’ json file.
If replace is True, replace the json file (with the ‘file_name’) content with the new_dictionary.
If the file does not exist, create a new one with the new_dictionary.
If none of the above, append the new dictionary to the content of the json file.
- Parameters:
- file_namestr
json file name for storing the parameters.
- new_dictionarydict
dictionary to be appended to the json file.
- old_dictionarydict, optional
If provided the values of the new dictionary will be appended to the old dictionary and save in the ‘file_name’ json file. Default is None.
- replacebool, optional
If True, replace the json file with the dictionary. Default is False.
- gwsnr.utils.add_dictionaries_together(dictionary1, dictionary2)[source]
Adds two dictionaries with the same keys together.
- Parameters:
- dictionary1dict
dictionary to be added.
- dictionary2dict
dictionary to be added.
- Returns:
- dictionarydict
dictionary with added values.
- gwsnr.utils.get_param_from_json(json_file)[source]
Function to get the parameters from json file.
- Parameters:
- json_filestr
json file name for storing the parameters.
- Returns:
- paramdict
- gwsnr.utils.load_ann_h5_from_module(package, directory, filename)[source]
Function to load a specific dataset from an .h5 file within the package
- Parameters:
- packagestr
name of the package
- directorystr
name of the directory within the package
- filenamestr
name of the .h5 file
- Returns:
- modelkeras.models.Model
Keras model loaded from the .h5 file
- gwsnr.utils.load_json_from_module(package, directory, filename)[source]
Function to load a specific dataset from a .json file within the package
- Parameters:
- packagestr
name of the package
- directorystr
name of the directory within the package
- filenamestr
name of the .json file
- Returns:
- datadict
Dictionary loaded from the .json file
- gwsnr.utils.load_pickle_from_module(package, directory, filename)[source]
Function to load a specific dataset from a .pkl file within the package
- Parameters:
- packagestr
name of the package
- directorystr
name of the directory within the package
- filenamestr
name of the .pkl file
- Returns:
- datadict
Dictionary loaded from the .pkl file
- gwsnr.utils.dealing_with_psds(psds=None, ifos=None, f_min=20.0, sampling_frequency=2048.0)[source]
Function to deal with psds inputs and for creating bilby.gw.detector.PowerSpectralDensity objects.
- Parameters:
- psdsdict
dictionary of psds. psds.keys()=detector names, psds.values()=psds file names or pycbc psd names
- ifoslist or None
List of interferometer objects or interferometer name list. Default is None. If None, bilby’s default interferometer objects will be used.
- f_minfloat
Minimum frequency of the psds. Default is 20.
- sampling_frequencyfloat
Sampling frequency of the psds. Default is 2048.
- Returns:
- psds_listlist
list of bilby.gw.detector.PowerSpectralDensity objects
- detector_tensor_listlist
list of detector tensors
- detector_listlist
list of detector names
- gwsnr.utils.power_spectral_density_pycbc(psd, f_min=20.0, sampling_frequency=2048.0)[source]
psd array finder from pycbc
- Parameters:
- psdstr
name of the psd e.g. ‘aLIGOaLIGODesignSensitivityT1800044’
- f_minfloat
minimum frequency of the psd default: 20.
- sampling_frequencyfloat
sampling frequency of the psd default: 2048.
- Returns:
- psd_arraybilby.gw.detector.psd.PowerSpectralDensity object
- gwsnr.utils.interpolator_check(param_dict_given, interpolator_dir, create_new)[source]
Function for interpolator (snr_partialsacaled) check and generation if not exists.
- Parameters:
- param_dict_givendict
dictionary of parameters based on which the existence of interpolator will be checked
- interpolator_dirstr
path to the interpolator pickle file
- create_newbool
if True, new interpolator will be generated even if the interpolator exists if False, existing interpolator will be used if exists, otherwise new interpolator will be generated
- Returns:
- psds_list_list
list of psd objects
- detector_tensor_list_list
list of detector tensors
- detector_list_list
list of detector names
- gwsnr.utils.interpolator_pickle_path(param_dict_given, path='./interpolator_pickle')[source]
Function for storing or getting interpolator (snr_partialsacaled) pickle path
- Parameters:
- param_dict_givendict
dictionary of parameters based on which the existence of interpolator will be checked
- pathstr
path to the directory where the interpolator pickle file will be stored
- Returns:
- path_interpolatorstr
path to the interpolator pickle file e.g. ‘./interpolator_pickle/L1/partialSNR_dict_0.pickle’
- it_exist: bool
True if the interpolator exists False if the interpolator does not exists
- gwsnr.utils.noise_weighted_inner_prod_h_inner_h(params)[source]
Probaility of detection of GW for the given sensitivity of the detectors
- Parameters:
- paramslist
list of parameters for the inner product calculation List contains:
- params[0]float
mass_1
- params[1]float
mass_2
- params[2]float
luminosity_distance
- params[3]float
theta_jn
- params[4]float
psi
- params[5]float
phase
- params[6]float
ra
- params[7]float
dec
- params[8]float
geocent_time
- params[9]float
a_1
- params[10]float
a_2
- params[11]float
tilt_1
- params[12]float
tilt_2
- params[13]float
phi_12
- params[14]float
phi_jl
- params[15]float
lambda_1
- params[16]float
lambda_2
- params[17]float
eccentricity
- params[18]float
approximant
- params[19]float
f_min
- params[20]float
f_ref
- params[21]float
duration
- params[22]float
sampling_frequency
- params[23]int
index tracker
- params[24]list
list of psds for each detector
- params[25]str
frequency_domain_source_model name
- Returns:
- SNRs_listlist
contains opt_snr for each detector and net_opt_snr
- params[22]int
index tracker
- gwsnr.utils.noise_weighted_inner_prod_d_inner_h(params)[source]
Probaility of detection of GW for the given sensitivity of the detectors
- Parameters:
- paramslist
list of parameters for the inner product calculation List contains:
- params[0]float
mass_1
- params[1]float
mass_2
- params[2]float
luminosity_distance
- params[3]float
theta_jn
- params[4]float
psi
- params[5]float
phase
- params[6]float
ra
- params[7]float
dec
- params[8]float
geocent_time
- params[9]float
a_1
- params[10]float
a_2
- params[11]float
tilt_1
- params[12]float
tilt_2
- params[13]float
phi_12
- params[14]float
phi_jl
- params[15]float
lambda_1
- params[16]float
lambda_2
- params[17]float
eccentricity
- params[18]float
approximant
- params[19]float
f_min
- params[20]float
f_ref
- params[21]float
duration
- params[22]float
sampling_frequency
- params[23]int
index tracker
- params[24]list
list of psds for each detector
- params[25]str
frequency_domain_source_model name
- params[26]list or None
noise realization. If None, then PSD as noise realization
- Returns:
- SNRs_listlist
contains opt_snr for each detector and net_opt_snr
- params[22]int
index tracker
- gwsnr.utils.noise_weighted_inner_prod_ripple(params)[source]
Probaility of detection of GW for the given sensitivity of the detectors
- Parameters:
- paramslist
list of parameters for the inner product calculation List contains:
- params[0]numpy.ndarray
plus polarization
- params[1]numpy.ndarray
cross polarization
- params[2]numpy.ndarray
frequency array
- params[3]float
cutt-off size of given arrays
- params[4]float
minimum frequency
- params[5]float
duration
- params[6]int
index
- params[7]list
psd objects of given detectors
- Returns:
- SNRs_listlist
contains opt_snr for each detector and net_opt_snr
- params[22]int
index tracker