Skip to content

Commit

Permalink
add nb
Browse files Browse the repository at this point in the history
  • Loading branch information
devincowan committed Oct 6, 2023
1 parent d99ffad commit 9b4a503
Show file tree
Hide file tree
Showing 4 changed files with 273 additions and 6 deletions.
259 changes: 259 additions & 0 deletions docs/Basic_Operations.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "HHsuQMMJyms4"
},
"source": [
"# HS RDF HydroShare Python Client Basic Resource Operation Examples \n",
"\n",
"\n",
"---\n",
"\n",
"\n",
"The following code snippets show examples for how to use the HS RDF HydroShare Python Client for performing basic resource operations. "
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "b_Tj5gJx0fRj"
},
"source": [
"## Install the HS RDF Python Client\n",
"\n",
"The HS RDF Python Client for HydroShare won't be installed by default, so it has to be installed first before you can work with it. Use the following command to install the Python Client from the GitHub repository. Eventually we will distribute this package via the Python Package Index (PyPi) so that it can be installed via pip from PyPi."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "hzriLgMl0oJ2"
},
"outputs": [],
"source": [
"!pip install hsclient"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "CZNOazcn9-23"
},
"source": [
"## Authenticating with HydroShare\n",
"\n",
"Before you start interacting with resources in HydroShare you will need to authenticate. To authenticate with HydroShare, you can either specify your username and password or you can call the `sign_in()` function, which will prompt you to input your username and password. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "3njsiY73m7_V"
},
"outputs": [],
"source": [
"from hsclient import HydroShare\n",
"\n",
"username = 'username'\n",
"password = 'password'\n",
"hs = HydroShare(username, password)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In most cases you will not want anyone to see your username and password, so you can also call the `sign_in()` function to be prompted for your username and password. This is better to use if you are sharing a Jupyter Notebook."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from hsclient import HydroShare\n",
"\n",
"hs = HydroShare()\n",
"hs.sign_in()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "xWITDJt79xiA"
},
"source": [
"## Basic Resource Operations"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "TH3UUihSojIb"
},
"source": [
"### Create a New Empty Resource\n",
"\n",
"A \"resource\" is a container for your content in HydroShare. Think of it as a \"working directory\" into which you are going to organize the code and/or data you are using and want to share. The following code can be used to create a new, empty resource within which you can create content and metadata.\n",
"\n",
"This code creates a new resource in HydroShare. It also creates an in-memory object representation of that resource in your local environmment that you can then manipulate with further code."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "W9azvJ_Co87w"
},
"outputs": [],
"source": [
"# Create the new, empty resource\n",
"new_resource = hs.create()\n",
"\n",
"# Get the HydroShare identifier for the new resource\n",
"resIdentifier = new_resource.resource_id\n",
"print('The HydroShare Identifier for your new resource is: ' + resIdentifier)\n",
"\n",
"# Construct a hyperlink for the new resource\n",
"print('Your new resource is available at: ' + new_resource.metadata.url)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "tBhL3LdOLCOx"
},
"source": [
"### Retrieving an Existing Resource\n",
"\n",
"If you want to work on an existing resource rather than creating a new one, you can retrieve an existing resource using its HydroShare Identifier. The resource identifier is passed as a string. The resource's metadata is retrieved and loaded into memory."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "-My8I_cmLOIf"
},
"outputs": [],
"source": [
"# Get an existing resource using its identifier\n",
"existing_resource = hs.resource(resIdentifier)\n",
"\n",
"print('Just retrieved the resource with ID: ' + resIdentifier)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "R142RJv-xZBx"
},
"source": [
"### Deleting a Resource\n",
"\n",
"If you want to delete a resource you are currently working with, you can just call the `delete()` function on that resource. This will delete your local copy of the resource and the resource in HydroShare."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "G9LBisuOx5WM"
},
"outputs": [],
"source": [
"new_resource.delete()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "7msplpxjHwqQ"
},
"source": [
"Alternatively, if you know the HydroShare identifier of the resource you want to delete, you can use it to delete the resource."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "Wf91WAB1H5KS"
},
"outputs": [],
"source": [
"# Delete the resource using its identifier\n",
"hs.resource(resIdentifier).delete()\n",
"print('Deleted resource: ' + resIdentifier)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "lZY3F7gj1e_k"
},
"source": [
"## Download an Entire Resource\n",
"\n",
"HydroShare allows you to download an entire resource as a zipped file that uses the BagIt packaging standard. You can identify the resource you want to download using its HydroShare identifier. When you call the `download()` function on the resource, you can pass a path where you want to save the zipped file. Leaving the path blank downloads the files to the directory.\n",
"\n",
"This example downloads the HydroShare resource containing these example Jupyter Notebooks."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "Xqgoq9yk15e4"
},
"outputs": [],
"source": [
"# Get the resource you want to download using its identifier\n",
"res = hs.resource(resIdentifier)\n",
"\n",
"# Download the resource as a zipped file. Pass in a file path as a string if you\n",
"# want to download to a particular location.\n",
"res.download()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"colab": {
"collapsed_sections": [],
"name": "HS_RDF_Examples.ipynb",
"provenance": [],
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3",
"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.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
3 changes: 3 additions & 0 deletions docs/about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# CUAHSI Documentation Portal

The place to go for all your documentation needs
8 changes: 6 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ theme:

plugins:
- mkdocstrings
- mkdocs-jupyter

repo_url: https://github.com/CUAHSI/mkdocs-example

nav:
- About: index.md
- Data Best Practices:
- About: about.md
- CZ Data Best Practices:
- Sharing Samples and Sample Metadata: sample_data/registering_samples.md
- Sharing Laboratory Analytical Data: sample_data/sample_data.md
- Sharing Geospatial Data: geospatial_data/geospatial_data.md
- Sharing Environmental Time Series Data: time_series_data/time_series_data.md
- Sharing Multiple Data Types Together: multiple_data_types/multiple_data_types.md
- Some Notebooks:
- HSClient: Basic_Operations.ipynb

9 changes: 5 additions & 4 deletions requirements-mkdocs.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mkdocs>=1.3.0,<2.0.0
mkdocstrings>=0.19.0,<1.0.0
mkdocstrings-python>=0.7.1,<1.0.0
mkdocs-material>=8.3.7,<9.0.0
mkdocs>=1.3.0
mkdocstrings>=0.19.0
mkdocstrings-python>=0.7.1
mkdocs-material>=8.3.7
mkdocs-jupyter>=0.24.5

0 comments on commit 9b4a503

Please sign in to comment.