Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not write to local disk in notebook 00 #465

Merged
merged 1 commit into from
Feb 26, 2025
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
24 changes: 18 additions & 6 deletions docs/notebooks/00_Introduction_to_JupyterLab.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,30 @@
"metadata": {},
"outputs": [],
"source": [
"# We will do this with the numpy package:\n",
"# NBVAL_IGNORE_OUTPUT\n",
"\n",
"# For demonstration purposes, we will use the `tempfile` package to create a temporary file to store the array:\n",
"from tempfile import NamedTemporaryFile\n",
"\n",
"# We will do this with the `numpy` package:\n",
"import numpy as np\n",
"\n",
"c = np.random.rand(100) # Create 100 random values and store them in variable \"c\"\n",
"np.savetxt(\"array_c.txt\", c) # Write the array to a file named \"array_c.txt\""
"# If we wanted to save this to a file, we could use the following code:\n",
"# np.savetxt(\"array_c.txt\", c) # Write the array to a file\n",
"\n",
"file = NamedTemporaryFile(delete=False) # Create a temporary file to store the array\n",
"np.savetxt(file.name, c) # Write the array to a temporary file\n",
"\n",
"# The file path is stored in the variable `file.name`\n",
"file.name"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you look in your workspace, you will see a new file named \"array_c.txt\". All files you generate will be written to the folder in which your notebook is running from.\n",
"If you look in your workspace, you will see a new temporary file. If given an arbitrary name (e.g. `array_c.txt`), the files you generate will be written to the folder in which your notebook is running from.\n",
"\n",
"Now let's read it back in and verify that the values are the same. We can do this by taking the sum of the absolute differences between each element. If the sum is 0, that means we have succeeded:"
]
Expand All @@ -163,15 +175,15 @@
"metadata": {},
"outputs": [],
"source": [
"d = np.loadtxt(\"array_c.txt\")\n",
"d = np.loadtxt(file)\n",
"print(sum(abs(c - d)))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As you can see, files can be accessed easily by simply referring to them by their name if they are in the same folder as the notebook. If they aren't you also need to specify the folder path. Example \"writable-workspace/array_c.txt\". This is also true for all files, even those you upload yourself. You can also access data that can be found online on an accessible server using the URL, but we will get to that in a later notebook."
"As you can see, files can be accessed easily by simply referring to them by their name if they are in the same folder as the notebook. If they aren't you also need to specify the folder path, e.g. `writable-workspace/array_c.txt`. This is also true for all files, even those you upload yourself. You can also access data that can be found online on an accessible server using the URL, but we will get to that in a later notebook."
]
},
{
Expand All @@ -197,7 +209,7 @@
"\n",
"To add packages, you can simply add a cell and \"! pip install **package**\" as required, which will add it to your local server. It will need to be re-added every time you close and re-spawn your server. You can also use the Jupyter conda plugin to install via conda (Settings --> Conda Packages Manager).\n",
"\n",
"Otherwise, you can always install the PAVICS-Hydro environment on your local computer following the instructions found [here] (https://pavics-sdi.readthedocs.io/projects/raven/en/latest/index.html). Note that these instructions are for more advanced python users / developers.\n",
"Otherwise, you can always install the PAVICS-Hydro environment on your local computer following the instructions found [here](https://pavics-sdi.readthedocs.io/projects/raven/en/latest/index.html). Note that these instructions are for more advanced python users / developers.\n",
"\n",
"In the next notebooks, we will start using your JupyterLab instance to start doing hydrological and hydroclimatological science!"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,6 @@
"all_properties = {**shape_info, **land_use, **terrain}\n",
"display(all_properties)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Loading