changed owncloud download notebook

This commit is contained in:
Michael Weig 2026-03-09 20:25:54 +01:00
parent ef785283f0
commit 0b2c629d16
3 changed files with 114 additions and 157 deletions

2
EDA/login.yaml Normal file
View File

@ -0,0 +1,2 @@
- url: # enter url
- password: # enter passwort

View File

@ -1,157 +0,0 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "aab6b326-a583-47ad-8bb7-723c2fddcc63",
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"# %pip install pyocclient\n",
"import yaml\n",
"import owncloud\n",
"import pandas as pd\n",
"import time"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4f42846c-27c3-4394-a40a-e22d73c2902e",
"metadata": {},
"outputs": [],
"source": [
"start = time.time()\n",
"\n",
"with open(\"../login.yaml\") as f:\n",
" cfg = yaml.safe_load(f)\n",
"url, password = cfg[0][\"url\"], cfg[1][\"password\"]\n",
"file = \"adabase-public-0022-v_0_0_2.h5py\"\n",
"oc = owncloud.Client.from_public_link(url, folder_password=password)\n",
"\n",
"\n",
"oc.get_file(file, \"tmp22.h5\")\n",
"\n",
"end = time.time()\n",
"print(end - start)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3714dec2-85d0-4f76-af46-ea45ebec2fa3",
"metadata": {},
"outputs": [],
"source": [
"start = time.time()\n",
"df_performance = pd.read_hdf(\"tmp22.h5\", \"PERFORMANCE\")\n",
"end = time.time()\n",
"print(end - start)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f50e97d0",
"metadata": {},
"outputs": [],
"source": [
"print(22)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c131c816",
"metadata": {},
"outputs": [],
"source": [
"df_performance"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6ae47e52-ad86-4f8d-b929-0080dc99f646",
"metadata": {},
"outputs": [],
"source": [
"start = time.time()\n",
"df_4_col = pd.read_hdf(\"tmp.h5\", \"SIGNALS\", mode=\"r\", columns=[\"STUDY\"], start=0, stop=1)\n",
"end = time.time()\n",
"print(end - start)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7c139f3a-ede8-4530-957d-d1bb939f6cb5",
"metadata": {},
"outputs": [],
"source": [
"df_4_col.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a68d58ea-65f2-46c4-a2b2-8c3447c715d7",
"metadata": {},
"outputs": [],
"source": [
"df_4_col.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "95aa4523-3784-4ab6-bf92-0227ce60e863",
"metadata": {},
"outputs": [],
"source": [
"df_4_col.info()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "defbcaf4-ad1b-453f-9b48-ab0ecfc4b5d5",
"metadata": {},
"outputs": [],
"source": [
"df_4_col.isna().sum()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "72313895-c478-44a5-9108-00b0bec01bb8",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"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.11.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

View File

@ -0,0 +1,112 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "457e7807",
"metadata": {},
"source": [
"# Get data from owncloud"
]
},
{
"cell_type": "markdown",
"id": "dc9ed3f8",
"metadata": {},
"source": [
"Imports"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# %pip install pyocclient\n",
"import os\n",
"import time\n",
"import yaml\n",
"import owncloud\n",
"import pandas as pd\n"
]
},
{
"cell_type": "markdown",
"id": "68e34abc",
"metadata": {},
"source": [
"Download and save"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"start = time.time()\n",
"\n",
"# TODO: User input: directory where downloaded files should be saved\n",
"save_dir = r\"./downloads\"\n",
"\n",
"\n",
"os.makedirs(save_dir, exist_ok=True)\n",
"\n",
"# Load credentials\n",
"with open(\"login.yaml\", \"r\") as f:\n",
" cfg = yaml.safe_load(f)\n",
"\n",
"url = cfg[0][\"url\"]\n",
"password = cfg[1][\"password\"]\n",
"\n",
"# Connect to OwnCloud public link\n",
"oc = owncloud.Client.from_public_link(url, folder_password=password)\n",
"\n",
"# List all available files in the shared folder\n",
"remote_files = oc.list(\".\")\n",
"\n",
"# Keep only HDF5 files and sort them by name\n",
"hdf5_files = sorted([f.get_name() for f in remote_files if f.get_name().endswith(\".hdf5\")])\n",
"\n",
"print(f\"Found {len(hdf5_files)} .hdf5 files in OwnCloud\")\n",
"\n",
"if not hdf5_files:\n",
" print(\"No .hdf5 files found.\")\n",
"else:\n",
" for i, remote_name in enumerate(hdf5_files):\n",
" local_name = f\"tmp_{i:04d}.h5\"\n",
" local_path = os.path.join(save_dir, local_name)\n",
"\n",
" try:\n",
" oc.get_file(remote_name, local_path)\n",
" print(f\"Downloaded: {remote_name} -> {local_path}\")\n",
" except Exception as e:\n",
" print(f\"Failed to download {remote_name}: {e}\")\n",
"\n",
"end = time.time()\n",
"print(f\"Finished in {end - start:.2f} seconds\")\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"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.11.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}