Module: RFits::Compressible
- Included in:
- Image
- Defined in:
- lib/rfits/rfits.rb
Overview
A set of routines for setting and retrieving compression characterstics.
Constant Summary collapse
- COMPRESSION_TYPE_MAP =
{ IO::Proxy::RICE_1 => :rice, IO::Proxy::GZIP_1 => :gzip, IO::Proxy::PLIO_1 => :plio, IO::Proxy::HCOMPRESS_1 => :hcompress }
- COMPRESSION_DIM_KEY =
'ZNAXIS'
- COMPRESSION_TYPE_KEY =
'ZCOMPTYPE'
- COMPRESSION_TILE_KEY_ROOT =
'ZTILE'
- COMPRESSION_VAR_KEY_ROOT =
'ZNAME'
- COMPRESSION_VAR_VAL_ROOT =
'ZVAL'
- COMPRESSION_NOISE_BIT_NAME_VALUE =
'NOISEBIT'
- COMPRESSION_SCALE_NAME_VALUE =
'SCALE'
- COMPRESSION_SMOOTH_NAME_VALUE =
'SMOOTH'
Instance Method Summary collapse
-
#activate_compression ⇒ Object
Activate compression on the image.
-
#compression_type ⇒ Object
Retrieve the compression type of the image.
-
#compression_type=(ctype) ⇒ Object
Set the compression type of the image.
-
#deactivate_compression ⇒ Object
Turn off compression for the image.
-
#hcomp_scale ⇒ Object
Get the hcompress scale if the image is compressed using hcompress.
-
#hcomp_scale=(scale) ⇒ Object
Set the hcompress scale if the image is compressed using hcompress.
-
#hcomp_smooth ⇒ Object
Get the hcompress smoothing factor if the image is compressed using hcompress.
-
#hcomp_smooth=(smooth) ⇒ Object
Set the hcompress smoothing factor if the image is compressed using hcompress.
-
#noise_bits ⇒ Object
Get the noise bits for the compressed image.
-
#noise_bits=(bits) ⇒ Object
Set the noise bits for the compressed image.
-
#tile_dim ⇒ Object
Get the tile dimensions for the compressed image.
-
#tile_dim=(tilesizes) ⇒ Object
Set the tile dimensions for the compressed image.
Instance Method Details
#activate_compression ⇒ Object
Activate compression on the image. “options” is a hash with the following keys:
- :compression_type
-
the type of compression (:rice, :gzip, :plio, :hcompress). Required.
- :tile_dim
-
the size of the tiles used in compression. Optional.
- :noise_bits
-
applicable for floating point images only. Optional.
- :hcomp_scale
-
scale factor for use in hcompress compression. Optional.
- :hcomp_smooth
-
smoothing factor for use in hcompress compression. Optional.
856 857 858 859 860 861 862 |
# File 'lib/rfits/rfits.rb', line 856 def activate_compression self.compression_type = self.[:compression_type] if self.[:compression_type] self.tile_dim = self.[:tile_dim] if self.[:tile_dim] self.noise_bits = self.[:noise_bits] if self.[:noise_bits] self.hcomp_scale = self.[:hcomp_scale] if self.[:hcomp_scale] self.hcomp_smooth = self.[:hcomp_smooth] if self.[:hcomp_smooth] end |
#compression_type ⇒ Object
Retrieve the compression type of the image. Possible values: :rice, :gzip, :plio, :hcompress
870 871 872 873 874 875 876 877 878 879 880 881 882 883 |
# File 'lib/rfits/rfits.rb', line 870 def compression_type reset_position() ctype = case self.header['ZCMPTYPE'] when 'GZIP_1' then IO::Proxy::GZIP_1 when 'RICE_1' then IO::Proxy::RICE_1 when 'HCOMPRESS_1' then IO::Proxy::HCOMPRESS_1 when 'PLIO_1' then IO::Proxy::PLIO_1 else raise "Unknown compression type #{self.header[COMPRESSION_TYPE_KEY]}." end COMPRESSION_TYPE_MAP[ctype] end |
#compression_type=(ctype) ⇒ Object
Set the compression type of the image. Possible values: :rice, :gzip, :plio, :hcompress
image.compression_type = :gzip
887 888 889 890 |
# File 'lib/rfits/rfits.rb', line 887 def compression_type=(ctype) ctype ? IO::Proxy.fits_set_compression_type(self.file.io, COMPRESSION_TYPE_MAP.invert[ctype.to_sym] || ctype) : IO::Proxy.fits_set_compression_type(self.file.io, nil) end |
#deactivate_compression ⇒ Object
Turn off compression for the image.
865 866 867 |
# File 'lib/rfits/rfits.rb', line 865 def deactivate_compression self.compression_type = 0 end |
#hcomp_scale ⇒ Object
Get the hcompress scale if the image is compressed using hcompress.
926 927 928 929 930 931 932 933 |
# File 'lib/rfits/rfits.rb', line 926 def hcomp_scale reset_position() zname_name, zname_value, zname_comment = self.header.find { |name, value, comment| name.match(/^#{COMPRESSION_VAR_KEY_ROOT}/) and value == COMPRESSION_SCALE_NAME_VALUE } zname_name ? self.header["#{COMPRESSION_VAR_VAL_ROOT}#{zname_name.match(/^#{COMPRESSION_VAR_KEY_ROOT}(\d+)$/)[1]}"] : nil end |
#hcomp_scale=(scale) ⇒ Object
Set the hcompress scale if the image is compressed using hcompress.
936 937 938 |
# File 'lib/rfits/rfits.rb', line 936 def hcomp_scale=(scale) IO::Proxy.fits_set_hcomp_scale(self.file.io, scale.to_i) end |
#hcomp_smooth ⇒ Object
Get the hcompress smoothing factor if the image is compressed using hcompress.
941 942 943 944 945 946 947 948 |
# File 'lib/rfits/rfits.rb', line 941 def hcomp_smooth reset_position() zname_name, zname_value, zname_comment = self.header.find { |name, value, comment| name.match(/^#{COMPRESSION_VAR_KEY_ROOT}/) and value == COMPRESSION_SMOOTH_NAME_VALUE } zname_name ? self.header["#{COMPRESSION_VAR_VAL_ROOT}#{zname_name.match(/^#{COMPRESSION_VAR_KEY_ROOT}(\d+)$/)[1]}"] : nil end |
#hcomp_smooth=(smooth) ⇒ Object
Set the hcompress smoothing factor if the image is compressed using hcompress.
951 952 953 |
# File 'lib/rfits/rfits.rb', line 951 def hcomp_smooth=(smooth) IO::Proxy.fits_set_hcomp_smooth(self.file.io, smooth.to_i) end |
#noise_bits ⇒ Object
Get the noise bits for the compressed image.
911 912 913 914 915 916 917 918 |
# File 'lib/rfits/rfits.rb', line 911 def noise_bits reset_position() zname_name, zname_value, zname_comment = self.header.find { |name, value, comment| name.match(/^#{COMPRESSION_VAR_KEY_ROOT}/) and value == COMPRESSION_NOISE_BIT_NAME_VALUE } zname_name ? self.header["#{COMPRESSION_VAR_VAL_ROOT}#{zname_name.match(/^#{COMPRESSION_VAR_KEY_ROOT}(\d+)$/)[1]}"] : nil end |
#noise_bits=(bits) ⇒ Object
Set the noise bits for the compressed image.
921 922 923 |
# File 'lib/rfits/rfits.rb', line 921 def noise_bits=(bits) IO::Proxy.fits_set_noise_bits(self.file.io, bits.to_i) end |
#tile_dim ⇒ Object
Get the tile dimensions for the compressed image.
893 894 895 896 897 898 899 900 901 902 |
# File 'lib/rfits/rfits.rb', line 893 def tile_dim reset_position() tile_dims = [] (1..self.header[COMPRESSION_DIM_KEY]).each do |i| tile_dims << self.header["#{COMPRESSION_TILE_KEY_ROOT}#{i}"] end tile_dims end |
#tile_dim=(tilesizes) ⇒ Object
Set the tile dimensions for the compressed image.
image.tile_dim = [5, 5]
906 907 908 |
# File 'lib/rfits/rfits.rb', line 906 def tile_dim=(tilesizes) IO::Proxy.fits_set_tile_dim(self.file.io, tilesizes.size, tilesizes) end |