19
19
import autorino .handle as arohdl
20
20
21
21
from rinexmod import rinexmod_api
22
+ from rinexmod import metadata as rimo_mda
23
+
24
+ import datetime as dt
22
25
23
26
# import autorino.session as aroses
24
27
# import autorino.epochrange as aroepo
@@ -96,6 +99,11 @@ def read_cfg(configfile_path, epoch_range=None, main_cfg_path=None):
96
99
else :
97
100
y_main = None
98
101
102
+ if not y_main and check_from_main (y ):
103
+ errmsg = "FROM_MAIN keyword used in cfg file, but no main cfg file provided (-m option)"
104
+ logger .error (errmsg )
105
+ raise FileNotFoundError (None , errmsg )
106
+
99
107
y = update_w_main_dic (y , y_main )
100
108
101
109
print_cfg_for_debug = False
@@ -110,7 +118,6 @@ def read_cfg(configfile_path, epoch_range=None, main_cfg_path=None):
110
118
111
119
return steps_lis_lis , steps_dic_dic , y_station
112
120
113
-
114
121
def read_cfg_sessions (y_sessions_dict , epoch_range_inp = None , y_station = None ):
115
122
"""
116
123
Reads and interprets session configurations from a dictionary
@@ -139,7 +146,9 @@ def read_cfg_sessions(y_sessions_dict, epoch_range_inp=None, y_station=None):
139
146
"""
140
147
141
148
# ++++ METADATA
142
- if y_station ["site" ]["sitelog_path" ]:
149
+ # Load as sitelog
150
+
151
+ if y_station ["device" ]["attributes_from_sitelog" ]:
143
152
slpath = y_station ["site" ]["sitelog_path" ]
144
153
if os .path .isdir (slpath ) or os .path .isfile (slpath ):
145
154
# Load the metadata if the path is a directory or a file
@@ -148,9 +157,9 @@ def read_cfg_sessions(y_sessions_dict, epoch_range_inp=None, y_station=None):
148
157
# If not, consider it as a string
149
158
# (because the path might be translated later in the object)
150
159
metadata = slpath
160
+ # Load as devie block
151
161
else :
152
- ###### MUST BE IMPLEMENTED WITH MANUAL VALUES
153
- metadata = None
162
+ metadata = _device2mda (y_station )
154
163
155
164
steps_lis_lis = []
156
165
steps_dic_dic = {}
@@ -206,12 +215,8 @@ def read_cfg_sessions(y_sessions_dict, epoch_range_inp=None, y_station=None):
206
215
if "inp_file_regex" in y_stp .keys ():
207
216
inp_file_regex = y_stp ["inp_file_regex" ]
208
217
else :
209
- logger .warning (
210
- "Compatibility Warning: inp_file_regex not defined in the cfg files, set to .*"
211
- )
212
- logger .warning (
213
- "Compatibility Warning: you should upgrade your config file to >v15"
214
- )
218
+ logger .warning ("Compatibility! inp_file_regex not defined in cfg files" )
219
+ logger .warning ("upgrade your config file to >v15, set to .* for now" )
215
220
inp_file_regex = ".*"
216
221
217
222
kwargs_for_step = {
@@ -298,7 +303,7 @@ def _check_parent_dir_exist(parent_dir, parent_dir_key=None):
298
303
parent_dir_key = "a directory"
299
304
300
305
logger .error (
301
- "%s is not correctly defined in the main cfgfiles file"
306
+ "%s is not correctly defined in the main cfgfiles file "
302
307
"(FROM_MAIN can not be replaced)" ,
303
308
parent_dir_key ,
304
309
)
@@ -405,6 +410,48 @@ def _get_dir_path(y_step, dir_type="out", check_parent_dir_exist=True):
405
410
return dir_path , dir_parent , structure
406
411
407
412
413
+ def _device2mda (y_station ):
414
+ """
415
+ Convert a device block from a configuration file to a MetaData object.
416
+ """
417
+ y_dev = y_station ["device" ]
418
+ y_sit = y_station ['site' ]
419
+
420
+ metadata = rimo_mda .MetaData ()
421
+ rec_dic = dict ()
422
+ if y_dev ["rec_type" ]:
423
+ rec_dic ["Receiver Type" ] = y_dev ["rec_type" ]
424
+ if y_dev ["rec_sn" ]:
425
+ rec_dic ["Serial Number" ] = y_dev ["rec_sn" ]
426
+ if y_dev ["rec_fw" ]:
427
+ rec_dic ["Firmware Version" ] = y_dev ["rec_fw" ]
428
+
429
+ ant_dic = dict ()
430
+ if y_dev ["ant_type" ]:
431
+ ant_dic ["Antenna Type" ] = y_dev ["ant_type" ]
432
+ if y_dev ["ant_sn" ]:
433
+ ant_dic ["Serial Number" ] = y_dev ["ant_sn" ]
434
+
435
+ if y_dev ["ecc_une" ]:
436
+ ant_dic ["Marker->ARP Up Ecc. (m)" ] = y_dev ["ecc_une" ][0 ]
437
+ ant_dic ["Marker->ARP North Ecc(m)" ] = y_dev ["ecc_une" ][1 ]
438
+ ant_dic ["Marker->ARP East Ecc(m)" ] = y_dev ["ecc_une" ][2 ]
439
+
440
+ metadata .add_instru (rec_dic , ant_dic )
441
+
442
+ metadata .set_meta (site_id = y_sit ['site_id' ],
443
+ domes = y_sit ['domes' ],
444
+ operator = y_sit ['operator' ],
445
+ x = y_sit ["position_xyz" ][0 ],
446
+ y = y_sit ["position_xyz" ][1 ],
447
+ z = y_sit ["position_xyz" ][2 ],
448
+ country = y_sit ["country" ],
449
+ date_prepared = dt .datetime .now (),
450
+ agency = y_sit ["agency" ])
451
+
452
+ return metadata
453
+
454
+
408
455
def format_dir_path (dir_parent , structure ):
409
456
"""
410
457
Formats a directory path by adding or removing a leading slash.
@@ -426,6 +473,30 @@ def format_dir_path(dir_parent, structure):
426
473
427
474
return dir_parent , structure
428
475
476
+ def check_from_main (y ):
477
+ """
478
+ Check if the FROM_MAIN keyword is used in the configuration file.
479
+
480
+ This function takes a dictionary representing the configuration file.
481
+ It checks if the 'FROM_MAIN' keyword is used in the configuration file.
482
+ If it is, it returns True. Otherwise, it returns False.
483
+
484
+ Parameters
485
+ ----------
486
+ y : dict
487
+ A dictionary representing the configuration file.
488
+
489
+ Returns
490
+ -------
491
+ bool
492
+ True if the 'FROM_MAIN' keyword is used in the configuration file.
493
+ False otherwise.
494
+ """
495
+ if "FROM_MAIN" in str (y ):
496
+ return True
497
+ else :
498
+ return False
499
+
429
500
430
501
def update_w_main_dic (d , u = None , specific_value = "FROM_MAIN" ):
431
502
"""
@@ -476,7 +547,8 @@ def run_steps(
476
547
It is the opposite behavior of the regular one using steps_select_list
477
548
Default is False.
478
549
verbose : bool, optional
479
- A flag indicating whether to print the tables during the execution of the steps. Default is True.
550
+ A flag indicating whether to print the tables during the execution of the steps.
551
+ Default is True.
480
552
force : bool, optional
481
553
A flag indicating whether to force the execution of the steps.
482
554
overrides the 'force' parameters in the configuration file.
0 commit comments