Class: RFits::Image
- Includes:
- Compressible
- Defined in:
- lib/rfits/rfits.rb
Overview
An Image HDU.
Constant Summary collapse
- IMG_TYPE_MAP =
{ IO::Proxy::BYTE_IMG => :byte, IO::Proxy::SHORT_IMG => :short, IO::Proxy::LONG_IMG => :long, IO::Proxy::LONGLONG_IMG => :longlong, IO::Proxy::FLOAT_IMG => :float, IO::Proxy::DOUBLE_IMG => :double }
Constants included from Compressible
Compressible::COMPRESSION_DIM_KEY, Compressible::COMPRESSION_NOISE_BIT_NAME_VALUE, Compressible::COMPRESSION_SCALE_NAME_VALUE, Compressible::COMPRESSION_SMOOTH_NAME_VALUE, Compressible::COMPRESSION_TILE_KEY_ROOT, Compressible::COMPRESSION_TYPE_KEY, Compressible::COMPRESSION_TYPE_MAP, Compressible::COMPRESSION_VAR_KEY_ROOT, Compressible::COMPRESSION_VAR_VAL_ROOT
Constants inherited from HDU
Instance Attribute Summary collapse
-
#compression_options ⇒ Object
readonly
Returns the value of attribute compression_options.
Attributes inherited from HDU
Instance Method Summary collapse
-
#bitpix(equiv = true) ⇒ Object
Number of bits per data pixel.
-
#bitpix=(bitpix) ⇒ Object
Alter the datatype of the image.
-
#compressed? ⇒ Boolean
Returns true if the image is compressed, false otherwise.
-
#create(at) ⇒ Object
Actually create a physical image (i.e. write bytes).
-
#dim ⇒ Object
The number of dimensions of the image (i.e. 2).
-
#image_type ⇒ Object
The type of image.
-
#initialize(file, extpos, bitpix, naxes, coptions = nil) ⇒ Image
constructor
Instantiate a new image in the specified file at the specified position, of a certain data type and size.
-
#naxes ⇒ Object
Alias for Image#size.
-
#naxes=(naxes) ⇒ Object
Alter image dimensions to the specified size.
-
#naxis ⇒ Object
Alias for Image#dim.
-
#resize(bitpix, naxes) ⇒ Object
Resize the image to the specified dimensions and data type.
-
#size ⇒ Object
The size of each dimension (i.e. [512, 512]).
Methods included from Compressible
#activate_compression, #compression_type, #compression_type=, #deactivate_compression, #hcomp_scale, #hcomp_scale=, #hcomp_smooth, #hcomp_smooth=, #noise_bits, #noise_bits=, #tile_dim, #tile_dim=
Methods inherited from HDU
#hdu_type, #position, #reset_position
Constructor Details
#initialize(file, extpos, bitpix, naxes, coptions = nil) ⇒ Image
Instantiate a new image in the specified file at the specified position, of a certain data type and size. “coptions” is optional, but if present see Compressible#activate_compression for allowed format.
If you do activate compression for an image there is one “gotcha” that might take you by surprise: if there are no existing HDUs in the file and you add a compressed image, an extra image HDU at the start of the file will be created. In other words, your new compressed image will be at fits not fits. This is because cfitsio compresses the image by wrapping it in a binary table, but the FITS specification mandates that the primary HDU must always be an image array.
980 981 982 983 984 985 986 987 |
# File 'lib/rfits/rfits.rb', line 980 def initialize(file, extpos, bitpix, naxes, =nil) super(file, extpos) @bitpix = bitpix @naxes = naxes @compression_options = end |
Instance Attribute Details
#compression_options ⇒ Object (readonly)
Returns the value of attribute compression_options.
960 961 962 |
# File 'lib/rfits/rfits.rb', line 960 def @compression_options end |
Instance Method Details
#bitpix(equiv = true) ⇒ Object
Number of bits per data pixel. By default returns the “equivalent type” unless equiv is set to false.
1044 1045 1046 1047 |
# File 'lib/rfits/rfits.rb', line 1044 def bitpix(equiv=true) reset_position() equiv ? IO::Proxy.fits_get_img_equivtype(self.file.io) : IO::Proxy.fits_get_img_type(self.file.io) end |
#bitpix=(bitpix) ⇒ Object
Alter the datatype of the image.
img.bitpix = IO::Proxy::LONG_IMG
1051 1052 1053 1054 |
# File 'lib/rfits/rfits.rb', line 1051 def bitpix=(bitpix) reset_position() IO::Proxy.fits_resize_img(self.file.io, bitpix, self.naxis, self.naxes) end |
#compressed? ⇒ Boolean
Returns true if the image is compressed, false otherwise.
1064 1065 1066 1067 |
# File 'lib/rfits/rfits.rb', line 1064 def compressed? reset_position() IO::Proxy.fits_is_compressed_image(self.file.io) == 1 ? true : false end |
#create(at) ⇒ Object
Actually create a physical image (i.e. write bytes). “at” is the position at which to insert the image.
991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 |
# File 'lib/rfits/rfits.rb', line 991 def create(at) self.deactivate_compression # A dummy image gets added if to the top of the file if # the first image added is compressed. @extpos = (self.file.length == 0 and self.) ? at + 1 : at self.file.set_position(at - 1 < 0 ? 0 : at - 1) self.activate_compression() if self. IO::Proxy.fits_insert_img(self.file.io, @bitpix, @naxes.size, @naxes) # This just makes sure something is written out right away. self.header['RFITS1234'] = 'temp' self.header.delete('RFITS1234') end |
#dim ⇒ Object
The number of dimensions of the image (i.e. 2).
1013 1014 1015 1016 |
# File 'lib/rfits/rfits.rb', line 1013 def dim reset_position() IO::Proxy.fits_get_img_dim(self.file.io) end |
#image_type ⇒ Object
The type of image. Possibilities include: :byte, :short, :long, :longlong, :float, :double
1037 1038 1039 1040 1041 |
# File 'lib/rfits/rfits.rb', line 1037 def image_type reset_position() etype = IO::Proxy.fits_get_img_equivtype(self.file.io) IMG_TYPE_MAP[etype] || etype end |
#naxes ⇒ Object
Alias for Image#size
1025 1026 1027 |
# File 'lib/rfits/rfits.rb', line 1025 def naxes self.size end |
#naxes=(naxes) ⇒ Object
Alter image dimensions to the specified size.
img.naxes = [1000, 200]
1031 1032 1033 1034 |
# File 'lib/rfits/rfits.rb', line 1031 def naxes=(naxes) reset_position() IO::Proxy.fits_resize_img(self.file.io, self.bitpix, naxes.size, naxes) end |
#naxis ⇒ Object
Alias for Image#dim
1008 1009 1010 |
# File 'lib/rfits/rfits.rb', line 1008 def naxis self.dim end |
#resize(bitpix, naxes) ⇒ Object
Resize the image to the specified dimensions and data type.
img.resize(IO::Proxy::LONG_IMG, [1000, 200])
1058 1059 1060 1061 |
# File 'lib/rfits/rfits.rb', line 1058 def resize(bitpix, naxes) reset_position() IO::Proxy.fits_resize_img(self.file.io, bitpix, naxes.size, naxes) end |
#size ⇒ Object
The size of each dimension (i.e. [512, 512]).
1019 1020 1021 1022 |
# File 'lib/rfits/rfits.rb', line 1019 def size reset_position() IO::Proxy.fits_get_img_size(self.file.io, self.naxis) end |