Coverage for /Users/andrewkaiser/Documents/GradSchool/Research/gwent/gwent/snr.py : 85%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
"""Calculates SNR Matrix
Parameters ---------- source : object Instance of a gravitational wave source class instrument : object Instance of a gravitational wave detector class var_x : str x-axis variable sample_rate_x : int Number of samples at which SNRMatrix is calculated corresponding to the x-axis variable var_y : str y-axis variable sample_rate_y : array samples at which SNRMatrix was calculated corresponding to the y-axis variable
Returns ------- sample_x : array samples at which SNRMatrix was calculated corresponding to the x-axis variable sample_y : array samples at which SNRMatrix was calculated corresponding to the y-axis variable SNRMatrix : array-like the sample_rate_y X sample_rate_x matrix at which the SNR was calculated corresponding to the particular x and y-axis variable choices
Notes ----- Uses the variable given and the data range to sample the space either logrithmically or linearly based on the selection of variables. Then it computes the SNR for each value. Returns the variable ranges used to calculate the SNR for each matrix, then returns the SNRs with size of the sample_yXsample_x
""" else: raise ValueError("%s is not an accepted input option." % keys)
# Get Samples for variables source, instrument, var_x, sample_rate_x, var_y, sample_rate_y )
"""Calculation runs much faster when it doesn't recalculate the noise every time."""
# Update Attribute (also updates dictionary) else: # Update Attribute (also updates dictionary)
# Update Attribute (also updates dictionary) # Update Attribute (also updates dictionary) else:
else: # Chirping Source recalculate_strain == True ): # If we need to calculate the waveform everytime # Delete old PhenomD waveform
else:
"""Gets the x and y-axis samples
Parameters ---------- source : object Instance of a gravitational wave source class instrument : object Instance of a gravitational wave detector class var_x : str x-axis variable sample_rate_x : int Number of samples at which SNRMatrix is calculated corresponding to the x-axis variable var_y : str y-axis variable sample_rate_y : array samples at which SNRMatrix was calculated corresponding to the y-axis variable
Returns ------- sample_x : array samples at which SNRMatrix was calculated corresponding to the x-axis variable sample_y : array samples at which SNRMatrix was calculated corresponding to the y-axis variable
Notes ----- The function uses that to create a sample space for the variable either in linear space or logspace for M,z,L,A_acc for everything else.
"""
var_x_min = source.var_dict[var_x]["min"].value var_x_max = source.var_dict[var_x]["max"].value else: else: else: raise ValueError(var_x + " is not a variable in the source or the instrument.")
var_y_min = source.var_dict[var_y]["min"].value var_y_max = source.var_dict[var_y]["max"].value else: else: else: else: raise ValueError(var_y + " is not a variable in the source or the instrument.")
# order of magnitude cut var_x_min != None and var_x_max != None ): # If the variable has non-None 'min',and 'max' dictionary attributes instrument.var_dict[var_x]["sampled"] = True # sample in integer steps sample_range = var_x_max - var_x_min if sample_range > 10: sample_rate = max(2, int(sample_range / 10)) sample_x = np.arange(var_x_min, var_x_max, sample_rate) if var_x_max not in sample_x: sample_x = np.append(sample_x, var_x_max) else: sample_x = np.arange(var_x_min, var_x_max + 1) else: # Any other variables get sorted to linear if max-min < order of magnitude cut (oom_cut) # Otherwse the samples are in logspace else: np.log10(var_x_min), np.log10(var_x_max), sample_rate_x ) else: else: raise ValueError(var_x + " does not have an assigned min and/or max.")
var_y_min != None and var_y_max != None ): # If the variable has non-None 'min',and 'max' dictionary attributes # sample in integer steps sample_rate = max(2, int(sample_range / 10)) sample_y = np.arange(var_y_min, var_y_max, sample_rate) if var_y_max not in sample_y: sample_y = np.append(sample_y, var_y_max) else: else: # Any other variables get sorted to linear if max-min < order of magnitude cut (oom_cut) # Otherwse the samples are in logspace else: np.log10(var_y_min), np.log10(var_y_max), sample_rate_y ) else: else: raise ValueError(var_y + " does not have an assigned min and/or max value.")
"""Recalculate noise curves if something is varied
Parameters ---------- source : object Instance of a gravitational wave source class instrument : object Instance of a gravitational wave detector class """ raise ValueError("Cannot vary a loaded instrument's parameters")
instrument, "_sensitivitycurve" ):
"""Calculates the SNR for a monochromatic source
Parameters ---------- source : object Instance of a gravitational wave source class instrument : object Instance of a gravitational wave detector class inc : None,float,int, optional The inclination of the monochromatic source in radians.
""" source.instrument = instrument
source.h_gw = binary.Get_Mono_Strain(source, inc=inc) else: source.h_gw = binary.Get_Mono_Strain(source, inc=inc) else:
np.max(instrument.T_obs.to("s")) / instrument.S_n_f[indxfgw] )
"""Calculates the SNR for an evolving source
Parameters ---------- source : object Instance of a gravitational wave source class instrument : object Instance of a gravitational wave detector class
Notes ----- Uses an interpolated method to align waveform and instrument noise, then integrates over the overlapping region. See eqn 18 from Robson,Cornish,and Liu 2018 <https://arxiv.org/abs/1803.01944> Values outside of the sensitivity curve are arbitrarily set to 1e30 so the SNR is effectively 0
"""
# Previously, it was designed to integrate from initial observed frequency f(t_init) to f(t_init-T_obs) # Does not work unless t_init is randomly sampled, which we don't do # indxfgw_start = np.abs(source.f-source.f_init).argmin() # indxfgw_end = np.abs(source.f-source.f_T_obs).argmin()
source.instrument = instrument source.Check_Freq_Evol()
# Only want to integrate from observed frequency (f(T_obs_before_merger)) till merger # If the SMBH has already merged set the SNR to ~0 else:
################################# # Interpolate the Strain Noise Spectral Density to only the frequencies the # strain runs over # Set Noise to 1e30 outside of signal frequencies np.log10(instrument.fT.value), np.log10(instrument.S_n_f.value), kind="cubic", fill_value=30.0, bounds_error=False, )
# Rescaled by 1.5 to make SNR plots match...
instrument, detector.GroundBased ):
# CALCULATE SNR FOR BOTH NOISE CURVES integrand.value, f_cut.value, axis=0 ) # SNR**2 else: SNRsqrd = integral_consts * np.trapz(integrand, f_cut, axis=0) # SNR**2
sample_x, sample_y, SNRMatrix, save_location, SNR_filename, sample_filename ): """Saves SNR Matrix
Parameters ---------- sample_x : array samples at which SNRMatrix was calculated corresponding to the x-axis variable sample_y : array samples at which SNRMatrix was calculated corresponding to the y-axis variable SNRMatrix : array-like the matrix at which the SNR was calculated corresponding to the particular x and y-axis variable choices save_location : str the directory to which the Samples and SNR are saved SNR_filename : str the name of the SNR file sample_filename : str the name of the sample file
""" np.savetxt(save_location + SNR_filename, SNRMatrix) np.savetxt(save_location + sample_filename, np.transpose([sample_x, sample_y])) |