Skip to content

Commit bcf1baa

Browse files
committed
v2: handle merged observable.observableTransformation observable.noiseDistribution
Update to changes in PEtab v2 draft, see PEtab-dev/PEtab#619. Closes #375.
1 parent 87cec8c commit bcf1baa

File tree

4 files changed

+8
-33
lines changed

4 files changed

+8
-33
lines changed

petab/v2/C.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@
147147
OBSERVABLE_FORMULA = "observableFormula"
148148
#: Noise formula column in the observable table
149149
NOISE_FORMULA = "noiseFormula"
150-
#: Observable transformation column in the observable table
151-
OBSERVABLE_TRANSFORMATION = "observableTransformation"
152150
#: Noise distribution column in the observable table
153151
NOISE_DISTRIBUTION = "noiseDistribution"
154152

@@ -162,7 +160,6 @@
162160
#: Optional columns of observable table
163161
OBSERVABLE_DF_OPTIONAL_COLS = [
164162
OBSERVABLE_NAME,
165-
OBSERVABLE_TRANSFORMATION,
166163
NOISE_DISTRIBUTION,
167164
]
168165

@@ -181,8 +178,6 @@
181178
LOG = "log"
182179
#: Logarithmic base 10 transformation
183180
LOG10 = "log10"
184-
#: Supported observable transformations
185-
OBSERVABLE_TRANSFORMATIONS = [LIN, LOG, LOG10]
186181

187182

188183
# NOISE MODELS
@@ -232,7 +227,7 @@
232227

233228

234229
#: Supported noise distributions
235-
NOISE_MODELS = [NORMAL, LAPLACE]
230+
NOISE_DISTRIBUTIONS = [NORMAL, LAPLACE, LOG_NORMAL, LOG_LAPLACE]
236231

237232

238233
# VISUALIZATION

petab/v2/core.py

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
__all__ = [
3333
"Observable",
3434
"ObservableTable",
35-
"ObservableTransformation",
3635
"NoiseDistribution",
3736
"Change",
3837
"Condition",
@@ -87,20 +86,6 @@ def _valid_petab_id(v: str) -> str:
8786
return v
8887

8988

90-
class ObservableTransformation(str, Enum):
91-
"""Observable transformation types.
92-
93-
Observable transformations as used in the PEtab observables table.
94-
"""
95-
96-
#: No transformation
97-
LIN = C.LIN
98-
#: Logarithmic transformation (natural logarithm)
99-
LOG = C.LOG
100-
#: Logarithmic transformation (base 10)
101-
LOG10 = C.LOG10
102-
103-
10489
class ParameterScale(str, Enum):
10590
"""Parameter scales.
10691
@@ -122,6 +107,10 @@ class NoiseDistribution(str, Enum):
122107
NORMAL = C.NORMAL
123108
#: Laplace distribution
124109
LAPLACE = C.LAPLACE
110+
#: Log-normal distribution
111+
LOG_NORMAL = C.LOG_NORMAL
112+
#: Log-Laplace distribution
113+
LOG_LAPLACE = C.LOG_LAPLACE
125114

126115

127116
class PriorDistribution(str, Enum):
@@ -173,10 +162,6 @@ class Observable(BaseModel):
173162
name: str | None = Field(alias=C.OBSERVABLE_NAME, default=None)
174163
#: Observable formula.
175164
formula: sp.Basic | None = Field(alias=C.OBSERVABLE_FORMULA, default=None)
176-
#: Observable transformation.
177-
transformation: ObservableTransformation = Field(
178-
alias=C.OBSERVABLE_TRANSFORMATION, default=ObservableTransformation.LIN
179-
)
180165
#: Noise formula.
181166
noise_formula: sp.Basic | None = Field(alias=C.NOISE_FORMULA, default=None)
182167
#: Noise distribution.
@@ -193,9 +178,7 @@ class Observable(BaseModel):
193178
"name",
194179
"formula",
195180
"noise_formula",
196-
"noise_formula",
197181
"noise_distribution",
198-
"transformation",
199182
mode="before",
200183
)
201184
@classmethod

petab/v2/lint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,12 @@ class CheckPosLogMeasurements(ValidationTask):
326326
log-transformation are positive."""
327327

328328
def run(self, problem: Problem) -> ValidationIssue | None:
329-
from .core import ObservableTransformation as ot
329+
from .core import NoiseDistribution as nd
330330

331331
log_observables = {
332332
o.id
333333
for o in problem.observable_table.observables
334-
if o.transformation in [ot.LOG, ot.LOG10]
334+
if o.noise_distribution in [nd.LOG_NORMAL, nd.LOG_LAPLACE]
335335
}
336336
if log_observables:
337337
for m in problem.measurement_table.measurements:

petab/v2/problem.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,6 @@ def add_observable(
903903
formula: str,
904904
noise_formula: str | float | int = None,
905905
noise_distribution: str = None,
906-
transform: str = None,
907906
name: str = None,
908907
**kwargs,
909908
):
@@ -914,7 +913,6 @@ def add_observable(
914913
formula: The observable formula
915914
noise_formula: The noise formula
916915
noise_distribution: The noise distribution
917-
transform: The observable transformation
918916
name: The observable name
919917
kwargs: additional columns/values to add to the observable table
920918
@@ -929,8 +927,7 @@ def add_observable(
929927
record[NOISE_FORMULA] = noise_formula
930928
if noise_distribution is not None:
931929
record[NOISE_DISTRIBUTION] = noise_distribution
932-
if transform is not None:
933-
record[OBSERVABLE_TRANSFORMATION] = transform
930+
934931
record.update(kwargs)
935932

936933
self.observable_table += core.Observable(**record)

0 commit comments

Comments
 (0)