From ac125ec20ec194062154b73bc8c3f6ea7eb99c9b Mon Sep 17 00:00:00 2001 From: Will Barnes Date: Fri, 26 Jan 2024 09:21:23 -0500 Subject: [PATCH 1/3] fix a bug in the temperature bin lengths --- sunkit_dem/base_model.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sunkit_dem/base_model.py b/sunkit_dem/base_model.py index 2e84b15..50330c1 100644 --- a/sunkit_dem/base_model.py +++ b/sunkit_dem/base_model.py @@ -58,9 +58,12 @@ def __init_subclass__(cls, **kwargs): cls._registry[cls] = cls.defines_model_for @u.quantity_input - def __init__(self, data, kernel, temperature_bin_edges: u.K, **kwargs): + def __init__(self, data, kernel, temperature_bin_edges: u.K, kernel_temperatures=None, **kwargs): self.temperature_bin_edges = temperature_bin_edges self.data = data + self.kernel_temperatures = kernel_temperatures + if self.kernel_temperatures is None: + self.kernel_temperatures = self.temperature_bin_centers self.kernel = kernel @property @@ -100,7 +103,7 @@ def kernel(self): def kernel(self, kernel): if len(kernel) != len(self.data): raise ValueError('Number of kernels must be equal to length of wavelength dimension.') - if not all([v.shape == self.temperature_bin_centers.shape for _,v in kernel.items()]): + if not all([v.shape == self.kernel_temperatures.shape for _, v in kernel.items()]): raise ValueError('Temperature bin centers and kernels must have the same shape.') self._kernel = kernel From 2dfe156327693b02603be688bc0ea5edad501f17 Mon Sep 17 00:00:00 2001 From: Will Barnes Date: Sun, 23 Jun 2024 03:10:16 -0400 Subject: [PATCH 2/3] apply mask from data, relax units on kernel matrix --- sunkit_dem/base_model.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/sunkit_dem/base_model.py b/sunkit_dem/base_model.py index 50330c1..e6571fd 100644 --- a/sunkit_dem/base_model.py +++ b/sunkit_dem/base_model.py @@ -92,9 +92,23 @@ def data(self, data): if not isinstance(data, ndcube.NDCollection): raise ValueError('Input data must be an NDCollection') if not all([hasattr(data[k], 'unit') for k in data]): - raise u.UnitsError('Each NDCube in NDCubeSequence must have units') + raise u.UnitsError('Each NDCube in NDCollection must have units') self._data = data + @property + def combined_mask(self): + """ + Combined mask of all members of ``data``. Will be True if any member is masked. + This is propagated to the final DEM result + """ + combined_mask = [] + for k in self._keys: + if self.data[k].mask is not None: + combined_mask.append(self.data[k].mask) + else: + combined_mask.append(np.full(self.data[k].shape, False)) + return np.any(combined_mask, axis=0) + @property def kernel(self): return self._kernel @@ -109,14 +123,14 @@ def kernel(self, kernel): @property def data_matrix(self): - return np.stack([self.data[k].data*self.data[k].unit for k in self._keys]) + return np.stack([self.data[k].data for k in self._keys]) @property def kernel_matrix(self): - return np.stack([self.kernel[k] for k in self._keys]) + return np.stack([self.kernel[k].value for k in self._keys]) def fit(self, *args, **kwargs): - """ + r""" Apply inversion procedure to data. Returns @@ -129,9 +143,13 @@ def fit(self, *args, **kwargs): dem_dict = self._model(*args, **kwargs) wcs = self._make_dem_wcs() meta = self._make_dem_meta() - dem = ndcube.NDCube(dem_dict.pop('dem'), + dem_data = dem_dict.pop('dem') + mask = np.full(dem_data.shape, False) + mask[:,...] = self.combined_mask + dem = ndcube.NDCube(dem_data, wcs, meta=meta, + mask=mask, uncertainty=StdDevUncertainty(dem_dict.pop('uncertainty'))) cubes = [('dem', dem),] for k in dem_dict: From d4e41d3fb668fc5ede0aca3c5706bd03252cd6b2 Mon Sep 17 00:00:00 2001 From: Will Barnes Date: Thu, 25 Jul 2024 16:29:27 -0600 Subject: [PATCH 3/3] fix temperature bin center calculation --- sunkit_dem/base_model.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sunkit_dem/base_model.py b/sunkit_dem/base_model.py index e6571fd..c2c7c37 100644 --- a/sunkit_dem/base_model.py +++ b/sunkit_dem/base_model.py @@ -75,9 +75,7 @@ def _keys(self): @property @u.quantity_input def temperature_bin_centers(self) -> u.K: - log_temperature = np.log10(self.temperature_bin_edges.value) - log_temperature_centers = (log_temperature[1:] + log_temperature[:-1])/2. - return u.Quantity(10.**log_temperature_centers, self.temperature_bin_edges.unit) + return (self.temperature_bin_edges[1:] + self.temperature_bin_edges[:-1])/2. @property def data(self) -> ndcube.NDCollection: