Commit 28df40ce authored by Médéric Boquien's avatar Médéric Boquien
Browse files

Rather than relying on deepcopy, let's build the new SED objects ourselves. As...

Rather than relying on deepcopy, let's build the new SED objects ourselves. As we know the structure perfectly we can do that much more efficiently. To do se we add a copy() member to the SED class. This function creates a new object and initialises its members with proper copies.
parent e2305864
......@@ -363,3 +363,21 @@ class SED(object):
"""
save_sed_to_vo(self, filename, mass)
def copy(self):
sed = SED()
sed.sfh = (self._sfh[0].copy(), self._sfh[1].copy())
sed.modules = self.modules[:]
if self.wavelength_grid is not None:
sed.wavelength_grid = self.wavelength_grid.copy()
sed.luminosity = self.luminosity.copy()
sed.luminosities = self.luminosities.copy()
else:
sed.wavelength_grid = None
sed.luminosity = None
sed.luminosities = None
sed.contribution_names = self.contribution_names[:]
sed.info = self.info.copy()
sed.mass_proportional_info = self.mass_proportional_info[:]
return sed
......@@ -3,8 +3,6 @@
# Licensed under the CeCILL-v2 licence - see Licence_CeCILL_V2-en.txt
# Author: Yannick Roehlly
from copy import deepcopy
class SedStore(object):
"""In memory storage"""
......@@ -25,7 +23,11 @@ class SedStore(object):
"""
# We return a copy not to modify the stored object.
return deepcopy(self.dictionary.get(key))
sed = self.dictionary.get(key)
if sed is not None:
return sed.copy()
else:
return None
def add(self, key, value):
"""Add a new key, value pair to the cache.
......@@ -37,7 +39,7 @@ class SedStore(object):
"""
# We store a copy not to modify the stored object.
self.dictionary[key] = deepcopy(value)
self.dictionary[key] = value.copy()
def delete(self, key):
"""Delete a key, value pair from the cache
......
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