diff --git a/common/python/nomadcore/caching_backend.py b/common/python/nomadcore/caching_backend.py index e0f85954ebba20f155d5cfd8c0f602ad8843f928..acf7f94c3bb5adbf47cdbe12b460c9f5ddede884 100644 --- a/common/python/nomadcore/caching_backend.py +++ b/common/python/nomadcore/caching_backend.py @@ -398,7 +398,8 @@ class ActiveBackend(object): def addValue(self, metaName, value, gIndex = -1): """adds a json value corresponding to metaName the value is added to the section the meta info metaName is in - a gIndex of -1 means the latest section""" + a gIndex of -1 means the latest section + """ dataManager = self.dataManagers[metaName] cachingLevel = dataManager.cachingLevel if cachingLevel == CachingLevel.Forward or cachingLevel == CachingLevel.ForwardAndCache or cachingLevel == CachingLevel.PreOpenedCache: @@ -412,15 +413,16 @@ class ActiveBackend(object): added to the section the meta info metaName is in A gIndex of -1 means the latest section. """ - value = self.convert_unit(metaName, value, unit) + if unit is not None: + value = self.convert_unit(metaName, value, unit) dataManager = self.dataManagers[metaName] cachingLevel = dataManager.cachingLevel if cachingLevel == CachingLevel.Forward or cachingLevel == CachingLevel.ForwardAndCache or cachingLevel == CachingLevel.PreOpenedCache: if self.superBackend: self.superBackend.addRealValue(metaName, value, gIndex) - if cachingLevel == CachingLevel.ForwardAndCache or cachingLevel == CachingLevel.Cache or cachingLevel == CachingLevel.PreOpenedCache: - dataManager.superSectionManager.addRealValue(dataManager.metaInfo, value, gIndex) + if cachingLevel == CachingLevel.ForwardAndCache or cachingLevel == CachingLevel.Cache: + dataManager.superSectionManager.addValue(dataManager.metaInfo, value, gIndex) def addArray(self, metaName, shape, gIndex = -1): """adds a new array value of the given size corresponding to metaName @@ -438,7 +440,8 @@ class ActiveBackend(object): def setArrayValues(self, metaName, values, offset = None, gIndex = -1, unit=None): """Adds values to the last array added, array must be a numpy array """ - values = self.convert_unit(metaName, values, unit) + if unit is not None: + values = self.convert_unit(metaName, values, unit) dataManager = self.dataManagers[metaName] cachingLevel = dataManager.cachingLevel @@ -452,7 +455,9 @@ class ActiveBackend(object): """Adds an array value with the given array values. Values must be a numpy array. """ - values = self.convert_unit(metaName, values, unit) + if unit is not None: + values = self.convert_unit(metaName, values, unit) + dataManager = self.dataManagers[metaName] cachingLevel = dataManager.cachingLevel if cachingLevel == CachingLevel.Forward or cachingLevel == CachingLevel.ForwardAndCache or cachingLevel == CachingLevel.PreOpenedCache: @@ -476,9 +481,6 @@ class ActiveBackend(object): def convert_unit(self, metaName, value, unit): """Try to perform a unit conversion. """ - if unit is None: - return value - # If a unit has been specified in the metainfo, check that the # conversion can be done metaInfo = self.metaInfoEnv().infoKindEl(metaName) diff --git a/common/python/nomadcore/csvparsing.py b/common/python/nomadcore/csvparsing.py index 4d5e515afe1242477e838ea8b2e495d565b25fbb..ca9e158c3a9f6fcde328b3a59422bafbf880d4f4 100644 --- a/common/python/nomadcore/csvparsing.py +++ b/common/python/nomadcore/csvparsing.py @@ -5,7 +5,7 @@ logger = logging.getLogger(__name__) #=============================================================================== -def iread(filepath, columns, delimiter=r"\s+", comments=r"#", start=None, end=None, n_conf=None): +def iread(filepath, columns=None, delimiter=r"\s+", comments=r"#", start=None, end=None, n_conf=None): """Used to iterate a CSV-like file. If a separator is provided the file is iterated one configuration at a time. Only keeps one configuration of the file in memory. If no separator is given, the whole file will be @@ -164,6 +164,6 @@ def iread(filepath, columns, delimiter=r"\s+", comments=r"#", start=None, end=No conf.append(line_values) i_line += 1 if i_line == n_conf: - yield conf + yield np.array(conf) conf = [] i_line = 0 diff --git a/common/python/nomadcore/local_backend.py b/common/python/nomadcore/local_backend.py index 17ef6e6e6ae418effedb3b18ee05d4030e2549c0..2a7e54eba73210be90d6847d8476601e45022b50 100644 --- a/common/python/nomadcore/local_backend.py +++ b/common/python/nomadcore/local_backend.py @@ -103,6 +103,9 @@ class LocalBackend(object): dataManager.superSectionManager.addValue(dataManager.metaInfo, value, gIndex) + def addRealValue(self, metaName, value, gIndex=-1): + self.addValue(metaName, value, gIndex) + def addArrayValues(self, metaName, values, gIndex=-1): dataManager = self.dataManagers[metaName]