Giter Site home page Giter Site logo

astrojs / fitsjs Goto Github PK

View Code? Open in Web Editor NEW
84.0 84.0 21.0 2.57 MB

JavaScript library for reading the FITS astronomical format. Functionality includes reading of images, data cubes, compressed images, binary and ascii tables.

Home Page: http://astrojs.github.io/fitsjs/

License: MIT License

CoffeeScript 31.22% HTML 2.91% JavaScript 63.25% Shell 0.21% Python 0.39% CSS 2.02%

fitsjs's Introduction

astrojs

astrojs is a project to develop and consolidate javascript libraries for astronomical applications. Similar to the astropy project, astrojs is gathering useful libraries under a single namespace so they may become shared resources to the astronomical community. There are many codes floating around the web, which if they were consolidated in a central location, would be of much greater value.

If you have a javascript resource that you would like to contribute, please contact Amit Kapadia.

astrojs library

This library is a development tool that provides a library template and convenience functions for developing under the javascript astro namespace. It is most useful when developing astrojs libraries using the coffeescript language. A future release will support development for pure javascript libraries. There are four functions available from the command line.

astrojs new [project name]
astrojs class [class name]
astrojs server
astrojs build

installation

The astrojs module is built using NodeJS. Why Node? Node is another flavor of javascript, javascript that runs server side. A Node module may be developed and run in a similar why to any other scripting language, such as python. As this is a javascript initiative, any utilities should be developed in javascript. If Node is not installed, please refer to its documentation and downloads page.

Upon installation of Node a package manager called NPM will be available. The astrojs module is available via the Node Packaged Modules service. To install the astrojs module run

npm install astrojs -g

This will install astrojs globally, and it will function as a command line utility. (It most likely needs to be run using sudo).

creating an astrojs project

To create an astrojs project run

astrojs new [project name]

This will generate the following project files under a directory named by [project name]:

Cakefile
index.js
lib/
package.json
README.md
src/
  |----[project name].coffee
test/
  |----favicon.ico
  |----lib/jasmine-html.js
  |----lib/jasmine.css
  |----lib/jasmine.js
  |----lib/MIT.LICENSE
  |----SpecRunner.html
  |----specs/

generating a new class

Javascript is a prototype-based language, however a class-like structure can be emulated using particular development patterns. Use of this modules means that the developer is adopting a module pattern for library development. Executing

astrojs new [class name]

from within an astrojs project directory will generate template code for a new class and test functions.

starting a local development server

Development always requires testing. When developing an astrojs module, it is encouraged to test all functionality. Frequently a local testing server is needed. Calling

astrojs server

will spin up a local testing server at http://0.0.0.0:8000. This is useful when tests require data that must be accessed on the same domain as the script (e.g. ajax requests for json or binary files).

This command support two options.

astrojs server -p 8001

allows a port to be specified, and

astrojs server -m

minifies the code, which is useful in some development edge cases.

building an astrojs project

This module encourages development to occur in a modular fashion. Often development of libraries can quickly become overwhelming. Good practice encourages codes to be modulated into separate files, however this requires a build step when delivering the final javascript library. Calling

astrojs build

concatenates all files in the src directory, and provides the final product in the lib directory. It is important to specify the dependency order using the key _dependencyOrder in package.json.

example

For an example of using this module for development, please refer to the fitsjs library.

fitsjs's People

Contributors

kapadia avatar merg1255 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fitsjs's Issues

Add support for 64bit Float

At the moment, all 64bit floating point data gets converted to 32bit. The Image.prototype._getFrame function should have the bitpix<0 if condition updated to differentiate between values of -64 and -32.

Specifically, modifying image.coffee such that from line 88 the code reads:

      arr = new Uint32Array(buffer)

      swapEndian = (value) ->
        return ((value & 0xFF) << 24) | ((value & 0xFF00) << 8) | ((value >> 8) & 0xFF00) | ((value >> 24) & 0xFF)

      while i--
        value = arr[i]
        arr[i] = swapEndian(value)

      if bitpix == -64
        i = arr.length
        while i-=2
          tmp = arr[i]
          arr[i] = arr[i + 1]
          arr[i + 1] = tmp
        arr = new Float64Array(buffer)
      else       
        # Initialize a Float32 array using the same buffer
        arr = new Float32Array(buffer)

Access the Image data

