Browse Source

추가 'download_sample.py'

Hio-Been Han 3 years ago
parent
commit
e3320f0b60
1 changed files with 54 additions and 0 deletions
  1. 54 0
      download_sample.py

+ 54 - 0
download_sample.py

@@ -0,0 +1,54 @@
+# Demo 1-1. Setting an enviroment
+from os import listdir, mkdir, path, system, getcwd
+dir_origin = '' # <- Change this in local machine
+if len(dir_origin)<1: dir_origin = getcwd()+'/'
+dir_dataset= 'dataset/'
+print('\n=1=========== Start Downloading =================\n')
+print('Target directory ... => [%s%s]'%(dir_origin,dir_dataset))
+
+#!rm -rf /content/dataset/
+import requests
+def download_sample( dataset_to_download = range(1,7), dir_dataset = dir_dataset ):
+  # Check directory
+  if not path.isdir('%s%s'%(dir_origin,dir_dataset)):
+    mkdir('%s%s'%(dir_origin,dir_dataset))
+    mkdir('%s%s/rawdata/'%(dir_origin,dir_dataset))
+
+  # File names to be downloaded
+  file_ids = [ 'meta.csv', 'montage.csv' ]
+  for set_id in dataset_to_download:
+    file_ids.append( 'rawdata/epochs_animal%s.set'%set_id )
+    file_ids.append( 'rawdata/epochs_animal%s.fdt'%set_id )
+
+  # Request & download
+  repo_url = 'https://gin.g-node.org/hiobeen/Mouse_hdEEG_ASSR_Hwang_et_al/raw/9a35f6b1a53f87a96d76b8b7912738cb7d8d3d36/'
+  for file_id in file_ids:
+    fname_dest = "%s%s%s"%(dir_origin, dir_dataset, file_id)
+    if path.isfile(fname_dest) is False:
+      print('...copying to [%s]...'%fname_dest)
+      file_url = '%s%s'%(repo_url, file_id)
+      r = requests.get(file_url, stream = True)
+      with open(fname_dest, "wb") as file:
+          for block in r.iter_content(chunk_size=1024):
+              if block: file.write(block)
+    else:
+      print('...skipping already existing file [%s]...'%fname_dest)
+
+# Initiate downloading
+dataset_to_download = [2] # Partial download to prevent long download time
+#dataset_to_download = [1,2,3,4,5,6] # Download of whole dataset
+download_sample(dataset_to_download)
+print('\n============= Download finished ==================\n\n')
+
+# List up 'dataset/' directory
+print('\n=2== List of available files in google drive ====\n')
+print(listdir('%sdataset/'%dir_origin))
+print('\n============= End of the list ==================\n\n')
+
+# List up dataset/rawdata/*.set and ~/*.fdt files
+print('\n=3== List of available files in google drive ====\n')
+print(listdir('%sdataset/rawdata/'%dir_origin))
+print('\n============= End of the list ==================\n\n')
+
+# Install mne-python module
+#system('pip install mne');