Skip to content

Commit

Permalink
add download within jupter
Browse files Browse the repository at this point in the history
  • Loading branch information
changliao1025 committed Aug 23, 2023
1 parent f9f4f1e commit 99a3f38
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion notebooks/mpas_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"import sys\n",
"from pathlib import Path\n",
"from os.path import realpath\n",
"import importlib"
"import importlib\n",
"import requests"
]
},
{
Expand Down Expand Up @@ -146,6 +147,43 @@
"sys.path.append(sPath_parent)"
]
},
{
"cell_type": "markdown",
"id": "9f2f1520",
"metadata": {},
"source": [
"We need to download an additional NetCDF file for this example.\n",
"This file is stored on the Github release:\n",
"https://github.com/changliao1025/pyflowline/releases/tag/0.2.0\n",
"https://github.com/changliao1025/pyflowline/releases/download/0.2.0/lnd_cull_mesh.nc"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c52960d0",
"metadata": {},
"outputs": [],
"source": [
"\n",
"sFilename_mpas = 'https://github.com/changliao1025/pyflowline/releases/download/0.2.0/lnd_cull_mesh.nc'\n",
"\n",
"#combind folder with filename to get the full path\n",
"sFilename_download = os.path.join(sPath_parent, 'mpas_mesh.nc')\n",
"\n",
"# Send an HTTP GET request to the URL\n",
"response = requests.get(sFilename_mpas)\n",
"\n",
"# Check if the request was successful\n",
"if response.status_code == 200:\n",
" # Save the content of the response to the local file\n",
" with open(sFilename_download, 'wb') as file:\n",
" file.write(response.content)\n",
" print(f\"File '{sFilename_download}' downloaded successfully.\")\n",
"else:\n",
" print(f\"Failed to download file from '{sFilename_mpas}'.\")"
]
},
{
"cell_type": "markdown",
"id": "25edfaeb",
Expand Down Expand Up @@ -315,6 +353,16 @@
" sMesh_type_in= sMesh_type, sDate_in=sDate)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "17e011b8",
"metadata": {},
"outputs": [],
"source": [
"oPyflowline.change_model_parameter('sFilename_mesh_netcdf', sFilename_download)"
]
},
{
"attachments": {},
"cell_type": "markdown",
Expand Down

0 comments on commit 99a3f38

Please sign in to comment.