Probably it is just a lack of documentation (or of understanding from my side)...

However I have opened a .fits file, and the first "dataunit" is an Image. Through it I have access to the different parameters ("width","height",...) but I do not know how to access the pixel values.

I have tried the "getFrame(0,callback,opts)" but the returned "pixels" (into the callback) is undefined. I have also tried to directly build a "Float32Array" wrapping the "buffer" but the data I can extract from it seems to be random (and are certainly not the expected values)

For a file containing uint8 the array wrapping works well and I get my image, the problem seems to be specific for the float (bitpix: -32)

Safari loading error

I'm developing a web tool for browsing FITS files and make use of webfits and thus fitsjs. In most browsers, everything works as expected, but Safari on Mac OS X 10.6.8 throws an error at line 690 of fits.js (when attempting to load a valid FITS file):

TypeError: '[object BlobConstructor]' is not a constructor (evaluating 'new Blob([fn1], {
        type: mime
      })')

Help appreciated.

Peter

Dev code cleanup

@kapadia As mentioned in the README, the code file should be free from repeated code that spawns web workers.

Cannot find way to display the image

Hello,

I am writing a frontend in react for my instrument, which will display fits files, created by the instrument.

The files have 4 frames in 1 data unit in 1 HDU.

I have only found this library to read fits files in javascript properly (JS9 wouldn't work for the love of God).

Right now I have the following callback after reading the image file:

var hdu = this.getHDU();
var array1 = new Uint8Array(hdu.data.frameOffsets[0].buffers[0]);
setFrame1(new Blob([array1.buffer], { type: "image/png" }));
var array2 = new Uint8Array(hdu.data.frameOffsets[1].buffers[0]);
setFrame2(new Blob([array2.buffer], { type: "image/png" }));
var array3 = new Uint8Array(hdu.data.frameOffsets[2].buffers[0]);
setFrame3(new Blob([array3.buffer], { type: "image/png" }));
var array4 = new Uint8Array(hdu.data.frameOffsets[3].buffers[0]);
setFrame4(new Blob([array4.buffer], { type: "image/png" }));

It works nicely and I am getting the frame arrays, that I have verified. But when I set the img components as such:

<img src={URL.createObjectURL(frame1)} alt={"test1"} loading="lazy" />
<img src={URL.createObjectURL(frame2)} alt={"test2"} loading="lazy" />
<img src={URL.createObjectURL(frame3)} alt={"test3"} loading="lazy" />
<img src={URL.createObjectURL(frame4)} alt={"test4"} loading="lazy" />

It only displays a broken image symbol.

I am sure I am missing something too obvious, but please some help will be greatly appreciated.

Handling large FITS files

Would it be easy to mention up to which file size can the js library read data?
For example, can it handle 1GB files inside a browser through HTML5 chunk loading? Any examples?

Thanks

Use a wrapperclass for DataView instead of extending it

I may be wrong here, but it might be more effective to create your own DataView class that is used as a wrapper for the native javascript DataView object. Then instead of prototyping new methods, you can define your own functions that wrap the native DataView methods.

This will enable to you pass the bitpix paramter to your wrapper class and keep all of the logic of using the right accessor in the wrapper class - instead of cluttering up the File and Image objects with it.

I think that would result in making the code more readable and then you'll be able implement Issue #5 more easily.

Example: TESS

Thanks for making this! I'm excited to apply it to some TESS FITS data, but I don't think I understand the method used to lookup the light curve in the binary table extension header.

Could anybody help me with a simple example of accessing SAP_FLUX data?

Include version in js file

@kapadia Streamline the dev process.
Include in every generated js file the corresponding version, along with the distribution licence information.

And of course, the original creator of the library. :)

Support fot HDF5

@kapadia Have you considered creating a library also for HDF5 files?
Btw, which format do you use more often? Getting a JS version for common ones is a good way to transition to the browser.

Support for 16bits unsigned images

Salut,
There is a problem for loading unsigned 16 bits images ( BITPIX = 16 and BZERO = 32768)
This is the fix to handle them correctly :

in Image.prototype._getFrame :

Line 760:
change
...
case 16:
tmp = new Int16Array(buffer);
...
with
...
case 16:
if(bzero==32768)
tmp = new Uint16Array(buffer);
else
tmp = new Int16Array(buffer);
...

Thanks for your nice work!
Pierre

