{- |
Module:      Telescope.Fits
Copyright:   (c) 2024 Sean Hess
License:     BSD3
Maintainer:  Sean Hess <shess@nso.edu>
Stability:   experimental
Portability: portable

Read, Generate, and Write FITS (Flexible Image Transport System) files

@
import Data.ByteString qualified as BS

test :: IO ()
test = do
  inp <- BS.readFile "samples/simple2x3.fits"
  f <- decode inp
  print f.primaryHDU.dataArray.axes
  print f.primaryHDU.dataArray.bitpix
  print $ lookup \"BTYPE\" f.primaryHDU.header

  a <- decodeArray @Ix2 @Int f.primaryHDU.dataArray
  print $ size a
  print $ a !> 0
@
-}
module Telescope.Fits
  ( decode
  , encode
  , decodeArray
  , encodeArray

    -- * Headers
  , lookup
  , Header (..)
  , Value (..)
  , LogicalConstant

    -- * Types
  , Fits (..)
  , PrimaryHDU (..)
  , ImageHDU (..)
  , DataArray (..)
  , Extension (..)
  , Axis
  , Axes
  , Row
  , Column
  , BitPix (..)

    -- * Generate
  , addComment
  , keyword
  , emptyDataArray

    -- * Exports from Data.Massiv.Array
  , Array
  , Ix1
  , Ix2
  , Ix3
  , Ix4
  , Ix5
  , size
  , (!>)
  , (!?>)
  , (<!)
  , (<!?)
  , (<!>)
  , Dim (..)
  ) where

import Data.Fits (lookup)
import Telescope.Fits.Encoding
import Telescope.Fits.Encoding.DataArray
import Telescope.Fits.Header (addComment, keyword)
import Telescope.Fits.Types
import Prelude hiding (lookup)

import Data.ByteString qualified as BS


test :: IO ()
test :: IO ()
test = do
  ByteString
inp <- FilePath -> IO ByteString
BS.readFile FilePath
"samples/simple2x3.fits"
  Fits
f <- ByteString -> IO Fits
forall (m :: * -> *). MonadThrow m => ByteString -> m Fits
decode ByteString
inp
  Axes Column -> IO ()
forall a. Show a => a -> IO ()
print Fits
f.primaryHDU.dataArray.axes
  BitPix -> IO ()
forall a. Show a => a -> IO ()
print Fits
f.primaryHDU.dataArray.bitpix
  DataArray -> IO ()
forall a. Show a => a -> IO ()
print Fits
f.primaryHDU.dataArray
  Maybe Value -> IO ()
forall a. Show a => a -> IO ()
print (Maybe Value -> IO ()) -> Maybe Value -> IO ()
forall a b. (a -> b) -> a -> b
$ Text -> Header -> Maybe Value
lookup Text
"BTYPE" Fits
f.primaryHDU.header

  Array D Ix2 Int
a <- forall ix a (m :: * -> *).
(MonadThrow m, Index ix, AxesIndex ix, Prim a, GetPix a) =>
DataArray -> m (Array D ix a)
decodeArray @Ix2 @Int Fits
f.primaryHDU.dataArray
  Sz Ix2 -> IO ()
forall a. Show a => a -> IO ()
print (Sz Ix2 -> IO ()) -> Sz Ix2 -> IO ()
forall a b. (a -> b) -> a -> b
$ Array D Ix2 Int -> Sz Ix2
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array D ix e -> Sz ix
size Array D Ix2 Int
a
  Array D Int Int -> IO ()
forall a. Show a => a -> IO ()
print (Array D Int Int -> IO ()) -> Array D Int Int -> IO ()
forall a b. (a -> b) -> a -> b
$ Array D Ix2 Int
a Array D Ix2 Int -> Int -> Array D (Lower Ix2) Int
forall r ix e.
(HasCallStack, Index ix, Index (Lower ix), Source r e) =>
Array r ix e -> Int -> Array r (Lower ix) e
!> Int
0