Skip to content

Commit

Permalink
Calibraton timecourse unity (#19)
Browse files Browse the repository at this point in the history
* added calibration attributes

* new implementation calibration timecourse diff

* working mode selector

* fixed failing tests

* updated docs
  • Loading branch information
haeussma authored Oct 24, 2024
1 parent 3f0c653 commit b790f6e
Show file tree
Hide file tree
Showing 114 changed files with 746,524 additions and 131,325 deletions.
10 changes: 6 additions & 4 deletions chromatopy/ioutils/enzymeml.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ def add_measurements_to_enzymeml(

doc.measurements.append(enzml_measurement)

patch_init_t0(doc)

return doc


Expand Down Expand Up @@ -321,7 +323,7 @@ def add_measurement_to_MeasurementData(
add_data(
measurement_data=measurement_data_instances[molecule_id],
chromatogram=chrom,
reaction_time=measurement.reaction_time,
reaction_time=measurement.data.value,
calibrators=calibrators,
calibrator_type=strategy,
extrapolate=extrapolate,
Expand Down Expand Up @@ -513,7 +515,7 @@ def extract_measurement_conditions(
# extract measurement conditions
phs = [measurement.ph for measurement in measurements]
temperatures = [measurement.temperature for measurement in measurements]
time_units = [measurement.time_unit.name for measurement in measurements]
time_units = [measurement.data.unit.name for measurement in measurements]
temperature_units = [
measurement.temperature_unit.name # type: ignore
for measurement in measurements # type: ignore
Expand All @@ -534,14 +536,14 @@ def extract_measurement_conditions(
assert (
measurements[0].temperature is not None
), "The temperature needs to be defined."
assert measurements[0].time_unit is not None, "The time unit needs to be defined."
assert measurements[0].data.unit is not None, "The time unit needs to be defined."
assert (
measurements[0].temperature_unit is not None
), "The temperature unit needs to be defined."

ph = measurements[0].ph
temperature = measurements[0].temperature
time_unit = measurements[0].time_unit
time_unit = measurements[0].data.unit
temperature_unit = measurements[0].temperature_unit

return ph, temperature, time_unit, temperature_unit
Expand Down
103 changes: 101 additions & 2 deletions chromatopy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ class Measurement(BaseModel):
) # type: ignore

id: str
reaction_time: float
time_unit: UnitDefinition
data: Data
temperature: float
temperature_unit: UnitDefinition
ph: float
Expand Down Expand Up @@ -212,6 +211,100 @@ def add_to_chromatograms(
return self.chromatograms[-1]


class Data(BaseModel):
model_config: ConfigDict = ConfigDict( # type: ignore
validate_assigment=True,
use_enum_values=True,
) # type: ignore

value: float
unit: UnitDefinition
data_type: DataType

# JSON-LD fields
ld_id: str = Field(
serialization_alias="@id",
default_factory=lambda: "chromatopy:Data/" + str(uuid4()),
)
ld_type: list[str] = Field(
serialization_alias="@type",
default_factory=lambda: [
"chromatopy:Data",
],
)
ld_context: dict[str, str | dict] = Field(
serialization_alias="@context",
default_factory=lambda: {
"chromatopy": "https://github.com/FAIRChemistry/chromatopy",
},
)

def set_attr_term(
self,
attr: str,
term: str | dict,
prefix: str | None = None,
iri: str | None = None,
):
"""Sets the term for a given attribute in the JSON-LD object
Example:
# Using an IRI term
>> obj.set_attr_term("name", "http://schema.org/givenName")
# Using a prefix and term
>> obj.set_attr_term("name", "schema:givenName", "schema", "http://schema.org")
# Usinng a dictionary term
>> obj.set_attr_term("name", {"@id": "http://schema.org/givenName", "@type": "@id"})
Args:
attr (str): The attribute to set the term for
term (str | dict): The term to set for the attribute
Raises:
AssertionError: If the attribute is not found in the model
"""

assert (
attr in self.model_fields
), f"Attribute {attr} not found in {self.__class__.__name__}"

if prefix:
validate_prefix(term, prefix)

add_namespace(self, prefix, iri)
self.ld_context[attr] = term

def add_type_term(
self, term: str, prefix: str | None = None, iri: str | None = None
):
"""Adds a term to the @type field of the JSON-LD object
Example:
# Using a term
>> obj.add_type_term("https://schema.org/Person")
# Using a prefixed term
>> obj.add_type_term("schema:Person", "schema", "https://schema.org/Person")
Args:
term (str): The term to add to the @type field
prefix (str, optional): The prefix to use for the term. Defaults to None.
iri (str, optional): The IRI to use for the term prefix. Defaults to None.
Raises:
ValueError: If prefix is provided but iri is not
ValueError: If iri is provided but prefix is not
"""

if prefix:
validate_prefix(term, prefix)

add_namespace(self, prefix, iri)
self.ld_type.append(term)


class Chromatogram(BaseModel):
model_config: ConfigDict = ConfigDict( # type: ignore
validate_assigment=True,
Expand Down Expand Up @@ -466,6 +559,7 @@ def add_type_term(
class UnitDefinition(BaseModel):
model_config: ConfigDict = ConfigDict( # type: ignore
validate_assigment=True,
use_enum_values=True,
) # type: ignore

id: Optional[str] = Field(default=None)
Expand Down Expand Up @@ -696,6 +790,11 @@ class SignalType(Enum):
UV = "uv/visible absorbance detector"


class DataType(Enum):
CALIBRATION = "calibration"
TIMECOURSE = "timecourse"


class UnitType(Enum):
AMPERE = "ampere"
AVOGADRO = "avogadro"
Expand Down
Loading

0 comments on commit b790f6e

Please sign in to comment.