-
Notifications
You must be signed in to change notification settings - Fork 20
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
base: main
Are you sure you want to change the base?
Stix cube #119
Changes from 1 commit
445c78b
3b74d41
fdd7344
a99474c
3a9c1a2
f5ebb65
51ec0db
11c4e08
95ac698
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
||
from stixpy.extern.meta import Meta | ||
|
||
|
||
class PossionUncertainty(NDUncertainty): | ||
@property | ||
def uncertainty_type(self): | ||
return "possion" | ||
|
||
def _data_unit_to_uncertainty_unit(self, value): | ||
return value.unit | ||
|
||
def _propagate_add(self, other_uncert, *args, **kwargs): | ||
return np.sqrt | ||
|
||
def _propagate_subtract(self, other_uncert, *args, **kwargs): | ||
return None | ||
|
||
def _propagate_multiply(self, other_uncert, *args, **kwargs): | ||
return None | ||
|
||
def _propagate_divide(self, other_uncert, *args, **kwargs): | ||
return None | ||
|
||
|
||
# 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 | ||
|
||
# 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 | ||
|
||
# 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") | ||
|
||
# fake coords for detector and pixel | ||
detector_coord = QuantityTableCoordinate( | ||
np.arange(pd_shape[1]) * u.dimensionless_unscaled, names="detector", physical_types="custom:detector" | ||
) | ||
pixel_coord = QuantityTableCoordinate( | ||
np.arange(pd_shape[2]) * u.dimensionless_unscaled, names="pixel", physical_types="custom:pixel" | ||
) | ||
|
||
combine_coord = energy_coord & pixel_coord & detector_coord & time_coord | ||
|
||
combine_coord = time_coord & energy_coord | ||
|
||
# I'm not sure what should live in the meta vs extra_coords | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, |
||
meta = Meta({"detector": ["a", "b", "c"]}, data_shape=pd_shape) | ||
|
||
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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very exciting!