Class: AstroSubframeOrganizer::Astrophoto

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Logging
Defined in:
lib/astro_subframe_organizer/astrophoto.rb

Overview

Class describing the properties of the file that we can determine from the filename generated by the ASIAir. Depending on your camera and your filter setup, the file structure may be different. This script was written for use with the ASIAir Plus version 1.9, using a Canon EOS 1500 (T7) DSLR camera with all the filename metadata turned on. You may have more metadata, or a different order of metadata depending on which camera setup you have, or if you have an EFW (electronic filter wheel). In that case, you will need to change the order or add more properties in the initialize method so that your data is properly parsed. You will also likely want to change your ‘target_dir` for each type so that it organizes your data properly.

Constant Summary collapse

TYPES =
[
  DARK = 'Dark',
  FLAT = 'Flat',
  LIGHT = 'Light',
  BIAS = 'Bias',
].freeze

Instance Method Summary collapse

Methods included from Logging

#logger

Constructor Details

#initialize(path) ⇒ Astrophoto

Returns a new instance of Astrophoto.



53
54
55
# File 'lib/astro_subframe_organizer/astrophoto.rb', line 53

def initialize(path)
  @file_parser = FilenameParser.for_file(path)
end

Instance Method Details

#already_moved?Boolean

True if the path is already at the target destination. We don’t need to move or ask anything about these files.

Returns:

  • (Boolean)


98
99
100
# File 'lib/astro_subframe_organizer/astrophoto.rb', line 98

def already_moved?
  .already_moved?(target_path)
end

#camera=(value) ⇒ Object



67
68
69
70
71
# File 'lib/astro_subframe_organizer/astrophoto.rb', line 67

def camera=(value)
  @target_dir = nil
  @target_path = nil
  .camera = value
end

#current_dirObject

The current directory of the file. If this is different from the target directory, you will be asked whether you want to move it or not.



92
93
94
# File 'lib/astro_subframe_organizer/astrophoto.rb', line 92

def current_dir
  File.dirname(path)
end

#file_metadataObject



57
58
59
# File 'lib/astro_subframe_organizer/astrophoto.rb', line 57

def 
  @file_metadata ||= @file_parser.parse
end

#filter=(value) ⇒ Object



73
74
75
76
77
# File 'lib/astro_subframe_organizer/astrophoto.rb', line 73

def filter=(value)
  @target_dir = nil
  @target_path = nil
  .filter = value
end

#move(is_dry_run, bar = nil) ⇒ Object

Performs the move. If ‘is_dry_run` is true, it will not move the files, but will output the file’s current location and target location so you can verify it is correct before performing the actual move.



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/astro_subframe_organizer/astrophoto.rb', line 105

def move(is_dry_run, bar = nil)
  destination = target_path
  dest_dir    = target_dir

  # Logic to create directory
  FileUtils.mkdir_p(dest_dir) unless is_dry_run || File.exist?(dest_dir)

  if File.exist?(destination)
    # NOTE: Frequent logging can cause the progress bar to flicker or move
    msg = "File already exists #{destination}. Skipping..."
    bar ? bar.log(msg) : logger.warn(msg)
  else
    FileUtils.move(path, destination, verbose: is_dry_run, noop: is_dry_run)
    self.path = destination unless is_dry_run
  end
end

#target_dirObject

The directory structure used to group and categorize the files, which will include useful grouping keywords for PixInsight’s WeightedBatchPreProcessing script.



81
82
83
# File 'lib/astro_subframe_organizer/astrophoto.rb', line 81

def target_dir
  @target_dir ||= File.join(current_dir, PathBuilder.build_for())
end

#target_pathObject

The full path where this file will be moved.



86
87
88
# File 'lib/astro_subframe_organizer/astrophoto.rb', line 86

def target_path
  @target_path ||= File.join(target_dir, filename)
end

#telescope=(value) ⇒ Object



61
62
63
64
65
# File 'lib/astro_subframe_organizer/astrophoto.rb', line 61

def telescope=(value)
  @target_dir = nil
  @target_path = nil
  .telescope = value
end