diff --git a/examples/create_synth_dlis.py b/examples/create_synth_dlis.py index d12c3f91..42844122 100644 --- a/examples/create_synth_dlis.py +++ b/examples/create_synth_dlis.py @@ -3,7 +3,7 @@ import logging from dlis_writer.writer.file import DLISFile -from dlis_writer.logical_record.eflr_types import Origin +from dlis_writer.logical_record.eflr_types.origin import OriginObject from dlis_writer.utils.logging import install_logger from dlis_writer.utils.enums import RepresentationCode @@ -14,7 +14,8 @@ # set up origin & file header with custom parameters - by creating an instance or dict of kwargs -origin = Origin.make_object("DEFAULT ORIGIN", file_set_number=1, company="XXX") +origin = OriginObject("DEFAULT ORIGIN", file_set_number=1, company="XXX") +origin.creation_time.value = datetime(year=2023, month=12, day=6, hour=12, minute=30, second=5) file_header = {'sequence_number': 2} diff --git a/src/dlis_writer/logical_record/core/eflr/eflr.py b/src/dlis_writer/logical_record/core/eflr/eflr.py index cf46e1d4..39dfab46 100644 --- a/src/dlis_writer/logical_record/core/eflr/eflr.py +++ b/src/dlis_writer/logical_record/core/eflr/eflr.py @@ -112,6 +112,20 @@ def _make_body_bytes(self) -> bytes: return bts + def register_child(self, child: EFLRObject): + """Register a child EFLRObject with this EFLR.""" + + if not isinstance(child, self.object_type): + raise TypeError(f"Expected an instance of {self.object_type}; got {type(child)}: {child}") + + self._object_dict[child.name] = child + + if len(self._object_dict) == 1: + for attr_name, attr in child.attributes.items(): + self._attributes[attr_name] = attr.copy() + + child.origin_reference = self.origin_reference + def make_object_in_this_set(self, name: str, get_if_exists: bool = False, **kwargs) -> EFLRObject: """Make an EFLRObject according the specifications and register it with this EFLR instance. @@ -126,14 +140,9 @@ def make_object_in_this_set(self, name: str, get_if_exists: bool = False, **kwar if get_if_exists and name in self._object_dict: return self._object_dict[name] - obj = self.object_type(name, self, **kwargs) - self._object_dict[name] = obj - - if len(self._object_dict) == 1: - for attr_name, attr in obj.attributes.items(): - self._attributes[attr_name] = attr.copy() + obj = self.object_type(name, parent=self, **kwargs) - obj.origin_reference = self.origin_reference + self.register_child(obj) return obj diff --git a/src/dlis_writer/logical_record/core/eflr/eflr_meta.py b/src/dlis_writer/logical_record/core/eflr/eflr_meta.py index 2b204afe..0eaad26d 100644 --- a/src/dlis_writer/logical_record/core/eflr/eflr_meta.py +++ b/src/dlis_writer/logical_record/core/eflr/eflr_meta.py @@ -5,7 +5,6 @@ from typing_extensions import Self from dlis_writer.logical_record.core.logical_record import LRMeta -from dlis_writer.logical_record.core.eflr.eflr_object import EFLRObject if TYPE_CHECKING: from dlis_writer.logical_record.core.eflr.eflr import EFLR diff --git a/src/dlis_writer/logical_record/core/eflr/eflr_object.py b/src/dlis_writer/logical_record/core/eflr/eflr_object.py index cecc34ce..001be809 100644 --- a/src/dlis_writer/logical_record/core/eflr/eflr_object.py +++ b/src/dlis_writer/logical_record/core/eflr/eflr_object.py @@ -1,6 +1,6 @@ import logging from functools import cached_property -from typing import TYPE_CHECKING, Any, Union +from typing import TYPE_CHECKING, Any, Union, Optional from dlis_writer.utils.struct_writer import write_struct_obname from dlis_writer.logical_record.core.attribute.attribute import Attribute @@ -15,12 +15,15 @@ class EFLRObject: """Model an object belonging to an Explicitly Formatted Logical Record - e.g. a particular channel.""" - def __init__(self, name: str, parent: "EFLR", **kwargs): + parent_eflr_class: type["EFLR"] = NotImplemented + + def __init__(self, name: str, parent: Optional["EFLR"] = None, set_name: Optional[str] = None, **kwargs): """Initialise an EFLRObject. Args: name : Name of the object. This will be the name it is stored with in the created DLIS file. - parent : EFLR instance this object belongs to. + parent : EFLR instance this object belongs to. If not provided, retrieved/made based on set_name. + set_name : Set name of the parent EFLR instance. **kwargs : Values to be set in attributes of this object. Note: @@ -30,14 +33,40 @@ def __init__(self, name: str, parent: "EFLR", **kwargs): """ - self.name = name #: name of the object - self.parent = parent #: EFLR instance this object belongs to + self.name = name #: name of the object + self.parent = self._get_parent(parent=parent, set_name=set_name) #: EFLR instance this object belongs to + self.parent.register_child(self) self.origin_reference: Union[int, None] = None #: origin reference value, common for records sharing origin self.copy_number = 0 #: copy number of the object self.set_attributes(**{k: v for k, v in kwargs.items() if v is not None}) + @classmethod + def _get_parent(cls, parent: Optional["EFLR"] = None, set_name: Optional[str] = None) -> "EFLR": + """Validate, retrieve, or create a parent EFLR instance. + + Args: + parent : Parent EFLR instance. If not provided, set_name will be used to retrieve/make one. + set_name : Set name of the parent EFLR instance. If parent is provided, it is checked against its + set_name. + + Returns: + The parent EFLR instance. + """ + + if parent is not None: + if not isinstance(parent, cls.parent_eflr_class): + raise TypeError(f"Expected an instance of {cls.parent_eflr_class.__name__}; " + f"got a {type(parent)}: {parent}") + if parent.set_name != set_name and set_name is not None: + raise ValueError(f"The provided set name: {set_name} does not match the set name of the " + f"provided parent EFLR: {parent.set_name}") + + return parent + + return cls.parent_eflr_class.get_or_make_eflr(set_name=set_name) + @property def attributes(self) -> dict[str, Attribute]: """Attributes defined for this EFLRObject (sub)class with its values for the current instance.""" diff --git a/src/dlis_writer/logical_record/eflr_types/axis.py b/src/dlis_writer/logical_record/eflr_types/axis.py index 8bfcf18c..27c5ad8e 100644 --- a/src/dlis_writer/logical_record/eflr_types/axis.py +++ b/src/dlis_writer/logical_record/eflr_types/axis.py @@ -8,12 +8,11 @@ class AxisObject(EFLRObject): parent: "Axis" - def __init__(self, name: str, parent: "Axis", **kwargs): + def __init__(self, name: str, **kwargs): """Initialise AxisObject. Args: name : Name of the AxisObject. - parent : Axis EFLR instance this AxisObject belongs to. **kwargs : Values of to be set as characteristics of the AxisObject Attributes. """ @@ -22,7 +21,7 @@ def __init__(self, name: str, parent: "Axis", **kwargs): converter=self.convert_maybe_numeric) self.spacing = NumericAttribute('spacing', parent_eflr=self) - super().__init__(name, parent, **kwargs) + super().__init__(name, **kwargs) class Axis(EFLR): @@ -32,3 +31,5 @@ class Axis(EFLR): logical_record_type = EFLRType.AXIS object_type = AxisObject + +AxisObject.parent_eflr_class = Axis diff --git a/src/dlis_writer/logical_record/eflr_types/calibration.py b/src/dlis_writer/logical_record/eflr_types/calibration.py index d41e804e..b6dcfae1 100644 --- a/src/dlis_writer/logical_record/eflr_types/calibration.py +++ b/src/dlis_writer/logical_record/eflr_types/calibration.py @@ -16,12 +16,11 @@ class CalibrationMeasurementObject(EFLRObject): parent: "CalibrationMeasurement" - def __init__(self, name: str, parent: "CalibrationMeasurement", **kwargs): + def __init__(self, name: str, **kwargs): """Initialise CalibrationMeasurementObject. Args: name : Name of the CalibrationMeasurementObject. - parent : CalibrationMeasurement EFLR instance this CalibrationMeasurementObject belongs to. **kwargs : Values of to be set as characteristics of the CalibrationMeasurementObject Attributes. """ @@ -42,7 +41,7 @@ def __init__(self, name: str, parent: "CalibrationMeasurement", **kwargs): self.plus_tolerance = NumericAttribute('plus_tolerance', multivalued=True, parent_eflr=self) self.minus_tolerance = NumericAttribute('minus_tolerance', multivalued=True, parent_eflr=self) - super().__init__(name, parent, **kwargs) + super().__init__(name, **kwargs) class CalibrationMeasurement(EFLR): @@ -58,12 +57,11 @@ class CalibrationCoefficientObject(EFLRObject): parent: "CalibrationCoefficient" - def __init__(self, name: str, parent: "CalibrationCoefficient", **kwargs): + def __init__(self, name: str, **kwargs): """Initialise CalibrationCoefficientObject. Args: name : Name of the CalibrationCoefficientObject. - parent : CalibrationCoefficient EFLR instance this CalibrationCoefficientObject belongs to. **kwargs : Values of to be set as characteristics of the CalibrationCoefficientObject Attributes. """ @@ -73,7 +71,7 @@ def __init__(self, name: str, parent: "CalibrationCoefficient", **kwargs): self.plus_tolerances = NumericAttribute('plus_tolerances', multivalued=True, parent_eflr=self) self.minus_tolerances = NumericAttribute('minus_tolerances', multivalued=True, parent_eflr=self) - super().__init__(name, parent, **kwargs) + super().__init__(name, **kwargs) class CalibrationCoefficient(EFLR): @@ -89,12 +87,11 @@ class CalibrationObject(EFLRObject): parent: "Calibration" - def __init__(self, name: str, parent: "Calibration", **kwargs): + def __init__(self, name: str, **kwargs): """Initialise CalibrationObject. Args: name : Name of the CalibrationObject. - parent : Calibration EFLR instance this CalibrationObject belongs to. **kwargs : Values of to be set as characteristics of the CalibrationObject Attributes. """ @@ -109,7 +106,7 @@ def __init__(self, name: str, parent: "Calibration", **kwargs): self.parameters = EFLRAttribute('parameters', object_class=Parameter, multivalued=True, parent_eflr=self) self.method = Attribute('method', representation_code=RepC.IDENT, parent_eflr=self) - super().__init__(name, parent, **kwargs) + super().__init__(name, **kwargs) class Calibration(EFLR): @@ -118,3 +115,8 @@ class Calibration(EFLR): set_type = 'CALIBRATION' logical_record_type = EFLRType.STATIC object_type = CalibrationObject + + +CalibrationMeasurementObject.parent_eflr_class = CalibrationMeasurement +CalibrationCoefficientObject.parent_eflr_class = CalibrationCoefficient +CalibrationObject.parent_eflr_class = Calibration diff --git a/src/dlis_writer/logical_record/eflr_types/channel.py b/src/dlis_writer/logical_record/eflr_types/channel.py index 9f314005..e2ca9bd2 100644 --- a/src/dlis_writer/logical_record/eflr_types/channel.py +++ b/src/dlis_writer/logical_record/eflr_types/channel.py @@ -19,12 +19,11 @@ class ChannelObject(EFLRObject): parent: "Channel" - def __init__(self, name, parent: "Channel", dataset_name: Optional[str] = None, **kwargs): + def __init__(self, name, dataset_name: Optional[str] = None, **kwargs): """Initialise ChannelObject. Args: name : Name of the ChannelObject. - parent : Channel EFLR instance this ChannelObject belongs to. dataset_name : Name of the data corresponding to this channel in the SourceDataObject. **kwargs : Values of to be set as characteristics of the ChannelObject Attributes. """ @@ -47,7 +46,7 @@ def __init__(self, name, parent: "Channel", dataset_name: Optional[str] = None, self._dataset_name: Union[str, None] = dataset_name - super().__init__(name, parent, **kwargs) + super().__init__(name, **kwargs) self.set_defaults() @@ -157,3 +156,6 @@ class Channel(EFLR): set_type = 'CHANNEL' logical_record_type = EFLRType.CHANNL object_type = ChannelObject + + +ChannelObject.parent_eflr_class = Channel diff --git a/src/dlis_writer/logical_record/eflr_types/computation.py b/src/dlis_writer/logical_record/eflr_types/computation.py index e4303a20..a0f12fb9 100644 --- a/src/dlis_writer/logical_record/eflr_types/computation.py +++ b/src/dlis_writer/logical_record/eflr_types/computation.py @@ -15,12 +15,11 @@ class ComputationObject(EFLRObject): parent: "Computation" - def __init__(self, name: str, parent: "Computation", **kwargs): + def __init__(self, name: str, **kwargs): """Initialise ComputationObject. Args: name : Name of the ComputationObject. - parent : Computation EFLR instance this ComputationObject belongs to. **kwargs : Values of to be set as characteristics of the ComputationObject Attributes. """ @@ -32,7 +31,7 @@ def __init__(self, name: str, parent: "Computation", **kwargs): self.values = NumericAttribute('values', multivalued=True, parent_eflr=self) self.source = EFLRAttribute('source', parent_eflr=self) - super().__init__(name, parent, **kwargs) + super().__init__(name, **kwargs) self._set_defaults() self.check_values_and_zones() @@ -58,3 +57,6 @@ class Computation(EFLR): set_type = 'COMPUTATION' logical_record_type = EFLRType.STATIC object_type = ComputationObject + + +ComputationObject.parent_eflr_class = Computation diff --git a/src/dlis_writer/logical_record/eflr_types/equipment.py b/src/dlis_writer/logical_record/eflr_types/equipment.py index 04453f95..e692a1b8 100644 --- a/src/dlis_writer/logical_record/eflr_types/equipment.py +++ b/src/dlis_writer/logical_record/eflr_types/equipment.py @@ -8,12 +8,11 @@ class EquipmentObject(EFLRObject): parent: "Equipment" - def __init__(self, name: str, parent: "Equipment", **kwargs): + def __init__(self, name: str, **kwargs): """Initialise EquipmentObject. Args: name : Name of the EquipmentObject. - parent : Equipment EFLR instance this EquipmentObject belongs to. **kwargs : Values of to be set as characteristics of the EquipmentObject Attributes. """ @@ -35,7 +34,7 @@ def __init__(self, name: str, parent: "Equipment", **kwargs): self.radial_drift = NumericAttribute('radial_drift', parent_eflr=self) self.angular_drift = NumericAttribute('angular_drift', parent_eflr=self) - super().__init__(name, parent, **kwargs) + super().__init__(name, **kwargs) class Equipment(EFLR): @@ -45,3 +44,5 @@ class Equipment(EFLR): logical_record_type = EFLRType.STATIC object_type = EquipmentObject + +EquipmentObject.parent_eflr_class = Equipment diff --git a/src/dlis_writer/logical_record/eflr_types/file_header.py b/src/dlis_writer/logical_record/eflr_types/file_header.py index 9d3e9b77..6f751a12 100644 --- a/src/dlis_writer/logical_record/eflr_types/file_header.py +++ b/src/dlis_writer/logical_record/eflr_types/file_header.py @@ -16,12 +16,11 @@ class FileHeaderObject(EFLRObject): identifier_length_limit = 65 #: max length of the file header name - def __init__(self, identifier: str, parent: "FileHeader", sequence_number: int = 1, **kwargs): + def __init__(self, identifier: str, sequence_number: int = 1, **kwargs): """Initialise FileHeaderObject. Args: identifier : Name of the FileHeaderObject. - parent : FileHeader EFLR instance this FileHeaderObject belongs to. sequence_number : Sequence number of the file. **kwargs : Values of to be set as characteristics of the FileHeaderObject Attributes. """ @@ -34,7 +33,7 @@ def __init__(self, identifier: str, parent: "FileHeader", sequence_number: int = if len(identifier) > self.identifier_length_limit: raise ValueError(f"'identifier' length should not exceed {self.identifier_length_limit} characters") - super().__init__(name='0', parent=parent, **kwargs) + super().__init__(name='0', **kwargs) def _make_attrs_bytes(self) -> bytes: """Create bytes describing the values of attributes of FIleHeaderObject.""" @@ -73,3 +72,5 @@ def _make_template_bytes(self) -> bytes: return bts + +FileHeaderObject.parent_eflr_class = FileHeader diff --git a/src/dlis_writer/logical_record/eflr_types/frame.py b/src/dlis_writer/logical_record/eflr_types/frame.py index b4a7c446..9be9d2b4 100644 --- a/src/dlis_writer/logical_record/eflr_types/frame.py +++ b/src/dlis_writer/logical_record/eflr_types/frame.py @@ -26,12 +26,11 @@ class FrameObject(EFLRObject): 'VERTICAL-DEPTH' ) - def __init__(self, name: str, parent: "Frame", **kwargs): + def __init__(self, name: str, **kwargs): """Initialise FrameObject. Args: name : Name of the FrameObject. - parent : Frame EFLR instance this FrameObject belongs to. **kwargs : Values of to be set as characteristics of the FrameObject Attributes. """ @@ -46,7 +45,7 @@ def __init__(self, name: str, parent: "Frame", **kwargs): self.index_min = NumericAttribute('index_min', parent_eflr=self) self.index_max = NumericAttribute('index_max', parent_eflr=self) - super().__init__(name, parent, **kwargs) + super().__init__(name, **kwargs) @classmethod def parse_index_type(cls, value: str) -> str: @@ -136,3 +135,6 @@ class Frame(EFLR): set_type = 'FRAME' logical_record_type = EFLRType.FRAME object_type = FrameObject + + +FrameObject.parent_eflr_class = Frame diff --git a/src/dlis_writer/logical_record/eflr_types/group.py b/src/dlis_writer/logical_record/eflr_types/group.py index fd9a313c..ed95d53e 100644 --- a/src/dlis_writer/logical_record/eflr_types/group.py +++ b/src/dlis_writer/logical_record/eflr_types/group.py @@ -13,7 +13,7 @@ class GroupObject(EFLRObject): parent: "Group" - def __init__(self, name: str, parent: "Group", **kwargs): + def __init__(self, name: str, **kwargs): """Initialise GroupObject. Args: @@ -27,7 +27,7 @@ def __init__(self, name: str, parent: "Group", **kwargs): self.object_list = EFLRAttribute('object_list', multivalued=True, parent_eflr=self) self.group_list = EFLRAttribute('group_list', object_class=Group, multivalued=True, parent_eflr=self) - super().__init__(name, parent, **kwargs) + super().__init__(name, **kwargs) class Group(EFLR): @@ -36,3 +36,6 @@ class Group(EFLR): set_type = 'GROUP' logical_record_type = EFLRType.STATIC object_type = GroupObject + + +GroupObject.parent_eflr_class = Group diff --git a/src/dlis_writer/logical_record/eflr_types/long_name.py b/src/dlis_writer/logical_record/eflr_types/long_name.py index 25b3ad25..b91a54b3 100644 --- a/src/dlis_writer/logical_record/eflr_types/long_name.py +++ b/src/dlis_writer/logical_record/eflr_types/long_name.py @@ -8,12 +8,11 @@ class LongNameObject(EFLRObject): parent: "LongName" - def __init__(self, name: str, parent: "LongName", **kwargs): + def __init__(self, name: str, **kwargs): """Initialise LongNameObject. Args: name : Name of the LongNameObject. - parent : LongName EFLR instance this LongNameObject belongs to. **kwargs : Values of to be set as characteristics of the LongNameObject Attributes. """ @@ -37,7 +36,7 @@ def __init__(self, name: str, parent: "LongName", **kwargs): self.standard_symbol = Attribute('standard_symbol', representation_code=RepC.ASCII, parent_eflr=self) self.private_symbol = Attribute('private_symbol', representation_code=RepC.ASCII, parent_eflr=self) - super().__init__(name, parent, **kwargs) + super().__init__(name, **kwargs) class LongName(EFLR): @@ -46,3 +45,6 @@ class LongName(EFLR): set_type = 'LONG-NAME' logical_record_type = EFLRType.LNAME object_type = LongNameObject + + +LongNameObject.parent_eflr_class = LongName diff --git a/src/dlis_writer/logical_record/eflr_types/message.py b/src/dlis_writer/logical_record/eflr_types/message.py index 2ddd4536..2496428e 100644 --- a/src/dlis_writer/logical_record/eflr_types/message.py +++ b/src/dlis_writer/logical_record/eflr_types/message.py @@ -8,12 +8,11 @@ class MessageObject(EFLRObject): parent: "Message" - def __init__(self, name: str, parent: "Message", **kwargs): + def __init__(self, name: str, **kwargs): """Initialise MessageObject. Args: name : Name of the MessageObject. - parent : Message EFLR instance this MessageObject belongs to. **kwargs : Values of to be set as characteristics of the MessageObject Attributes. """ @@ -25,7 +24,7 @@ def __init__(self, name: str, parent: "Message", **kwargs): self.angular_drift = NumericAttribute('angular_drift', parent_eflr=self) self.text = Attribute('text', representation_code=RepC.ASCII, multivalued=True, parent_eflr=self) - super().__init__(name, parent, **kwargs) + super().__init__(name, **kwargs) class Message(EFLR): @@ -41,18 +40,17 @@ class CommentObject(EFLRObject): parent: "Comment" - def __init__(self, name: str, parent: "Comment", **kwargs): + def __init__(self, name: str, **kwargs): """Initialise CommentObject. Args: name : Name of the CommentObject. - parent : Comment EFLR instance this CommentObject belongs to. **kwargs : Values of to be set as characteristics of the CommentObject Attributes. """ self.text = Attribute('text', representation_code=RepC.ASCII, multivalued=True, parent_eflr=self) - super().__init__(name, parent, **kwargs) + super().__init__(name, **kwargs) class Comment(EFLR): @@ -61,3 +59,7 @@ class Comment(EFLR): set_type = 'COMMENT' logical_record_type = EFLRType.SCRIPT object_type = CommentObject + + +MessageObject.parent_eflr_class = Message +CommentObject.parent_eflr_class = Comment diff --git a/src/dlis_writer/logical_record/eflr_types/no_format.py b/src/dlis_writer/logical_record/eflr_types/no_format.py index 9c15d2e4..2d3a0281 100644 --- a/src/dlis_writer/logical_record/eflr_types/no_format.py +++ b/src/dlis_writer/logical_record/eflr_types/no_format.py @@ -8,19 +8,18 @@ class NoFormatObject(EFLRObject): parent: "NoFormat" - def __init__(self, name: str, parent: "NoFormat", **kwargs): + def __init__(self, name: str, **kwargs): """Initialise NoFormatObject. Args: name : Name of the NoFormatObject. - parent : NoFormat EFLR instance this NoFormatObject belongs to. **kwargs : Values of to be set as characteristics of the NoFormatObject Attributes. """ self.consumer_name = Attribute('consumer_name', representation_code=RepC.IDENT, parent_eflr=self) self.description = Attribute('description', representation_code=RepC.ASCII, parent_eflr=self) - super().__init__(name, parent, **kwargs) + super().__init__(name, **kwargs) class NoFormat(EFLR): @@ -29,3 +28,6 @@ class NoFormat(EFLR): set_type = 'NO-FORMAT' logical_record_type = EFLRType.UDI object_type = NoFormatObject + + +NoFormatObject.parent_eflr_class = NoFormat diff --git a/src/dlis_writer/logical_record/eflr_types/origin.py b/src/dlis_writer/logical_record/eflr_types/origin.py index 6094bef7..8170dafd 100644 --- a/src/dlis_writer/logical_record/eflr_types/origin.py +++ b/src/dlis_writer/logical_record/eflr_types/origin.py @@ -14,12 +14,11 @@ class OriginObject(EFLRObject): parent: "Origin" - def __init__(self, name: str, parent: "Origin", **kwargs): + def __init__(self, name: str, **kwargs): """Initialise OriginObject. Args: name : Name of the OriginObject. - parent : Origin EFLR instance this OriginObject belongs to. **kwargs : Values of to be set as characteristics of the OriginObject Attributes. """ @@ -49,7 +48,7 @@ def __init__(self, name: str, parent: "Origin", **kwargs): logger.info("Creation time ('creation_time') not specified; setting it to the current date and time") kwargs["creation_time"] = datetime.now() - super().__init__(name, parent, **kwargs) + super().__init__(name, **kwargs) class Origin(EFLR): @@ -58,3 +57,6 @@ class Origin(EFLR): set_type = 'ORIGIN' logical_record_type = EFLRType.OLR object_type = OriginObject + + +OriginObject.parent_eflr_class = Origin diff --git a/src/dlis_writer/logical_record/eflr_types/parameter.py b/src/dlis_writer/logical_record/eflr_types/parameter.py index 27ca9bbe..43948205 100644 --- a/src/dlis_writer/logical_record/eflr_types/parameter.py +++ b/src/dlis_writer/logical_record/eflr_types/parameter.py @@ -15,12 +15,11 @@ class ParameterObject(EFLRObject): parent: "Parameter" - def __init__(self, name: str, parent: "Parameter", **kwargs): + def __init__(self, name: str, **kwargs): """Initialise ParameterObject. Args: name : Name of the ParameterObject. - parent : Parameter EFLR instance this ParameterObject belongs to. **kwargs : Values of to be set as characteristics of the ParameterObject Attributes. """ @@ -30,7 +29,7 @@ def __init__(self, name: str, parent: "Parameter", **kwargs): self.zones = EFLRAttribute('zones', object_class=Zone, multivalued=True, parent_eflr=self) self.values = Attribute('values', converter=self.convert_maybe_numeric, multivalued=True, parent_eflr=self) - super().__init__(name, parent, **kwargs) + super().__init__(name, **kwargs) self._set_defaults() @@ -49,3 +48,5 @@ class Parameter(EFLR): logical_record_type = EFLRType.STATIC object_type = ParameterObject + +ParameterObject.parent_eflr_class = Parameter diff --git a/src/dlis_writer/logical_record/eflr_types/path.py b/src/dlis_writer/logical_record/eflr_types/path.py index 99d756ad..4e546520 100644 --- a/src/dlis_writer/logical_record/eflr_types/path.py +++ b/src/dlis_writer/logical_record/eflr_types/path.py @@ -16,12 +16,11 @@ class PathObject(EFLRObject): parent: "Path" - def __init__(self, name: str, parent: "Path", **kwargs): + def __init__(self, name: str, **kwargs): """Initialise PathObject. Args: name : Name of the PathObject. - parent : Path EFLR instance this PathObject belongs to. **kwargs : Values of to be set as characteristics of the PathObject Attributes. """ @@ -38,7 +37,7 @@ def __init__(self, name: str, parent: "Path", **kwargs): self.measure_point_offset = NumericAttribute('measure_point_offset', parent_eflr=self) self.tool_zero_offset = NumericAttribute('tool_zero_offset', parent_eflr=self) - super().__init__(name, parent, **kwargs) + super().__init__(name, **kwargs) class Path(EFLR): @@ -47,3 +46,6 @@ class Path(EFLR): set_type = 'PATH' logical_record_type = EFLRType.FRAME object_type = PathObject + + +PathObject.parent_eflr_class = Path diff --git a/src/dlis_writer/logical_record/eflr_types/process.py b/src/dlis_writer/logical_record/eflr_types/process.py index a9003f41..8b6a40d4 100644 --- a/src/dlis_writer/logical_record/eflr_types/process.py +++ b/src/dlis_writer/logical_record/eflr_types/process.py @@ -18,12 +18,11 @@ class ProcessObject(EFLRObject): allowed_status = ('COMPLETE', 'ABORTED', 'IN-PROGRESS') #: allowed values of the 'status' Attribute - def __init__(self, name: str, parent: "Process", **kwargs): + def __init__(self, name: str, **kwargs): """Initialise ProcessObject. Args: name : Name of the ProcessObject. - parent : Process EFLR instance this ProcessObject belongs to. **kwargs : Values of to be set as characteristics of the ProcessObject Attributes. """ @@ -43,7 +42,7 @@ def __init__(self, name: str, parent: "Process", **kwargs): self.parameters = EFLRAttribute('parameters', object_class=Parameter, multivalued=True, parent_eflr=self) self.comments = Attribute('comments', representation_code=RepC.ASCII, multivalued=True, parent_eflr=self) - super().__init__(name, parent, **kwargs) + super().__init__(name, **kwargs) @classmethod def check_status(cls, status): @@ -58,3 +57,6 @@ class Process(EFLR): set_type = 'PROCESS' logical_record_type = EFLRType.STATIC object_type = ProcessObject + + +ProcessObject.parent_eflr_class = Process diff --git a/src/dlis_writer/logical_record/eflr_types/splice.py b/src/dlis_writer/logical_record/eflr_types/splice.py index 5b06d048..90dca82f 100644 --- a/src/dlis_writer/logical_record/eflr_types/splice.py +++ b/src/dlis_writer/logical_record/eflr_types/splice.py @@ -15,12 +15,11 @@ class SpliceObject(EFLRObject): parent: "Splice" - def __init__(self, name: str, parent: "Splice", **kwargs): + def __init__(self, name: str, **kwargs): """Initialise SpliceObject. Args: name : Name of the SpliceObject. - parent : Splice EFLR instance this SpliceObject belongs to. **kwargs : Values of to be set as characteristics of the SpliceObject Attributes. """ @@ -28,7 +27,7 @@ def __init__(self, name: str, parent: "Splice", **kwargs): self.input_channels = EFLRAttribute('input_channels', object_class=Channel, multivalued=True, parent_eflr=self) self.zones = EFLRAttribute('zones', object_class=Zone, multivalued=True, parent_eflr=self) - super().__init__(name, parent, **kwargs) + super().__init__(name, **kwargs) class Splice(EFLR): @@ -37,3 +36,6 @@ class Splice(EFLR): set_type = 'SPLICE' logical_record_type = EFLRType.STATIC object_type = SpliceObject + + +SpliceObject.parent_eflr_class = Splice diff --git a/src/dlis_writer/logical_record/eflr_types/tool.py b/src/dlis_writer/logical_record/eflr_types/tool.py index c18e1fc7..01ffb123 100644 --- a/src/dlis_writer/logical_record/eflr_types/tool.py +++ b/src/dlis_writer/logical_record/eflr_types/tool.py @@ -16,12 +16,11 @@ class ToolObject(EFLRObject): parent: "Tool" - def __init__(self, name: str, parent: "Tool", **kwargs): + def __init__(self, name: str, **kwargs): """Initialise ToolObject. Args: name : Name of the ToolObject. - parent : Tool EFLR instance this ToolObject belongs to. **kwargs : Values of to be set as characteristics of the ToolObject Attributes. """ @@ -33,7 +32,7 @@ def __init__(self, name: str, parent: "Tool", **kwargs): self.channels = EFLRAttribute('channels', object_class=Channel, multivalued=True, parent_eflr=self) self.parameters = EFLRAttribute('parameters', object_class=Parameter, multivalued=True, parent_eflr=self) - super().__init__(name, parent, **kwargs) + super().__init__(name, **kwargs) class Tool(EFLR): @@ -42,3 +41,6 @@ class Tool(EFLR): set_type = 'TOOL' logical_record_type = EFLRType.STATIC object_type = ToolObject + + +ToolObject.parent_eflr_class = Tool diff --git a/src/dlis_writer/logical_record/eflr_types/well_reference_point.py b/src/dlis_writer/logical_record/eflr_types/well_reference_point.py index 2115b872..45587ead 100644 --- a/src/dlis_writer/logical_record/eflr_types/well_reference_point.py +++ b/src/dlis_writer/logical_record/eflr_types/well_reference_point.py @@ -8,12 +8,11 @@ class WellReferencePointObject(EFLRObject): parent: "WellReferencePoint" - def __init__(self, name: str, parent: "WellReferencePoint", **kwargs): + def __init__(self, name: str, **kwargs): """Initialise WellReferencePointObject. Args: name : Name of the WellReferencePointObject. - parent : WellReferencePoint EFLR instance this WellReferencePointObject belongs to. **kwargs : Values of to be set as characteristics of the WellReferencePointObject Attributes. """ @@ -40,7 +39,7 @@ def __init__(self, name: str, parent: "WellReferencePoint", **kwargs): self.coordinate_3_value = NumericAttribute( 'coordinate_3_value', representation_code=RepC.FDOUBL, parent_eflr=self) - super().__init__(name, parent, **kwargs) + super().__init__(name, **kwargs) class WellReferencePoint(EFLR): @@ -49,3 +48,6 @@ class WellReferencePoint(EFLR): set_type = 'WELL-REFERENCE' logical_record_type = EFLRType.OLR object_type = WellReferencePointObject + + +WellReferencePointObject.parent_eflr_class = WellReferencePoint diff --git a/src/dlis_writer/logical_record/eflr_types/zone.py b/src/dlis_writer/logical_record/eflr_types/zone.py index 710fc55f..3b7e327f 100644 --- a/src/dlis_writer/logical_record/eflr_types/zone.py +++ b/src/dlis_writer/logical_record/eflr_types/zone.py @@ -1,5 +1,3 @@ -from datetime import datetime - from dlis_writer.logical_record.core.eflr import EFLR, EFLRObject from dlis_writer.utils.enums import EFLRType, RepresentationCode as RepC from dlis_writer.logical_record.core.attribute import Attribute, DTimeAttribute @@ -12,12 +10,11 @@ class ZoneObject(EFLRObject): domains = ('BOREHOLE-DEPTH', 'TIME', 'VERTICAL-DEPTH') #: allowed values for 'domain' Attribute - def __init__(self, name: str, parent: "Zone", **kwargs): + def __init__(self, name: str, **kwargs): """Initialise ZoneObject. Args: name : Name of the ZoneObject. - parent : Zone EFLR instance this ZoneObject belongs to. **kwargs : Values of to be set as characteristics of the ZoneObject Attributes. """ @@ -26,14 +23,7 @@ def __init__(self, name: str, parent: "Zone", **kwargs): self.maximum = DTimeAttribute('maximum', allow_float=True, parent_eflr=self) self.minimum = DTimeAttribute('minimum', allow_float=True, parent_eflr=self) - super().__init__(name, parent, **kwargs) - - if self.domain.value == 'TIME': - if not all(isinstance(v, (datetime, type(None))) for v in (self.minimum.value, self.minimum.value)): - raise TypeError("Zone maximum and minimum should be instances of datetime.datetime") - else: - if not all(isinstance(v, ((int, float), type(None))) for v in (self.minimum.value, self.minimum.value)): - raise TypeError("Zone maximum and minimum should be numbers") + super().__init__(name, **kwargs) @classmethod def check_domain(cls, domain: str) -> str: @@ -50,3 +40,6 @@ class Zone(EFLR): set_type = 'ZONE' logical_record_type = EFLRType.STATIC object_type = ZoneObject + + +ZoneObject.parent_eflr_class = Zone