Commit 012d2f7d authored by Médéric Boquien's avatar Médéric Boquien

Add the first implementation of a new parameters handler, this time when model...

Add the first implementation of a new parameters handler, this time when model parameters are provided in an input file rather than given explicitly in pcigale.ini. It is never called for now as it requires some adjustments to be done in a subsequent patch so the proper keyword is added to pcigale.ini and handled accordingly.
parent f7e7d502
......@@ -8,6 +8,10 @@ import collections
import itertools
import numpy as np
from astropy.table import Table
from ..utils import read_table
class ParametersHandler(object):
"""Class to abstract the call to the relevant parameters handler depending
......@@ -127,3 +131,84 @@ class ParametersHandlerGrid(object):
return module_idx
return len(self.shape)
class ParametersHandlerFile(object):
"""Class to generate a parameters handler for list of parameters given in an
input file."""
def __init__(self, configuration):
"""Instantiate the class.
configuration: dictionary
Contains the name of the file containing the parameters
table = read_table(configuration['parameters_file'])
self.modules = []
for colname in table.colnames:
module = colname.split('.', 1)[0]
if module not in self.modules:
self.parameters = [table[[colname for colname in table.colnames if
for module in self.modules]
for module_table in self.parameters:
for colname in t.colnames:
t[colname].name = colname.split('.', 1)[1]
del table
def from_index(self, index):
"""Provides the parameters of a model given an index.
index: int
index of the model for which we want the parameters
params: list
Parameters of the model corresponding to the index
# As we have a simple file, this corresponds to the line number
params = [{name: self.parameters[idx_module][name][index] for name in
self.parameters[idx_module].colnames} for idx_module, module
in enumerate(self.modules)]
return params
def index_module_changed(self, index1, index2):
"""Find the index of the first module affected by a change of parameters.
index1: int
First index
index2: int
Second index
module_idx: int
Index of the first module that has a different parameter
params1 = [table[index1].as_void() for table in self.parameters]
params2 = [table[index2].as_void() for table in self.parameters]
idx = next((i for i, (param1, param2) in
enumerate(zip(params1, params2)) if param1 != param2),
return idx
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment