Class RFits::File
In: lib/rfits/rfits.rb
Parent: Object

A class representing a FITS file.

Methods

<<   []   []=   close   delete   delete_at   each   first   last   length   mode   new   open   path   url_type  

Included Modules

Enumerable

Attributes

io  [R] 

Public Class methods

Open an existing FITS file or create a new one. The mode parameter may be on of:

  • r opens a file for reading. If it doesn‘t exist, it creates it.
  • rw opens afile for reading and writing. If it doesn‘t exist, it creates it.
  • rw+ opens a file for reading and writing. If it exists, it truncates it.
 fits = RFits::File.new('m31.fits', 'rw')  # this is probably what you want

Works as RFits::File#new but accepts a block. The FITS file is automatically closed after execution of the block.

 RFits::File.open('m31.fits', 'rw') do |fits|
   # do things to the FITS file, fits.close gets called  automatically
 end

Public Instance methods

Append a new HDU to the file.

 fits << RFits::Image.new(@fits, nil, RFits::IO::Proxy::LONG_IMG, [4, 4])  # notice you can leave the position nil

Get the specified HDU associated with the FITS file. Contrary to FITS conventions this is *zero-based* access. So:

 primary_hdu = fits[0]  # primary array
 hdu = fits[2]  # third HDU

Insert a new HDU at the specified position.

 fits[1] = RFits::Image.new(@fits, nil, RFits::IO::Proxy::LONG_IMG, [2, 3])  # the old hdu at pos 1 gets pushed down

Close the FITS file.

 file.close()

Delete the specified HDU.

 fits.delete(hdu)

Delete the HDU at the specified position. Again, this is zero-based access.

 fits.delete_at(2)  # delete the third HDU

Iterates through each HDU in the FITS file.

 fits.each do |hdu|
   # do something...
 end

Get the first HDU in the file.

Get the last HDU in the file.

The number of HDUs in the FITS file.

The IO mode of the FITS file (i.e. IO::Proxy::READWRITE or IO::Proxy::READONLY)

 puts file.mode   # 1 = IO::Proxy::READWRITE

The filesystem path to the FITS file.

 puts file.path   # m31.fits

The type of URL of the FITS file (i.e. file:// or ftp://).

 puts file.url_type   # file://

[Validate]