-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from ColmTalbot/general-generator-access
Add general generator interface
- Loading branch information
Showing
10 changed files
with
146 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,74 @@ | ||
import inspect | ||
|
||
from .base import MemoryGenerator # isort: skip | ||
from . import approximant, mwm, nr, surrogate | ||
from .approximant import Approximant | ||
from .mwm import MWM | ||
from .nr import SXSNumericalRelativity | ||
from .surrogate import Surrogate | ||
from . import approximant, mwm, nr, surrogate # isort: skip | ||
from .approximant import Approximant # isort: skip | ||
from .mwm import MWM # isort: skip | ||
from .nr import SXSNumericalRelativity # isort: skip | ||
from .surrogate import Surrogate # isort: skip | ||
|
||
|
||
GENERATORS = dict( | ||
base=MemoryGenerator, | ||
EOBNR=Approximant, | ||
MWM=MWM, | ||
NRHybSur=Surrogate, | ||
NRSur=Surrogate, | ||
Phenom=Approximant, | ||
SXS=SXSNumericalRelativity, | ||
) | ||
|
||
|
||
def memory_generator(model, **kwargs): | ||
""" | ||
Create a memory generator from any of the registered classes. | ||
Parameters | ||
========== | ||
model: str | ||
The name of the model to use. | ||
kwargs: | ||
Arguments to pass to the :code:`__init__` method of the generator. | ||
Returns | ||
======= | ||
MemoryGenerator | ||
The memory generator instance. | ||
""" | ||
cls_ = None | ||
for key, value in GENERATORS.items(): | ||
if key in model: | ||
cls_ = value | ||
if cls_ is None: | ||
raise ValueError( | ||
f"Unknown waveform generator {model}. " | ||
"Should match one of {GENERATORS.keys()}" | ||
) | ||
all_keys = inspect.signature(cls_).parameters.keys() | ||
model_kwargs = {key: kwargs[key] for key in all_keys if key in kwargs} | ||
return cls_(**model_kwargs) | ||
|
||
|
||
def register_generator(model: str, generator: MemoryGenerator): | ||
""" | ||
Register a new memory generator. | ||
If you have implemented a new memory generator (that matches the API) | ||
here, you can use this to automatically have it be found by | ||
:code:`gwmemory.time_domain_memory`. | ||
Parameters | ||
========== | ||
model: str | ||
The name to register the model as. | ||
generator: MemoryGenerator | ||
The new model to register. | ||
""" | ||
import warnings | ||
|
||
if model in GENERATORS: | ||
warnings.warn(f"Overwriting previously registered model {model}.") | ||
else: | ||
for key in GENERATORS: | ||
if key in model: | ||
warnings.warn(f"Collision with existing model {key}.") | ||
GENERATORS[model] = generator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
lalsuite | ||
NRSur7dq2 | ||
python-lalsimulation | ||
gwsurrogate | ||
sxs | ||
pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
basemap>=1.3.6 | ||
ipykernel | ||
ipython | ||
ipython_genutils | ||
jinja2 | ||
sphinx | ||
pygments | ||
numpydoc | ||
nbsphinx | ||
numpydoc | ||
pandoc | ||
pygments | ||
pytest-cov | ||
sphinx | ||
sphinx_rtd_theme |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
numpy | ||
scipy | ||
pandas | ||
deepdish | ||
sympy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters