Skip to content

Commit be90114

Browse files
committed
wcs graphs are working!!!
1 parent aa43776 commit be90114

File tree

3 files changed

+53
-21
lines changed

3 files changed

+53
-21
lines changed

src/NSO/Image/Asdf.hs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ import Text.Casing (quietSnake)
4747
-- TODO: fix gwcs
4848
-- TODO: labeled meta.axes for profiles
4949

50-
51-
5250
asdfDocument :: Id Inversion -> Dataset -> [Dataset] -> PixelsPerBin -> UTCTime -> L1Asdf -> Frames L2FitsMeta -> Document
5351
asdfDocument inversionId dscanon dsets bin now l1asdf metas =
5452
let frames = Frames $ NE.sort metas.frames
@@ -155,7 +153,7 @@ data QuantitiesSection = QuantitiesSection
155153
, gwcs :: QuantityGWCS
156154
}
157155
instance ToAsdf QuantitiesSection where
158-
schema _ = "tag:sunpy.org:ndcube/ndcube/ndcollection-1.0.0"
156+
schema _ = "tag:sunpy.org:ndcube/ndcollection-1.0.0"
159157
toValue section =
160158
Object
161159
[ ("meta", toNode meta)
@@ -285,7 +283,7 @@ newtype ArmsProfileAxes f = ArmsProfileAxes (Arms (ArmProfile AlignedAxes))
285283

286284

287285
instance ToAsdf ProfilesSection where
288-
schema _ = "tag:sunpy.org:ndcube/ndcube/ndcollection-1.0.0"
286+
schema _ = "tag:sunpy.org:ndcube/ndcollection-1.0.0"
289287
toValue section =
290288
Object
291289
[ ("meta", toNode meta)

src/NSO/Image/GWCS.hs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import Data.Massiv.Array qualified as M
88
import Debug.Trace
99
import NSO.Image.Fits.Profile
1010
import NSO.Image.Fits.Quantity
11-
import NSO.Image.GWCS.L1GWCS (HPLat, HPLon, L1GWCS (..), L1WCSTransform (..), Time, Zero, l1FixInputs, l1ScaleAxes, l1WCSTransform)
11+
import NSO.Image.GWCS.L1GWCS (HPLat, HPLon, L1GWCS (..), L1WCSTransform (..), Time, Zero)
12+
import NSO.Image.GWCS.L1GWCS qualified as L1
1213
import NSO.Image.Headers (Observation (..), Obsgeo (..))
1314
import NSO.Image.Headers.Types (Degrees (..), Key (..), Meters (..), PixelsPerBin (..))
1415
import NSO.Image.Headers.WCS (PC (..), PCXY (..), WCSAxisKeywords (..), WCSCommon (..), WCSHeader (..), Wav, X, Y, toWCSAxis)
@@ -56,16 +57,17 @@ transformQuantity
5657
transformQuantity bin l1trans axes =
5758
fullTransform
5859
where
59-
-- dropUnusedZeros fullTransform
60-
6160
fullTransform :: Transform (Pix Depth, Pix X, Pix Y) (Linear Depth, HPLon, HPLat, Time, Zero Wav, Zero Stokes)
6261
fullTransform =
6362
let mid = middleFrame axes
6463
in transformOpticalDepth (toWCSAxis mid.depth.keys) <&> spaceTimeTransform
6564

6665
spaceTimeTransform :: Transform (Pix X, Pix Y) (HPLon, HPLat, Time, Zero Wav, Zero Stokes)
67-
spaceTimeTransform = l1FixInputs |> l1ScaleAxes bin |> l1WCSTransform l1trans
66+
spaceTimeTransform = L1.fixInputs |> L1.scaleZeroAxes bin |> L1.varyingTransform l1trans
67+
6868

69+
-- inverseTransform :: Transform (Linear Depth, HPLon, HPLat, Time, Zero Wav, Zero Stokes) (Pix Depth, Pix X, Pix Y)
70+
-- inverseTransform = _
6971

7072
-- dropUnusedZeros :: Transform inp (a, b, c, d, Zero z1, Zero z2) -> Transform inp (w, x, y, z)
7173
-- dropUnusedZeros (Transform t) = Transform t
@@ -209,7 +211,7 @@ quantityGWCS bin l1gwcs primaries quants =
209211
{ name = "optical_depth"
210212
, axes =
211213
NE.fromList
212-
[ FrameAxis 0 "optical_depth" "optical_depth" Pixel
214+
[ FrameAxis 0 "optical depth" "phys.absorption.opticalDepth" Pixel
213215
]
214216
}
215217

@@ -270,8 +272,8 @@ celestialFrame n helioFrame =
270272
, referenceFrame = helioFrame
271273
, axes =
272274
NE.fromList
273-
[ FrameAxis n "helioprojective longitude" (AxisType "pos.helioprojective.lon") Unit.Arcseconds
274-
, FrameAxis (n + 1) "helioprojective latitude" (AxisType "pos.helioprojective.lat") Unit.Arcseconds
275+
[ FrameAxis n "pos.helioprojective.lon" (AxisType "pos.helioprojective.lon") Unit.Arcseconds
276+
, FrameAxis (n + 1) "pos.helioprojective.lat" (AxisType "pos.helioprojective.lat") Unit.Arcseconds
275277
]
276278
}
277279

src/NSO/Image/GWCS/L1GWCS.hs

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import NSO.Image.Headers.WCS (Wav, X, Y)
55
import NSO.Prelude hiding (identity)
66
import NSO.Types.Common (Stokes)
77
import Telescope.Asdf
8+
import Telescope.Asdf.Core (Quantity (..), Unit (..))
89
import Telescope.Asdf.GWCS as GWCS
910
import Telescope.Data.Parser
1011

@@ -64,8 +65,8 @@ instance ToAsdf L1WCSTransform where
6465
toValue (L1WCSTransform n) = n.value
6566

6667

67-
l1WCSTransform :: L1WCSTransform -> Transform (Scale X, Zero Wav, Pix Y, Zero Stokes) (HPLon, HPLat, Time, Zero Wav, Zero Stokes)
68-
l1WCSTransform t = originalL1Transform |> reorderOutput
68+
varyingTransform :: L1WCSTransform -> Transform (Scale X, Zero Wav, Pix Y, Zero Stokes) (HPLon, HPLat, Time, Zero Wav, Zero Stokes)
69+
varyingTransform t = originalL1Transform |> reorderOutput
6970
where
7071
originalL1Transform :: Transform (Scale X, Zero Wav, Pix Y, Zero Stokes) (HPLon, Wav, HPLat, Time, Stokes)
7172
originalL1Transform = transform t
@@ -74,16 +75,47 @@ l1WCSTransform t = originalL1Transform |> reorderOutput
7475
reorderOutput = transform $ Mapping [0, 2, 3, 1, 4]
7576

7677

77-
-- "fix" inputs to unused input axes in the l1 transform: wavlength and stokes
78-
l1FixInputs :: Transform (Pix X, Pix Y) (Pix X, Pix Wav, Pix Y, Pix Stokes)
79-
l1FixInputs = transform $ Mapping [0, 0, 1, 0]
80-
81-
82-
l1ScaleAxes :: PixelsPerBin -> Transform (Pix X, Pix Wav, Pix Y, Pix Stokes) (Scale X, Zero Wav, Pix Y, Zero Stokes)
83-
l1ScaleAxes (PixelsPerBin p) = binX <&> zero <&> identity @(Pix Y) <&> zero
78+
scaleZeroAxes :: PixelsPerBin -> Transform (Pix X, Pix Wav, Pix Y, Pix Stokes) (Scale X, Zero Wav, Pix Y, Zero Stokes)
79+
scaleZeroAxes (PixelsPerBin p) = binX <&> zero <&> identity @(Pix Y) <&> zero
8480
where
8581
binX :: Transform (Pix X) (Scale X)
8682
binX = scale (fromIntegral p)
8783

8884
zero :: (ToAxes a) => Transform (Pix a) (Zero a)
89-
zero = transform $ Scale 0
85+
zero = transform $ Const1D $ Quantity Pixel (Integer 0)
86+
87+
88+
fixInputs :: Transform (Pix X, Pix Y) (Pix X, Pix Wav, Pix Y, Pix Stokes)
89+
fixInputs = transform $ Mapping [0, 0, 1, 0]
90+
91+
92+
data Const1D = Const1D Quantity
93+
instance ToAsdf Const1D where
94+
schema _ = "!transform/constant-1.2.0"
95+
toValue (Const1D q) =
96+
Object
97+
[ ("dimensions", toNode $ Integer 1)
98+
, ("value", toNode q)
99+
]
100+
instance FromAsdf Const1D where
101+
parseValue val = do
102+
o <- parseValue @Object val
103+
Const1D <$> o .: "value"
104+
105+
-- fixWavStokes0 :: (ToAxes out) => Transform (Pix X, Pix Wav, Pix Y, Pix Stokes) out -> Transform (Pix X, Pix Y) out
106+
-- fixWavStokes0 (Transform t) = transform $ FixInputs t [(1, 0), (3, 0)]
107+
--
108+
--
109+
-- -- This ONLY works with integers for some reason (doesn't like quantities)
110+
-- -- combine with Const1D or Scale or something to convert it to a quantity?
111+
-- data FixInputs = FixInputs Transformation [(Int, Int)]
112+
-- instance ToAsdf FixInputs where
113+
-- schema _ = "!transform/fix_inputs-1.2.0"
114+
-- toValue (FixInputs t fs) =
115+
-- Object [("forward", toNode [toNode t, toNode forward])]
116+
-- where
117+
-- forward =
118+
-- Object
119+
-- [ ("keys", toNode $ fmap fst fs)
120+
-- , ("values", toNode $ fmap snd fs)
121+
-- ]

0 commit comments

Comments
 (0)