polyfemos.back.interpreter.Interpreter¶
-
class
polyfemos.back.interpreter.Interpreter[source]¶ Bases:
objectClass for reading ‘*.conf’ files
Contents of the ‘*.conf’ files are interpreted at run time.
Public Methods
-
__init__()[source]¶ Sets the global program starttime,
self.__now. Calls_init_timedict()to initializeself.__timedict.Creates empty
Stations()instance (self.station).
-
add_par(*args)[source]¶ Creates
Parameterinstance and adds it to the most recently defined station inself.stations.argsare passed straight to the__init__().
-
add_station(*args)[source]¶ Tries to define and add a station (
Station) instance toself.stations.argsare passed straight to the__init__().
-
apply_async(func_, args, deepcopy=True)[source]¶ Asynchronously calls
func_withargsusingProcessPool(alias ofmultiprocess.pool.Poolfrom multiprocess). Additional information in Python’s own multiprocessing packagePool.If
deepcopyandself.flags["multiprocessing"]are bothFalse, the function is called normallyfunc_(*args).
-
call_func(funckey, *args)[source]¶ Calls function available in
self.functions.argsare the arguments passed to the functionself.functions[funckey]['func'].- Parameters
funckey (str) – name of the function
-
close_and_join()[source]¶ If
self.poolis previously set up, terminates the pool workers by calling methods close and join.
-
data_coverage_image(*args)[source]¶ Calls
data_coverage_image()withself.flagsandargs.
-
define_flag(flag, value)[source]¶ - Parameters
flag (str) – name of the FLAG
value – value of the FLAG, the type depends on the flag
-
process_logs(*args)[source]¶ Processes all stations in
self.stations. Callsprocess_logs()withself.flags,self.stations, andargs.
-
readfile(conffile)[source]¶ Reads and interprets contents of the ‘*.conf’ files.
- Parameters
conffile (str) – path to ‘*.conf’ file
-
save_starttime(tolast=False)[source]¶ If
tolastisFalse, loads the ‘laststarttime’ value from the pklfile (FLAG execution_time_file) before saving theself.__timedict. After this the ‘laststarttime’ should be unchanged, and ‘thisstarttime’ should contain the starttime of this exact program run.If
tolastisTrue, the value of ‘thisstarttime’ is saved to ‘laststarttime’.- Parameters
tolast (bool, optional) – defaults to
False
-
start()[source]¶ Program execution is halted if the difference between program starttime and midnight is lesser than value of the FLAG ‘wait_after_midnight’.
Saves the current program starttime to ‘thisstarttime’. see
save_starttime()for more info.
Private Methods
-
_init_flags()[source]¶ Ititializes
self.__flagsandself.flagsdictionaries.self.__flagsconsists of flag types and default values.self.flagswill store the flag values, changed or default.If default value of the FLAG is
None, the user most likely needs to provide correct value in the ‘*.conf’ file.All available FLAGs, their types and default values:
sohtextfilepath
filepath(),None, Filepath of the output ‘*.stf’ file. Do not include file extension when defining the path, the corresponding extension will be automatically included.sohalertpath
filepath(),None, Filepath of the output ‘*.alert’ file. Do not include file extension when defining the path, the corresponding extension will be automatically included.sohcsvpath
filepath(),None, Filepath of the output ‘*.csv’ file. Do not include file extension when defining the path, the corresponding extension will be automatically included.wait_after_midnight
int_(),0, Given in seconds. As the START command is called, if difference between current program starttime and midnight is lesser than this value, program execution is halted (without saving any starttime values).write_sohalertfile
[not in use]
bool_(),True, Defines if ‘*.alert’ file is created/updatedwrite_sohtextfile
[not in use]
bool_(),True, Defines if ‘*.stf’ file is created/updatedwrite_sohcsvfile
[not in use]
bool_(),True, Defines if ‘*.csv’ file is created/updatedretroactive
bool_(),FalseIf
False, appends lines to previously created files. One new line per station-parameter combination.If
True, creates ‘*.stf’ and ‘*.csv’ files from scratch, Files created retroactively, have an additional ‘retro’ identifier in the filename. Retroactive option overwrites previously created ‘retro’-files.save_starttime
bool_(),False, Defines if current program starttime is saved to ‘laststarttime’ when program execution is finishedrealtimeness_limit
int_(),0, Given in seconds, for datacoverage parameters (codes ‘DCD’ and ‘DCL’), defines the time interval in which the data is still considered to be in “realtime”. See_data_coverage()for more info.average_calc_length
int_(),1, Sets theaverage_calc_lengthindata_timing_quality(), which is used for codes ‘XXX.TQ’.execution_time_file
staticfilepath(),None, A pickle file where ‘thisstarttime’ and ‘laststarttime’ program starttime values are saved and available for reference via this FLAG during program execution. Include the full path in the definition including the extension (*.pkl).multiprocessing
bool_(),True, Defines if multiprocessing is used or not.max_processes
int_(),4, Maximum number of CPUs used for multiprocessing, see_init_pool()for more info.
-
_init_funcs_and_commands(today)[source]¶ All possible commands in addition to functions called using the ‘RUN’ command are defined here. Additionally, the amount of arguments and their types for each function and command is defined.
If today special variable is used in case of types
ordinal()orutcdatetime(), the variable is replaced with the value oftoday.- Parameters
today (
UTCDateTime) –
-
_init_pool()[source]¶ Initializes
self.pool(ProcessPool) attribute. Sets the maximum amount of CPUs used by the pool, this is defined with the FLAG max_processes. Two CPUs are left unused if possible (i.e. the machine has 3 or more CPUs). In every case the pool will use at least 1 CPU. Seeapply_async()for more info.If
self.poolis already initialized, do nothing.
-