Class: AstroSubframeOrganizer::FileMetadata
- Inherits:
-
Object
- Object
- AstroSubframeOrganizer::FileMetadata
- Defined in:
- lib/astro_subframe_organizer/file_metadata.rb
Overview
Value object representing parsed metadata from an astrophotography file
Instance Attribute Summary collapse
-
#bin ⇒ Object
readonly
Returns the value of attribute bin.
-
#camera ⇒ Object
Returns the value of attribute camera.
-
#ccd_temp ⇒ Object
readonly
Returns the value of attribute ccd_temp.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#dark_flat ⇒ Object
Returns the value of attribute dark_flat.
-
#exposure ⇒ Object
readonly
Returns the value of attribute exposure.
-
#file_format ⇒ Object
readonly
Returns the value of attribute file_format.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#filter ⇒ Object
Returns the value of attribute filter.
-
#gain ⇒ Object
readonly
Returns the value of attribute gain.
-
#image_index ⇒ Object
readonly
Returns the value of attribute image_index.
-
#iso ⇒ Object
readonly
Returns the value of attribute iso.
-
#mosaic_pane ⇒ Object
readonly
Returns the value of attribute mosaic_pane.
-
#path ⇒ Object
Returns the value of attribute path.
-
#rotation ⇒ Object
readonly
Returns the value of attribute rotation.
-
#target ⇒ Object
Returns the value of attribute target.
-
#telescope ⇒ Object
Returns the value of attribute telescope.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
-
.from_parsed_data(parsed_data) ⇒ Object
Factory method to create FileMetadata from parsed parser result.
Instance Method Summary collapse
-
#already_moved?(target_path) ⇒ Boolean
True if the path is already at target destination.
-
#current_dir ⇒ Object
Current directory of the file.
- #dark_flat? ⇒ Boolean
-
#flatset_id ⇒ Object
The date formatted like ‘20220508’.
-
#initialize(type:, path:, filename:, file_format:, exposure: nil, bin: nil, camera: nil, iso: nil, gain: nil, created_at: nil, ccd_temp: nil, image_index: nil, target: nil, telescope: nil, filter: nil, dark_flat: false, mosaic_pane: nil, rotation: nil) ⇒ FileMetadata
constructor
rubocop:disable Metrics/ParameterLists.
-
#maybe_flat_dark? ⇒ Boolean
True if the dark is likely a dark flat and hasn’t already been organized as dark flat.
-
#month ⇒ Object
The Year-Month in which image was taken.
- #normalized_rotation ⇒ Object
- #rounded_ccd_temp(tolerance: Config.temperature_tolerance) ⇒ Object
Constructor Details
#initialize(type:, path:, filename:, file_format:, exposure: nil, bin: nil, camera: nil, iso: nil, gain: nil, created_at: nil, ccd_temp: nil, image_index: nil, target: nil, telescope: nil, filter: nil, dark_flat: false, mosaic_pane: nil, rotation: nil) ⇒ FileMetadata
rubocop:disable Metrics/ParameterLists
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 19 def initialize( # rubocop:disable Metrics/ParameterLists type:, path:, filename:, file_format:, exposure: nil, bin: nil, camera: nil, iso: nil, gain: nil, created_at: nil, ccd_temp: nil, image_index: nil, target: nil, telescope: nil, filter: nil, dark_flat: false, mosaic_pane: nil, rotation: nil ) @type = type @path = path @filename = filename @file_format = file_format @exposure = exposure @bin = bin @camera = camera @iso = iso @gain = gain @created_at = created_at @ccd_temp = ccd_temp @image_index = image_index @target = target @telescope = telescope @filter = filter @dark_flat = dark_flat @mosaic_pane = mosaic_pane @rotation = rotation end |
Instance Attribute Details
#bin ⇒ Object (readonly)
Returns the value of attribute bin.
7 8 9 |
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 7 def bin @bin end |
#camera ⇒ Object
Returns the value of attribute camera.
6 7 8 |
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 6 def camera @camera end |
#ccd_temp ⇒ Object (readonly)
Returns the value of attribute ccd_temp.
7 8 9 |
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 7 def ccd_temp @ccd_temp end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
7 8 9 |
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 7 def created_at @created_at end |
#dark_flat ⇒ Object
Returns the value of attribute dark_flat.
6 7 8 |
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 6 def dark_flat @dark_flat end |
#exposure ⇒ Object (readonly)
Returns the value of attribute exposure.
7 8 9 |
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 7 def exposure @exposure end |
#file_format ⇒ Object (readonly)
Returns the value of attribute file_format.
7 8 9 |
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 7 def file_format @file_format end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
7 8 9 |
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 7 def filename @filename end |
#filter ⇒ Object
Returns the value of attribute filter.
6 7 8 |
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 6 def filter @filter end |
#gain ⇒ Object (readonly)
Returns the value of attribute gain.
7 8 9 |
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 7 def gain @gain end |
#image_index ⇒ Object (readonly)
Returns the value of attribute image_index.
7 8 9 |
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 7 def image_index @image_index end |
#iso ⇒ Object (readonly)
Returns the value of attribute iso.
7 8 9 |
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 7 def iso @iso end |
#mosaic_pane ⇒ Object (readonly)
Returns the value of attribute mosaic_pane.
7 8 9 |
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 7 def mosaic_pane @mosaic_pane end |
#path ⇒ Object
Returns the value of attribute path.
6 7 8 |
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 6 def path @path end |
#rotation ⇒ Object (readonly)
Returns the value of attribute rotation.
7 8 9 |
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 7 def rotation @rotation end |
#target ⇒ Object
Returns the value of attribute target.
6 7 8 |
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 6 def target @target end |
#telescope ⇒ Object
Returns the value of attribute telescope.
6 7 8 |
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 6 def telescope @telescope end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 6 def type @type end |
Class Method Details
.from_parsed_data(parsed_data) ⇒ Object
Factory method to create FileMetadata from parsed parser result
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 46 def self.from_parsed_data(parsed_data) return parsed_data if parsed_data.instance_of? FileMetadata new( type: parsed_data[:type], path: parsed_data[:path], filename: parsed_data[:filename], file_format: parsed_data[:file_format], target: parsed_data[:target], mosaic_pane: parsed_data[:mosaic_pane], exposure: parsed_data[:exposure], bin: parsed_data[:bin], camera: parsed_data[:camera], iso: parsed_data[:iso], gain: parsed_data[:gain], created_at: parsed_data[:created_at], ccd_temp: parsed_data[:ccd_temp], image_index: parsed_data[:image_index], telescope: parsed_data[:telescope], filter: parsed_data[:filter], dark_flat: parsed_data[:dark_flat] || false, rotation: parsed_data[:rotation], ) end |
Instance Method Details
#already_moved?(target_path) ⇒ Boolean
True if the path is already at target destination
111 112 113 114 115 116 117 |
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 111 def already_moved?(target_path) p1 = File.(path) p2 = File.(target_path) # On Windows, path comparison should be case-insensitive Gem.win_platform? ? p1.casecmp?(p2) : p1 == p2 end |
#current_dir ⇒ Object
Current directory of the file
106 107 108 |
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 106 def current_dir File.dirname(path) end |
#dark_flat? ⇒ Boolean
71 72 73 |
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 71 def dark_flat? dark_flat end |
#flatset_id ⇒ Object
The date formatted like ‘20220508’. If pictures taken in latter half of day, assume flatset will be generated the next day
92 93 94 95 96 97 98 |
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 92 def flatset_id if type == 'Light' && created_at.hour >= 12 created_at.next_day.strftime('%Y%m%d') else created_at.strftime('%Y%m%d') end end |
#maybe_flat_dark? ⇒ Boolean
True if the dark is likely a dark flat and hasn’t already been organized as dark flat
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 76 def maybe_flat_dark? exp_val = exposure.to_f exp_units = exposure.gsub(exp_val.to_s, '') exp_in_seconds = case exp_units when 's' exp_val when 'ms' exp_val / 1000.0 when 'us' exp_val / 1_000_000.0 end type == 'Dark' && exp_in_seconds <= 10.0 && !dark_flat? end |
#month ⇒ Object
The Year-Month in which image was taken. Useful for grouping darks by season
101 102 103 |
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 101 def month created_at.strftime('%Y-%m') end |
#normalized_rotation ⇒ Object
128 129 130 131 132 133 |
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 128 def normalized_rotation return nil if rotation.nil? angle = rotation.to_i % 180 format('%d', angle) end |
#rounded_ccd_temp(tolerance: Config.temperature_tolerance) ⇒ Object
119 120 121 122 123 124 125 126 |
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 119 def rounded_ccd_temp(tolerance: Config.temperature_tolerance) return nil if ccd_temp.nil? temp_value = ccd_temp.to_f rounded = (temp_value / tolerance).round * tolerance # Master darks output by PixInsight have CCD-TEMP formatted `CCD-TEMP_-10.` for some reason. format('%.1fC', rounded).gsub('0C', '') end |