oasislmf.lookup.factory¶
Classes¶
A factory class to create the Keys Server that will be use to generate the keys files |
|
A basic implementation of the KeyServerInterface |
Module Contents¶
- class oasislmf.lookup.factory.KeyServerFactory[source]¶
Bases:
object
A factory class to create the Keys Server that will be use to generate the keys files All Key Server must implement the interface defined in lookup.interface.KeyServerInterface
Oasis provides a built-in Key Server that manage the generation of the key files from the key provided by a built-in or a custom Key Lookup.
The factory now return a KeyServer object and not a KeyLookup. The parameter to pass has also been simplified usage of all the below parameter are now deprecated
complex_lookup_config_fp => pass the path to your complex lookup config directly in lookup_config_fg
lookup_module_path => set as key ‘lookup_module_path’ in the lookup config
model_keys_data_path => set as key ‘keys_data_path’ in the lookup config
model_version_file_path => set the model information (‘supplier_id’, ‘model_id’, ‘model_version’) directly into the config
- classmethod get_model_info(model_version_file_path)[source]¶
Get model information from the model version file.
- classmethod update_deprecated_args(config_dir, config, complex_lookup_config_fp, model_keys_data_path, model_version_file_path, lookup_module_path)[source]¶
- classmethod create(model_keys_data_path=None, model_version_file_path=None, lookup_module_path=None, lookup_config=None, lookup_config_json=None, lookup_config_fp=None, complex_lookup_config_fp=None, user_data_dir=None, output_directory=None)[source]¶
Creates a keys lookup class instance for the given model and supplier - local file paths are required for the model keys data folder, the model version file and the Git repository for the model keys server. Returns a pair
(model_info, klc)
, wheremodel_info
is a dictionary holding model information from the model version file and klc is the lookup service class instance for the model.
- class oasislmf.lookup.factory.BasicKeyServer(config, config_dir=None, user_data_dir=None, output_dir=None)[source]¶
A basic implementation of the KeyServerInterface will load the KeyLookup class from config[‘lookup_module_path’] if present or used the built-in KeyLookup KeyLookup must implement the KeyLookupInterface
will provide a multiprocess solution if KeyLoopup implement the process_locations_multiproc method
both single and multiprocess solutions will use low amount of memory as they process the key by chunk of limited size.
This class implement all the file writing method that were previously handled by the lookup factory
- abstract get_locations(location_fp)[source]¶
load exposure data from location_fp and return the exposure dataframe
- static lookup_multiproc_worker(error_queue, lookup_cls, config, config_dir, user_data_dir, output_dir, lookup_id, loc_queue, key_queue)[source]¶
- generate_key_files_singleproc(loc_df, successes_fp, errors_fp, output_format, keys_success_msg, **kwargs)[source]¶
- generate_key_files_multiproc(loc_df, successes_fp, errors_fp, output_format, keys_success_msg, num_cores, num_partitions, **kwargs)[source]¶
Process and return the lookup results a location row Used in multiprocessing based query
location_row is of type <class ‘pandas.core.series.Series’>
- generate_key_files(location_fp=None, successes_fp=None, errors_fp=None, output_format='oasis', keys_success_msg=False, multiproc_enabled=True, multiproc_num_cores=-1, multiproc_num_partitions=-1, location_df=None, **kwargs)[source]¶
generate key files by calling: 1. get_locations to get a location object from the location_fp 2. process_locations or process_locations_multiproc to get results object from the locations object 3. write_keys_file to writes the relevant files from the results object