Browse Source

업데이트 'download_sample.py'

Hio-Been Han 2 years ago
parent
commit
ffb1d3bfcc
1 changed files with 22 additions and 19 deletions
  1. 22 19
      download_sample.py

+ 22 - 19
download_sample.py

@@ -1,27 +1,30 @@
-# Demo 1-1. Setting an enviroment
+# Demo 1-1. Setting an enviroment (download_sample.py)
 from os import listdir, mkdir, path, system, getcwd
 import warnings; warnings.simplefilter("ignore")
 dir_origin = dir_origin = getcwd()+'/' # <- Change this in local machine
 dir_dataset= 'dataset/'
-print('\n1============ Start Downloading =================\n')
+print('\n1)============ Start Downloading =================\n')
 print('Target directory ... => [%s%s]'%(dir_origin,dir_dataset))
 
 #!rm -rf /content/dataset/
 import requests, time
-def download_dataset( dataset_to_download = range(1,7), dir_dataset = dir_dataset ):
+def download_dataset( animal_list = 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))
+    mkdir('%s%s/dataset_1/'%(dir_origin,dir_dataset))
+    mkdir('%s%s/dataset_2/'%(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 )
+  for set_id in animal_list:
+    file_ids.append( 'dataset_1/epochs_animal%s.set'%set_id )
+    file_ids.append( 'dataset_1/epochs_animal%s.fdt'%set_id )
+    file_ids.append( 'dataset_2/epochs_animal%s.set'%set_id )
+    file_ids.append( 'dataset_2/epochs_animal%s.fdt'%set_id )
 
   # Request & download
-  repo_url = 'https://gin.g-node.org/hiobeen/Mouse_hdEEG_ASSR_Hwang_et_al/raw/9a35f6b1a53f87a96d76b8b7912738cb7d8d3d36/'
+  repo_url = 'https://gin.g-node.org/hiobeen/Mouse_hdEEG_ASSR_Hwang_et_al/raw/f6c0dfc00c03922a2311f9551e335bdd1f571436/'
   for file_id in file_ids:
     fname_dest = "%s%s%s"%(dir_origin, dir_dataset, file_id)
     if path.isfile(fname_dest) is False:
@@ -31,25 +34,25 @@ def download_dataset( dataset_to_download = range(1,7), dir_dataset = dir_datase
       with open(fname_dest, "wb") as file:
           for block in r.iter_content(chunk_size=1024):
               if block: file.write(block)
+      time.sleep(1) # wait a second to prevent possible errors
     else:
       print('...skipping already existing file [%s]...'%fname_dest)
-    time.sleep(1)
 
 # 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_dataset(dataset_to_download)
+animal_list = [2] # Partial download to prevent long download time
+#animal_list = [1,2,3,4,5,6] # Full download 
+download_dataset(animal_list)
 print('\n============= Download finished ==================\n\n')
 
 # List up 'dataset/' directory
-print('\n2=== List of available files in google drive ====\n')
+print('\n2)=== 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('\n3=== 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');
+system('pip install mne');
+
+# Make figure output directory
+dir_fig = 'figures/'
+if not path.isdir(dir_fig): mkdir('%s%s'%(dir_origin, dir_fig))
+