Skip to content

Commit

Permalink
Merge pull request #56 from ECCCO-mission/add-weightless-runs
Browse files Browse the repository at this point in the history
Add weightless runs, Bumps to Python 3.10
  • Loading branch information
jmbhughes authored Jun 5, 2024
2 parents e976631 + f5042ef commit c6ae31a
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
3 changes: 2 additions & 1 deletion overlappogram/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions overlappogram/error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class OverlappogramWarning(Warning):
pass


class NoWeightsWarnings(OverlappogramWarning):
"""There are no weights passed to unfold."""
6 changes: 5 additions & 1 deletion overlappogram/inversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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]
Expand All @@ -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)
Expand Down
22 changes: 14 additions & 8 deletions overlappogram/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ requires = ["setuptools",

[project]
name = "overlappogram"
version = "0.0.3"
version = "0.0.4"
dependencies = ["numpy",
"astropy",
"scikit-learn",
Expand All @@ -19,7 +19,7 @@ dependencies = ["numpy",
"click",
"tqdm"
]
requires-python = ">=3.9"
requires-python = ">=3.10"
authors = [
{name = "J. Marcus Hughes", email = "[email protected]"},
{name = "Dyana Beabout", email = "[email protected]"},
Expand Down

0 comments on commit c6ae31a

Please sign in to comment.