Skip to content

Commit

Permalink
add deprecation to tofs
Browse files Browse the repository at this point in the history
  • Loading branch information
nvaytet committed Oct 10, 2024
1 parent e9db7d4 commit 67e73b0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/tof/chopper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import scipp as sc

from .deprecation import deprecated
from .reading import ComponentReading, ReadingField
from .utils import two_pi

Expand Down Expand Up @@ -214,3 +215,8 @@ def __repr__(self) -> str:

def __str__(self) -> str:
return self.__repr__()

@property
@deprecated("Use 'toas' instead.")
def tofs(self) -> ReadingField:
return self.toas
36 changes: 36 additions & 0 deletions src/tof/deprecation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2024 Scipp contributors (https://github.com/scipp)

import functools
import warnings
from collections.abc import Callable


class VisibleDeprecationWarning(UserWarning):
"""Visible deprecation warning.
By default, Python and in particular Jupyter will not show deprecation
warnings, so this class can be used when a very visible warning is helpful.
"""


VisibleDeprecationWarning.__module__ = 'tof'


def deprecated(message: str = '') -> Callable:
def decorator(function: Callable) -> Callable:
@functools.wraps(function)
def wrapper(*args, **kwargs):
warnings.warn(
f'{function.__name__} is deprecated. {message}',
VisibleDeprecationWarning,
stacklevel=2,
)
return function(*args, **kwargs)

return wrapper

return decorator


__all__ = ['deprecated']
6 changes: 6 additions & 0 deletions src/tof/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import scipp as sc

from .deprecation import deprecated
from .reading import ComponentReading, ReadingField


Expand Down Expand Up @@ -57,3 +58,8 @@ def __repr__(self) -> str:

def __str__(self) -> str:
return self.__repr__()

@property
@deprecated("Use 'toas' instead.")
def tofs(self) -> ReadingField:
return self.toas
2 changes: 2 additions & 0 deletions src/tof/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ def run(self):
container[c.name]['data'] = self.source.data.copy(deep=False)
t = birth_time + (c.distance / speed).to(unit=birth_time.unit, copy=False)
container[c.name]['data'].coords['toa'] = t
# TODO: remove 'tof' coordinate once deprecation period is over
container[c.name]['data'].coords['tof'] = t
if isinstance(c, Detector):
container[c.name]['visible_mask'] = initial_mask
container[c.name]['data'].masks['blocked_by_others'] = ~initial_mask
Expand Down
2 changes: 2 additions & 0 deletions src/tof/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2024 Scipp contributors (https://github.com/scipp)

from dataclasses import dataclass

Expand Down

0 comments on commit 67e73b0

Please sign in to comment.