Header Parsing

Issues when parsing nasty ESO headers like:

SIMPLE = T / Standard FITS format: NOST 100-2.0
BITPIX = -32 / No. of bits per pixel
NAXIS = 2 / No. of axes in image
NAXIS1 = 2670 / No. of pixels
NAXIS2 = 2592 / No. of pixels
EXTEND = T / FITS extension may be present
BLOCKED = T / FITS file may be blocked
COMMENT NOST 100-2.0: Hanisch,R. et al. 2001, Astron. & Astrophys. 376, 559

CRPIX1 = 1. / Reference pixel
CRVAL1 = -318.314017694 / Coordinate at reference pixel
CDELT1 = 1. / Coord. incr. per pixel (original value)
CTYPE1 = ' PIXEL ' / Units of coordinate
CRPIX2 = 1. / Reference pixel
CRVAL2 = -777.12286106 / Coordinate at reference pixel
CDELT2 = 1. / Coord. incr. per pixel (original value)
CTYPE2 = ' ' / Units of coordinate
BUNIT = ' PIXEL ' / Units of data values
DATAMAX = 686.397277832 / Maximum data value
DATAMIN = -999. / Minimum data value

ORIGIN = 'ESO-MIDAS' / Written by MIDAS
DATE = '2009-12-11T14:45:33' / [UTC] Date of writing
FILENAME= 'cR.bdf ' / Original file base-name
MIDASFTP= 'IMAGE ' / MIDAS File Type

