Commit 13e8fe35 authored by Médéric Boquien's avatar Médéric Boquien

astropy.Table stores columns made of strings (for instance the...

astropy.Table stores columns made of strings (for instance the sfhdelayed.normalise parameter) using the np.str_ type. The issue is that this type is not marshalable, making it impossible to use the modules parameters as keys to cache the partially computed SED in a dictionary. To solve this, rather than using the table directly, we split it into several dictionaries, one for each module. Each dictionary contains the arguments of lists that we convert to the right type.
parent 292edfed
...@@ -160,13 +160,25 @@ class ParametersHandlerFile(object): ...@@ -160,13 +160,25 @@ class ParametersHandlerFile(object):
if module not in self.modules: if module not in self.modules:
self.modules.append(module) self.modules.append(module)
self.parameters = [table[[colname for colname in table.colnames if # The parameters file is read using astropy.Table. Unfortunately, it
colname.startswith(module)]] # stores strings as np.str_, which is not marshalable, which means we
for module in self.modules] # cannot use the list of parameter to build a key for the cache. This
# overcome this, rather than using the table directly, we split it into
for module_table in self.parameters: # several dictionaries, one for each module. Each dictionary contains
for colname in t.colnames: # the arguments in the form of lists that we convert to the right type:
t[colname].name = colname.split('.', 1)[1] # float for numbers and str for strings.
self.parameters = []
for module in self.modules:
dict_params = {}
for colname in table.colnames:
if colname.startswith(module):
parname = colname.split('.', 1)[1]
if type(table[colname][0]) is np.str_:
dict_params[parname] = [str(val) for val in
table[colname]]
else:
dict_params[parname] = list(table[colname])
self.parameters.append(dict_params)
del table del table
...@@ -187,7 +199,7 @@ class ParametersHandlerFile(object): ...@@ -187,7 +199,7 @@ class ParametersHandlerFile(object):
# As we have a simple file, this corresponds to the line number # As we have a simple file, this corresponds to the line number
params = [{name: self.parameters[idx_module][name][index] for name in params = [{name: self.parameters[idx_module][name][index] for name in
self.parameters[idx_module].colnames} for idx_module, module self.parameters[idx_module]} for idx_module, module
in enumerate(self.modules)] in enumerate(self.modules)]
return params return params
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment