Skip to content
Merged
Show file tree
Hide file tree
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
102 changes: 102 additions & 0 deletions docs/add_entry.ipynb
Original file line number Diff line number Diff line change
@@ -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
}
102 changes: 15 additions & 87 deletions docs/file-manifest-update.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "33d17704-1b0c-40dc-929c-75338f83c3c2",
"metadata": {},
"outputs": [],
Expand All @@ -13,7 +13,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"id": "7b0ca451-df41-4d13-ac4c-3e2b7601eba4",
"metadata": {},
"outputs": [],
Expand All @@ -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": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
],
"text/plain": []
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"path = pathlib.Path().cwd()\n",
"\n",
Expand All @@ -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": [],
Expand All @@ -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",
Expand All @@ -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",
")"
]
}
Expand Down
11 changes: 6 additions & 5 deletions src/toolviper/utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,11 @@ def add_entry(
"""
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(
Expand All @@ -185,20 +186,20 @@ 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:
logger.error(
"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_)

Expand Down
Loading