OBJECT = 'average frame' / MIDAS desc.: IDENT(1)
RA = 146.33936 / MIDAS desc.: O_POS(1)
DEC = -14.29499 / MIDAS desc.: O_POS(2)
DATE-OBS= '09/04/92' / MIDAS desc.: O_TIME(1)
MJD-OBS = 48721.06194 / MIDAS desc.: O_TIME(4)
TM-START= 5351.615999965 / MIDAS desc.: O_TIME(5)
EXPTIME = 300. / MIDAS desc.: O_TIME(7)
COMMENT IP_FILE 'IHAP/FITS/EM9204090129133.FITS::USER ' / IHAP: Begin of keywor
COMMENT d
COMMENT IP_FEND / IHAP: End of keyword file
COMMENT EXPTIME 300.000
COMMENT IP_CBEND / IHAP: comment block end
TELESCOP= 'ESONTTB ' / MIDAS desc.: TELESCOP(1)
INSTRUME= 'EMMI ' / MIDAS desc.: INSTRUME(1)
OBSERVER= 'Giavalisco' / MIDAS desc.: OBSERVER(1)
AIRMASS = 1.03685 / MIDAS desc.: O_AIRM(1)
HISTORY Extracted from: ONTT.1992-04-09T01:29:11.000.fits
HISTORY FLIP/IMAGE E92_09T012911.bdf Y
HISTORY FLIP/IMAGE E92_09T012911.bdf Y
HISTORY FLIP/IMAGE E92_09T012911.bdf X
HISTORY FLIP/IMAGE E92_09T012911.bdf X
HISTORY FLIP/IMAGE E92_09T012911.b
HISTORY df X REBIN/ROTATE E92_
HISTORY 09T012911 rE92_09T012911 keyword E95_01T042813 NO COMPUTE/
HISTORY IMAG R_92 = R_92 - 2.254456e+03
HISTORY COMPUTE/IMAG R_92 = R_92/300
HISTORY AVERAGE/IMAG R = R_92,R_95 M -999 average -1,999
HISTORY REPLACE/IMAGE R cR w_mask00/.5,>=med00
HISTORY
ARCFILE = 'ONTT.1992-04-09T01:29:11.000.fits'
CHECKSUM= 'ZBJ9a9I8VAI8Z7I8' / HDU checksum updated 2007-01-05T16:22:42
DATASUM = '3477596210' / data unit checksum updated 2007-01-05T16:22:42
HIERARCH ESO GEN ID = 'ARC-0001/1.2' / Version of related document
HIERARCH ESO GEN PROJ ID = '000.00.000' / ESO program identification
HIERARCH ESO GEN EXPO NO = 18089 / Image Sequence Number
HIERARCH ESO GEN EXPO TYPE = 'SCI ' / Type of exposure
HIERARCH ESO GEN EXPO LST = 35799. / Loc. Sid. time at start of ex.
HIERARCH ESO TEL ID = 'ESONTTB ' / Telescope Identification
HIERARCH ESO TEL LON = 70.7345 / Telescope Longitude (+=West)
HIERARCH ESO TEL LAT = -29.2584 / Telescope Latitude (+=North)
HIERARCH ESO TEL ALTITUDE = 2440 / Telescope Altitude
HIERARCH ESO TEL FOCU LEN = 38.482 / Focus lenght (m)
HIERARCH ESO TEL FOCU SCALE = 1.489 / Focus scale (deg/m) = 5.36""/mm
HIERARCH ESO TEL TRAK RATEA = 0.0042 / Traking rate in alpha (deg/s)
HIERARCH ESO TEL TRAK RATED = 0. / Traking rate in delta (deg/s)
HIERARCH ESO ADA ID = 'ADAPTB ' / Adapter Identification
HIERARCH ESO ADA MODE = 'STD ' / Mode (standard)
HIERARCH ESO ADA ROT = 0. / Rotat. at the start of the exp.
HIERARCH ESO ADA GUID-1 X = 0.01714 / Guide probe x position (m)
HIERARCH ESO ADA GUID-1 Y = 0.1004 / Guide probe y position (m)
HIERARCH ESO ADA GUID-2 X = 0.000503 / Guide probe x position (m)
HIERARCH ESO ADA GUID-2 Y = 0.001106 / Guide probe y position (m)
HIERARCH ESO INS ID = 'EMMI #1 ' / Instrument Identification
HIERARCH ESO INS COMP ID = 'HP RTE-A V5' / Instrument computer op. sys.
HIERARCH ESO INS MODE = 'RILD ' / Mode EMMI is in
HIERARCH ESO INS OPTI-2 NO = 1 / Mirror Wheel position
HIERARCH ESO INS OPTI-2 TYPE = 'MIRROR ' / What is this element
HIERARCH ESO INS OPTI-2 ID = 'RILD MIR' / Mirror unique identification
HIERARCH ESO INS OPTI-2 NAME = 'RILD ' / Mirror position
HIERARCH ESO INS OPTI-3 NO = 1 / LD Slits Wheel position
HIERARCH ESO INS OPTI-3 TYPE = 'FREE ' / What is this element
HIERARCH ESO INS MIRR-3 NAME = 'UPPER RED' / Upper folding mirror red
HIERARCH ESO INS MIRR-3 ST = F / Mirror IN when true
HIERARCH ESO INS OPTI-7 NO = 1 / Filter Wheel red position
HIERARCH ESO INS OPTI-7 TYPE = 'FILTER ' / What is this element
HIERARCH ESO INS OPTI-7 ID = '#608 ' / Filter unique identification
HIERARCH ESO INS OPTI-7 NAME = 'R ' / Filter position
HIERARCH ESO INS OPTI-9 NO = 9 / Grism Wheel position
HIERARCH ESO INS OPTI-9 TYPE = 'FREE ' / What is this element
HIERARCH ESO DET NAME = 'FA_2048_L' / Detector name
HIERARCH ESO DET ID = 'ccd$24 ' / Detector serial id.
HIERARCH ESO DET TYPE = 'CCD Ford' / Detector type
HIERARCH ESO DET PIXSIZE = 1.5E-05 / Size of pixel (m)
HIERARCH ESO DET BITS = 16 / ADU bits per pixel
HIERARCH ESO DET FRAM NAXIS1 = 1501 / Number of pixels along x
HIERARCH ESO DET FRAM CRVAL1 = 250 / x coordinate of lower left pixel
HIERARCH ESO DET FRAM CRPIX1 = 1 / x coordinate of reference pixel
HIERARCH ESO DET FRAM CDELT1 = 1 / Binning factor along x
HIERARCH ESO DET FRAM NAXIS2 = 1501 / Number of pixels along y
HIERARCH ESO DET FRAM CRVAL2 = 250 / y coordinate of lower left pixel
HIERARCH ESO DET FRAM CRPIX2 = 1 / y coordinate of reference pixel
HIERARCH ESO DET FRAM CDELT2 = 1 / Binning factor along y
HIERARCH ESO DET DKTIME= 361.25 / Dark current time (s)
HIERARCH ESO DET TEMP-VAR = 0.1 / Temperature drift during exposure
HIERARCH ESO DET TEMPMEAN = 158.4 / Mean detector temperature (K)
HIERARCH ESO DET COMP ID = 'ccdr-V1.0' / A900 CCD-program name+vers
HIERARCH ESO DET PARM1 = 'CLOCK=fd2048'
HIERARCH ESO DET PARM2 = 'HLO1 : -5.06 VLO1 : -8.01 VDD1 : 23.34'
HIERARCH ESO DET PARM3 = 'HHI1 : 5.03 VHI1 : 2.01 VDR1 : 11.97'
HIERARCH ESO DET PARM4 = 'HLO2 : -5.00 RLO1 : -1.07 VGS1 : 3.63'
HIERARCH ESO DET PARM5 = 'HHI2 : 5.01 RHI1 : 7.04 ICCD1 : 0.00'
HIERARCH ESO DET PARM6 = 'TL 1, 5 telem. data'
HIERARCH ESO DET DATE = '01/04/91' / CCD implementation date
HIERARCH ESO DET MODE = 'SLOW ' / Readout mode
HIERARCH ESO DET GAIN = 2 / Gain
HIERARCH ESO DET AD-VALUE = 1.5 / Electrons per AD unit
HIERARCH ESO DET DIT = 300. / Defined integration time (sec)
HIERARCH ESO DET SHUT TMOPEN = 0.5 / Time needed to open shutter(sec)
HIERARCH ESO DET SHUT TMCLOS = 0.5 / Time needed to close shutter(sec)

