-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Specify values as range and add error scaling (#187)
* Add support for ranges in IDS Operator * Implement scaling to error bounds on range operations * Update documentation * Remove IDSSampler * Add tests for IDS Operation * Delete file and fix test * Skip tests if imas is not available
- Loading branch information
1 parent
bf324ac
commit 8007b1f
Showing
16 changed files
with
322 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
from functools import singledispatch | ||
|
||
import numpy as np | ||
|
||
from ..schema import BaseModel, IDSOperation | ||
from ._mapping import IDSMapping | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@singledispatch | ||
def apply_model(model: BaseModel, ids_mapping: IDSMapping) -> None: | ||
"""Apply operation in model to IDS. Data are modified in-place. | ||
Parameters | ||
---------- | ||
model | ||
The model describes the operation to apply to the data. | ||
ids_mapping : IDSMapping | ||
Core profiles IDSMapping, data to apply operation to. | ||
Must contain the IDS path. | ||
Raises | ||
------ | ||
NotImplementedError | ||
When the model is unknown | ||
""" | ||
|
||
raise NotImplementedError(f'Unknown model: {model}') | ||
|
||
|
||
@apply_model.register | ||
def _(model: IDSOperation, ids_mapping: IDSMapping) -> None: | ||
|
||
npfunc = getattr(np, model.operator) | ||
|
||
profile = ids_mapping.flat_fields[model.ids] | ||
|
||
if model.scale_to_error: | ||
sigma_key = model.ids + model._upper_suffix | ||
|
||
if model.value < 0: | ||
lower_key = model.ids + model._lower_suffix | ||
if lower_key in ids_mapping.flat_fields: | ||
sigma_key = lower_key | ||
|
||
sigma_bound = ids_mapping.flat_fields[sigma_key] | ||
sigma = abs(sigma_bound - profile) | ||
|
||
value = sigma * model.value | ||
else: | ||
value = model.value | ||
|
||
logger.info('Apply %s', model) | ||
|
||
logger.debug('data range before: %s - %s', profile.min(), profile.max()) | ||
npfunc(profile, value, out=profile) | ||
logger.debug('data range after: %s - %s', profile.min(), profile.max()) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
from ._basemodel import BaseModel | ||
from ._dimensions import (IDSOperation, IDSOperationDim, IDSSampler, | ||
IDSSamplerDim) | ||
from ._dimensions import ARange, IDSOperation, IDSOperationDim, LinSpace | ||
from ._imas import ImasBaseModel | ||
from ._plot import PlotModel | ||
|
||
__all__ = [ | ||
'BaseModel', | ||
'IDSOperation', | ||
'IDSOperationDim', | ||
'IDSSampler', | ||
'IDSSamplerDim', | ||
'ImasBaseModel', | ||
'PlotModel', | ||
'LinSpace', | ||
'ARange', | ||
] |
Oops, something went wrong.