Skip to content

Commit 3d516f4

Browse files
Merge pull request #54 from observerly/docs/README
docs: add README.md to workspace root in @observerly/fits
2 parents c363f8b + 5999cab commit 3d516f4

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

README.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# @observerly/fits
2+
3+
## Introduction
4+
5+
🌌 fits is observerly's lightweight (~1.9 KB min+gzip), zero-dependency\*, type safe FITS image library written in TypeScript. It is aimed to be a modern and simple tool to use in the browser, for reading the FITS file format according to the 4th version of the [FITS specification](./docs/fits/standard/).
6+
7+
The key tenants of the library is to use as JavaScript primatives, where we do not rely on, or enforce reliance on, any third-party related libraries. This is to ensure that the library can be used in any environment, and that the user can supplement usage with their own datetime libraries of choice, if required.
8+
9+
The final output image is a 2D array of pixel values, which can be used to render the image in a canvas, or any other image rendering library of choice. The final output image pixel values is a ZScaleInterval of the original pixel values, returned as a Float32Array.
10+
11+
The library makes no opinion of what you can do with the resulting image data, and is designed to be as flexible as possible to allow the user to use the data in any way they see fit, whether that be rendering the image, or processing the data in some other way. However, it is more than possible to convert the values to an RGBA Uint8ClampedArray for use with the HTMLCanvasElement, the [Canvas_API](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API) or any other image rendering library of choice.
12+
13+
### Installation
14+
15+
You can install fits using your favorite package manager:
16+
17+
```bash
18+
npm install @observerly/fits
19+
```
20+
21+
or
22+
23+
```bash
24+
yarn add @observerly/fits
25+
```
26+
27+
```bash
28+
pnpm add @observerly/fits
29+
```
30+
31+
```bash
32+
bun add @observerly/fits
33+
```
34+
35+
### Documentation
36+
37+
TBD
38+
39+
### Usage
40+
41+
The two below examples demonstrate how to load a FITS file from a local file or a URL, respectively, in a browser environment.
42+
43+
#### Load from Local File
44+
45+
```ts
46+
import { FITS } from '@observerly/fits'
47+
48+
const fileInput = document.getElementById('fitsFileInput')
49+
50+
fileInput.addEventListener('change', async (event) => {
51+
const file = (event.target as HTMLInputElement).files[0]
52+
53+
const buffer = await file.arrayBuffer()
54+
55+
const fits = await new FITS().readFromBuffer(buffer)
56+
57+
const headers = fits.getHeaders()
58+
59+
const image = fits.getImageHDU() // of type Float32Array
60+
})
61+
```
62+
63+
#### Load from URL
64+
65+
```ts
66+
import { FITS } from '@observerly/fits'
67+
68+
const url = `fits.observerly.com/Rosetta_Nebula_[Ha]_Monochrome_M_300s_2024-11-26T17_20_00Z`
69+
70+
const response = await fetch(url)
71+
72+
if (!response.ok) {
73+
throw new Error(`HTTP error! Status: ${response.status}`)
74+
}
75+
76+
const buffer = await response.arrayBuffer()
77+
78+
const fits = await new FITS().readFromBuffer(buffer)
79+
80+
const headers = fits.getHeaders()
81+
82+
const image = fits.getImageHDU() // of type Float32Array
83+
```
84+
85+
#### 2D CanvasHTMLElement Rendering
86+
87+
```ts
88+
// ... load FITS file as above
89+
90+
const image = fits.getImageHDU() // of type Float32Array
91+
92+
const canvas = document.createElement('canvas')
93+
94+
canvas.width = fits.getHeader('NAXIS1')
95+
96+
canvas.height = fits.getHeader('NAXIS2')
97+
98+
const ctx = canvas.getContext('2d')
99+
100+
const imageData = ctx.createImageData(canvas.width, canvas.height)
101+
102+
const data = imageData.data
103+
104+
for (let i = 0; i < image.length; i++) {
105+
const value = image[i]
106+
data[i * 4] = value
107+
data[i * 4 + 1] = value
108+
data[i * 4 + 2] = value
109+
data[i * 4 + 3] = 255
110+
}
111+
112+
ctx.putImageData(imageData, 0, 0)
113+
```
114+
115+
## Miscellany
116+
117+
\*It is dependency-free to ensure it can be used safely within both node, deno, bun and browser environments.
118+
119+
## License
120+
121+
@observerly/FITS is licensed under the MIT license. See [MIT](./LICENSE) for details.

0 commit comments

Comments
 (0)