Class: Atmospheris::Export::PressureAttrs

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Includes:
Utils
Defined in:
lib/atmospheris/export/pressure_attrs.rb

Direct Known Subclasses

Iso25331985::PressureAttrs

Instance Method Summary collapse

Methods included from Utils

#ft_to_m, #m_to_ft, #round_to_sig_figs, #values_in_m_ft

Instance Method Details

#realize_altitudes(hgmm, hgmf, hgpm, hgpf, precision: :reduced) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/atmospheris/export/pressure_attrs.rb', line 38

def realize_altitudes(hgmm, hgmf, hgpm, hgpf, precision: :reduced)
  self.geometric_altitudes = [
    UnitValueFloat.new(
      value: precision == :reduced ? hgmm.round(1) : hgmm,
      unitsml: "m"
    ),
    UnitValueFloat.new(
      value: precision == :reduced ? hgmf.round : hgmf,
      unitsml: "ft"
    )
  ]

  self.geopotential_altitudes = [
    UnitValueFloat.new(
      value: precision == :reduced ? hgpm.round(1) : hgpm,
      unitsml: "m"
    ),
    UnitValueFloat.new(
      value: precision == :reduced ? hgpf.round : hgpf,
      unitsml: "ft"
    )
  ]
end

#realize_pressures(input, unit:) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/atmospheris/export/pressure_attrs.rb', line 62

def realize_pressures(input, unit:)
  self.pressures = case unit
                   when :mbar
                     [
                       UnitValueFloat.new(value: input, unitsml: "mbar"),
                       UnitValueFloat.new(
                         value: Isa::NormalPrecision.instance.mbar_to_mmhg(input),
                         unitsml: "mm_Hg"
                       )
                     ]
                   when :mmhg
                     [
                       UnitValueFloat.new(
                         value: Isa::NormalPrecision.instance.mmhg_to_mbar(input),
                         unitsml: "mbar"
                       ),
                       UnitValueFloat.new(value: input, unitsml: "mm_Hg")
                     ]
                   else
                     raise ArgumentError,
                           "Invalid unit: #{unit}. Use :mbar or :mmhg."
                   end
end

#set_pressure(value:, unit: :mbar, precision: :reduced) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/atmospheris/export/pressure_attrs.rb', line 25

def set_pressure(value:, unit: :mbar, precision: :reduced)
  method_name = "geopotential_altitude_from_pressure_#{unit}"
  gp_h_m = Isa::NormalPrecision.instance.send(method_name, value)
  gp_h_ft = m_to_ft(gp_h_m)
  gm_h_m = Isa::NormalPrecision.instance.geometric_altitude_from_geopotential(gp_h_m)
  gm_h_ft = m_to_ft(gm_h_m)

  realize_altitudes(gm_h_m, gm_h_ft, gp_h_m, gp_h_ft, precision: precision)
  realize_pressures(value, unit: unit)

  self
end