polyfemos.back.interpreter.Interpreter

class polyfemos.back.interpreter.Interpreter[source]

Bases: object

Class 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 initialize self.__timedict.

Creates empty Stations() instance (self.station).

add_par(*args)[source]

Creates Parameter instance and adds it to the most recently defined station in self.stations. args are passed straight to the __init__().

add_station(*args)[source]

Tries to define and add a station (Station) instance to self.stations. args are passed straight to the __init__().

apply_async(func_, args, deepcopy=True)[source]

Asynchronously calls func_ with args using ProcessPool (alias of multiprocess.pool.Pool from multiprocess). Additional information in Python’s own multiprocessing package Pool.

If deepcopy and self.flags["multiprocessing"] are both False, the function is called normally func_(*args).

Parameters
  • func_ (func) –

  • args (list) – arguments to the func_

  • deepcopy (bool, optional) – defaults to True, only used if multiprocessing is not used. If True, the args are deepcopied before calling the func_.

call_func(funckey, *args)[source]

Calls function available in self.functions.

args are the arguments passed to the function self.functions[funckey]['func'].

Parameters

funckey (str) – name of the function

close_and_join()[source]

If self.pool is previously set up, terminates the pool workers by calling methods close and join.

data_coverage_image(*args)[source]

Calls data_coverage_image() with self.flags and args.

define_flag(flag, value)[source]
Parameters
  • flag (str) – name of the FLAG

  • value – value of the FLAG, the type depends on the flag

define_var(key, value)[source]
Parameters
  • key (str) – variable name

  • value (str) – value to be set to variable

exit_scope()[source]

Effectively does nothing at the moment

plot_ppsd(*args)[source]

TODO

args

process_logs(*args)[source]

Processes all stations in self.stations. Calls process_logs() with self.flags, self.stations, and args.

readfile(conffile)[source]

Reads and interprets contents of the ‘*.conf’ files.

Parameters

conffile (str) – path to ‘*.conf’ file

replace_var(key)[source]
Parameters

key (str) – the name of the variable starting with the variable symbol

Return type

str

Returns

Anything contained in self.vars[key], if key is previously defined variable.

save_starttime(tolast=False)[source]

If tolast is False, loads the ‘laststarttime’ value from the pklfile (FLAG execution_time_file) before saving the self.__timedict. After this the ‘laststarttime’ should be unchanged, and ‘thisstarttime’ should contain the starttime of this exact program run.

If tolast is True, 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.

stop(quit_=True, save_starttime=True)[source]
Parameters
  • quit_ (bool, optional) – defaults to True, If True the program does nothing anymore.

  • save_starttime (bool, optional) – defaults to True, In order to save starttime value, save_starttime and FLAG ‘save_starttime’ both are required to be True.

Private Methods

_init_flags()[source]

Ititializes self.__flags and self.flags dictionaries. self.__flags consists of flag types and default values. self.flags will 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/updated

write_sohtextfile

[not in use]

bool_(), True, Defines if ‘*.stf’ file is created/updated

write_sohcsvfile

[not in use]

bool_(), True, Defines if ‘*.csv’ file is created/updated

retroactive

bool_(), False

If 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 finished

realtimeness_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 the average_calc_length in data_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() or utcdatetime(), the variable is replaced with the value of today.

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. See apply_async() for more info.

If self.pool is already initialized, do nothing.

_init_timedict()[source]

Sets ‘thisstarttime’ and ‘laststarttime’ values to self.__now.