@@ -7,7 +7,7 @@ import Data.Massiv.Array (Array, D, Ix2, Ix3)
7
7
import Data.Massiv.Array qualified as M
8
8
import NSO.Image.Fits.Profile
9
9
import NSO.Image.Fits.Quantity
10
- import NSO.Image.GWCS.L1Transform (HPLat , HPLon , L1WCSTransform (.. ), Time , l1WCSTransform )
10
+ import NSO.Image.GWCS.L1Transform (HPLat , HPLon , L1WCSTransform (.. ), Time , Zero , l1WCSTransform )
11
11
import NSO.Image.Headers (Observation (.. ), Obsgeo (.. ))
12
12
import NSO.Image.Headers.Types (Degrees (.. ), Key (.. ), Meters (.. ))
13
13
import NSO.Image.Headers.WCS (PC (.. ), PCXY (.. ), WCSAxisKeywords (.. ), WCSCommon (.. ), WCSHeader (.. ), Wav , X , Y , toWCSAxis )
@@ -16,6 +16,7 @@ import NSO.Image.Types.Frame (Depth, Frames (..), Stokes, middleFrame)
16
16
import NSO.Image.Types.Quantity (OpticalDepth )
17
17
import NSO.Prelude as Prelude
18
18
import NSO.Types.Common (DateTime (.. ))
19
+ import Numeric (showFFloat )
19
20
import Telescope.Asdf (Anchor (.. ), ToAsdf (.. ), Value (.. ))
20
21
import Telescope.Asdf.Core (Quantity (.. ), Unit (Arcseconds , Pixel , Unit ))
21
22
import Telescope.Asdf.Core qualified as Unit
@@ -49,39 +50,43 @@ transformProfile common axes =
49
50
50
51
transformQuantity
51
52
:: L1WCSTransform
52
- -> WCSCommon
53
53
-> Frames (QuantityAxes 'WCSMain)
54
54
-> Transform (Pix Depth , Pix X , Pix Y ) (Linear Depth , HPLon , HPLat , Time )
55
- transformQuantity l1trans common axes =
56
- let mid = middleFrame axes
57
- in transformOpticalDepth (toWCSAxis mid. depth. keys) <&> l1WCSTransform l1trans -- varyingCelestialTransform common (fmap wcsFrame axes)
55
+ transformQuantity l1trans axes =
56
+ dropUnusedZeros fullTransform
58
57
where
59
- wcsFrame :: QuantityAxes 'WCSMain -> WCSFrame QuantityAxes
60
- wcsFrame axs =
61
- WCSFrame
62
- { x = toWCSAxis axs. slitX. keys
63
- , y = toWCSAxis axs. dummyY. keys
64
- , pcxy = pcs axs
65
- }
66
-
67
- pcs :: QuantityAxes 'WCSMain -> PCXY QuantityAxes 'WCSMain
68
- pcs axs = fromMaybe identityPCXY $ do
69
- pcx <- axs. slitX. pcs
70
- pcy <- axs. dummyY. pcs
71
- pure $ PCXY {xx = pcx. slitX, xy = pcx. dummyY, yx = pcy. slitX, yy = pcy. dummyY}
58
+ fullTransform :: Transform (Pix Depth , Pix X , Pix Y ) (Linear Depth , HPLon , HPLat , Time , Zero Wav , Zero Stokes )
59
+ fullTransform =
60
+ let mid = middleFrame axes
61
+ in transformOpticalDepth (toWCSAxis mid. depth. keys) <&> l1WCSTransform l1trans
62
+
63
+ dropUnusedZeros :: Transform inp (a , b , c , d , Zero z1 , Zero z2 ) -> Transform inp (w , x , y , z )
64
+ dropUnusedZeros (Transform t) = Transform t
72
65
73
66
74
67
identityPCXY :: PCXY s 'WCSMain
75
68
identityPCXY =
76
69
PCXY {xx = PC 1 , xy = PC 0 , yx = PC 0 , yy = PC 1 }
77
70
78
71
72
+ data LinearOpticalDepth = LinearOpticalDepth { intercept :: Quantity , slope :: Quantity }
73
+ deriving (Generic )
74
+ instance ToAsdf LinearOpticalDepth where
75
+ schema _ = " !transform/linear1d-1.0.0"
76
+
77
+
79
78
transformOpticalDepth :: WCSAxis 'WCSMain Depth -> Transform (Pix Depth ) (Linear Depth )
80
79
transformOpticalDepth wcsOD =
81
- linear (wcsIntercept wcsOD) (Scale $ factor1digit wcsOD. cdelt)
80
+ let Intercept i = wcsIntercept wcsOD
81
+ s = wcsOD. cdelt
82
+ in transform $ LinearOpticalDepth (Quantity Pixel (factor1digit i)) (Quantity (Unit " pix.pixel**-1" ) (factor1digit s))
82
83
where
83
- factor1digit :: Double -> Double
84
- factor1digit d = fromIntegral (round @ Double @ Integer (d * 10 )) / 10
84
+ -- intercept: !unit/quantity-1.1.0 {datatype: float64, unit: !unit/unit-1.0.0 pix, value: 853.7012736084624}
85
+ -- slope: !unit/quantity-1.1.0 {datatype: float64, unit: !unit/unit-1.0.0 pix.pixel**-1, value: 9.99852488051306e-4}
86
+ -- linear (wcsIntercept wcsOD) (Scale $ factor1digit wcsOD.cdelt)
87
+
88
+ factor1digit :: Double -> Value
89
+ factor1digit d = String $ cs $ showFFloat (Just 1 ) d " " -- fromIntegral (round @Double @Integer (d * 10)) / 10
85
90
86
91
87
92
transformSpatial
@@ -168,11 +173,10 @@ quantityGWCS :: L1WCSTransform -> Frames PrimaryHeader -> Frames (QuantityHeader
168
173
quantityGWCS l1trans primaries quants =
169
174
let midPrim = middleFrame primaries
170
175
firstPrim = head primaries. frames
171
- midQuan = middleFrame quants
172
- in QuantityGWCS $ GWCS (inputStep midQuan. wcs. common) (outputStep firstPrim midPrim)
176
+ in QuantityGWCS $ GWCS inputStep (outputStep firstPrim midPrim)
173
177
where
174
- inputStep :: WCSCommon -> GWCSStep CoordinateFrame
175
- inputStep common = GWCSStep pixelFrame (Just (transformQuantity l1trans common (fmap axis quants)). transformation)
178
+ inputStep :: GWCSStep CoordinateFrame
179
+ inputStep = GWCSStep pixelFrame (Just (transformQuantity l1trans (fmap axis quants)). transformation)
176
180
where
177
181
axis :: QuantityHeader x -> QuantityAxes 'WCSMain
178
182
axis q = q. wcs. axes
0 commit comments