Skip to content

Commit

Permalink
Merge branch 'master' into cnf_urlconfig_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dachengx authored Jan 24, 2025
2 parents a2f559e + 4519fa7 commit 711b18a
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 54 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/pypi_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup python
uses: actions/[email protected]
with:
python-version: '3.9'
python-version: "3.10"

- name: Checkout repo
uses: actions/checkout@v4
Expand All @@ -28,8 +28,6 @@ jobs:

- name: Publish a Python distribution to PyPI
# Do the publishing
# Might want to add but does not work on workflow_dispatch :
# if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
with:
user: ${{ secrets.token }}
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ jobs:
strategy:
fail-fast: False
matrix:
python-version: [ "3.9", "3.10" ]
test: [ 'coveralls', 'pytest', 'pytest_no_database' ]
python-version: ["3.10", "3.11"]
test: ["coveralls", "pytest", "pytest_no_database"]
# Drop some not crucial tests for python 3.10 and 3.11
exclude:
- python-version: "3.11"
test: coveralls
- python-version: "3.10"
test: pytest_no_database
- python-version: "3.11"
test: pytest_no_database

Expand All @@ -62,6 +60,7 @@ jobs:
pip install pytest hypothesis coverage coveralls
pip install git+https://github.com/XENONnT/base_environment.git --force-reinstall
pip install git+https://github.com/AxFoundation/strax.git --force-reinstall
pip install .
- name: Start MongoDB
uses: supercharge/[email protected]
Expand Down Expand Up @@ -103,6 +102,7 @@ jobs:
run: |
coverage run --source=straxen -m pytest --durations 0
coverage report
- name: Coveralls
# Make the coverage report and upload
env:
Expand All @@ -128,5 +128,6 @@ jobs:
bash .github/scripts/create_pre_apply_function.sh $HOME
coverage run --append --source=straxen -m pytest -v
coveralls --service=github
- name: goodbye
run: echo "tests done, bye bye"
run: echo 'tests done, bye bye'
2 changes: 1 addition & 1 deletion .github/workflows/test_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ 3.9 ]
python-version: ["3.10"]
steps:
- name: Setup python
uses: actions/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ build:
apt_packages:
- graphviz
tools:
python: "3.9"
python: "3.10"

python:
install:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def __getattr__(cls, name):
# -- Options for intersphinx extension ---------------------------------------

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {"https://docs.python.org/": None}
intersphinx_mapping = {"python": ("https://docs.python.org/3", None)}


