Skip to content
Snippets Groups Projects
Commit 43e6765f authored by Edward Fauchon-Jones's avatar Edward Fauchon-Jones
Browse files

Add independent (of `lvcnrcheck`) format spec

parent d3f31d8a
No related branches found
No related tags found
No related merge requests found
# Copyright (C) 2016 Edward Fauchon-Jones
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from .specs import *
from collections import OrderedDict
format1 = OrderedDict((
('General Fields', OrderedDict((
('type', Type),
('Format', Format),
('simulation-type', SimulationType),
('name', Name),
('alternative-names', AlternativeNames),
('NR-group', NRGroup),
('NR-code', NRCode),
('revision-date', RevisionDate),
('point-of-contact-email', PointOfContactEmail),
('INSPIRE-bibtex-keys', INSPIREBibtexKeys),
('license', License),
('auxiliary-info', AuxiliaryInfo),
('NR-techniques', NRTechniques)))),
('Error Assessment', OrderedDict((
('files-in-error-series', FilesInErrorSeries),
('comparable-simulation', ComparableSimulation),
('production-run', ProductionRun)))),
('CBC Parameters', OrderedDict((
("object1", Object1),
("object2", Object2),
("mass1", Mass1),
("mass2", Mass2),
("eta", Eta),
("f_lower_at_1MSUN", FLowerAt1MSUN),
("spin1x", Spin1x),
("spin1y", Spin1y),
("spin1z", Spin1z),
("spin2x", Spin2x),
("spin2y", Spin2y),
("spin2z", Spin2z),
("LNhatx", LNhatx),
("LNhaty", LNhaty),
("LNhatz", LNhatz),
("nhatx", Nhatx),
("nhaty", Nhaty),
("nhatz", Nhatz),
("Omega", Omega),
("eccentricity", Eccentricity),
("mean_anomaly", MeanAnomaly))))))
format2 = OrderedDict((
('mass1-vs-time', Mass1VsTime),
('mass2-vs-time', Mass2VsTime),
('spin1-vs-time', Spin1VsTime),
('spin2-vs-time', Spin2VsTime),
('position1-vs-time', Position1VsTime),
('position2-vs-time', Position2VsTime),
('LNhat-vs-time', LNhatVsTime),
('Omega-vs-time', OmegaVsTime),
('nhat-vs-time', NhatVsTime)))
format3 = OrderedDict((
('remnant-mass-vs-time', RemnantMassVsTime),
('remnant-spin-vs-time', RemnantSpinVsTime),
('remnant-position-vs-time', RemnantPositionVsTime)))
# Copyright (C) 2016 Edward Fauchon-Jones
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import h5py as h5
VALID = 0
WRONG_VALUE = 1
WRONG_TYPE = 2
MISSING = 3
class Spec(object):
"""LVCNR Wavform Repository format specification field
Parameters
----------
name: str
Lisp-case name of the format specification field `Spec` represents.
dtype: object
Type of the format specification field `Spec` represents.
values: (list of `dtype`), optional
List of values that the format specification field `Spec` represents
may take.
Attributes
----------
name: str
Lisp-case name of the format specification field `Spec` represents.
dtype: object
Type of the format specification field `Spec` represents.
values: (list of `dtype`) or None
List of values that the format specification field `Spec` represents
may take. If not specified it will be None.
"""
name = ""
dtype = object
values = None
def __init(self, name, dtype, values=None):
self.name = name
self.dtype = dtype
self.values = values
@classmethod
def valid(self, sim):
"""Validate represented field against format specification.
This will validate that the type of the represented field agrees with
the format specifictaion and if `self.values` is not `None` that it
takes one of these values.
Parameters
----------
sim: lvcnrpy.Sim.Sim
LVCNR Waveform HDF5 Sim object in which to validate the represented
format specification field.
Returns
-------
valid: int
0 if field in `sim` is valid. 1 if the value of the field is not
in `self.values`. 2 if the value is not of type `self.dtype`. 3 if
the field is missing.
"""
value = sim.att(self.name)
if value is not None:
if isinstance(value, self.dtype):
if self.values is None or value in self.values:
return 0
else:
return 1
else:
return 2
else:
return 3
# General Fields
class Type(Spec):
"""Specification for the `type` field"""
name = 'type'
dtype = basestring
values = ["NRinjection"]
class Format(Spec):
"""Specification for the `Format` field"""
name = 'Format'
dtype = int
values = [1, 2, 3]
class SimulationType(Spec):
"""Specification for the `simulation-type` field"""
name = 'simulation-type'
dtype = basestring
values = ['aligned-spins', 'non-spinning', 'precessing']
class Name(Spec):
"""Specification for the `name` field"""
name = 'name'
dtype = basestring
class AlternativeNames(Spec):
"""Specification for the `Format` field"""
name = 'alternative-names'
type = basestring
class NRGroup(Spec):
"""Specification for the `Format` field"""
name = 'NR-group'
dtype = basestring
class NRCode(Spec):
"""Specification for the `Format` field"""
name = 'NR-code'
dtype = basestring
class RevisionDate(Spec):
"""Specification for the `Format` field"""
name = 'revision-date'
dtype = basestring
class PointOfContactEmail(Spec):
"""Specification for the `Format` field"""
name = 'point-of-contact-email'
dtype = basestring
class INSPIREBibtexKeys(Spec):
"""Specification for the `Format` field"""
name = 'INSPIRE-bibtex-keys'
dtype = basestring
class License(Spec):
"""Specification for the `Format` field"""
name = 'license'
dtype = basestring
values = ['LSC-internal', 'public']
class AuxiliaryInfo(Spec):
"""Specification for the `Format` field"""
name = 'auxiliary-info'
dtype = h5.Group
@classmethod
def valid(self, sim):
try:
value = sim[self.name]
except:
value = None
if value is not None:
if isinstance(value, self.dtype):
return 0
else:
return 2
else:
return 3
class NRTechniques(Spec):
"""Specification for the `Format` field"""
name = 'NR-techniques'
dtype = basestring
# Error Assessment
class FilesInErrorSeries(Spec):
"""Specification for the `files-in-error-series` field"""
name = 'files-in-error-series'
dtype = basestring
class ComparableSimulation(Spec):
"""Specification for the `comparable-simulation` field"""
name = 'comparable-simulation'
dtype = basestring
class ProductionRun(Spec):
"""Specification for the `production-run` field"""
name = 'production-run'
dtype = int
values = [0, 1]
# CBC Parameters
class Object1(Spec):
"""Specification for the `object1` field"""
name = "object1"
dtype = basestring
values = ['BH', 'NS']
class Object2(Spec):
"""Specification for the `object2` field"""
name = "object2"
dtype = basestring
values = ['BH', 'NS']
class Mass1(Spec):
"""Specification for the `mass1` field"""
name = "mass1"
dtype = float
class Mass2(Spec):
"""Specification for the `mass2` field"""
name = "mass2"
dtype = float
class Eta(Spec):
"""Specification for the `eta` field"""
name = "eta"
dtype = float
class FLowerAt1MSUN(Spec):
"""Specification for the `f_lower_at_1MSUN` field"""
name = "f_lower_at_1MSUN"
dtype = float
class Spin1x(Spec):
"""Specification for the `spin1x` field"""
name = "spin1x"
dtype = float
class Spin1y(Spec):
"""Specification for the `spin1y` field"""
name = "spin1y"
dtype = float
class Spin1z(Spec):
"""Specification for the `spin1z` field"""
name = "spin1z"
dtype = float
class Spin2x(Spec):
"""Specification for the `spin2x` field"""
name = "spin2x"
dtype = float
class Spin2y(Spec):
"""Specification for the `spin2y` field"""
name = "spin2y"
dtype = float
class Spin2z(Spec):
"""Specification for the `spin2z` field"""
name = "spin2z"
dtype = float
class LNhatx(Spec):
"""Specification for the `LNhatx` field"""
name = "LNhatx"
dtype = float
class LNhaty(Spec):
"""Specification for the `LNhaty` field"""
name = "LNhaty"
dtype = float
class LNhatz(Spec):
"""Specification for the `LNhatz` field"""
name = "LNhatz"
dtype = float
class Nhatx(Spec):
"""Specification for the `Nhatx` field"""
name = "nhatx"
dtype = float
class Nhaty(Spec):
"""Specification for the `Nhaty` field"""
name = "nhaty"
dtype = float
class Nhatz(Spec):
"""Specification for the `Nhatz` field"""
name = "nhatz"
dtype = float
class Omega(Spec):
"""Specification for the `Omega` field"""
name = "Omega"
dtype = float
class Eccentricity(Spec):
"""Specification for the `eccentricity` field"""
name = "eccentricity"
dtype = float
class MeanAnomaly(Spec):
"""Specification for the `mean_anomaly` field"""
name = "mean_anomaly"
dtype = float
# Format 2
class DatasetSpec(Spec):
dtype = h5.Dataset
componentCount = 1
@classmethod
def valid(self, sim):
try:
value = sim[name]
except:
value = None
if value is not None:
if isinstance(value, self.dtype):
if len(value[0]) == self.componentCount:
return 0
else:
return 1
else:
return 2
else:
return 3
class Mass1VsTime(DatasetSpec):
"""Specification for the `mass1-vs-time` field"""
name = 'mass1-vs-time'
componentCount = 2
class Mass2VsTime(DatasetSpec):
"""Specification for the `mass2-vs-time` field"""
name = 'mass2-vs-time'
componentCount = 2
class Spin1VsTime(DatasetSpec):
"""Specification for the `spin1-vs-time` field"""
name = 'spin1-vs-time'
componentCount = 4
class Spin2VsTime(DatasetSpec):
"""Specification for the `spin2-vs-time` field"""
name = 'spin2-vs-time'
componentCount = 4
class Position1VsTime(DatasetSpec):
"""Specification for the `mean_anomaly` field"""
name = 'position1-vs-time'
componentCount = 4
class Position2VsTime(DatasetSpec):
"""Specification for the `position2-vs-time` field"""
name = 'position2-vs-time'
componentCount = 4
class LNhatVsTime(DatasetSpec):
"""Specification for the `LNhat-vs-time` field"""
name = 'LNhat-vs-time'
componentCount = 4
class OmegaVsTime(DatasetSpec):
"""Specification for the `Omega-vs-time` field"""
name = 'Omega-vs-time'
componentCount = 2
class NhatVsTime(DatasetSpec):
"""Specification for the `nhat-vs-time` field"""
name = 'nhat-vs-time'
componentCount = 4
# Format 3
class RemnantMassVsTime(DatasetSpec):
"""Specification for the `remnant-mass-vs-time`` field"""
name = 'remnant-mass-vs-time'
componentCount = 2
class RemnantSpinVsTime(DatasetSpec):
"""Specification for the `remnant-spin-vs-time`` field"""
name = 'remnant-spin-vs-time'
componentCount = 4
class RemnantPositionVsTime(DatasetSpec):
"""Specification for the `remnant-position-vs-time`` field"""
name = 'remnant-position-vs-time'
componentCount = 4
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