@@ -160,18 +160,43 @@ def gcnet_postprocessing(l3):
160
160
# df_in.loc[[df_in.z_surf_combined.first_valid_index()],:].index.astype('int64')[0]
161
161
# ) + df_in.loc[df_in.z_surf_combined.first_valid_index(), 'z_surf_combined']
162
162
# return l3m
163
-
163
+
164
+ def build_station_dict (config_folder ):
165
+ station_dict = {}
166
+
167
+ # Iterate through all files in the given folder
168
+ for filename in os .listdir (config_folder ):
169
+ if filename .endswith (".toml" ):
170
+ # Construct full file path
171
+ file_path = os .path .join (config_folder , filename )
172
+
173
+ # Load TOML file
174
+ with open (file_path , 'r' ) as file :
175
+ data = toml .load (file )
176
+ station_key = next (iter (data ))
177
+ station_data = data [station_key ]
178
+
179
+ if station_data ["station_site" ] in station_dict :
180
+ station_dict [station_data ["station_site" ]].append (station_key )
181
+ else :
182
+ station_dict [station_data ["station_site" ]] = [station_key ]
183
+
184
+ return station_dict
185
+
164
186
def join_l3 ():
165
187
args = parse_arguments_joinl3 ()
166
-
167
-
168
- config_file = os .path .join (args .config_folder , args .site + '.toml' )
169
- conf = toml .load (config_file )
188
+ logging .basicConfig (
189
+ format = "%(asctime)s; %(levelname)s; %(name)s; %(message)s" ,
190
+ level = logging .INFO ,
191
+ stream = sys .stdout ,
192
+ )
193
+
194
+ station_dict = build_station_dict (args .config_folder )
170
195
171
196
l3m = xr .Dataset ()
172
197
l3m .attrs ['level' ] = 'L3'
173
- for stid in conf [ 'stations' ]:
174
- print (stid )
198
+ for stid in station_dict [ args . site ]:
199
+ logger . info (stid )
175
200
176
201
is_promice = False
177
202
is_gcnet = False
@@ -183,7 +208,7 @@ def join_l3():
183
208
if os .path .isfile (filepath ):
184
209
is_gcnet = True
185
210
if not is_promice and not is_gcnet :
186
- print (stid , 'not found either in' , args .folder_l3 , 'or' , args .folder_gcnet )
211
+ logger . info (stid , 'not found either in' , args .folder_l3 , 'or' , args .folder_gcnet )
187
212
continue
188
213
189
214
l3 , _ = loadArr (filepath )
@@ -213,14 +238,15 @@ def join_l3():
213
238
214
239
# if l3 (older data) has variables that does not have l3m (newer data)
215
240
# then they are removed from l3
216
- print ( 'dropping' )
241
+ list_dropped = []
217
242
for v in l3 .data_vars :
218
243
if v not in l3m .data_vars :
219
244
if v != 'z_stake' :
220
- print (v )
245
+ list_dropped . append (v )
221
246
l3 = l3 .drop (v )
222
247
else :
223
248
l3m [v ] = ('time' , l3m .t_u .data * np .nan )
249
+ logger .info ('Unused variables in older dataset:' ,list_dropped )
224
250
225
251
# saving attributes of station under an attribute called $stid
226
252
l3m = l3m .assign_attrs ({stid : l3 .attrs .copy ()})
@@ -241,7 +267,7 @@ def join_l3():
241
267
242
268
# Assign site id
243
269
l3m .attrs ['site_id' ] = args .site
244
- l3m .attrs ['stations' ] = conf [ 'stations' ]
270
+ l3m .attrs ['stations' ] = station_dict [ args . site ]
245
271
246
272
if args .outpath is not None :
247
273
prepare_and_write (l3m , args .outpath , args .variables , args .metadata , '60min' )
0 commit comments