Commit 03a4bddd authored by Gregory Ashton's avatar Gregory Ashton
Browse files

Clean up of the earth/sun ephemeris handling

- Provide a function in the BaseSearchClass to read in the ephemeris
  files
- Some clean up of docstrings
parent df586f0a
......@@ -5,7 +5,6 @@ import os
import logging
import copy
import glob
import numpy as np
import scipy.special
......@@ -27,15 +26,14 @@ else:
helper_functions.set_up_matplotlib_defaults()
args, tqdm = helper_functions.set_up_command_line_arguments()
earth_ephem, sun_ephem = helper_functions.set_up_ephemeris_configuration()
detector_colors = {'h1': 'C0', 'l1': 'C1'}
class Bunch(object):
""" Turns dictionary into object with attribute-style access
Parameter
---------
Parameters
----------
dict
Input dictionary
......@@ -178,18 +176,7 @@ def predict_fstat(h0, cosi, psi, Alpha, Delta, Freq, sftfilepattern,
class BaseSearchClass(object):
""" The base search class providing parent methods to other searches
Attributes
----------
earth_ephem_default, sun_ephem_default : str
Paths to the earth and sun ephemeris files to use if not specified
elsewhere
"""
earth_ephem_default = earth_ephem
sun_ephem_default = sun_ephem
""" The base search class providing parent methods to other searches """
def _add_log_file(self):
""" Log output to a file, requires class to have outdir and label """
......@@ -306,19 +293,37 @@ class BaseSearchClass(object):
raise IOError('No sfts found matching {}'.format(
self.sftfilepattern))
def set_ephemeris_files(self, earth_ephem=None, sun_ephem=None):
""" Set the ephemeris files to use for the Earth and Sun
class ComputeFstat(object):
""" Base class providing interface to `lalpulsar.ComputeFstat` """
Parameters
----------
earth_ephem, sun_ephem: str
Paths of the two files containing positions of Earth and Sun,
respectively at evenly spaced times, as passed to CreateFstatInput
earth_ephem_default = earth_ephem
sun_ephem_default = sun_ephem
Note: If not manually set, default values in ~/.pyfstat are used
"""
earth_ephem_default, sun_ephem_default = (
helper_functions.get_ephemeris_files())
if earth_ephem is None:
self.earth_ephem = earth_ephem_default
if sun_ephem is None:
self.sun_ephem = sun_ephem_default
class ComputeFstat(BaseSearchClass):
""" Base class providing interface to `lalpulsar.ComputeFstat` """
@helper_functions.initializer
def __init__(self, tref, sftfilepattern=None, minStartTime=None,
maxStartTime=None, binary=False, transient=True, BSGL=False,
detectors=None, minCoverFreq=None, maxCoverFreq=None,
earth_ephem=None, sun_ephem=None, injectSources=None,
injectSqrtSX=None, assumeSqrtSX=None, SSBprec=None):
injectSources=None, injectSqrtSX=None, assumeSqrtSX=None,
SSBprec=None):
"""
Parameters
----------
......@@ -343,10 +348,6 @@ class ComputeFstat(object):
The min and max cover frequency passed to CreateFstatInput, if
either is None the range of frequencies in the SFT less 1Hz is
used.
earth_ephem, sun_ephem : str
Paths of the two files containing positions of Earth and Sun,
respectively at evenly spaced times, as passed to CreateFstatInput.
If None defaults will be used.
injectSources : dict or str
Either a dictionary of the values to inject, or a string pointing
to the .cff file to inject
......@@ -362,11 +363,7 @@ class ComputeFstat(object):
"""
if earth_ephem is None:
self.earth_ephem = self.earth_ephem_default
if sun_ephem is None:
self.sun_ephem = self.sun_ephem_default
self.set_ephemeris_files()
self.init_computefstatistic_single_point()
def _get_SFTCatalog(self):
......@@ -827,15 +824,15 @@ class ComputeFstat(object):
return ax
class SemiCoherentSearch(BaseSearchClass, ComputeFstat):
class SemiCoherentSearch(ComputeFstat):
""" A semi-coherent search """
@helper_functions.initializer
def __init__(self, label, outdir, tref, nsegs=None, sftfilepattern=None,
binary=False, BSGL=False, minStartTime=None,
maxStartTime=None, minCoverFreq=None, maxCoverFreq=None,
detectors=None, earth_ephem=None, sun_ephem=None,
injectSources=None, assumeSqrtSX=None, SSBprec=None):
detectors=None, injectSources=None, assumeSqrtSX=None,
SSBprec=None):
"""
Parameters
----------
......@@ -853,10 +850,7 @@ class SemiCoherentSearch(BaseSearchClass, ComputeFstat):
"""
self.fs_file_name = "{}/{}_FS.dat".format(self.outdir, self.label)
if self.earth_ephem is None:
self.earth_ephem = self.earth_ephem_default
if self.sun_ephem is None:
self.sun_ephem = self.sun_ephem_default
self.set_ephemeris_files()
self.transient = True
self.init_computefstatistic_single_point()
self.init_semicoherent_parameters()
......@@ -957,7 +951,7 @@ class SemiCoherentSearch(BaseSearchClass, ComputeFstat):
return d_detStat
class SemiCoherentGlitchSearch(BaseSearchClass, ComputeFstat):
class SemiCoherentGlitchSearch(ComputeFstat):
""" A semi-coherent glitch search
This implements a basic `semi-coherent glitch F-stat in which the data
......@@ -970,8 +964,7 @@ class SemiCoherentGlitchSearch(BaseSearchClass, ComputeFstat):
def __init__(self, label, outdir, tref, minStartTime, maxStartTime,
nglitch=0, sftfilepattern=None, theta0_idx=0, BSGL=False,
minCoverFreq=None, maxCoverFreq=None, assumeSqrtSX=None,
detectors=None, earth_ephem=None, sun_ephem=None,
SSBprec=None, injectSources=None):
detectors=None, SSBprec=None, injectSources=None):
"""
Parameters
----------
......@@ -994,10 +987,7 @@ class SemiCoherentGlitchSearch(BaseSearchClass, ComputeFstat):
"""
self.fs_file_name = "{}/{}_FS.dat".format(self.outdir, self.label)
if self.earth_ephem is None:
self.earth_ephem = self.earth_ephem_default
if self.sun_ephem is None:
self.sun_ephem = self.sun_ephem_default
self.set_ephemeris_files()
self.transient = True
self.binary = False
self.init_computefstatistic_single_point()
......@@ -1017,7 +1007,7 @@ class SemiCoherentGlitchSearch(BaseSearchClass, ComputeFstat):
np.array([delta_phi, delta_F0s, delta_F1s, delta_F2]).T)
thetas = self._calculate_thetas(theta, delta_thetas, tboundaries,
theta0_idx=self.theta0_idx)
theta0_idx=self.theta0_idx)
twoFSum = 0
for i, theta_i_at_tref in enumerate(thetas):
......
......@@ -13,7 +13,7 @@ import matplotlib.pyplot as plt
import pyfstat.helper_functions as helper_functions
from pyfstat.core import (BaseSearchClass, ComputeFstat,
SemiCoherentGlitchSearch, SemiCoherentSearch, tqdm,
args, earth_ephem, sun_ephem, read_par)
args, read_par)
class GridSearch(BaseSearchClass):
......@@ -22,9 +22,8 @@ class GridSearch(BaseSearchClass):
def __init__(self, label, outdir, sftfilepattern, F0s=[0], F1s=[0], F2s=[0],
Alphas=[0], Deltas=[0], tref=None, minStartTime=None,
maxStartTime=None, nsegs=1, BSGL=False, minCoverFreq=None,
maxCoverFreq=None, earth_ephem=None, sun_ephem=None,
detectors=None, SSBprec=None, injectSources=None,
input_arrays=False, assumeSqrtSX=None):
maxCoverFreq=None, detectors=None, SSBprec=None,
injectSources=None, input_arrays=False, assumeSqrtSX=None):
"""
Parameters
----------
......@@ -45,11 +44,6 @@ class GridSearch(BaseSearchClass):
For all other parameters, see `pyfstat.ComputeFStat` for details
"""
if earth_ephem is None:
self.earth_ephem = self.earth_ephem_default
if sun_ephem is None:
self.sun_ephem = self.sun_ephem_default
if os.path.isdir(outdir) is False:
os.mkdir(outdir)
self.set_out_file()
......@@ -61,7 +55,6 @@ class GridSearch(BaseSearchClass):
self.search = ComputeFstat(
tref=self.tref, sftfilepattern=self.sftfilepattern,
minCoverFreq=self.minCoverFreq, maxCoverFreq=self.maxCoverFreq,
earth_ephem=self.earth_ephem, sun_ephem=self.sun_ephem,
detectors=self.detectors, transient=False,
minStartTime=self.minStartTime, maxStartTime=self.maxStartTime,
BSGL=self.BSGL, SSBprec=self.SSBprec,
......@@ -75,7 +68,6 @@ class GridSearch(BaseSearchClass):
BSGL=self.BSGL, minStartTime=self.minStartTime,
maxStartTime=self.maxStartTime, minCoverFreq=self.minCoverFreq,
maxCoverFreq=self.maxCoverFreq, detectors=self.detectors,
earth_ephem=self.earth_ephem, sun_ephem=self.sun_ephem,
injectSources=self.injectSources)
def cut_out_tstart_tend(*vals):
......@@ -313,7 +305,7 @@ class GridGlitchSearch(GridSearch):
F1s=[0], F2s=[0], delta_F0s=[0], delta_F1s=[0], tglitchs=None,
Alphas=[0], Deltas=[0], tref=None, minStartTime=None,
maxStartTime=None, minCoverFreq=None, maxCoverFreq=None,
write_after=1000, earth_ephem=None, sun_ephem=None):
write_after=1000):
"""
Parameters
......@@ -333,16 +325,11 @@ class GridGlitchSearch(GridSearch):
"""
if tglitchs is None:
self.tglitchs = [self.maxStartTime]
if earth_ephem is None:
self.earth_ephem = self.earth_ephem_default
if sun_ephem is None:
self.sun_ephem = self.sun_ephem_default
self.search = SemiCoherentGlitchSearch(
label=label, outdir=outdir, sftfilepattern=self.sftfilepattern,
tref=tref, minStartTime=minStartTime, maxStartTime=maxStartTime,
minCoverFreq=minCoverFreq, maxCoverFreq=maxCoverFreq,
earth_ephem=self.earth_ephem, sun_ephem=self.sun_ephem,
BSGL=self.BSGL)
if os.path.isdir(outdir) is False:
......@@ -372,8 +359,7 @@ class FrequencySlidingWindow(GridSearch):
Alpha, Delta, tref, minStartTime=None,
maxStartTime=None, window_size=10*86400, window_delta=86400,
BSGL=False, minCoverFreq=None, maxCoverFreq=None,
earth_ephem=None, sun_ephem=None, detectors=None,
SSBprec=None, injectSources=None):
detectors=None, SSBprec=None, injectSources=None):
"""
Parameters
----------
......@@ -392,11 +378,6 @@ class FrequencySlidingWindow(GridSearch):
For all other parameters, see `pyfstat.ComputeFStat` for details
"""
if earth_ephem is None:
self.earth_ephem = self.earth_ephem_default
if sun_ephem is None:
self.sun_ephem = self.sun_ephem_default
if os.path.isdir(outdir) is False:
os.mkdir(outdir)
self.set_out_file()
......@@ -411,7 +392,6 @@ class FrequencySlidingWindow(GridSearch):
self.search = ComputeFstat(
tref=self.tref, sftfilepattern=self.sftfilepattern,
minCoverFreq=self.minCoverFreq, maxCoverFreq=self.maxCoverFreq,
earth_ephem=self.earth_ephem, sun_ephem=self.sun_ephem,
detectors=self.detectors, transient=True,
minStartTime=self.minStartTime, maxStartTime=self.maxStartTime,
BSGL=self.BSGL, SSBprec=self.SSBprec,
......@@ -487,8 +467,7 @@ class DMoff_NO_SPIN(GridSearch):
@helper_functions.initializer
def __init__(self, par, label, outdir, sftfilepattern, minStartTime=None,
maxStartTime=None, minCoverFreq=None, maxCoverFreq=None,
earth_ephem=None, sun_ephem=None, detectors=None,
injectSources=None, assumeSqrtSX=None):
detectors=None, injectSources=None, assumeSqrtSX=None):
"""
Parameters
----------
......@@ -506,11 +485,6 @@ class DMoff_NO_SPIN(GridSearch):
For all other parameters, see `pyfstat.ComputeFStat` for details
"""
if earth_ephem is None:
self.earth_ephem = self.earth_ephem_default
if sun_ephem is None:
self.sun_ephem = self.sun_ephem_default
if os.path.isdir(outdir) is False:
os.mkdir(outdir)
......
......@@ -80,7 +80,7 @@ def set_up_command_line_arguments():
return args, tqdm
def set_up_ephemeris_configuration():
def get_ephemeris_files():
""" Returns the earth_ephem and sun_ephem """
config_file = os.path.expanduser('~')+'/.pyfstat.conf'
if os.path.isfile(config_file):
......
......@@ -13,8 +13,6 @@ import lalpulsar
from pyfstat.core import BaseSearchClass, tqdm, args
import pyfstat.helper_functions as helper_functions
earth_ephem, sun_ephem = helper_functions.set_up_ephemeris_configuration()
class KeyboardInterruptError(Exception):
pass
......@@ -49,6 +47,7 @@ class Writer(BaseSearchClass):
see `lalapps_Makefakedata_v5 --help` for help with the other paramaters
"""
self.set_ephemeris_files()
self.tstart = int(tstart)
self.duration = int(duration)
......@@ -372,15 +371,11 @@ class GlitchWriter(Writer):
class FrequencyModulatedArtifactWriter(Writer):
""" Instance object for generating SFTs containing artifacts """
earth_ephem_default = earth_ephem
sun_ephem_default = sun_ephem
@helper_functions.initializer
def __init__(self, label, outdir=".", tstart=700000000,
data_duration=86400, F0=30, F1=0, tref=None, h0=10, Tsft=1800,
sqrtSX=1, Band=4, Pmod=lal.DAYSID_SI, Pmod_phi=0, Pmod_amp=1,
Alpha=None, Delta=None, IFO='H1', earth_ephem=None,
sun_ephem=None):
Alpha=None, Delta=None, IFO='H1'):
"""
Parameters
----------
......@@ -399,6 +394,7 @@ class FrequencyModulatedArtifactWriter(Writer):
see `lalapps_Makefakedata_v4 --help` for help with the other paramaters
"""
self.set_ephemeris_files()
self.tstart = int(tstart)
self.data_duration = int(data_duration)
......@@ -414,11 +410,6 @@ class FrequencyModulatedArtifactWriter(Writer):
self.cosi = 0
self.Fmax = F0
if self.earth_ephem is None:
self.earth_ephem = self.earth_ephem_default
if self.sun_ephem is None:
self.sun_ephem = self.sun_ephem_default
if Alpha is not None and Delta is not None:
self.n = np.array([np.cos(Alpha)*np.cos(Delta),
np.sin(Alpha)*np.cos(Delta),
......
......@@ -16,8 +16,8 @@ import corner
import dill as pickle
import pyfstat.core as core
from pyfstat.core import tqdm, args, earth_ephem, sun_ephem, read_par
from pyfstat.optimal_setup_functions import get_Nstar_estimate, get_optimal_setup
from pyfstat.core import tqdm, args, read_par
import pyfstat.optimal_setup_functions as optimal_setup_functions
import pyfstat.helper_functions as helper_functions
......@@ -33,17 +33,17 @@ class MCMCSearch(core.BaseSearchClass):
asini='', period='s', ecc='', tp='', argp='')
rescale_dictionary = {}
@helper_functions.initializer
def __init__(self, label, outdir, theta_prior, tref, minStartTime,
maxStartTime, sftfilepattern=None, nsteps=[100, 100],
nwalkers=100, ntemps=1, log10temperature_min=-5,
theta_initial=None, scatter_val=1e-10, rhohatmax=1000,
binary=False, BSGL=False, minCoverFreq=None, SSBprec=None,
maxCoverFreq=None, detectors=None, earth_ephem=None,
sun_ephem=None, injectSources=None, assumeSqrtSX=None):
maxCoverFreq=None, detectors=None,
injectSources=None, assumeSqrtSX=None):
"""
Parameters
----------
label, outdir: str
A label and directory to read/write data from/to
sftfilepattern: str
......@@ -83,10 +83,6 @@ class MCMCSearch(core.BaseSearchClass):
minCoverFreq, maxCoverFreq: float
Minimum and maximum instantaneous frequency which will be covered
over the SFT time span as passed to CreateFstatInput
earth_ephem, sun_ephem: str
Paths of the two files containing positions of Earth and Sun,
respectively at evenly spaced times, as passed to CreateFstatInput
If None defaults defined in BaseSearchClass will be used
"""
......@@ -108,11 +104,6 @@ class MCMCSearch(core.BaseSearchClass):
else:
self.betas = None
if earth_ephem is None:
self.earth_ephem = self.earth_ephem_default
if sun_ephem is None:
self.sun_ephem = self.sun_ephem_default
if args.clean and os.path.isfile(self.pickle_path):
os.rename(self.pickle_path, self.pickle_path+".old")
......@@ -137,7 +128,6 @@ class MCMCSearch(core.BaseSearchClass):
self.search = core.ComputeFstat(
tref=self.tref, sftfilepattern=self.sftfilepattern,
minCoverFreq=self.minCoverFreq, maxCoverFreq=self.maxCoverFreq,
earth_ephem=self.earth_ephem, sun_ephem=self.sun_ephem,
detectors=self.detectors, BSGL=self.BSGL, transient=False,
minStartTime=self.minStartTime, maxStartTime=self.maxStartTime,
binary=self.binary, injectSources=self.injectSources,
......@@ -1516,7 +1506,7 @@ class MCMCGlitchSearch(MCMCSearch):
theta_initial=None, scatter_val=1e-10, rhohatmax=1000,
dtglitchmin=1*86400, theta0_idx=0, detectors=None,
BSGL=False, minCoverFreq=None, maxCoverFreq=None,
earth_ephem=None, sun_ephem=None, injectSources=None):
injectSources=None):
"""
Parameters
----------
......@@ -1570,10 +1560,6 @@ class MCMCGlitchSearch(MCMCSearch):
minCoverFreq, maxCoverFreq: float
Minimum and maximum instantaneous frequency which will be covered
over the SFT time span as passed to CreateFstatInput
earth_ephem, sun_ephem: str
Paths of the two files containing positions of Earth and Sun,
respectively at evenly spaced times, as passed to CreateFstatInput
If None defaults defined in BaseSearchClass will be used
"""
......@@ -1590,11 +1576,6 @@ class MCMCGlitchSearch(MCMCSearch):
self.betas = np.logspace(0, self.log10temperature_min, self.ntemps)
else:
self.betas = None
if earth_ephem is None:
self.earth_ephem = self.earth_ephem_default
if sun_ephem is None:
self.sun_ephem = self.sun_ephem_default
if args.clean and os.path.isfile(self.pickle_path):
os.rename(self.pickle_path, self.pickle_path+".old")
......@@ -1611,8 +1592,7 @@ class MCMCGlitchSearch(MCMCSearch):
label=self.label, outdir=self.outdir, sftfilepattern=self.sftfilepattern,
tref=self.tref, minStartTime=self.minStartTime,
maxStartTime=self.maxStartTime, minCoverFreq=self.minCoverFreq,
maxCoverFreq=self.maxCoverFreq, earth_ephem=self.earth_ephem,
sun_ephem=self.sun_ephem, detectors=self.detectors, BSGL=self.BSGL,
maxCoverFreq=self.maxCoverFreq, detectors=self.detectors, BSGL=self.BSGL,
nglitch=self.nglitch, theta0_idx=self.theta0_idx,
injectSources=self.injectSources)
......@@ -1778,8 +1758,7 @@ class MCMCSemiCoherentSearch(MCMCSearch):
theta_initial=None, scatter_val=1e-10, rhohatmax=1000,
detectors=None, BSGL=False, minStartTime=None,
maxStartTime=None, minCoverFreq=None, maxCoverFreq=None,
earth_ephem=None, sun_ephem=None, injectSources=None,
assumeSqrtSX=None):
injectSources=None, assumeSqrtSX=None):
"""
"""
......@@ -1797,11 +1776,6 @@ class MCMCSemiCoherentSearch(MCMCSearch):
self.betas = np.logspace(0, self.log10temperature_min, self.ntemps)
else:
self.betas = None
if earth_ephem is None:
self.earth_ephem = self.earth_ephem_default
if sun_ephem is None:
self.sun_ephem = self.sun_ephem_default
if args.clean and os.path.isfile(self.pickle_path):
os.rename(self.pickle_path, self.pickle_path+".old")
......@@ -1827,11 +1801,10 @@ class MCMCSemiCoherentSearch(MCMCSearch):
logging.info('Setting up search object')
self.search = core.SemiCoherentSearch(
label=self.label, outdir=self.outdir, tref=self.tref,
nsegs=self.nsegs, sftfilepattern=self.sftfilepattern, binary=self.binary,
BSGL=self.BSGL, minStartTime=self.minStartTime,
nsegs=self.nsegs, sftfilepattern=self.sftfilepattern,
binary=self.binary, BSGL=self.BSGL, minStartTime=self.minStartTime,
maxStartTime=self.maxStartTime, minCoverFreq=self.minCoverFreq,
maxCoverFreq=self.maxCoverFreq, detectors=self.detectors,
earth_ephem=self.earth_ephem, sun_ephem=self.sun_ephem,
injectSources=self.injectSources, assumeSqrtSX=self.assumeSqrtSX)
def logp(self, theta_vals, theta_prior, theta_keys, search):
......@@ -1888,7 +1861,7 @@ class MCMCFollowUpSearch(MCMCSemiCoherentSearch):
return True
else:
logging.info(
'Old setup does not match one of NstarMax, Nsegs0 or prior')
"Old setup doesn't match one of NstarMax, Nsegs0 or prior")
except KeyError as e:
logging.info(
'Error found when comparing with old setup: {}'.format(e))
......@@ -1926,13 +1899,13 @@ class MCMCFollowUpSearch(MCMCSemiCoherentSearch):
generate_setup = True
if generate_setup:
nsegs_vals, Nstar_vals = get_optimal_setup(
NstarMax, Nsegs0, self.tref, self.minStartTime,
self.maxStartTime, self.theta_prior,
self.search.detector_names, self.earth_ephem,
self.sun_ephem)
self.write_setup_input_file(run_setup_input_file, NstarMax, Nsegs0,
nsegs_vals, Nstar_vals,
nsegs_vals, Nstar_vals = (
optimal_setup_functions.get_optimal_setup(
NstarMax, Nsegs0, self.tref, self.minStartTime,
self.maxStartTime, self.theta_prior,
self.search.detector_names))
self.write_setup_input_file(run_setup_input_file, NstarMax,
Nsegs0, nsegs_vals, Nstar_vals,
self.theta_prior)
run_setup = [((self.nsteps[0], 0), nsegs, False)
......@@ -1954,10 +1927,9 @@ class MCMCFollowUpSearch(MCMCSemiCoherentSearch):
if args.no_template_counting:
Nstar_vals.append([1, 1, 1])
else:
Nstar = get_Nstar_estimate(
Nstar = optimal_setup_functions.get_Nstar_estimate(
rs[1], self.tref, self.minStartTime, self.maxStartTime,
self.theta_prior, self.search.detector_names,
self.earth_ephem, self.sun_ephem)
self.theta_prior, self.search.detector_names)
Nstar_vals.append(Nstar)
if log_table:
......@@ -2137,7 +2109,6 @@ class MCMCTransientSearch(MCMCSearch):
self.search = core.ComputeFstat(
tref=self.tref, sftfilepattern=self.sftfilepattern,
minCoverFreq=self.minCoverFreq, maxCoverFreq=self.maxCoverFreq,
earth_ephem=self.earth_ephem, sun_ephem=self.sun_ephem,
detectors=self.detectors, transient=True,
minStartTime=self.minStartTime, maxStartTime=self.maxStartTime,
BSGL=self.BSGL, binary=self.binary,
......
......@@ -15,7 +15,7 @@ import pyfstat.helper_functions as helper_functions
def get_optimal_setup(
NstarMax, Nsegs0, tref, minStartTime, maxStartTime, prior,
detector_names, earth_ephem, sun_ephem):
detector_names):
""" Using an optimisation step, calculate the optimal setup ladder
Parameters
......@@ -29,7 +29,6 @@ def get_optimal_setup(
Prior dictionary, each item must either be a fixed scalar value, or
a uniform prior.
detector_names : list of str
earth_ephem, sun_ephem : str
Returns
-------
......@@ -43,7 +42,7 @@ def get_optimal_setup(
Nstar_0 = get_Nstar_estimate(
Nsegs0, tref, minStartTime, maxStartTime, prior,
detector_names, earth_ephem, sun_ephem)
detector_names)
logging.info(
'Stage {}, nsegs={}, Nstar={}'.format(0, Nsegs0, int(Nstar_0)))
......@@ -55,7 +54,7 @@ def get_optimal_setup(
while nsegs_i > 1:
nsegs_i, Nstar_i = _get_nsegs_ip1(
nsegs_i, NstarMax, tref, minStartTime, maxStartTime, prior,
detector_names, earth_ephem, sun_ephem)
detector_names)
nsegs_vals.append(nsegs_i)
Nstar_vals.append(Nstar_i)
i += 1
......@@ -66,13 +65,13 @@ def get_optimal_setup(
def _get_nsegs_ip1(nsegs_i, NstarMax, tref, minStartTime, maxStartTime, prior,
detector_names, earth_ephem, sun_ephem):
detector_names):
""" Calculate Nsegs_{i+1} given Nsegs_{i} """
log10NstarMax = np.log10(NstarMax)
log10Nstari = np.log10(get_Nstar_estimate(
nsegs_i, tref, minStartTime, maxStartTime, prior,
detector_names, earth_ephem, sun_ephem))
detector_names))
def f(nsegs_ip1):
if nsegs_ip1[0] > nsegs_i:
......@@ -83,8 +82,7 @@ def _get_nsegs_ip1(nsegs_i, NstarMax, tref, minStartTime, maxStartTime, prior,
if nsegs_ip1 == 0:
nsegs_ip1 = 1
Nstarip1 = get_Nstar_estimate(
nsegs_ip1, tref, minStartTime, maxStartTime, prior,
detector_names, earth_ephem, sun_ephem)
nsegs_ip1, tref, minStartTime, maxStartTime, prior, detector_names)
if Nstarip1 is None:
return 1e6
else:
......@@ -99,7 +97,7 @@ def _get_nsegs_ip1(nsegs_i, NstarMax, tref, minStartTime, maxStartTime, prior,
if res.success:
return nsegs_ip1, get_Nstar_estimate(
nsegs_ip1, tref, minStartTime, maxStartTime, prior,
detector_names, earth_ephem, sun_ephem)
detector_names)
else: