Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

channelmap updates #78

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions src/legendmeta/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import logging
import os
import re
from datetime import datetime
from getpass import getuser
from pathlib import Path
Expand Down Expand Up @@ -103,7 +104,7 @@ def reset(self) -> None:
self._repo.git.checkout(self._default_git_ref)

def channelmap(
self, on: str | datetime | None = None, system: str = "all"
self, on: str | datetime | None = None, system: str | None = None
) -> AttrsDict:
"""Get a LEGEND channel map.

Expand All @@ -116,9 +117,11 @@ def channelmap(
----------
on
a :class:`~datetime.datetime` object or a string matching the
pattern ``YYYYmmddTHHMMSSZ``.
pattern ``YYYYmmddTHHMMSSZ``, or ``p# r#``, which are period and
run numbers.
system: 'all', 'phy', 'cal', 'lar', ...
query only a data taking "system".
query only a data taking "system". If on is None, default to
'all', otherwise this must be provided

Warning
-------
Expand All @@ -136,12 +139,35 @@ def channelmap(
>>> channel.analysis.usability
'on'

>>> channel = lmeta.channelmap(on=datetime.now(), system='cal').V05267B

>>> channel = lmeta.channelmap('p08 r005', system='cal').V05267B
Comment on lines 141 to +144
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
>>> channel = lmeta.channelmap(on=datetime.now(), system='cal').V05267B
>>> channel = lmeta.channelmap('p08 r005', system='cal').V05267B
>>> channel = lmeta.channelmap(on=datetime.now(), system='cal').V05267B
>>> channel = lmeta.channelmap('p08 r005', system='cal').V05267B


See Also
--------
.textdb.TextDB.on
"""
if on is None:
on = datetime.now()
if system is None:
system = "all"

if system is None:
msg = "Use of channelmap with an on arg but no system arg is deprecated and will raise an error in the future. Provide a value (e.g. 'all', 'cal', 'phy', etc.)"
Copy link
Member

@gipert gipert Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
msg = "Use of channelmap with an on arg but no system arg is deprecated and will raise an error in the future. Provide a value (e.g. 'all', 'cal', 'phy', etc.)"
msg = (
"Use of channelmap with an on arg but no system arg is "
"deprecated and will raise an error in the future. Provide "
"a value (e.g. 'all', 'cal', 'phy', etc.)"
)

log.warning(msg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.warning(msg)
import warnings
warnings.warn(msg, DeprecationWarning, stacklevel=2)

# msg = "System cannot be None. Provide a value (e.g. 'all', 'cal', 'phy', etc.)"
# raise ValueError(msg)

try:
pd, run = re.fullmatch("([pP][0-9]+)\\s*([rR][0-9]+)", on).group(1, 2)
runinfo = self.dataprod.runinfo[pd][run]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this generate an understandable error message if the string does not match?

if system == "all":
on = next(iter(runinfo.values())).start_key
else:
on = runinfo[system].start_key
except (AttributeError, TypeError):
# on is not a period/run
pass

chmap = self.hardware.configuration.channelmaps.on(
on, pattern=None, system=system
Expand Down
Loading