Class: AstroSubframeOrganizer::Utils::FitsStripper
- Inherits:
-
Object
- Object
- AstroSubframeOrganizer::Utils::FitsStripper
- Defined in:
- lib/astro_subframe_organizer/utils/fits_stripper.rb
Overview
Strips image data and identifying location information from FITS files. The resulting file is valid FITS with NAXIS set to 0, meaning no data array follows the header block.
Location headers stripped: SITELAT, SITELONG, SITEELEV, RA, DEC, OBJCTRA, OBJCTDEC, CRVAL1, CRVAL2, CRPIX1, CRPIX2, and WCS keywords.
Constant Summary collapse
- BLOCK_SIZE =
2880- CARD_SIZE =
80- CARDS_PER_BLOCK =
BLOCK_SIZE / CARD_SIZE
- LOCATION_HEADERS =
%w[ SITELAT SITELONG SITEELEV RA DEC OBJCTRA OBJCTDEC ].freeze
- WCS_PREFIXES =
WCS (World Coordinate System) headers that encode pointing information
%w[CRVAL CRPIX CD1_ CD2_ A_ B_ AP_ BP_ CTYPE CUNIT].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #already_stripped? ⇒ Boolean
-
#initialize(input_path, output_path = nil) ⇒ FitsStripper
constructor
A new instance of FitsStripper.
- #strip ⇒ Object
Constructor Details
#initialize(input_path, output_path = nil) ⇒ FitsStripper
Returns a new instance of FitsStripper.
33 34 35 36 |
# File 'lib/astro_subframe_organizer/utils/fits_stripper.rb', line 33 def initialize(input_path, output_path = nil) @input_path = input_path @output_path = output_path || input_path # default to in-place end |
Class Method Details
.strip(input_path, output_path = nil) ⇒ Object
29 30 31 |
# File 'lib/astro_subframe_organizer/utils/fits_stripper.rb', line 29 def self.strip(input_path, output_path = nil) new(input_path, output_path).strip end |
Instance Method Details
#already_stripped? ⇒ Boolean
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/astro_subframe_organizer/utils/fits_stripper.rb', line 38 def already_stripped? File.open(@input_path, 'rb') do |f| loop do block = f.read(BLOCK_SIZE) return false unless block&.length == BLOCK_SIZE cards = block.scan(/.{#{CARD_SIZE}}/mo) naxis_card = cards.find { |c| c.start_with?('NAXIS =') } return naxis_card.match?(/=\s+0\b/) if naxis_card return false if header_end?(block) end end false end |
#strip ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/astro_subframe_organizer/utils/fits_stripper.rb', line 54 def strip header_blocks = read_header_blocks patched = patch_naxis(header_blocks) patched = strip_location_headers(patched) File.binwrite(@output_path, patched) @output_path end |