Support for FITS file format (astronomy)

I am wondering if any astronomers out there have already found a way to read files in the FITS format for images and tabular data.

I found a standalone javascript library that looks promising, but it has no recent updates and was never uploaded to npm so is only available as a github download.

I tried importing this with:

import(await FileAttachment("fits.js").url())

but that fails with module is not defined. I have very little experience with javascript modules and import/require so there may be an easy workaround but I haven’t stumbled upon it yet. Alternatively, perhaps there is a way to regenerate this file from its coffeescript source so that it can uploaded to npm?

hi @dkirkby

you can load this package doing this

FITS = require('fitsjs').catch(() => window.astro.FITS)

you can use a promise as a callback function when FITS file is loaded, then your FITS data would be friendly available to other cells

fitsData = new Promise(async resolve => {
  const fits = new FITS(
    await FileAttachment("UITfuv2582gc.fits").url(),

here is a demo


Thank-you @radames, that is really helpful!

1 Like