def setup(app):
Expand Down
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ classifiers = [
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: BSD License",
"Natural Language :: English",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Intended Audience :: Science/Research",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Scientific/Engineering :: Physics",
Expand All @@ -29,8 +30,8 @@ straxen_print_versions = "straxen.scripts.straxen_print_versions:main"
straxer = "straxen.scripts.straxer:main"

[tool.poetry.dependencies]
python = ">=3.9,<3.13"
strax = ">=2.0.3"
python = ">=3.10,<3.13"
strax = ">=2.0.5"
bokeh = "*"
commentjson = "*"
gitpython = "*"
Expand Down
4 changes: 2 additions & 2 deletions straxen/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def open_resource(file_name: str, fmt="text"):


@export
def get_resource(x: str, fmt="text"):
def get_resource(x: str, fmt="text", readable=False):
"""
Get the resource from an online source to be opened here. We will
sequentially try the following:
Expand Down Expand Up @@ -201,7 +201,7 @@ def get_resource(x: str, fmt="text"):
elif straxen.uconfig is not None:
downloader = utilix.mongo_storage.MongoDownloader()
if x in downloader.list_files():
path = downloader.download_single(x)
path = downloader.download_single(x, human_readable_file_name=readable)
return open_resource(path, fmt=fmt)
# 4. load from URL
if "://" in x:
Expand Down
4 changes: 2 additions & 2 deletions straxen/config/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def get_item_or_attr(obj, key, default=None):


@URLConfig.register("resource")
def get_resource(name: str, fmt: str = "text", **kwargs):
def get_resource(name: str, fmt: str = "text", readable: bool = False, **kwargs):
"""Fetch a straxen resource, allow a direct download using <fmt='abs_path'> otherwise kwargs are
passed directly to straxen.get_resource."""
if fmt == "abs_path":
downloader = utilix.mongo_storage.MongoDownloader()
return downloader.download_single(name)
return downloader.download_single(name, human_readable_file_name=readable)
return straxen.get_resource(name, fmt=fmt)


Expand Down
4 changes: 2 additions & 2 deletions straxen/plugins/events/corrected_areas.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class CorrectedAreas(strax.Plugin):
"Data will be corrected to this value",
)

# se gain for this run, allowing for using CMT. default to online
# se gain for this run, allowing for using xedocs. default to online
se_gain = straxen.URLConfig(
default="take://objects-to-dict://"
"xedocs://se_gains"
Expand All @@ -67,7 +67,7 @@ class CorrectedAreas(strax.Plugin):
help="Actual SE gain for a given run (allows for time dependence)",
)

# relative extraction efficiency which can change with time and modeled by CMT.
# relative extraction efficiency which can change with time and modeled by xedocs.
rel_extraction_eff = straxen.URLConfig(
default="take://objects-to-dict://"
"xedocs://rel_extraction_effs"
Expand Down
9 changes: 3 additions & 6 deletions straxen/plugins/events/event_pattern_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ class EventPatternFit(strax.Plugin):
help="S1 (x, y, z) optical/pattern map.",
infer_type=False,
default=(
"itp_map://"
"resource://"
"itp_map://resource://"
"XENONnT_s1_xyz_patterns_corrected_qes_MCva43fa9b_wires.pkl"
"?fmt=pkl"
),
Expand All @@ -55,8 +54,7 @@ class EventPatternFit(strax.Plugin):
help="S2 (x, y) optical/pattern map.",
infer_type=False,
default=(
"itp_map://"
"resource://"
"itp_map://resource://"
"XENONnT_s2_xy_patterns_LCE_corrected_qes_MCva43fa9b_wires.pkl"
"?fmt=pkl"
),
Expand All @@ -66,8 +64,7 @@ class EventPatternFit(strax.Plugin):
help="S2 (x, y) optical data-driven model",
infer_type=False,
default=(
"tf://"
"resource://"
"tf://resource://"
"XENONnT_s2_optical_map_data_driven_ML_v0_2021_11_25.tar.gz"
"?custom_objects=plugin.s2_map_custom_objects"
"&fmt=abs_path"
Expand Down
4 changes: 2 additions & 2 deletions straxen/plugins/events/event_positions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class EventPositions(strax.Plugin):
"""Computes the observed and corrected position for the main S1/S2 pairs in an event.
For XENONnT data, it returns the FDC corrected positions of the
default_reconstruction_algorithm. In case the fdc_map is given as a file (not through CMT), then
the coordinate system should be given as (x, y, z), not (x, y, drift_time).
default_reconstruction_algorithm. In case the fdc_map is given as a file (not through xedocs),
then the coordinate system should be given as (x, y, z), not (x, y, drift_time).
"""

Expand Down
16 changes: 8 additions & 8 deletions straxen/plugins/events/event_s1_positions_cnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ class EventS1PositionCNN(EventS1PositionBase):

tf_model_s1_cnn = straxen.URLConfig(
default=(
f"tf://"
f"resource://"
f"xedocs://posrec_models"
f"?version=ONLINE"
f"&run_id=plugin.run_id"
f"&kind=s1_cnn"
f"&fmt=abs_path"
f"&attr=value"
"tf://"
"resource://"
"xedocs://posrec_models"
"?version=ONLINE"
"&run_id=plugin.run_id"
"&kind=s1_cnn"
"&fmt=abs_path"
"&attr=value"
),
help=(
's1 position 3d reconstruction cnn model. Should be opened using the "tf" descriptor. '
Expand Down
16 changes: 8 additions & 8 deletions straxen/plugins/peaks/peak_s1_positions_cnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ class PeakS1PositionCNN(PeakS1PositionBase):

tf_model_s1_cnn = straxen.URLConfig(
default=(
f"tf://"
f"resource://"
f"xedocs://posrec_models"
f"?version=ONLINE"
f"&run_id=plugin.run_id"
f"&kind=s1_cnn"
f"&fmt=abs_path"
f"&attr=value"
"tf://"
"resource://"
"xedocs://posrec_models"
"?version=ONLINE"
"&run_id=plugin.run_id"
"&kind=s1_cnn"
"&fmt=abs_path"
"&attr=value"
),
help=(
's1 position 3d reconstruction cnn model. Should be opened using the "tf" descriptor. '
Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/peak_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_tight_coincidence(self: PluginTestCase):
peaklets = self.st.get_array(self.run_id, "peaklets", progress_bar=False)
message = "There might be some issue in tight_coincidence."
sum_tight_coincidence = np.sum(peaklets["tight_coincidence"])
assert np.abs(sum_tight_coincidence - 1990) < 5, message
assert sum_tight_coincidence == 1991, message


if __name__ == "__main__":
Expand Down
6 changes: 3 additions & 3 deletions tests/plugins/posrec_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ def test_posrec_set_path(

# Get current config
plugin = self.st.get_single_plugin(self.run_id, target)
cmt_config = plugin.config[config_name]
cmt_config_without_tf = cmt_config.replace("tf://", "")
config = plugin.config[config_name]
config_without_tf = config.replace("tf://", "")

# Hack URLConfigs to give back intermediate results (this should be easier..)
st_fixed_path = self.st.new_context()
st_fixed_path.set_config({config_name: cmt_config_without_tf})
st_fixed_path.set_config({config_name: config_without_tf})
plugin_fixed = st_fixed_path.get_single_plugin(self.run_id, target)
file_name = getattr(plugin_fixed, config_name)
self.assertTrue(os.path.exists(file_name))
Expand Down
6 changes: 3 additions & 3 deletions tests/plugins/s1_posrec_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def test_posrec_set_path(

# Get current config
plugin = self.st.get_single_plugin(self.run_id, target)
cmt_config = plugin.config[config_name]
cmt_config_without_tf = cmt_config.replace("tf://", "")
config = plugin.config[config_name]
config_without_tf = config.replace("tf://", "")
# Hack URLConfigs to give back intermediate results (this should be easier..)
st_fixed_path = self.st.new_context()
st_fixed_path.set_config({config_name: cmt_config_without_tf})
st_fixed_path.set_config({config_name: config_without_tf})
plugin_fixed = st_fixed_path.get_single_plugin(self.run_id, target)
file_name = getattr(plugin_fixed, config_name)
self.assertTrue(os.path.exists(file_name))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_mini_analyses.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def test_plot_pulses_nv(self):
)

def test_event_display(self):
"""Event display plot, needs CMT."""
"""Event display plot, needs xedocs."""
self.st.event_display(nt_test_run_id, time_within=self.first_event)

def test_event_display_no_rr(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_url_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_bodedga_get(self):
# Either g1 is 0, bodega changed or someone broke URLConfigs
self.assertTrue(p.test_config)

@unittest.skipIf(not straxen.utilix_is_configured(), "No db access, cannot test CMT.")
@unittest.skipIf(not straxen.utilix_is_configured(), "No db access, cannot test xedocs.")
def test_itp_dict(self, ab_value=20, cd_value=21, dump_as="json"):
"""Test that we are getting ~the same value from interpolating at the central date in a
dict.
Expand Down Expand Up @@ -310,7 +310,7 @@ def func2(**kwargs):
self.assertEqual(filtered2, all_kwargs)
func2(**filtered2)

@unittest.skipIf(not straxen.utilix_is_configured(), "No db access, cannot test CMT.")
@unittest.skipIf(not straxen.utilix_is_configured(), "No db access, cannot test xedocs.")
def test_dry_evaluation(self):
"""Check that running a dry evaluation can be done outside of the context of a URL config
and yield the same result."""
Expand Down

0 comments on commit 711b18a

Please sign in to comment.