-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e3eb09
commit b27b3f5
Showing
8 changed files
with
220 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
package.json | ||
package-lock.json | ||
node_modules/ | ||
.ipynb_checkpoints/ | ||
*.ipynb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Jupyter Notebook | ||
|
||
This Jupyter Notebook instance is preconfigured with an example notebook that shows the usage of [Pyscicat](https://github.com/scicatproject/pyscicat). | ||
|
||
## [Pyscicat Notebook](./config/notebooks/pyscicat.ipynb) | ||
This notebook demonstrates all the major actions Pyscicat is capable of: | ||
* logging into SciCat backend | ||
* dataset creation | ||
* datablock creation | ||
* attachment upload | ||
|
||
## [.env file](./config/.env) | ||
It contains the environment variables for connecting to the backend service deployed by this project | ||
|
||
## [Thumbnail image](./config/notebooks/example_files/thumbnail.png) | ||
An example image that is used for the attachment upload demonstration | ||
|
||
## Default configuration | ||
This service is only dependant on the backend service, since it demonstrates communication with the latter through Pyscicat. | ||
|
||
The notebooks are mounted to the container from the [config/notebooks](config/notebooks/) directory. The changes to these notebooks should *not* be contributed back to this repository, unless this is intentional. In the case you want to upstream changes to these notebooks, be sure to clear all the results from them. | ||
|
||
The [main readme](../../README.md) covers all dependencies of this package. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
BE_BASE_URL="http://backend:3000/api/v3/" | ||
USERNAME="admin" | ||
PASSWORD="2jf70TPNZsS" | ||
NOTEBOOK_ARGS="--NotebookApp.token=''" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# install pyscicat\n", | ||
"!pip install 'pyscicat>=0.4.4'" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# create scicat client\n", | ||
"\n", | ||
"from pyscicat.client import ScicatClient\n", | ||
"import os\n", | ||
"\n", | ||
"base_url = os.environ.get('BE_BASE_URL')\n", | ||
"username = os.environ.get('USERNAME')\n", | ||
"password = os.environ.get('PASSWORD')\n", | ||
"\n", | ||
"client = ScicatClient(base_url=base_url, username=username, password=password)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# create (raw) dataset\n", | ||
"\n", | ||
"from pyscicat.model import Ownable, RawDataset\n", | ||
"from datetime import datetime\n", | ||
"\n", | ||
"ownable = Ownable(\n", | ||
" ownerGroup=\"example_research_group\", # only obligatory element of this model\n", | ||
" accessGroups=['group1', 'group2'],\n", | ||
" instrumentGroup='instrument1'\n", | ||
")\n", | ||
"\n", | ||
"dataset = RawDataset(\n", | ||
" contactEmail=\"[email protected]\", # must be valid email in format\n", | ||
" creationTime=datetime(year=2024, month=4, day=12, hour=12, minute=35, second=30).isoformat(),\n", | ||
" datasetName=\"example_dataset\",\n", | ||
" description=\"You can insert a lengthy description here\",\n", | ||
" instrumentId=\"example.instrument.id\",\n", | ||
" isPublished=False,\n", | ||
" keywords=[\"important\", \"biology\", \"example\"],\n", | ||
" license=\"Public Domain\",\n", | ||
" numberOfFiles = 6,\n", | ||
" orcidOfOwner=\"0000-0001-5109-3700\",\n", | ||
" owner=\"Emmett Exemplum, PhD\",\n", | ||
" ownerEmail=\"example.exemplum@some_uni.ch\",\n", | ||
" size=589824, # in bytes!\n", | ||
" sourceFolder=\"/datasets/example_dataset\", # this will have to reflect the retrieval location for the archival system \n", | ||
" #sourceFolderHost=\"earth.net\", # same as above but the network host part (instead of filesystem)\n", | ||
" validationStatus=\"valid\",\n", | ||
" version=\"4.0.0\", # optional\n", | ||
" scientificMetadata={}, # optional\n", | ||
" principalInvestigator=\"Mr. Irvine Investigator\",\n", | ||
" creationLocation=\"University of Example, Exemplia\",\n", | ||
" #dataFormat=\"someformat\", # optional\n", | ||
" sampleId=\"example.sample.id\",\n", | ||
" **ownable.model_dump()\n", | ||
")\n", | ||
"\n", | ||
"# attempt to create dataset, *CAN* throw ScicatCommError\n", | ||
"dataset_id = client.datasets_create(dataset)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"scrolled": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# Add datablock to dataset\n", | ||
"\n", | ||
"from pyscicat.model import DataFile, CreateDatasetOrigDatablockDto\n", | ||
"from datetime import datetime\n", | ||
"\n", | ||
"# disable info level logging\n", | ||
"import logging\n", | ||
"logging.getLogger().setLevel(logging.FATAL)\n", | ||
"\n", | ||
"files = [\n", | ||
" \"file1.txt\",\n", | ||
" \"someimage.raw\",\n", | ||
" \"thumbnail/someimage.jpg\",\n", | ||
" \"thumbnail/FoilHoles.jpg\",\n", | ||
" \"transformations.json\",\n", | ||
" \"FoilHoles.raw\"\n", | ||
"]\n", | ||
"file_sizes = [\n", | ||
" 100,\n", | ||
" 204800,\n", | ||
" 20480,\n", | ||
" 20480,\n", | ||
" 1000,\n", | ||
" 342964\n", | ||
"]\n", | ||
"file_times = [\n", | ||
" datetime(year=2024, month=4, day=12, hour=12, minute=35, second=30),\n", | ||
" datetime(year=2024, month=2, day=4, hour=5, minute=56, second=39),\n", | ||
" datetime(year=2024, month=3, day=30, hour=19, minute=4, second=53),\n", | ||
" datetime(year=2024, month=4, day=2, hour=16, minute=25, second=37),\n", | ||
" datetime(year=2024, month=4, day=12, hour=8, minute=13, second=44),\n", | ||
" datetime(year=2024, month=2, day=4, hour=4, minute=24, second=17)\n", | ||
"]\n", | ||
"dataFileList = [\n", | ||
" DataFile(path=p, size=s, time=t.isoformat()) for (p, s, t) in zip(files, \n", | ||
" file_sizes, \n", | ||
" file_times)\n", | ||
"]\n", | ||
"\n", | ||
"data_block = CreateDatasetOrigDatablockDto(\n", | ||
" size=576, version=1, dataFileList=dataFileList\n", | ||
")\n", | ||
"\n", | ||
"client.datasets_origdatablock_create(dataset_id, data_block);" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Upload attachment\n", | ||
"\n", | ||
"from pyscicat.client import encode_thumbnail\n", | ||
"from pyscicat.model import Attachment\n", | ||
"\n", | ||
"attachment = Attachment(\n", | ||
" datasetId=dataset_id,\n", | ||
" thumbnail=encode_thumbnail(\"example_files/thumbnail.png\", \"png\"),\n", | ||
" caption=\"Example thumbnail image as attachment\",\n", | ||
" **ownable.model_dump()\n", | ||
")\n", | ||
"\n", | ||
"client.datasets_attachment_create(attachment);" | ||
] | ||
} | ||
], | ||
"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.11.8" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
services: | ||
jupyter: | ||
image: quay.io/jupyter/base-notebook:x86_64-notebook-7.1.2 | ||
depends_on: | ||
backend: | ||
condition: service_healthy | ||
labels: | ||
- traefik.http.routers.jupyter.rule=Host(`jupyter.localhost`) | ||
- traefik.http.services.jupyter.loadbalancer.server.port=8888 | ||
volumes: | ||
- ./config/notebooks:/home/jovyan/notebooks | ||
env_file: | ||
- config/.env |