Class: FesomYearlyOutputFile
- Inherits:
-
Object
- Object
- FesomYearlyOutputFile
- Defined in:
- lib/fesom_file.rb
Overview
i.e. a netcdf file with one year of fesom output
Instance Attribute Summary collapse
-
#approx_interval ⇒ Object
readonly
Returns the value of attribute approx_interval.
-
#frequency ⇒ Object
readonly
Returns the value of attribute frequency.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#time_method ⇒ Object
readonly
Returns the value of attribute time_method.
-
#unit ⇒ Object
readonly
Returns the value of attribute unit.
-
#variable_id ⇒ Object
readonly
Returns the value of attribute variable_id.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Class Method Summary collapse
-
.timestep_delta_from_cdl(cdl) ⇒ Object
fetch time axis from native fesom file CDL (i.e. ncdump -v time).
-
.unit_from_cdl(variable_id, cdl) ⇒ Object
variable unit from native fesom file CDL (i.e. ncdump).
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(variable_id:, year:, month:, day:, path:) ⇒ FesomYearlyOutputFile
constructor
A new instance of FesomYearlyOutputFile.
- #to_s ⇒ Object
Constructor Details
#initialize(variable_id:, year:, month:, day:, path:) ⇒ FesomYearlyOutputFile
Returns a new instance of FesomYearlyOutputFile.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fesom_file.rb', line 22 def initialize(variable_id:, year:, month:, day:, path:) @variable_id = variable_id @year = year.to_i @path = path begin cdl = NcdumpCache::ncdump_h(@variable_id, @path) @frequency = frequency_from_netcdf @unit = FesomYearlyOutputFile.unit_from_cdl variable_id, cdl rescue RuntimeError => e raise "file #{path}: #{e.}" end raise "can not determine unit for variable <#{variable_id}> of file <#{@path}>" unless @unit @approx_interval = Frequency.for_name(@frequency).approx_interval @time_method = Frequency.for_name(@frequency).time_method end |
Instance Attribute Details
#approx_interval ⇒ Object (readonly)
Returns the value of attribute approx_interval.
20 21 22 |
# File 'lib/fesom_file.rb', line 20 def approx_interval @approx_interval end |
#frequency ⇒ Object (readonly)
Returns the value of attribute frequency.
20 21 22 |
# File 'lib/fesom_file.rb', line 20 def frequency @frequency end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
20 21 22 |
# File 'lib/fesom_file.rb', line 20 def path @path end |
#time_method ⇒ Object (readonly)
Returns the value of attribute time_method.
20 21 22 |
# File 'lib/fesom_file.rb', line 20 def time_method @time_method end |
#unit ⇒ Object (readonly)
Returns the value of attribute unit.
20 21 22 |
# File 'lib/fesom_file.rb', line 20 def unit @unit end |
#variable_id ⇒ Object (readonly)
Returns the value of attribute variable_id.
20 21 22 |
# File 'lib/fesom_file.rb', line 20 def variable_id @variable_id end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
20 21 22 |
# File 'lib/fesom_file.rb', line 20 def year @year end |
Class Method Details
.timestep_delta_from_cdl(cdl) ⇒ Object
fetch time axis from native fesom file CDL (i.e. ncdump -v time)
91 92 93 94 95 96 97 |
# File 'lib/fesom_file.rb', line 91 def self.timestep_delta_from_cdl(cdl) txt = cdl.split("// global attributes:").last match = /^.*?time.*/.match txt txt = match.to_s /(?<t0>\d+), (?<t1>\d+)/ =~ txt t1.to_f - t0.to_f end |
.unit_from_cdl(variable_id, cdl) ⇒ Object
variable unit from native fesom file CDL (i.e. ncdump)
51 52 53 54 55 |
# File 'lib/fesom_file.rb', line 51 def self.unit_from_cdl(variable_id, cdl) match = /#{variable_id}:units = "(?<unit>.+)"/.match cdl # there seems to be an error with rubys "".=~ as we do not get access to the unit variable then interpolating variable_id, using //.match seems to solve this return match[:unit] if match nil end |
Instance Method Details
#<=>(other) ⇒ Object
40 41 42 |
# File 'lib/fesom_file.rb', line 40 def <=>(other) "#{@variable_id} #{@approx_interval} #{@frequency} #{@time_method} #{@year}" <=> "#{other.variable_id} #{other.approx_interval} #{other.frequency} #{other.time_method} #{other.year}" end |
#to_s ⇒ Object
45 46 47 |
# File 'lib/fesom_file.rb', line 45 def to_s "#{@variable_id} '#{@unit}' #{@frequency} #{@time_method} #{@year}" end |