HISTORY ESO-DESCRIPTORS START ................
HISTORY 'START_PRE','R_8',1,2,'3E23.15'
HISTORY 2.500000000000000E+02 2.500000000000000E+02
HISTORY
HISTORY 'SEEING','R_4',1,2,'5E14.7'
HISTORY 1.1211230E+00 1.1870620E+00
HISTORY
HISTORY 'START_S','R_8',1,2,'3E23.15'
HISTORY 2.502179570000000E+02 2.500067900000000E+02
HISTORY
HISTORY 'STEP_RATAN','R_8',1,2,'3E23.15'
HISTORY -1.000000000000000E+00 1.000000000000000E+00
HISTORY
HISTORY 'START_RATAN','R_8',1,2,'3E23.15'
HISTORY 1.750217957000000E+03 2.500067899999999E+02
HISTORY
HISTORY 'LHCUTS','R_4',1,4,'5E14.7'
HISTORY 0.0000000E+00 1.0000000E+01-9.9900000E+02 6.8639728E+02
HISTORY
HISTORY 'DISPLAY_DATA','I*4',1,9,'7I10'
HISTORY 2 2 1336 1297 0 -1 -1
HISTORY -1 -1
HISTORY
HISTORY ESO-DESCRIPTORS END ................

END

Won't read gzipped FITS files

HI,
I was just testing trying this out for the first time, as I could use some FITS interface for javascript, and it fails to open a gzipped event list.

Code (using jquery):

$(document).ready(reset);
function reset()
{
  var url="/some/url/test.fits.gz";
  var FITS=astro.FITS;
  var fits=new FITS(url, loadedFits);
}

function loadedFits()
{
  console.log("This file has "+this.hdus.length+" HDUs");
}

If I unzip test.fits.gz and update the URL it works, otherwise the page hangs until my browser times out. It's not a very large fits file.

Support for nodeJS

Hi guys, what's your idea behind the support for nodeJS ? is that making this library part of an npm package ?

Create Example

@kapadia
The next big addin would now be: create a simple working example. Like, choose an online sample FITS file, then create a simple page and extract a couple of images and a few binary/text data. It's also on the item list of README page. :)

Change the library availability

Hi @kapadia ! :)
Nice project.

Currently the js library is all rights reserved.
Could you please migrate to MIT licence (or some other free to use in products licence)? This way it could be used freely on many projects.

It will require mentioning about the library in the README and also in the js file.

no click or mousemove events

Hi. Trying example.html. Thanks, I like it so far but I'm not getting any response to mouse clicks or moves over the images. Load event works fine, I see images, I can change files, set scaling, color and frame. Running Chrome 42.0.2311.90 on Mac OS 10.10.3.

Implement getColumn for tables

Get column should be implemented such that bytes are skipped appropriately to avoid unneeded calls to DataView getters methods.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.