Class: NumRu::GAnalysis::BetaPlane

Inherits:
Object
  • Object
show all
Defined in:
lib/numru/ganalysis/beta_plane.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lat0_or_latary) ⇒ BetaPlane

Returns a new instance of BetaPlane.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/numru/ganalysis/beta_plane.rb', line 11

def initialize(lat0_or_latary)
  if lat0_or_latary.respond_to?(:mean)
    @lat0 = lat0_or_latary.mean.to_f
  else
    @lat0 = lat0_or_latary
  end
  @phi0 = lat0 * Math::PI / 180.0
  @f0 = 2 * Planet.omega * Math::sin(phi0)
  @beta = 2 * Planet.omega * Math::cos(phi0) / Planet::radius
  @a = Planet::radius 
end

Instance Attribute Details

#aObject (readonly)

Returns the value of attribute a.



23
24
25
# File 'lib/numru/ganalysis/beta_plane.rb', line 23

def a
  @a
end

#betaObject (readonly)

Returns the value of attribute beta.



23
24
25
# File 'lib/numru/ganalysis/beta_plane.rb', line 23

def beta
  @beta
end

#f0Object (readonly)

Returns the value of attribute f0.



23
24
25
# File 'lib/numru/ganalysis/beta_plane.rb', line 23

def f0
  @f0
end

#lat0Object (readonly)

Returns the value of attribute lat0.



23
24
25
# File 'lib/numru/ganalysis/beta_plane.rb', line 23

def lat0
  @lat0
end

#phi0Object (readonly)

Returns the value of attribute phi0.



23
24
25
# File 'lib/numru/ganalysis/beta_plane.rb', line 23

def phi0
  @phi0
end

Instance Method Details

#div_h(u, v, x = nil, y = nil) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/numru/ganalysis/beta_plane.rb', line 59

def div_h(u, v, x=nil, y=nil)
  lond, latd = Planet::find_lon_lat_dims(u)
  x, y = get_x_y(u) if !x || !y
  bc = GPhys::Derivative::CYCLIC_OR_LINEAR
  gx = u.cderiv(lond,bc,x)
  gy = v.threepoint_O2nd_deriv(latd,bc,y)
  div = gx + gy
  div.name = "div"
  div.long_name = "div(#{u.long_name},#{v.long_name})"
  div
end

#get_x_y(gphys) ⇒ Object

Derive the x and y from the lon and lat coordinates

ARGUMENTS

  • gphys (GPhys) : a GPhys object (having a lon&lat as coordinates)

RETURN VALUE

  • x, y

    (GPhys objects)



32
33
34
35
36
37
38
39
# File 'lib/numru/ganalysis/beta_plane.rb', line 32

def get_x_y(gphys)
  lam, phi, = Planet::get_lambda_phi(gphys)
  x = lam * (@a * Math::cos(@phi0))
  x.units = @a.units
  y = ( phi - @phi0 ) * @a
  y.units = @a.units
  [x, y]
end

#grad_h(gphys, x = nil, y = nil) ⇒ Object

Horizontal gradient

ARGUMENTS

  • gphys (GPhys) : a GPhys object (having a lon&lat as coordinates)

  • x [GPhys or nil] : the x coordinate, which can be obtained by the get_x_y method. If nil, internally calculated by get_x_y method.

  • y [GPhys or nil] : the y coordinate, which can be obtained by the get_x_y method. If nil, internally calculated by get_x_y method.

RETURN VALUE

  • grad_x, grad_y

    (GPhys objects)



52
53
54
55
56
57
# File 'lib/numru/ganalysis/beta_plane.rb', line 52

def grad_h(gphys, x=nil, y=nil)
  lond, latd = Planet::find_lon_lat_dims(gphys)
  x, y = get_x_y(gphys) if !x || !y
  bc = GPhys::Derivative::CYCLIC_OR_LINEAR
  [ gphys.cderiv(lond,bc,x), gphys.threepoint_O2nd_deriv(latd,bc,y) ]
end

#grad_x(gphys, x = nil) ⇒ Object

Gradient in the x direction

ARGUMENTS

  • gphys (GPhys) : a GPhys object (having a longitude as a coordinate)

  • x [GPhys or nil] : the x coordinate, which can be obtained by the get_x_y method. If nil, internally calculated by get_x_y method.

RETURN VALUE

  • grad_x (GPhys objects)



80
81
82
83
84
# File 'lib/numru/ganalysis/beta_plane.rb', line 80

def grad_x(gphys, x=nil)
  lond, latd = Planet::find_lon_lat_dims
  x, = get_x_y(gphys) if !x
  gphys.cderiv(lond,x)
end

#grad_y(gphys, y = nil) ⇒ Object

Gradient in the y direction

ARGUMENTS

  • gphys (GPhys) : a GPhys object (having a latitude as a coordinate)

  • y [GPhys or nil] : the y coordinate, which can be obtained by the get_x_y method. If nil, internally calculated by get_x_y method.

RETURN VALUE

  • grad_y (GPhys objects)



95
96
97
98
99
# File 'lib/numru/ganalysis/beta_plane.rb', line 95

def grad_y(gphys, y=nil)
  lond, latd = Planet::find_lon_lat_dims
  x, y = get_x_y(gphys) if !y
  gphys.threepoint_O2nd_deriv(latd,y)
end