@@ -78,7 +78,8 @@ def main():
78
78
merging_flag = False
79
79
merging_flag = concat_files ()
80
80
81
- get_pollyxt_logbook_files ()
81
+ if device != "martha" :
82
+ get_pollyxt_logbook_files ()
82
83
83
84
if merging_flag == True :
84
85
sys .exit (0 ) # Indicates success/True
@@ -94,7 +95,129 @@ def get_input_path(timestamp,device,raw_folder):
94
95
print (input_path )
95
96
return input_path
96
97
98
+ def get_input_path_martha (timestamp ,device ,raw_folder ):
99
+ #raw_folder="/data/level0/martha/MARTHA_DATA"
100
+ YYYY = timestamp [0 :4 ]
101
+ MM = timestamp [4 :6 ]
102
+ #input_path = Path(raw_folder,device,"data_zip",f"{YYYY}{MM}")
103
+ input_path = Path (raw_folder )
104
+ print (input_path )
105
+ return input_path
106
+
97
107
### start of function concat_pollyxt_files
108
+ def get_martha_files ():
109
+ '''
110
+ This function locates multiple pollyxt level0 nc-zip files from one day measurements,
111
+ unzipps the files to output_path
112
+ and returns a list of files to be merged
113
+ and the title of the new merged nc-file
114
+ '''
115
+ input_path = get_input_path_martha (timestamp ,device ,raw_folder )
116
+ path_exist = Path (input_path )
117
+
118
+ if path_exist .exists () == True :
119
+
120
+ ## set the searchpattern for the zipped-nc-files:
121
+ YYYY = timestamp [0 :4 ]
122
+ MM = timestamp [4 :6 ]
123
+ DD = timestamp [6 :8 ]
124
+
125
+ zip_searchpattern = str (YYYY )+ '_' + str (MM )+ '_' + str (DD )+ '*_*[0-9].nc'
126
+
127
+ polly_files = Path (r'{}' .format (input_path )).glob ('{}' .format (zip_searchpattern ))
128
+ polly_zip_files_list0 = [x for x in polly_files if x .is_file ()]
129
+
130
+
131
+
132
+ ## convert type path to type string
133
+ polly_zip_files_list = []
134
+ for file in polly_zip_files_list0 :
135
+ polly_zip_files_list .append (str (file ))
136
+
137
+ if len (polly_zip_files_list ) < 1 :
138
+ print ('no files found!' )
139
+ sys .exit ()
140
+ else :
141
+ print (polly_zip_files_list )
142
+
143
+ # Ensure the destination directory exists
144
+ Path (output_path ).mkdir (parents = True , exist_ok = True )
145
+
146
+ polly_files_list = []
147
+ to_unzip_list = []
148
+ for zip_file in polly_zip_files_list :
149
+ ## check for size of zip-files to ensure to exclude bad measurement files with wrong timestamp e.g. 19700101
150
+ f_size = os .path .getsize (zip_file )
151
+ print (zip_file )
152
+ if f_size > 150000 :
153
+ print (f_size )
154
+ print ("filesize passes" )
155
+ else :
156
+ print (f_size )
157
+ print ("filesize too small, file will be skipped!" )
158
+ continue ## go to next file
159
+
160
+ # ## check if zipfile is a valid zip-file
161
+ # if not is_zipfile(zip_file):
162
+ # print(f"invalid zip-file: {zip_file}\nskipping file.")
163
+ # #polly_zip_files_list.remove(zip_file)
164
+ # continue
165
+ # else:
166
+ # pass
167
+
168
+ #unzipped_nc = Path(zip_file).name
169
+ #unzipped_nc = Path(unzipped_nc)
170
+ #unzipped_nc = Path(output_path,unzipped_nc)
171
+ #print('here....')
172
+ #polly_files_list.append(unzipped_nc)
173
+ path = Path (zip_file )
174
+ polly_files_list .append (path )
175
+
176
+ ### check if unzipped files already exists in outputfolder
177
+ #if path.is_file() == False:
178
+ # to_unzip_list.append(zip_file)
179
+ #if path.is_file() == True:
180
+ # os.remove(unzipped_nc)
181
+ # to_unzip_list.append(zip_file)
182
+
183
+ # ## unzipping
184
+ # date_pattern = str(YYYY)+'_'+str(MM)+'_'+str(DD)
185
+ # if len(to_unzip_list) > 0:
186
+ # ## if working remotly on windows, copy zipped files first, than unzip
187
+ # if os_name.lower() == 'windows':
188
+ # print("\nCopy zipped files to local drive...")
189
+ # for zip_file in to_unzip_list:
190
+ # print(zip_file)
191
+ # shutil.copy2(Path(zip_file), Path(output_path) / Path(zip_file).name)
192
+ # print("\nUnzipping...")
193
+ # for zip_file in Path(output_path).iterdir():
194
+ # if zip_file.is_file() and date_pattern in zip_file.stem and zip_file.suffix == '.zip':
195
+ # with ZipFile(zip_file, 'r') as zip_ref:
196
+ # print("unzipping "+str(zip_file))
197
+ # zip_ref.extractall(output_path)
198
+ # print("Removing .zip file...")
199
+ # os.remove(zip_file)
200
+ #
201
+ # else:
202
+ # print("\nUnzipping...")
203
+ # for zip_file in to_unzip_list:
204
+ # with ZipFile(zip_file, 'r') as zip_ref:
205
+ # print("unzipping "+zip_file)
206
+ # zip_ref.extractall(output_path)
207
+
208
+
209
+ ## sort lists
210
+ polly_files_list .sort ()
211
+
212
+ print ("\n " + str (len (polly_files_list ))+ " files found:\n " )
213
+ print (polly_files_list )
214
+ print ("\n " )
215
+
216
+ else :
217
+ print ("\n No data was found in {}. Correct path?\n " .format (input_path ))
218
+ sys .exit ()
219
+ return polly_files_list
220
+
98
221
def get_pollyxt_files ():
99
222
'''
100
223
This function locates multiple pollyxt level0 nc-zip files from one day measurements,
@@ -315,7 +438,10 @@ def checking_vars():
315
438
'zenithangle'
316
439
]
317
440
318
- polly_files_list = get_pollyxt_files ()
441
+ if device == "martha" :
442
+ polly_files_list = get_martha_files ()
443
+ else :
444
+ polly_files_list = get_pollyxt_files ()
319
445
if len (polly_files_list ) == 1 :
320
446
return polly_files_list
321
447
@@ -625,10 +751,11 @@ def write_netcdf(ds: xarray.Dataset, out_file: Path) -> None:
625
751
626
752
ds .close ()
627
753
628
- print ("\n deleting individual .nc files ..." )
629
- for el in sel_polly_files_list :
630
- print (el )
631
- os .remove (el )
754
+ if device != "martha" :
755
+ print ("\n deleting individual .nc files ..." )
756
+ for el in sel_polly_files_list :
757
+ print (el )
758
+ os .remove (el )
632
759
destination_file = Path (output_path ,filestring )
633
760
if os .path .exists (destination_file ):
634
761
os .remove (destination_file ) # Remove the existing destination file
0 commit comments