From 3e48a584b0cb9c9d3d70db3e3b81a4d42b8b6086 Mon Sep 17 00:00:00 2001 From: Dacheng Xu Date: Sun, 25 Aug 2024 15:48:56 +0800 Subject: [PATCH] Be compatible with new `Plugin.run_id` (#1410) * Be compatible with new `Plugin.run_id` * Bug fix * debug for notebook --- bin/bootstrax | 2 +- notebooks/tutorials/SuperrunsExample.ipynb | 506 ++++++++------------- straxen/corrections_services.py | 2 +- straxen/get_corrections.py | 6 +- 4 files changed, 206 insertions(+), 310 deletions(-) diff --git a/bin/bootstrax b/bin/bootstrax index b4d938a15..f4541b1a8 100755 --- a/bin/bootstrax +++ b/bin/bootstrax @@ -1579,7 +1579,7 @@ def process_run(rd, send_heartbeats=args.production): "raw_records_mv", "raw_records_nv", ): - md = st.get_meta(run_id, rr_type) + md = st.get_metadata(run_id, rr_type) if len(md["chunks"]) and ( "first_time" in md["chunks"][0] and "last_endtime" in md["chunks"][0] diff --git a/notebooks/tutorials/SuperrunsExample.ipynb b/notebooks/tutorials/SuperrunsExample.ipynb index 3d0fa1944..f06741fab 100644 --- a/notebooks/tutorials/SuperrunsExample.ipynb +++ b/notebooks/tutorials/SuperrunsExample.ipynb @@ -20,16 +20,7 @@ "execution_count": 1, "id": "mineral-indianapolis", "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/home/dwenz/mymodules/straxen/straxen/rucio.py:29: UserWarning: No installation of rucio-clients found. Can't use rucio remote backend.\n", - " warnings.warn(\"No installation of rucio-clients found. Can't use rucio remote backend.\")\n" - ] - } - ], + "outputs": [], "source": [ "import strax\n", "import straxen" @@ -51,12 +42,12 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "id": "biblical-shame", "metadata": {}, "outputs": [], "source": [ - "from strax.testutils import Records, Peaks\n", + "from strax.testutils import Records, Peaks, PeakClassification\n", "\n", "superrun_name = \"_superrun_test\"\n", "st = strax.Context(\n", @@ -65,7 +56,7 @@ " \"./strax_data\", provide_run_metadata=True, readonly=False, deep_scan=True\n", " )\n", " ],\n", - " register=[Records, Peaks],\n", + " register=[Records, Peaks, PeakClassification],\n", " config={\"bonus_area\": 42},\n", ")\n", "st.set_context_config({\"use_per_run_defaults\": False})" @@ -73,27 +64,51 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "id": "suffering-burning", "metadata": {}, "outputs": [ { - "name": "stderr", - "output_type": "stream", - "text": [ - "Could not estimate run start and end time from run metadata: assuming it is 0 and inf\n", - "Could not estimate run start and end time from run metadata: assuming it is 0 and inf\n", - "Could not estimate run start and end time from run metadata: assuming it is 0 and inf\n" - ] + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "518184b9089146f083b20910b87d4b86", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Loading peaks: | | 0.00 % [00:00),\n", - " 'end': datetime.datetime(2021, 7, 14, 12, 30, 57, 830000, tzinfo=),\n", - " 'livetime': 30000000000.0,\n", - " 'name': '_superrun_test'}" + "{'comments': [{'comment': ''}],\n", + " 'end': datetime.datetime(2024, 8, 25, 2, 5, 48, 884000),\n", + " 'livetime': 30.0,\n", + " 'mode': [''],\n", + " 'name': '_superrun_test',\n", + " 'source': [''],\n", + " 'start': datetime.datetime(2024, 8, 25, 2, 4, 58, 884000),\n", + " 'sub_run_spec': {'0': 'all', '1': 'all', '2': 'all'},\n", + " 'tags': [{'name': ''}]}" ] }, - "execution_count": 8, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -436,17 +344,10 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "id": "delayed-reggae", "metadata": {}, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Checking data availability: 0it [00:00, ?it/s]\n" - ] - }, { "data": { "text/html": [ @@ -471,6 +372,7 @@ " name\n", " number\n", " mode\n", + " source\n", " tags\n", " \n", " \n", @@ -481,6 +383,7 @@ " 0.0\n", " \n", " \n", + " \n", " \n", " \n", " 1\n", @@ -488,6 +391,7 @@ " 1.0\n", " \n", " \n", + " \n", " \n", " \n", " 2\n", @@ -495,6 +399,7 @@ " 2.0\n", " \n", " \n", + " \n", " \n", " \n", " 3\n", @@ -502,20 +407,30 @@ " NaN\n", " \n", " \n", + " \n", + " \n", + " \n", + " 4\n", + " 024399\n", + " 24399.0\n", + " \n", + " \n", + " \n", " \n", " \n", "\n", "" ], "text/plain": [ - " name number mode tags\n", - "0 0 0.0 \n", - "1 1 1.0 \n", - "2 2 2.0 \n", - "3 _superrun_test NaN " + " name number mode source tags\n", + "0 0 0.0 \n", + "1 1 1.0 \n", + "2 2 2.0 \n", + "3 _superrun_test NaN \n", + "4 024399 24399.0 " ] }, - "execution_count": 9, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -536,19 +451,19 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 9, "id": "differential-rocket", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "d3d440291216445398c84724986d0f03", + "model_id": "d7a3a5f7d34e4c57a95e25fe2c7bbaa5", "version_major": 2, "version_minor": 0 }, "text/plain": [ - "Loading 3 runs: 0it [00:00, ?it/s]" + "Loading 3 runs: 0%| | 0/3 [00:00name\n", " number\n", " mode\n", + " source\n", " tags\n", - " records_available\n", + " peaks_available\n", " \n", " \n", " \n", @@ -849,6 +755,7 @@ " 0.0\n", " \n", " \n", + " \n", " True\n", " \n", " \n", @@ -857,6 +764,7 @@ " 1.0\n", " \n", " \n", + " \n", " True\n", " \n", " \n", @@ -865,6 +773,7 @@ " 2.0\n", " \n", " \n", + " \n", " True\n", " \n", " \n", @@ -873,6 +782,7 @@ " NaN\n", " \n", " \n", + " \n", " True\n", " \n", " \n", @@ -880,20 +790,20 @@ "" ], "text/plain": [ - " name number mode tags records_available\n", - "0 0 0.0 True\n", - "1 1 1.0 True\n", - "2 2 2.0 True\n", - "3 _superrun_test NaN True" + " name number mode source tags peaks_available\n", + "0 0 0.0 True\n", + "1 1 1.0 True\n", + "2 2 2.0 True\n", + "3 _superrun_test NaN True" ] }, - "execution_count": 16, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "st.select_runs(available=(\"records\",))" + "st.select_runs(available=(\"peaks\",))" ] }, { @@ -906,7 +816,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 16, "id": "authentic-marijuana", "metadata": {}, "outputs": [ @@ -916,66 +826,52 @@ "False" ] }, - "execution_count": 17, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "st.is_stored(subrun_ids[0], \"peaks\")" + "st.is_stored(subrun_ids[0], \"peak_classification\")" ] }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 17, "id": "continental-baptist", "metadata": {}, "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "c9f25a5ef0ca4afbb2543482c94170ed", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Loading 3 runs: 0it [00:00, ?it/s]" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, { "data": { "text/plain": [ - "True" + "False" ] }, - "execution_count": 18, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "st.make(superrun_name, \"peaks\")\n", - "st.is_stored(subrun_ids[0], \"peaks\")" + "st.make(superrun_name, \"peak_classification\")\n", + "st.is_stored(subrun_ids[0], \"peak_classification\")" ] }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 18, "id": "portuguese-imaging", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "121b0dc13154498284734ed242b5c620", + "model_id": "998fb135d8014180ba99faaece452db2", "version_major": 2, "version_minor": 0 }, "text/plain": [ - "Loading peaks: | | 0.00 % [00:00 ty.Dict[str, ty.Dict[str, tuple]] before_cmt, cmt, after_cmt = opt.partition("cmt://") p = context._get_plugins((data_type,), runid_test_str)[data_type] context._set_plugin_config(p, runid_test_str, tolerant=False) - del p.run_id + del p._Plugin__run_id p.config[option_key] = after_cmt try: correction_name = getattr(p, option_key) except AttributeError: - # make sure the correction name does not depend on runid + # make sure the correction name does not depend on run_id raise RuntimeError( - "Correction names should not depend on runids! " + "Correction names should not depend on run_ids! " f"Please check your option for {option_key}" )