krakrjak / fits-parse

Parse FITS files for Astronomy data analysis.
BSD 2-Clause "Simplified" License
2 stars 1 forks source link

More flexible types to support alt parsing #5

Closed seanhess closed 1 month ago

seanhess commented 1 month ago

Hey @krakrjak!

I've started a "Telescope" package with a higher-level interface here: https://github.com/dkistdc/telescope.hs. It supports multi-dimensional arrays, and writing FITS files. I had to make a few changes to fits-parse to give more flexibility to the user. They basically boil down to the following:

Change Header from a Map to an Association List: To write FITS files, controlling the order of headers is important.

newtype Header = Header { _records :: [HeaderRecord] }
    deriving (Eq, Semigroup, Monoid)

Added richer sub-types to make working with Header/Keywords easier:

data KeywordRecord = KeywordRecord
  { _keyword :: Text
  , _value :: Value
  , _comment :: Maybe Text
  }
  deriving (Show, Eq)

data HeaderRecord
    = Keyword KeywordRecord
    | Comment Text
    | BlankLine
    deriving (Show, Eq)

Exposing parsers for keywords, not just full HDUs

parsePrimaryKeywords :: Parser Dimensions
parsePrimaryKeywords = do
    parseKeywordRecord' "SIMPLE" parseLogic
    M.lookAhead parseDimensions

Any thoughts or comments?

seanhess commented 1 month ago

Oh, I also fixed a few parsing bugs along the way

seanhess commented 1 month ago

The telescope haddock: https://hackage.haskell.org/package/telescope-0.1.1/candidate

seanhess commented 1 month ago

Great, thanks!