From d27e2042a02a30e51872ec8309e315bfea1ee4e1 Mon Sep 17 00:00:00 2001 From: jrhosk Date: Sun, 15 Feb 2026 00:32:31 +0900 Subject: [PATCH 1/2] Tools notebook to add entry to json file. Mostly for personal use. --- docs/add_entry.ipynb | 102 ++++++++++++++++++++++++++++++++ docs/file-manifest-update.ipynb | 102 +++++--------------------------- src/toolviper/utils/tools.py | 16 ++--- 3 files changed, 126 insertions(+), 94 deletions(-) create mode 100644 docs/add_entry.ipynb diff --git a/docs/add_entry.ipynb b/docs/add_entry.ipynb new file mode 100644 index 0000000..99e0814 --- /dev/null +++ b/docs/add_entry.ipynb @@ -0,0 +1,102 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "414e2078-f6af-4d19-84b9-e083d6223cd6", + "metadata": {}, + "outputs": [], + "source": [ + "import toolviper\n", + "import pathlib" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "39df5372-e17a-4898-91dc-f598f1ab2a35", + "metadata": {}, + "outputs": [], + "source": [ + "path = pathlib.Path().cwd()\n", + "\n", + "toolviper.utils.data.update(path=str(path))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3471bb0e-41bc-45f6-b4ca-8999fb423a31", + "metadata": {}, + "outputs": [], + "source": [ + "entries = []\n", + "\n", + "entry = {\n", + " \"file\": str(path.joinpath(\"ngc5921-lsrk-cube.psf.zip\")),\n", + " \"path\": \"radps/image\",\n", + " \"dtype\": \"CASA image\",\n", + " \"telescope\": \"VLA\",\n", + " \"mode\": \"Interferometric\"\n", + "}\n", + "\n", + "entries.append(entry)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0870dba2-cf08-4130-aea2-8d64c60cff07", + "metadata": {}, + "outputs": [], + "source": [ + "_ = toolviper.utils.tools.add_entry(\n", + " entries=entries,\n", + " manifest=str(path.joinpath(\"file.download.json\")),\n", + " versioning=\"patch\"\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a113bb2b-fed4-4ede-8d8b-353958f59602", + "metadata": {}, + "outputs": [], + "source": [ + "#toolviper.utils.data.update()\n", + "\n", + "#toolviper.utils.data.download(file=\"ngc5921-lsrk-cube.psf\", folder=\"test\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7df91b02-3e25-4989-a76e-20ca4b7a9cb2", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.12" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/file-manifest-update.ipynb b/docs/file-manifest-update.ipynb index 76579f2..8b40c6d 100644 --- a/docs/file-manifest-update.ipynb +++ b/docs/file-manifest-update.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "33d17704-1b0c-40dc-929c-75338f83c3c2", "metadata": {}, "outputs": [], @@ -13,7 +13,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "id": "7b0ca451-df41-4d13-ac4c-3e2b7601eba4", "metadata": {}, "outputs": [], @@ -31,42 +31,10 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "id": "937a9e64-cc8a-4283-a3d8-1f5118592d52", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[\u001b[38;2;128;05;128m2025-11-25 09:28:05,853\u001b[0m] \u001b[38;2;50;50;205m INFO\u001b[0m\u001b[38;2;112;128;144m viperlog: \u001b[0m Updating file metadata information ... \n" - ] - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "0d3d304cc4d545b798bd0056c2b3c2a5", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Output()" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
\n"
-      ],
-      "text/plain": []
-     },
-     "metadata": {},
-     "output_type": "display_data"
-    }
-   ],
+   "outputs": [],
    "source": [
     "path = pathlib.Path().cwd()\n",
     "\n",
@@ -75,45 +43,27 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 4,
+   "execution_count": null,
    "id": "8e66f912-d356-486b-8992-6e3ce62ad672",
    "metadata": {},
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "updating: single-dish.ultra.calibrated.ms/ (stored 0%)\n",
-      "updating: single-dish.ultra.calibrated.ms/data.bin (stored 0%)\n"
-     ]
-    }
-   ],
+   "outputs": [],
    "source": [
     "make_random_file(file=\"single-dish.ultra.calibrated.ms\")"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 5,
+   "execution_count": null,
    "id": "05c07272-88ee-424a-9219-78e3ea52a0d7",
    "metadata": {},
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "updating: alma.mega.uncalibrated.ms/ (stored 0%)\n",
-      "updating: alma.mega.uncalibrated.ms/data.bin (stored 0%)\n"
-     ]
-    }
-   ],
+   "outputs": [],
    "source": [
     "make_random_file(file=\"alma.mega.uncalibrated.ms\")"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 6,
+   "execution_count": null,
    "id": "7fd8b0b1-302b-454d-921b-9929af36e44e",
    "metadata": {},
    "outputs": [],
@@ -133,30 +83,10 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 7,
+   "execution_count": null,
    "id": "d2bc0fd4-64c3-42e4-9422-9c6dd69a9c32",
    "metadata": {},
-   "outputs": [
-    {
-     "data": {
-      "text/plain": [
-       "[{'file': '/Users/joshua/Development/toolviper/docs/single-dish.ultra.calibrated.ms.zip',\n",
-       "  'path': 'single-dish',\n",
-       "  'dtype': 'ASDM',\n",
-       "  'telescope': 'Nobeyama',\n",
-       "  'mode': 'Holography'},\n",
-       " {'file': '/Users/joshua/Development/toolviper/docs/alma.mega.uncalibrated.ms.zip',\n",
-       "  'path': 'radps/measurement_set',\n",
-       "  'dtype': 'CASA MSv4',\n",
-       "  'telescope': 'Alma',\n",
-       "  'mode': 'Interferometric'}]"
-      ]
-     },
-     "execution_count": 7,
-     "metadata": {},
-     "output_type": "execute_result"
-    }
-   ],
+   "outputs": [],
    "source": [
     "entry = {\n",
     "    \"file\": str(path.joinpath(\"alma.mega.uncalibrated.ms.zip\")),\n",
@@ -171,17 +101,15 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 9,
+   "execution_count": null,
    "id": "0e98fb83-eb71-408d-b476-1d821d14b7f0",
    "metadata": {},
    "outputs": [],
    "source": [
-    "entries.append(entry)\n",
-    "\n",
     "_ = toolviper.utils.tools.add_entry(\n",
-    "    entries=entries,\n",
-    "    manifest=str(path.joinpath(\"file.download.json\")),\n",
-    "    versioning=\"patch\"\n",
+    "        entries=entries,\n",
+    "        manifest=str(path.joinpath(\"file.download.json\")),\n",
+    "        versioning=\"patch\"\n",
     ")"
    ]
   }
diff --git a/src/toolviper/utils/tools.py b/src/toolviper/utils/tools.py
index f63916a..640f470 100644
--- a/src/toolviper/utils/tools.py
+++ b/src/toolviper/utils/tools.py
@@ -116,6 +116,7 @@ def process_entry_(
 
     file_key = str(filename.name)
 
+
     if str(filename).endswith(".zip"):
         file_key = str(filename.name).split(".zip")[0]
 
@@ -130,7 +131,7 @@ def process_entry_(
         "mode": mode,
         "hash": toolviper.utils.tools.calculate_checksum(str(filename)),
     }
-
+    
     json_file["metadata"][file_key] = metadata
 
 
@@ -160,11 +161,11 @@ def add_entry(
     dict, None
     """
     import toolviper
-
+    logger.get_logger("viperlog").setLevel("DEBUG")
     # Make sure entries is a list even if it's a single entry
     if isinstance(entries, dict):
         entries = [entries]
-
+    json_file = None
     try:
         if manifest is None:
             manifest = pathlib.Path(toolviper.__path__[0]).joinpath(
@@ -185,8 +186,9 @@ def add_entry(
         for entry in entries:
             process_entry_(**entry, json_file=json_file)
 
-    except KeyError:
-        logger.error("entry not found in metadata ... skipping")
+
+    except KeyError as key_error:
+        logger.error(f"entry not found in metadata ... skipping: {key_error}")
         return None
 
     except TypeError:
@@ -194,11 +196,11 @@ def add_entry(
             "The file you are trying to add is likely the wrong type. Try zipping it."
         )
 
-    except OSError:
+    except OSError as os_error:
         logger.error("Error opening specified json manifest file.")
+        logger.error(str(os_error))
         return None
 
-    json_file = None
     with open("file.download.json", "w") as file_:
         json.dump(json_file, file_)
 

From b60db396cace39c57355711485f0cac93d7b414d Mon Sep 17 00:00:00 2001
From: jrhosk 
Date: Sun, 15 Feb 2026 09:58:24 +0900
Subject: [PATCH 2/2] Blacked.

---
 src/toolviper/utils/tools.py | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/toolviper/utils/tools.py b/src/toolviper/utils/tools.py
index 640f470..37462ab 100644
--- a/src/toolviper/utils/tools.py
+++ b/src/toolviper/utils/tools.py
@@ -116,7 +116,6 @@ def process_entry_(
 
     file_key = str(filename.name)
 
-
     if str(filename).endswith(".zip"):
         file_key = str(filename.name).split(".zip")[0]
 
@@ -131,7 +130,7 @@ def process_entry_(
         "mode": mode,
         "hash": toolviper.utils.tools.calculate_checksum(str(filename)),
     }
-    
+
     json_file["metadata"][file_key] = metadata
 
 
@@ -161,6 +160,7 @@ def add_entry(
     dict, None
     """
     import toolviper
+
     logger.get_logger("viperlog").setLevel("DEBUG")
     # Make sure entries is a list even if it's a single entry
     if isinstance(entries, dict):
@@ -186,7 +186,6 @@ def add_entry(
         for entry in entries:
             process_entry_(**entry, json_file=json_file)
 
-
     except KeyError as key_error:
         logger.error(f"entry not found in metadata ... skipping: {key_error}")
         return None