Class: CMORizer::Step::BaseStep

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(next_step) ⇒ BaseStep

Returns a new instance of BaseStep.



9
10
11
12
13
14
15
16
# File 'lib/step.rb', line 9

def initialize(next_step)
  @next_step = next_step
  @available_inputs = {}
  @forbid_inplace = false
  @initial_prefix = nil
  @needs_to_run = true
  @resultpath = nil
end

Instance Attribute Details

#forbid_inplace=(value) ⇒ Object (writeonly)

Sets the attribute forbid_inplace

Parameters:

  • value

    the value to set the attribute forbid_inplace to.



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

def forbid_inplace=(value)
  @forbid_inplace = value
end

#initial_prefix=(value) ⇒ Object (writeonly)

Sets the attribute initial_prefix

Parameters:

  • value

    the value to set the attribute initial_prefix to.



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

def initial_prefix=(value)
  @initial_prefix = value
end

#needs_to_run=(value) ⇒ Object (writeonly)

Sets the attribute needs_to_run

Parameters:

  • value

    the value to set the attribute needs_to_run to.



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

def needs_to_run=(value)
  @needs_to_run = value
end

#resultpathObject (readonly)

Returns the value of attribute resultpath.



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

def resultpath
  @resultpath
end

Instance Method Details

#add_input(input, years, number_of_eventual_input_years, should_process) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/step.rb', line 35

def add_input(input, years, number_of_eventual_input_years, should_process)
  @available_inputs[years] = input
  
  # some steps might be able to process each file as soon as it arrives
  # others, like merge, might require the maximum number of files to be available
  if can_process?(number_of_eventual_input_years)
    sorted_years_arrays = @available_inputs.keys.sort
    sorted_inputs = @available_inputs.values_at(*sorted_years_arrays)

    sorted_years = sorted_years_arrays.flatten
    @resultpath = create_outpath(*sorted_inputs)
    process(sorted_inputs, sorted_years, @resultpath) if should_process
    results, result_years = [@resultpath], sorted_years
    
    if results && @next_step
      results.each_index do |i|
        @next_step.add_input(results[i], [result_years[i]], number_of_eventual_input_years, should_process)
      end
    end
    @available_inputs.clear
  end
end

#create_outpath(*inpaths) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/step.rb', line 103

def create_outpath(*inpaths)
  step_suffix = self.class.to_s.split('::').last
  step_suffix = truncate_string(step_suffix)        
  
  if @initial_prefix
    prefix = "#{@initial_prefix}"
  else
    prefix = File.basename(inpaths[0])
  end

  # keep filename less than 255 chars, as most systems can not deal with more
  outname = "#{prefix}.#{step_suffix}"
  
  File.join @outdir, outname
end

#file_commandsObject



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

def file_commands
  raise "overwrite with concrete implementation for #{self.class} which returns one or many FileCommand objects"
end

#set_info(outdir:, grid_description_file:, global_attributes:, fesom_variable_name:, fesom_variable_frequency:, fesom_unit:, out_unit:, variable_id:, description:, standard_name:, out_cell_methods:, out_cell_measures:) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/step.rb', line 19

def set_info(outdir:, grid_description_file:, global_attributes:, fesom_variable_name:, fesom_variable_frequency:, fesom_unit:, out_unit:, variable_id:, description:, standard_name:, out_cell_methods:, out_cell_measures:)
  @outdir = outdir
  @grid_description_file = grid_description_file
  @global_attributes = global_attributes
  @fesom_variable_name = fesom_variable_name
  @fesom_variable_frequency = fesom_variable_frequency
  @fesom_unit = fesom_unit
  @out_unit = out_unit
  @variable_id = variable_id
  @description = description
  @standard_name = standard_name
  @out_cell_methods = out_cell_methods
  @out_cell_measures = out_cell_measures
end

#truncate_string(s) ⇒ Object

truncate to 10 characters so we do not get too long file names (apparently 255 chars max on mistral) remove characters from the middle to make the result somewhat more readable



93
94
95
96
97
98
99
100
# File 'lib/step.rb', line 93

def truncate_string(s)
  chars = s.chars
  loop do
    break if chars.size < 11
    chars.slice! 6
  end
  chars.join
end