{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Fetch the data using Python's `urllib` package\n", "This will download the data to your local drive if it doesn't exist already." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "#Import the packages needed to fetch the data\n", "import os, urllib" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "#Set the URL pointing to the data\n", "url='http://thredds.northwestknowledge.net:8080/thredds/fileServer/' + \\\n", " 'NWCSC_INTEGRATED_SCENARIOS_ALL_CLIMATE/macav2livneh/bcc-csm1-1/' + \\\n", " 'macav2livneh_pr_bcc-csm1-1_r1i1p1_historical_1990_2005_CONUS_monthly.nc'" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "macav2livneh_pr_bcc-csm1-1_r1i1p1_historical_1990_2005_CONUS_monthly.nc\n" ] } ], "source": [ "#Get the filename from the url\n", "fileName = url.split(\"/\")[-1]\n", "print(fileName)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Data already downloaded\n" ] } ], "source": [ "#Fetch the data and store as the local file\n", "if not os.path.exists(fileName):\n", " print(\"Fetching the dataset\")\n", " urllib.request.urlretrieve (url, fileName);\n", " print(\"Done!\")\n", "else:\n", " print(\"Data already downloaded\")" ] } ], "metadata": { "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.5.4" } }, "nbformat": 4, "nbformat_minor": 2 }