Class: Atmospheris::Iso5878::RiceDistribution

Inherits:
Object
  • Object
show all
Defined in:
lib/atmospheris/iso5878/rice_distribution.rb

Overview

Encapsulates a single Rice (circular normal) distribution instance with fixed parameters (Vr, sigma_r).

Wraps the existing module-level methods (bessel_i0, rice_pdf, etc.) in an object-oriented interface, enabling lazy caching and clean composition by WindObservation.

Examples:

dist = RiceDistribution.new(vr: 3.9, sigma_r: 5.9)
dist.mean           # => 6.03
dist.quantile(0.99) # => 14.7
dist.percentile_bounds

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vr:, sigma_r:) ⇒ RiceDistribution

Returns a new instance of RiceDistribution.

Parameters:

  • vr (Numeric)

    magnitude of vector mean wind (m/s)

  • sigma_r (Numeric)

    standard deviation of vector mean wind (m/s)



22
23
24
25
26
# File 'lib/atmospheris/iso5878/rice_distribution.rb', line 22

def initialize(vr:, sigma_r:)
  @vr = vr.to_f
  @sigma_r = sigma_r.to_f
  @sigma = @sigma_r / Math.sqrt(2)
end

Instance Attribute Details

#sigmaObject (readonly)

Returns the value of attribute sigma.



18
19
20
# File 'lib/atmospheris/iso5878/rice_distribution.rb', line 18

def sigma
  @sigma
end

#sigma_rObject (readonly)

Returns the value of attribute sigma_r.



18
19
20
# File 'lib/atmospheris/iso5878/rice_distribution.rb', line 18

def sigma_r
  @sigma_r
end

#vrObject (readonly)

Returns the value of attribute vr.



18
19
20
# File 'lib/atmospheris/iso5878/rice_distribution.rb', line 18

def vr
  @vr
end

Instance Method Details

#cdf(x) ⇒ Float

Cumulative distribution function at wind speed x.

Parameters:

  • x (Numeric)

    wind speed (m/s)

Returns:

  • (Float)

    probability in [0, 1]



38
39
40
# File 'lib/atmospheris/iso5878/rice_distribution.rb', line 38

def cdf(x)
  Iso5878.rice_cdf(x, vr, sigma_r)
end

#meanFloat

Analytical mean of the Rice distribution (Eq. 4). This is the calculated scalar mean wind speed Vsc.

Returns:

  • (Float)

    mean wind speed (m/s)



52
53
54
# File 'lib/atmospheris/iso5878/rice_distribution.rb', line 52

def mean
  @mean ||= Iso5878.rice_mean(vr, sigma_r)
end

#pdf(nu) ⇒ Float

Probability density at wind speed nu.

Parameters:

  • nu (Numeric)

    wind speed (m/s)

Returns:

  • (Float)


31
32
33
# File 'lib/atmospheris/iso5878/rice_distribution.rb', line 31

def pdf(nu)
  Iso5878.rice_pdf(nu, vr, sigma_r)
end

#percentile_boundsHash{Integer => PercentilePair}

Percentile bounds as defined in ISO 5878. Returns hash mapping percentage to PercentilePair (low/high).

Returns:



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/atmospheris/iso5878/rice_distribution.rb', line 59

def percentile_bounds
  @percentile_bounds ||= {
    1 => PercentilePair.new(
      low: quantile(0.01),
      high: quantile(0.99)
    ),
    10 => PercentilePair.new(
      low: quantile(0.10),
      high: quantile(0.90)
    ),
    20 => PercentilePair.new(
      low: quantile(0.20),
      high: quantile(0.80)
    )
  }
end

#quantile(p) ⇒ Float

Inverse CDF (quantile function) for probability p.

Parameters:

  • p (Numeric)

    probability in (0, 1)

Returns:

  • (Float)

    wind speed (m/s)



45
46
47
# File 'lib/atmospheris/iso5878/rice_distribution.rb', line 45

def quantile(p)
  Iso5878.rice_inv_cdf(p, vr, sigma_r)
end