Coder Social home page Coder Social logo

pyfits2itk's Introduction

pyfits2itk

pyfits2itk is a Python replacement for fits2itk from the IIC/Astronomical Medicine Project, which is no longer maintained. This module uses astropy to read in a FITS cube or image, performs some simple manipulations useful for converting astronomy data (such as flipping the RA/longitude axis) and then calls the pynrrd module (included) to write out a nrrd file for inport into 3D programs such as Slicer3D.

Since Slicer3D does not understand astronomy coordinates, you must preregister and congrid all cubes externally before converting them to nrrd.

There is limited support for converting astronomy coordinates into units Slicer3D does understand. See Advanced Usage.

Dependencies

astropy

If you have astropy (which requires numpy) then you're good to go.

Optional Dependencies

scipy

Scipy is used to do the interpolation regridding required if one wants to rescale the velocity axis.

Installation

python setup.py install

Example usage

import fits2itk

	# convert a FITS file using the default parameters
infile = "ngc1333_co.fits"
outfile = "ngc1333_co.nrrd"

fits2itk.convert(infile,outfile)

	#Or rescale the data and velocity scale relative to spatial
fits2itk.convert("13co10_done.fits","output.nrrd",data_scale=10,vel_scale=2.)


	# orconvert a FITS file using parameters defined
	# in an external file

fits2itk.convert(infile,outfile,vel_scale=1,use_conv="ngc1333_conv")

	# read in the nrrd file to examine it
readdata, options = fits2itk.read(filename)
print readdata.shape
print options

Advanced usage

If all your datasubes are fairly homogeneous, you can put them all on the same scale. Create a dictionary for this transformation and store it in a file, then call convert with use_conv='name of file'. See ngc1333_conv.py for an example. Note that the defaults here are sensible for the test cube, but probably note for your dataset.

In the following there are two cubes with different spatial/spectral resolution and only partially overlapping in space. With the use_conv option the dimensions are rescaled so that they will properly register when imported into Slicer3D (other 3D software not tested). The c18o32 file has velocities in km/s, while the 13co10 file has velocities in m/s, so vel_scale is used to account for this.

import fits2itk
fits2itk.convert("ngc1333_c18o32.fits","c18o32.nrrd",vel_scale=1000.,use_conv="ngc1333_conv")
fits2itk.convert("ngc1333_13co10.fits","13co10.nrrd",vel_scale=1.,use_conv="ngc1333_conv")

License

See LICENSE.

pyfits2itk's People

Contributors

hmeine avatar jaspervdg avatar jfoster17 avatar mhe avatar nocnokneo avatar robbie1977 avatar yanlend avatar

Watchers

 avatar  avatar

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.