Skip to content

Commit 080b710

Browse files
docs: add README.md to workspace root in @observerly/fits
docs: add README.md to workspace root in @observerly/fits
1 parent 82910fd commit 080b710

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed

README.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# @observerly/fits
2+
3+
## Introduction
4+
5+
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.
6+
7+
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.
8+
9+
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.
10+
11+
### Installation
12+
13+
You can install fits using your favorite package manager:
14+
15+
```bash
16+
npm install @observerly/fits
17+
```
18+
19+
or
20+
21+
```bash
22+
yarn add @observerly/fits
23+
```
24+
25+
```bash
26+
pnpm add @observerly/fits
27+
```
28+
29+
```bash
30+
bun add @observerly/fits
31+
```
32+
33+
### Documentation
34+
35+
TBD
36+
37+
### Usage
38+
39+
The two below examples demonstrate how to load a FITS file from a local file or a URL, respectively, in a browser environment.
40+
41+
#### Load from Local File
42+
43+
```ts
44+
import { FITS } from '@observerly/fits'
45+
46+
const fileInput = document.getElementById('fitsFileInput')
47+
48+
fileInput.addEventListener('change', async (event) => {
49+
const file = (event.target as HTMLInputElement).files[0]
50+
51+
const buffer = await file.arrayBuffer()
52+
53+
const fits = await new FITS().readFromBuffer(buffer)
54+
55+
const headers = fits.getHeaders()
56+
57+
const image = fits.getImageHDU() // of type Float32Array
58+
})
59+
```
60+
61+
#### Load from URL
62+
63+
```ts
64+
import { FITS } from '@observerly/fits'
65+
66+
const url = `fits.observerly.com/Rosetta_Nebula_[Ha]_Monochrome_M_300s_2024-11-26T17_20_00Z`
67+
68+
const response = await fetch(url)
69+
70+
if (!response.ok) {
71+
throw new Error(`HTTP error! Status: ${response.status}`)
72+
}
73+
74+
const buffer = await response.arrayBuffer()
75+
76+
const fits = await new FITS().readFromBuffer(buffer)
77+
78+
const headers = fits.getHeaders()
79+
80+
const image = fits.getImageHDU() // of type Float32Array
81+
```
82+
83+
#### 2D CanvasHTMLElement Rendering
84+
85+
```ts
86+
// ... load FITS file as above
87+
88+
const image = fits.getImageHDU() // of type Float32Array
89+
90+
const canvas = document.createElement('canvas')
91+
92+
canvas.width = fits.getHeader('NAXIS1')
93+
94+
canvas.height = fits.getHeader('NAXIS2')
95+
96+
const ctx = canvas.getContext('2d')
97+
98+
const imageData = ctx.createImageData(canvas.width, canvas.height)
99+
100+
const data = imageData.data
101+
102+
for (let i = 0; i < image.length; i++) {
103+
const value = image[i]
104+
data[i * 4] = value
105+
data[i * 4 + 1] = value
106+
data[i * 4 + 2] = value
107+
data[i * 4 + 3] = 255
108+
}
109+
110+
ctx.putImageData(imageData, 0, 0)
111+
```
112+
113+
## Miscellany
114+
115+
\*It is dependency-free to ensure it can be used safely within both node, deno, bun and browser environments.
116+
117+
## License
118+
119+
@observerly/FITS is licensed under the MIT license. See [MIT](./LICENSE) for details.

0 commit comments

Comments
 (0)