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

introduce Noise/Budget .run() method to simplify basic usage

Should cover/simplify the most common use case, equivalent to running:

load()
update(**kwargs)
calc_traces
parent 4322d80f
No related branches found
No related tags found
1 merge request!65Interface simplifications
Pipeline #102589 passed
...@@ -18,7 +18,7 @@ description is loaded, the noise budget can be calculated and plotted: ...@@ -18,7 +18,7 @@ description is loaded, the noise budget can be calculated and plotted:
>>> freq = np.logspace(1, 3, 1000) >>> freq = np.logspace(1, 3, 1000)
>>> Budget = gwinc.load_budget('aLIGO') >>> Budget = gwinc.load_budget('aLIGO')
>>> ifo = gwinc.precompIFO(freq, Budget.ifo) >>> ifo = gwinc.precompIFO(freq, Budget.ifo)
>>> traces = Budget(freq, ifo=ifo).calc_trace() >>> traces = Budget(freq, ifo=ifo).run()
>>> fig = gwinc.plot_noise(freq, traces) >>> fig = gwinc.plot_noise(freq, traces)
>>> fig.show() >>> fig.show()
``` ```
......
...@@ -113,7 +113,7 @@ def gwinc(freq, ifo, source=None, plot=False, PRfixed=True): ...@@ -113,7 +113,7 @@ def gwinc(freq, ifo, source=None, plot=False, PRfixed=True):
# from just ifo description, without having to specify full budget # from just ifo description, without having to specify full budget
Budget = load_budget('aLIGO') Budget = load_budget('aLIGO')
ifo = precompIFO(freq, ifo, PRfixed) ifo = precompIFO(freq, ifo, PRfixed)
traces = Budget(freq, ifo=ifo).calc_trace() traces = Budget(freq, ifo=ifo).run()
plot_style = getattr(Budget, 'plot_style', {}) plot_style = getattr(Budget, 'plot_style', {})
# construct matgwinc-compatible noises structure # construct matgwinc-compatible noises structure
......
...@@ -179,10 +179,7 @@ def main(): ...@@ -179,10 +179,7 @@ def main():
logging.info("precomputing ifo...") logging.info("precomputing ifo...")
ifo = precompIFO(freq, ifo) ifo = precompIFO(freq, ifo)
logging.info("calculating budget...") logging.info("calculating budget...")
budget = Budget(freq=freq, ifo=ifo) traces = Budget(freq=freq, ifo=ifo).run()
budget.load()
budget.update()
traces = budget.calc_trace()
# logging.info('recycling factor: {: >0.3f}'.format(ifo.gwinc.prfactor)) # logging.info('recycling factor: {: >0.3f}'.format(ifo.gwinc.prfactor))
# logging.info('BS power: {: >0.3f} W'.format(ifo.gwinc.pbs)) # logging.info('BS power: {: >0.3f} W'.format(ifo.gwinc.pbs))
......
...@@ -32,7 +32,7 @@ class BudgetItem: ...@@ -32,7 +32,7 @@ class BudgetItem:
return None return None
def update(self, **kwargs): def update(self, **kwargs):
"""Overload method for updating data needed to calculate final PSD. """Overload method for updating data.
By default any keyword arguments provided are written directly By default any keyword arguments provided are written directly
as attribute variables (as with __init__). as attribute variables (as with __init__).
...@@ -42,7 +42,7 @@ class BudgetItem: ...@@ -42,7 +42,7 @@ class BudgetItem:
setattr(self, key, val) setattr(self, key, val)
def calc(self): def calc(self):
"""Overload method for calculation of final PSD. """Overload method for final PSD calculation.
Should return an array of power-referenced values evaluated at Should return an array of power-referenced values evaluated at
all evaluation frequencies (self.freq). all evaluation frequencies (self.freq).
...@@ -152,6 +152,17 @@ class Noise(BudgetItem): ...@@ -152,6 +152,17 @@ class Noise(BudgetItem):
data = None data = None
return data, self.style return data, self.style
def run(self, **kwargs):
"""Convenience method to load, update, and return calc traces.
Equivalent of load(), update(), calc_traces() run in sequence.
Keyword arguments are passed to update().
"""
self.load()
self.update(**kwargs)
return self.calc_trace()
class Budget(Noise): class Budget(Noise):
"""GWINC Budget class """GWINC Budget class
......
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