Class: AstroSubframeOrganizer::FileMetadata

Inherits:
Object
  • Object
show all
Defined in:
lib/astro_subframe_organizer/file_metadata.rb

Overview

Value object representing parsed metadata from an astrophotography file

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#binObject (readonly)

Returns the value of attribute bin.



7
8
9
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 7

def bin
  @bin
end

#cameraObject

Returns the value of attribute camera.



6
7
8
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 6

def camera
  @camera
end

#ccd_tempObject (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_atObject (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_flatObject

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

#exposureObject (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_formatObject (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

#filenameObject (readonly)

Returns the value of attribute filename.



7
8
9
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 7

def filename
  @filename
end

#filterObject

Returns the value of attribute filter.



6
7
8
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 6

def filter
  @filter
end

#gainObject (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_indexObject (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

#isoObject (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_paneObject (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

#pathObject

Returns the value of attribute path.



6
7
8
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 6

def path
  @path
end

#rotationObject (readonly)

Returns the value of attribute rotation.



7
8
9
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 7

def rotation
  @rotation
end

#targetObject

Returns the value of attribute target.



6
7
8
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 6

def target
  @target
end

#telescopeObject

Returns the value of attribute telescope.



6
7
8
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 6

def telescope
  @telescope
end

#typeObject

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

Returns:

  • (Boolean)


111
112
113
114
115
116
117
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 111

def already_moved?(target_path)
  p1 = File.expand_path(path)
  p2 = File.expand_path(target_path)

  # On Windows, path comparison should be case-insensitive
  Gem.win_platform? ? p1.casecmp?(p2) : p1 == p2
end

#current_dirObject

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

Returns:

  • (Boolean)


71
72
73
# File 'lib/astro_subframe_organizer/file_metadata.rb', line 71

def dark_flat?
  dark_flat
end

#flatset_idObject

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

Returns:

  • (Boolean)


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

#monthObject

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_rotationObject



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