1111def _fetch_s3_file (s3_uri , save_to ):
1212
1313 bucket_name , key = _split_s3_uri (s3_uri )
14- #print(f"Fetching s3 object {key} from bucket {bucket_name}")
14+ # print(f"Fetching s3 object {key} from bucket {bucket_name}")
1515
1616 client = boto3 .client ("s3" )
1717 obj = client .get_object (
@@ -26,7 +26,7 @@ def _fetch_s3_file(s3_uri, save_to):
2626def _save_s3_file (s3_uri , out_filename , file_to_save = "/tmp/tmp" ):
2727 bucket , folder = _split_s3_uri (s3_uri )
2828 out_filepath = os .path .join (folder , out_filename )
29- #print(f"Save s3 object {out_filepath} to bucket {bucket}")
29+ # print(f"Save s3 object {out_filepath} to bucket {bucket}")
3030 client = boto3 .client ("s3" )
3131 client .upload_file (
3232 Filename = file_to_save ,
@@ -81,7 +81,6 @@ def copy_s3_files(in_fileglob, out_folder):
8181 in_fileglob: s3 uri of flies (wild card can be used)
8282 out_folder: local path where data will be stored
8383 '''
84-
8584 matching_keys = find_matching_s3_keys (in_fileglob )
8685 in_bucket_name = _split_s3_uri (in_fileglob )[0 ]
8786 out_scheme = urlparse (out_folder ).scheme
@@ -103,44 +102,43 @@ def copy_s3_files(in_fileglob, out_folder):
103102 os .remove (temp_filename )
104103
105104
106-
107105def load_data (inpath ):
108106
109107 if inpath .startswith ('s3' ):
110108 keys = find_matching_s3_keys (inpath )
111109 s3dir = _get_directory (inpath )
112- temp_path = '/scratch/zmaalick'
113-
110+ temp_path = 'data/'
111+ if os .path .exists (temp_path ) == 0 :
112+ os .mkdir (temp_path )
113+
114114 for key in keys :
115115 file = key .split ('/' )[- 1 ]
116116 if os .path .exists (os .path .join (temp_path , file )) == 0 :
117117 print (os .path .join (s3dir , file ))
118118 copy_s3_files (os .path .join (s3dir , file ), temp_path )
119119 else :
120120 print (key , ' already exist' )
121-
122121 files = inpath .split ('/' )[- 1 ]
122+ data = iris .load (os .path .join (temp_path , files ))
123123
124- data = iris .load (os .path .join (temp_path ,files ))
125-
126124 return data
127125
128126
129127def _get_directory (inpath ):
130128 path = inpath .split ('/' )
131- dirpath = 's3://'
129+ dirpath = 's3://'
132130 for p in path [2 :- 1 ]:
133- dirpath = os .path .join (dirpath ,p )
131+ dirpath = os .path .join (dirpath , p )
134132 return dirpath
135-
133+
134+
136135def flush_data ():
137136 import glob
138137 files = glob .glob ('/tmp/*.nc' )
139138 for file in files :
140139 os .remove (file )
141140
142-
143-
141+
144142def main ():
145143 in_fileglob = 's3://ias-pyprecis/data/cmip5/.nc'
146144 out_folder = '/home/h01/zmaalick/myprojs/PyPRECIS/aws-scripts'
0 commit comments