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

Add `GroupSpec` and improve doc on `DatasetSpec`

parent acc4e36f
No related branches found
No related tags found
No related merge requests found
......@@ -87,6 +87,61 @@ class Spec(object):
return 3
class GroupSpec(Spec):
"""Specification for `h5.Group` fields"""
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 DatasetSpec(Spec):
"""Specification for `h5.Dataset` fields
Attributes
----------
componentCount: int
Required number of components for each dataset element in the dataset.
"""
dtype = h5.Dataset
componentCount = 1
@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 that the number of components in the
dataset agrees with `self.componentCount`.
"""
try:
value = sim[self.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
# General Fields
class Type(Spec):
"""Specification for the `type` field"""
......@@ -158,24 +213,9 @@ class License(Spec):
values = ['LSC-internal', 'public']
class AuxiliaryInfo(Spec):
class AuxiliaryInfo(GroupSpec):
"""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):
......@@ -334,29 +374,6 @@ class MeanAnomaly(Spec):
# 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'
......
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