Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stix cube #119

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
41 changes: 38 additions & 3 deletions stixpy/product/scratch.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,60 @@
import astropy.units as u
import numpy as np
from astropy.nddata import NDUncertainty
from astropy.time import Time
from ndcube import NDCube
from ndcube.extra_coords import QuantityTableCoordinate, TimeTableCoordinate

Check warning on line 6 in stixpy/product/scratch.py

View check run for this annotation

Codecov / codecov/patch

stixpy/product/scratch.py#L6

Added line #L6 was not covered by tests

from stixpy.extern.meta import Meta

Check warning on line 8 in stixpy/product/scratch.py

View check run for this annotation

Codecov / codecov/patch

stixpy/product/scratch.py#L8

Added line #L8 was not covered by tests


class PossionUncertainty(NDUncertainty):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very exciting!

@property
def uncertainty_type(self):
return "possion"

Check warning on line 14 in stixpy/product/scratch.py

View check run for this annotation

Codecov / codecov/patch

stixpy/product/scratch.py#L11-L14

Added lines #L11 - L14 were not covered by tests

def _data_unit_to_uncertainty_unit(self, value):
return value.unit

Check warning on line 17 in stixpy/product/scratch.py

View check run for this annotation

Codecov / codecov/patch

stixpy/product/scratch.py#L16-L17

Added lines #L16 - L17 were not covered by tests

def _propagate_add(self, other_uncert, *args, **kwargs):
return np.sqrt

Check warning on line 20 in stixpy/product/scratch.py

View check run for this annotation

Codecov / codecov/patch

stixpy/product/scratch.py#L19-L20

Added lines #L19 - L20 were not covered by tests

def _propagate_subtract(self, other_uncert, *args, **kwargs):
return None

Check warning on line 23 in stixpy/product/scratch.py

View check run for this annotation

Codecov / codecov/patch

stixpy/product/scratch.py#L22-L23

Added lines #L22 - L23 were not covered by tests

def _propagate_multiply(self, other_uncert, *args, **kwargs):
return None

Check warning on line 26 in stixpy/product/scratch.py

View check run for this annotation

Codecov / codecov/patch

stixpy/product/scratch.py#L25-L26

Added lines #L25 - L26 were not covered by tests

def _propagate_divide(self, other_uncert, *args, **kwargs):
return None

Check warning on line 29 in stixpy/product/scratch.py

View check run for this annotation

Codecov / codecov/patch

stixpy/product/scratch.py#L28-L29

Added lines #L28 - L29 were not covered by tests


# Lets fake some STIX pixel like data
pd_shape = (2, 3, 4, 5) # time, detector, pixel, energy
pd = np.arange(np.prod(pd_shape)).reshape(pd_shape) * u.ct

Check warning on line 34 in stixpy/product/scratch.py

View check run for this annotation

Codecov / codecov/patch

stixpy/product/scratch.py#L33-L34

Added lines #L33 - L34 were not covered by tests

# and associated times and quantities
times = Time("2024-01-01T00:00:00") + np.arange(pd_shape[0]) * 2 * u.s
energies = (1 + 2 * np.arange(pd_shape[-1])) * u.keV

Check warning on line 38 in stixpy/product/scratch.py

View check run for this annotation

Codecov / codecov/patch

stixpy/product/scratch.py#L37-L38

Added lines #L37 - L38 were not covered by tests

# Create a gwcs
energy_coord = QuantityTableCoordinate(energies, names="energy", physical_types="em.energy")
# Create table coords
time_coord = TimeTableCoordinate(times, names="time", physical_types="time")
energy_coord = QuantityTableCoordinate(energies, names="energy", physical_types="em.energy")

Check warning on line 42 in stixpy/product/scratch.py

View check run for this annotation

Codecov / codecov/patch

stixpy/product/scratch.py#L41-L42

Added lines #L41 - L42 were not covered by tests

# fake coords for detector and pixel
detector_coord = QuantityTableCoordinate(

Check warning on line 45 in stixpy/product/scratch.py

View check run for this annotation

Codecov / codecov/patch

stixpy/product/scratch.py#L45

Added line #L45 was not covered by tests
np.arange(pd_shape[1]) * u.dimensionless_unscaled, names="detector", physical_types="custom:detector"
)
pixel_coord = QuantityTableCoordinate(

Check warning on line 48 in stixpy/product/scratch.py

View check run for this annotation

Codecov / codecov/patch

stixpy/product/scratch.py#L48

Added line #L48 was not covered by tests
np.arange(pd_shape[2]) * u.dimensionless_unscaled, names="pixel", physical_types="custom:pixel"
)

combine_coord = energy_coord & pixel_coord & detector_coord & time_coord

Check warning on line 52 in stixpy/product/scratch.py

View check run for this annotation

Codecov / codecov/patch

stixpy/product/scratch.py#L52

Added line #L52 was not covered by tests

combine_coord = time_coord & energy_coord

# I'm not sure what should live in the meta vs extra_coords
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In ndcube-land, a coordinate is a strictly monotonic sampling of a coordinate space, i.e., the values must be numerical, ordered and strictly increasing or decreasing. If your property doesn't satisfy this, then it's axis-aligned metadata. Once ndcube #455 is merged and ndcube 2.3 released, NDCube will support axis-aligned metadata. This will be the appropriate place for detector labels, as they will be sliced when the cube is sliced. And we can add functionality to a class STIXMeta(ndcube.Meta) so that detector labels are properly combined when the data is rebinned.

meta = Meta({"detector": ["a", "b", "c"]}, data_shape=pd_shape)

Check warning on line 56 in stixpy/product/scratch.py

View check run for this annotation

Codecov / codecov/patch

stixpy/product/scratch.py#L56

Added line #L56 was not covered by tests

scube = NDCube(data=pd, wcs=combine_coord.wcs, meta=meta)
scube.extra_coords.add("integration_time", 0, [2, 3] * u.s, physical_types="time.duration")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following from the above comment, "integration time" should be considered metadata, not a coordinate.

scube

Check warning on line 60 in stixpy/product/scratch.py

View check run for this annotation

Codecov / codecov/patch

stixpy/product/scratch.py#L58-L60

Added lines #L58 - L60 were not covered by tests
Loading