@@ -48,8 +48,8 @@ import Text.Casing (quietSnake)
48
48
-- TODO: fix gwcs
49
49
-- TODO: labeled meta.axes for profiles
50
50
51
- asdfDocument :: Id Inversion -> Dataset -> [Dataset ] -> PixelsPerBin -> UTCTime -> Arms ( Arm SpectralLine L1Asdf ) -> Frames L2FitsMeta -> Document
52
- asdfDocument inversionId dscanon dsets bin now l1asdfs metas =
51
+ asdfDocument :: Id Inversion -> Dataset -> [Dataset ] -> PixelsPerBin -> UTCTime -> L1Asdf -> Frames L2FitsMeta -> Document
52
+ asdfDocument inversionId dscanon dsets bin now l1asdf metas =
53
53
let frames = Frames $ NE. sort metas. frames
54
54
in Document (inversionTree frames)
55
55
where
@@ -59,18 +59,15 @@ asdfDocument inversionId dscanon dsets bin now l1asdfs metas =
59
59
{ fileuris
60
60
, meta = inversionMeta $ fmap (. primary) sorted
61
61
, quantities = quantitiesSection (fmap (. quantities) sorted) (qgwcs sorted)
62
- , profiles = profilesSection bin gwcs (head sorted. frames). primary $ fmap (. profiles) sorted
62
+ , profiles = profilesSection bin l1asdf . dataset . wcs (head sorted. frames). primary $ fmap (. profiles) sorted
63
63
}
64
64
65
- gwcs :: Arms (Arm SpectralLine L1GWCS )
66
- gwcs = fmap (fmap (\ a -> a. dataset. wcs)) l1asdfs
67
-
68
65
-- choose a single frame from which to calculate the GWCS
69
66
qgwcs :: Frames L2FitsMeta -> QuantityGWCS
70
67
qgwcs sorted =
71
68
quantityGWCS
72
69
bin
73
- ( head gwcs . arms) . value
70
+ l1asdf . dataset . wcs
74
71
(fmap (. primary) sorted)
75
72
(fmap (\ m -> m. quantities. items. opticalDepth) sorted)
76
73
@@ -276,14 +273,10 @@ data QuantityMeta info = QuantityMeta
276
273
data ProfilesSection = ProfilesSection
277
274
{ axes :: [AxisMeta ]
278
275
, arms :: Arms (Profiles ProfileTree )
279
- , gwcs :: Arms ( Arm SpectralLine ProfileGWCS )
276
+ , gwcs :: ProfileGWCS
280
277
}
281
278
282
279
283
- profileGWCSAnchor :: SpectralLine -> Anchor
284
- profileGWCSAnchor l = Anchor $ " ProfileGWCS" <> cs (show l)
285
-
286
-
287
280
-- data ArmProfileAxes = ArmProfileAxes
288
281
-- { arm :: ArmWavMeta
289
282
-- , fit :: AlignedAxes Fit
@@ -311,14 +304,16 @@ instance ToAsdf ProfilesSection where
311
304
in Arm pfs. fit. meta. spectralLine $ Profiles {fit = AlignedAxesF axs, original = AlignedAxesF axs}
312
305
313
306
meta =
314
- Object [(" axes" , toNode section. axes)]
315
- <> toValue section. gwcs
307
+ Object
308
+ [ (" axes" , toNode section. axes)
309
+ , (" gwcs" , toNode section. gwcs)
310
+ ]
316
311
317
312
318
- instance ToAsdf ( Arm SpectralLine ProfileGWCS ) where
319
- anchor ( Arm l _ ) = Just $ profileGWCSAnchor l
320
- toNode ( Arm _ ( ProfileGWCS p)) = toNode p
321
- toValue (Arm _ ( ProfileGWCS p)) = toValue p
313
+ instance ToAsdf ProfileGWCS where
314
+ schema ( ProfileGWCS g ) = schema g
315
+ anchor _ = Just $ Anchor $ knownText @ ProfileGWCS
316
+ toValue (ProfileGWCS g) = toValue g
322
317
323
318
324
319
instance ToAsdf (Arm SpectralLine (Profiles AlignedAxesF )) where
@@ -342,20 +337,21 @@ profileKey line pt = cs $ show line <> "_" <> suffix pt
342
337
-- toValue (ProfilesItems arms) = toValue arms
343
338
344
339
-- we need one ProfileMeta for each arm
345
- profilesSection :: PixelsPerBin -> Arms ( Arm SpectralLine L1GWCS ) -> PrimaryHeader -> Frames (Arms ArmFrameProfileMeta ) -> ProfilesSection
340
+ profilesSection :: PixelsPerBin -> L1GWCS -> PrimaryHeader -> Frames (Arms ArmFrameProfileMeta ) -> ProfilesSection
346
341
profilesSection bin l1gwcs primary profs =
347
342
let sampleFrame :: Arms ArmFrameProfileMeta = head profs. frames
348
343
in ProfilesSection
349
344
{ axes = [AxisMeta " frame_y" True , AxisMeta " slit_x" True , AxisMeta " wavelength" False , AxisMeta " stokes" True ]
350
345
, arms = profilesArmsTree profs
351
- , gwcs = Arms $ NE. zipWith armGWCS l1gwcs . arms sampleFrame. arms
346
+ , gwcs = profileGWCS bin l1gwcs primary ( head sampleFrame. arms) . fit . wcs
352
347
}
353
- where
354
- armGWCS :: Arm SpectralLine L1GWCS -> ArmFrameProfileMeta -> Arm SpectralLine ProfileGWCS
355
- armGWCS ag am =
356
- Arm ag. arm $ profileGWCS bin ag. value primary am. fit. wcs
357
348
358
349
350
+ -- where
351
+ -- armGWCS :: Arm SpectralLine L1GWCS -> ArmFrameProfileMeta -> Arm SpectralLine ProfileGWCS
352
+ -- armGWCS ag am =
353
+ -- Arm ag.arm $ profileGWCS bin ag.value primary am.fit.wcs
354
+
359
355
profilesArmsTree :: Frames (Arms ArmFrameProfileMeta ) -> Arms (Profiles ProfileTree )
360
356
profilesArmsTree framesByArms =
361
357
let Arms arms = armsFrames framesByArms :: Arms (Frames ArmFrameProfileMeta )
@@ -376,6 +372,7 @@ profilesArmsTree framesByArms =
376
372
ProfileTree
377
373
{ unit = Count
378
374
, data_ = fileManager shape. axes ix
375
+ , wcs = Ref
379
376
, meta =
380
377
ProfileTreeMeta
381
378
{ headers = HeaderTable heads
@@ -398,6 +395,7 @@ data ProfileTree fit = ProfileTree
398
395
{ unit :: Unit
399
396
, data_ :: FileManager
400
397
, meta :: ProfileTreeMeta fit
398
+ , wcs :: Ref ProfileGWCS
401
399
}
402
400
deriving (Generic )
403
401
instance (KnownText fit ) => ToAsdf (ProfileTree fit ) where
@@ -408,7 +406,7 @@ instance (KnownText fit) => ToAsdf (ProfileTree fit) where
408
406
[ (" unit" , toNode p. unit)
409
407
, (" data" , toNode p. data_)
410
408
, (" meta" , toNode p. meta)
411
- , (" wcs" , toNode $ Alias $ profileGWCSAnchor p . meta . spectralLine )
409
+ , (" wcs" , toNode p . wcs )
412
410
]
413
411
414
412
0 commit comments