SBART.Base_Models.Sampler_Model

SBART.Base_Models.Sampler_Model#

Classes

SamplerModel

Base Class for all SBART samplers.

class SamplerModel#

Bases: BASE

Base Class for all SBART samplers.

The samplers allow for the instantiation of a RV model, using the RV_Model which contain multiple Parameter representing the different free-parameters of the full RV model. By default, all samplers must have a RV_component. Internally, SBART works in meters per second and all RV-related measurements are converted to it after entering the pipeline.

The samplers implement a simple loop:

  • Draw a new, tentative, set of parameters of our RV model

  • Propose the new parameters to the model and evaluate its response

  • Evaluate any convergence metric that might exist.

  • Either restart the loop of exist (depending on convergence)

The Samplers are implemented in such a way that they can be applied at a order-by-order level or at a global, achromatic level.

Note: The majority of the Samplers only implement one of the two options

Note: The memory saving mode is controlled by the rv_calculation routines

__init__(mode, RV_step, RV_window, params_of_model=None, user_configs=None, needed_folders=None)#
store_shared_buffer(buffer)#
Return type:

None

set_mode(mode)#

Set the sampler to one of its two working modes:

  • order-wise

  • epoch-wise

Parameters:

mode (str) – The mode for the sampler

Raises:

InvalidConfiguration – If the mode is not one of the valid options

Return type:

None

generate_prior_of_model(dataClassProxy)#
add_extra_param(parameter)#
enable_param(param_name)#

External activation of the parameters of the model

Parameters:
  • param_name (str) – One of the available parameters

  • bounds – Bounds for the parameter

  • guess – Initial guess for the parameter

Return type:

NoReturn

lock_model_param(param_name)#
Return type:

NoReturn

apply_orderwise(optimizer_estimate, target, target_kwargs)#

Minimize the target function for the data of a single order. As the models might have multiple free-parameters, we ensure that the target always receives a list of elements.

Parameters:
  • optimizer_estimate (Union[float, list]) – Value at which the target function will be evaluated.

  • target (func) – Target function, which will be one the worker of the selected RV routine

  • target_kwargs ([type]) –

    Input arguments of the target function. Must contain the following:
    • dataClassProxy,

    • frameID

    • order

Returns:

Evaluation of

Return type:

func_output

optimize_orderwise(target, target_kwargs)#

Optimization over the functions that implements the orde-rwise application. This must be implemented by the children classes, as each model will use a different optimization strategy

Parameters:
  • target ([type]) – [description]

  • target_kwargs ([type]) –

    Input arguments of the target function. Must contain the following:
    • dataClassProxy,

    • frameID

    • order

Returns:

[description]

Return type:

[type]

apply_epochwise(optimizer_estimate, config_dict)#

Application of the model’s parameters to all spectral orders at the same time. The children classes must implement this on their own, as the application stratagies will end up being different for each

Parameters:
  • config_dict – Dictionary that will be passed to the target function

  • model_parameters – List with the model parameters in the correct order

manage_RV_calculation(dataClass, subInst, valid_orders, target_specific_configs, target_function, package_queue, output_pool)#

” This function has the goal of dispatching/managing the handling of the spectral data. Depending on the “mode”, it will either launch the order- or epoch-wise managers. Those managers control the data that is currently in memory, the “work packages” that are available to the pool of workers and the communication between the main “process” and the workers.

There is no “base” implementation of the epoch-wise manager, but there is base implementation of the order-wise manager:

  • Sequential iteration over all frames. For each frame:

    • Trigger the opening of the S2D arrays

    • Populate the package_queue with “work packages” for all valid orders

    • Wait for the responses

    • If the memory saving mode is enabled, close the S2D arrays

Parameters:
  • dataClass

  • subInst (str) – subInst for which we want to compute RVs

  • valid_orders (tuple) – List of the valid orders for the RV calculation

  • target_specific_configs (dict) –

  • target_function

  • package_queue – Communication queue between the main core (this one) and the workers

  • output_pool – Communication queue on which the workers place their outputs

Returns:

List of products that was collected from the workers TODO: confirm/update this type hint

Return type:

worker_products

Raises:

InvalidConfiguration – If there are no valid orders for the calculation of RVs

property N_model_params: int#

returns: Number of free-parameters that are currently enabled in our model :rtype: number_params

is_sampler(sampler_type)#

Check if the sampler is of a given type

Parameters:

sampler_type (str) –

Return type:

bool

enable_memory_savings()#
disable_memory_savings()#
enable_disk_savings()#

Save, as much as possible, disk space when saving the worker outputs. Each target function will decide on the details of such “savings”

Return type:

NoReturn

disable_disk_savings()#
Return type:

NoReturn

property RV_keyword: str#
Return type:

str

process_epochwise_metrics(outputs)#

Each children class must implement this, as it will be used to parse the outputs when the optimal RV is provided to the target!

Parameters:

outputs

compute_epochwise_combination(outputs)#

Each children class must implement this to combine the order-wise metrics into a “global” value for the optimization process :param outputs: