diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index cebb29c..4fefca5 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -19,7 +19,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: ["3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v3 diff --git a/README.md b/README.md index 90f2df8..07a9e19 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,6 @@ ![overlappogram example](https://raw.githubusercontent.com/ECCCO-mission/overlappogram/main/overlappogram.png) -🚧🚧🚧 **UNDER DEVELOPMENT** 🚧🚧🚧 - -**The package is still being developed. Expect breaking changes.** - Overlappogram is a Python package for inverting overlappogram observations of the Sun, for examples MaGIXS, CubIXSS, or ECCCO observations. diff --git a/overlappogram/cli.py b/overlappogram/cli.py index d7416d1..1273868 100644 --- a/overlappogram/cli.py +++ b/overlappogram/cli.py @@ -31,7 +31,8 @@ def unfold(config): os.makedirs(config["output"]["directory"], exist_ok=True) # make sure output directory exists - overlappogram = load_overlappogram(config["paths"]["overlappogram"], config["paths"]["weights"]) + overlappogram = load_overlappogram(config["paths"]["overlappogram"], + config["paths"]["weights"] if 'weights' in config['paths'] else None) response_cube = load_response_cube(config["paths"]["response"]) inversion = Inverter( diff --git a/overlappogram/error.py b/overlappogram/error.py new file mode 100644 index 0000000..b5d85f6 --- /dev/null +++ b/overlappogram/error.py @@ -0,0 +1,6 @@ +class OverlappogramWarning(Warning): + pass + + +class NoWeightsWarnings(OverlappogramWarning): + """There are no weights passed to unfold.""" diff --git a/overlappogram/inversion.py b/overlappogram/inversion.py index 4f961b8..10104e7 100644 --- a/overlappogram/inversion.py +++ b/overlappogram/inversion.py @@ -11,6 +11,7 @@ from sklearn.linear_model import ElasticNet from tqdm import tqdm +from overlappogram.error import NoWeightsWarnings from overlappogram.response import prepare_response_function __all__ = ["Inverter"] @@ -226,6 +227,9 @@ def _start_chunk_inversion(self, model_config, alpha, rho, num_threads): def _initialize_with_overlappogram(self, overlappogram): self._overlappogram = overlappogram + if self._overlappogram.uncertainty is None: + warnings.warn("Running in weightless mode since no weights array was provided.", NoWeightsWarnings) + if self._detector_row_range is None: self._detector_row_range = (0, overlappogram.data.shape[0]) self.total_row_count = self._detector_row_range[1] - self._detector_row_range[0] @@ -239,7 +243,7 @@ def _initialize_with_overlappogram(self, overlappogram): self._overlappogram.data[np.where(self._overlappogram.data < 0.0)] = 0.0 - # initialize all result cubes + # initialize all results cubes self._overlappogram_height, self._overlappogram_width = self._overlappogram.data.shape self._em_data = np.zeros((self._overlappogram_height, self._num_slits, self._num_deps), dtype=np.float32) self._inversion_prediction = np.zeros((self._overlappogram_height, self._overlappogram_width), dtype=np.float32) diff --git a/overlappogram/io.py b/overlappogram/io.py index 9b31420..0d82461 100644 --- a/overlappogram/io.py +++ b/overlappogram/io.py @@ -6,17 +6,23 @@ __all__ = ["load_overlappogram", "load_response_cube", "save_em_cube", "save_spectral_cube", "save_prediction"] -def load_overlappogram(image_path, weights_path) -> NDCube: +def load_overlappogram(image_path: str, weights_path: str | None) -> NDCube: with fits.open(image_path) as image_hdul: image = image_hdul[0].data header = image_hdul[0].header wcs = WCS(image_hdul[0].header) - with fits.open(weights_path) as weights_hdul: - weights = weights_hdul[0].data - return NDCube(image, wcs=wcs, uncertainty=StdDevUncertainty(1 / weights), meta=dict(header)) + if weights_path is None: + uncertainty = None + else: + with fits.open(weights_path) as weights_hdul: + weights = weights_hdul[0].data + uncertainty = StdDevUncertainty(1 / weights) -def load_response_cube(path) -> NDCube: + return NDCube(image, wcs=wcs, uncertainty=uncertainty, meta=dict(header)) + + +def load_response_cube(path: str) -> NDCube: with fits.open(path) as hdul: response = hdul[0].data header = hdul[0].header @@ -28,13 +34,13 @@ def load_response_cube(path) -> NDCube: return NDCube(response, wcs=wcs, meta=meta) -def save_em_cube(cube, path, overwrite=True) -> None: +def save_em_cube(cube, path: str, overwrite: bool = True) -> None: fits.writeto(path, cube, overwrite=overwrite) -def save_prediction(prediction, path, overwrite=True) -> None: +def save_prediction(prediction, path: str, overwrite: bool = True) -> None: fits.writeto(path, prediction, overwrite=overwrite) -def save_spectral_cube(spectral_cube, path, overwrite=True) -> None: +def save_spectral_cube(spectral_cube, path: str, overwrite: bool = True) -> None: fits.writeto(path, spectral_cube, overwrite=overwrite) diff --git a/pyproject.toml b/pyproject.toml index 1687797..0547c84 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ requires = ["setuptools", [project] name = "overlappogram" -version = "0.0.3" +version = "0.0.4" dependencies = ["numpy", "astropy", "scikit-learn", @@ -19,7 +19,7 @@ dependencies = ["numpy", "click", "tqdm" ] -requires-python = ">=3.9" +requires-python = ">=3.10" authors = [ {name = "J. Marcus Hughes", email = "hughes.jmb@gmail.com"}, {name = "Dyana Beabout", email = "dyana.l.beabout@nasa.gov"},