Skip to content

Instantly share code, notes, and snippets.

@monocongo
Created July 7, 2018 21:22
Show Gist options
  • Save monocongo/03d1b72023d3a6e05314eefd5146f58b to your computer and use it in GitHub Desktop.
Save monocongo/03d1b72023d3a6e05314eefd5146f58b to your computer and use it in GitHub Desktop.
Create files in Google Colaboratory local environment from files stored in Google Drive
"""## Pull data files from Google Drive
Install PyDrive which will be used to access Google Drive and kick off the process to authorize the notebook running in the Google Colaboratory environment to touch our Drive files. When this cell executes it'll provide a link to authenticate into a Google Drive account to instatiate a PyDrive client. The Drive account that is selected should be one which has access to our all variables dataset file that we'll use for training/testing our model.
"""
#!pip install -U -q PyDrive
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
# Authenticate and create the PyDrive client.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
"""Next we'll create dataset files within the Google Colaboratory environment corresponding to the flow and time tendency dataset files located on our Google Drive."""
filename_h0 = 'fv091x180L26_dry_HS.cam.h0.2000-12-27-00000.nc'
filename_h1 = 'fv091x180L26_dry_HS.cam.h1.2000-12-27-00000.nc'
id_h0 = '1vptBPguIMU4FrvkC91xAd7_wOxoylBW0'
id_h1 = '1ru8gmDKv8qPZGnfaTP2Sqv8Fsps48vAX'
file_h0 = drive.CreateFile({'id': id_h0}) # creates a file in the Colab env using the ID for file <filename_h0>
file_h1 = drive.CreateFile({'id': id_h1}) # creates a file in the Colab env using the ID for file <filename_h1>
file_h0.GetContentFile(filename_h0) # gets the file's contents and saves it as a local file named <filename_h0>
file_h1.GetContentFile(filename_h1) # gets the file's contents and saves it as a local file named <filename_h1>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment