Skip to content
Snippets Groups Projects
Commit 6948c1cd authored by Jameson Graef Rollins's avatar Jameson Graef Rollins
Browse files

clean up gwinc() return values, code, comments, docstring

The return values are now commensurate with gwinc_matlab, making them
essentially interoperable.
parent 4d55b3c9
No related branches found
No related tags found
No related merge requests found
......@@ -57,20 +57,22 @@ def main():
freq = np.logspace(np.log10(args.flo), np.log10(args.fhi), args.npoints)
if args.matlab:
from .gwinc_matlab import gwinc_matlab
def gwinc(freq, ifo, **kwargs):
score, noises, ifo = gwinc_matlab(freq, ifo, **kwargs)
plot_noise(noises)
# FIXME: weird import issue requires doing this here instead of
# above?
from .gwinc_matlab import gwinc_matlab as gwinc
# FIXME: why weird import issue requires doing this here instead
# of above?
else:
from . import gwinc
score, noises, ifo = gwinc(freq, ifo)
if args.interactive:
ipshell = InteractiveShellEmbed(
user_ns={'gwinc': gwinc,
'freq': freq,
user_ns={'freq': freq,
'noises': noises,
'ifo': ifo,
'plot_noise': plot_noise,
},
banner1='''
PYGWINC interactive plotter
......@@ -81,12 +83,12 @@ You may interact with plot using "plt." methods, e.g.:
>>> plt.savefig("foo.pdf")
''')
ipshell.enable_pylab()
ipshell.run_code("output = gwinc(freq, ifo, fig=True)")
ipshell.run_code("plot_noise(noises)")
if args.title:
ipshell.run_code("plt.title('{}')".format(args.title))
ipshell()
else:
gwinc(freq, ifo, fig=True)
plot_noise(noises)
if args.title:
plt.title(args.title)
if args.save:
......
......@@ -96,52 +96,31 @@ def noise_calc(ifo, f):
return noises
def gwinc(f, ifoin, source=None, fig=False):
"""Calculates strain noise due to various noise sources, for a
specified set of interferometer parameters. Also evaluates the
sensitivity of the interferometer to the detection of several potential
gravitational wave sources. Usage:
VARARGOUT = GWINC(F,IFO,SOURCE,VARARGIN)
F = frequency array
IFO = structure containing interferometer parameters
SOURCE = structure containing source parameters
Optional input arguments (the last 4 override IFO parameters):
VARARGIN{1}: PLOT_FLAG set to 4 for score, only calculating shotrad
3 for score and plots
2 for score only
1 to make plots but no score
else 0 (DEF)
VARARGIN{2}: LASER POWER -> ifo.Laser.Power
VARARGIN{3}: SRC PHASE -> ifo.Optics.SRM.Tunephase
VARARGIN{4}: SRM TRANS -> ifo.Optics.SRM.Transmittance
VARARGIN{5}: ITM TRANS -> ifo.Optics.ITM.Transmittance
VARARGIN{6}: PRM TRANS -> ifo.Optics.PRM.Transmittance
Optional output arguments
VARARGOUT{1}: SCORE structure containing source sensitivities
VARARGOUT{2}: NOISE structure containing noise terms
Ex.1 [score,noise] = gwinc(5,5000,IFOModel,SourceModel,1)"""
def gwinc(freq, ifoin, source=None, fig=False):
"""Calculate strain noise budget for a specified interferometer model.
Argument `freq` is the frequency array for which the noises will
be calculated, and `ifoin` is the IFO model (see the `load_ifo()`
function).
If `source` structure provided, so evaluates the sensitivity of
the detector to several potential gravitational wave
sources.
If `fig` is specified a plot of the budget will be created.
Returns tuple of (score, noises, ifo)
"""
ifo = copy.deepcopy(ifoin)
# -------------------------------------------------------
# parse arguments
#makescore = 0;
modeSR = 0
PRfixed = 0
# Parse varargin to decide to make plots or scores or both or neither
# Stick it into the IFO so that it gets passed around
# stick it into the IFO so that it gets passed around
ifo.modeSR = modeSR
# Adjust these parameters as command line arguments
# --------------------------------------------------------
# add some precomputed info to the ifo struct
ifo = precompIFO(ifo, PRfixed)
......@@ -152,18 +131,13 @@ def gwinc(f, ifoin, source=None, fig=False):
pass
#warning(['Thermal lensing limits input power to ' num2str(pbs/prfactor, 3) ' W']);
noises = noise_calc(ifo, f)
n = noises['Total']
ifo.nse = noises
retval = (n, noises)
noises = noise_calc(ifo, freq)
# Report astrophysical scores if so desired
# report astrophysical scores if so desired
score = None
if source:
sss = int73(f, n, ifo, source)
sss.Omega = intStoch(f, n, 0, ifo, source)
retval = (n, noises, sss)
score = int73(freq, noises['Total'], ifo, source)
score.Omega = intStoch(freq, noises['Total'], 0, ifo, source)
# --------------------------------------------------------
# output graphics
......@@ -223,10 +197,10 @@ def gwinc(f, ifoin, source=None, fig=False):
print('Lensing limited input power: %7.2f W' % (pbs/prfactor))
if source:
print('BNS Inspiral Range: ' + str(sss.effr0ns) + ' Mpc/ z = ' + str(sss.zHorizonNS))
print('BBH Inspiral Range: ' + str(sss.effr0bh) + ' Mpc/ z = ' + str(sss.zHorizonBH))
print('Stochastic Omega: %4.1g Universes' % sss.Omega)
print('BNS Inspiral Range: ' + str(score.effr0ns) + ' Mpc/ z = ' + str(score.zHorizonNS))
print('BBH Inspiral Range: ' + str(score.effr0bh) + ' Mpc/ z = ' + str(score.zHorizonBH))
print('Stochastic Omega: %4.1g Universes' % score.Omega)
plot.plot_noise(noises)
return retval
return score, noises, ifo
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment