Parent

NumRu::GPhys

GPhys extension with GAnalysis::Fitting

Public Instance Methods

corelation(other, *dims) click to toggle source
# File ../../lib/numru/ganalysis/covariance.rb, line 93
def corelation(other, *dims)
  GAnalysis.corelation(self, other, *dims)
end
Also aliased as: correlation
correlation(other, *dims) click to toggle source
Alias for: corelation
covariance(other, *dims) click to toggle source
# File ../../lib/numru/ganalysis/covariance.rb, line 89
def covariance(other, *dims)
  GAnalysis.covariance(self, other, *dims)
end
eof(*args) click to toggle source
# File ../../lib/numru/ganalysis/eof.rb, line 229
def eof(*args)
  GAnalysis.eof(self, *args)
end
histogram(opts=Hash.new) click to toggle source
# File ../../lib/numru/ganalysis/histogram.rb, line 155
def histogram(opts=Hash.new)
  GAnalysis.histogram(self, opts)
end
Also aliased as: histogram1D
histogram1D(opts=Hash.new) click to toggle source
Alias for: histogram
least_square_fit(functions, ensemble_dims=nil, indep_dims=nil) click to toggle source

Least square fit of a linear combination of any functions (GPhys version).

This method calls GAnalysis::Fitting.least_square_fit in the GAnalysis::Fitting module. See its document for the details, usage, and predifined functions.

ARGUMENTS

The arguments are the same as the third to fifth arguemnts of GAnalysis::Fitting.least_square_fit except that ensemble_dims and indep_dims accept dimension specification by names (in Strings).

  • functions [Array of Procs] Proc objects to represent the functions, which accept the elements of grid_locs as the arguments (so the number of arguments fed is equal to the length of grid_locs). (Some predifined functions are available in GAnalysis::Fitting).

  • ensemble_dims (optional) [nil (defualt) or Array of Integers or Strings] When grid_locs.length < data.rank, this argument can be used to specify the dimensions that are not included in grid_locs and are used for ensemble averaging

  • indep_dims (optional) [nil (defualt) or Array of Integers or Strings] When grid_locs.length < data.rank, this argument can be used to specify the dimensions that are not included in grid_locs and are treated as independent, so the fitting is made for each of their component.

RETURN VALUES

[ c, bf, diff ]

where

  • c is a NArray containing the coefficients of the functions and the constant offset; its length is one greater than the number of functions because of the offset. It is 1D unless the indep_dims argument is used (see the examples below).

  • bf is a GPhys having the best fit grid point values. Its rank is equal to data.rank unless ensemble_dims are given; ensemble_dims are deleted unlike the return value of GAnalysis::Fitting.least_square_fit.

  • rms of the difference between the data and best fit

USAGE

See GAnalysis::Fitting.least_square_fit.

# File ../../lib/numru/ganalysis/fitting.rb, line 460
def least_square_fit(functions, ensemble_dims=nil, indep_dims=nil)

  #< preparation >

  no_fitting_dims = Array.new
  if ensemble_dims
    ensemble_dims = ensemble_dims.collect{|d| @grid.dim_index(d)}
    no_fitting_dims += ensemble_dims
  end
  if indep_dims
    indep_dims = indep_dims.collect{|d| @grid.dim_index(d)}
    no_fitting_dims += indep_dims
  end
  fitting_dims = (0...rank).collect{|i| i} - no_fitting_dims
  grid_locs = fitting_dims.collect{|d| coord(d).val}
  data = self.val

  #< fitting >
  c, bf, diff = GAnalysis::Fitting.least_square_fit(data, grid_locs, 
                                      functions, ensemble_dims, indep_dims)

  #< make a GPhys of the best fit >

  if !ensemble_dims
    grid = self.grid
  else
    axes = Array.new
    (0...rank).each{|d| 
      axes.push(self.axis(d)) unless ensemble_dims.include?(d)
    }
    grid = Grid.new(*axes)
    shape = bf.shape
    ensemble_dims.sort.reverse_each{|d| shape.delete_at(d)}
    bf = bf.reshape(*shape)
  end

  va = VArray.new(bf, self.data, self.name)
  bf = GPhys.new(grid, va)

  [c, bf, diff]
end
logp_coord_p2z(pdim=nil) click to toggle source

Convert the pressure coordinate in self to log-pressure height (after duplicating self)

Return value: a GPhys

# File ../../lib/numru/ganalysis/log_p.rb, line 84
def logp_coord_p2z(pdim=nil)
  pdim = GAnalysis::Met.find_prs_d(self) if !pdim
  p = self.coord(pdim)
  z = GAnalysis::LogP.p2z(p)
  ax = self.axis(pdim).copy
  ax.set_pos(z)
  ax.name = z.name
  grid = self.grid.copy.set_axis(pdim, ax)
  GPhys.new(grid,self.data)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.