../lib/numru/gphys/grid.rb

# class NumRU::Grid

A class to handle discretized grids of physical quantities.

## Class Methods

#### `Grid.new( *axes )`

  Constructor.

  RETURN VALUE

  - a Grid

## Instance Methods

#### `axnames`

  Returns the names of the axes

  RETURN VALUE

  - an Array of String

#### `lost_axes`

  Returns info on axes eliminated during operations.

  Useful for annotation in plots, for example (See the code of GGraph for an application).

  RETURN VALUE

  - an Array of String

#### `axis(dim_or_dimname)`

  Returns an Axis

  ARGUMENTS

  - dim_or_dimname (String or Integer) to specify an axis.

  RETURN VALUE

  - an Axis

#### `dim_index(dimname)`

  Returns the integer id (count from zero) of the dimension

  ARGUMENT

  - dimname (String or Integer) : this method is trivial if is is an integer

  RETURN VALUE

  - an Integer

#### `set_axis(dim_or_dimname,ax)`

  Sets an axis.

  ARGUMENTS

  - dim_or_dimname (String or Integer) to specify an axis.
  - ax (Axis) the axis

  RETURN VALUE

  - self

#### `set_lost_axes( lost )`

  Sets info on axes eliminated.

  RETURN VALUE

  - self

#### `add_lost_axes( lost )`

  Adds info on axes eliminated to existing ones.

  RETURN VALUE

  - self

#### `delete_axes( at, deleted_by=nil )`

  Delete an axis.

  ARGUMENTS

  - at (String or Integer) to specify an axis.
  - deleted_by (String or nil) if non-nil, it is written in the internal lost-axis info. Best if you put the name of the method, in which this method is called.

  RETURN VALUE

  - a Grid

#### `copy`

  Makes a deep clone onto memory.

  RETURN VALUE

  - a Grid

#### `merge(other)`

  merge two grids by basically using copies of self's axes but using the other's if the length in self is 1 and the length in the other is longer

  ARGUMENTS

  - other (Grid)

  RETURN VALUE

  - a Grid

#### `shape`

  Returns the shape of self.

  RETURN VALUE

  - an Array of Integer

#### `[*slicer]`

  Returns a subset.

  ARGUMENTS

  - Same as those for NArray#[], NetCDFVar#[], etc.

  RETURN VALUE

  - a Grid

#### `cut(*args)`

  Similar to [], but the subset is specified by physical coordinate.

  ARGUMENTS

  - pattern 1: similar to those for [], where the first argument specifies a subset for the first dimension.
  - pattern 2: by a Hash, in which keys are axis names.

  EXAMPLES

  - Pattern 1

        gphys.cut(135.5,0..20.5,false)

  - Pattern 2

        gphys.cut({'lon'=>135.5,'lat'=>0..20})

  RETURN VALUE

  - an Array : [a Grid, slicer], where slicer is an array to be used to make a subset of an corresponding varray (to be used in GPhys#cut).

#### `cut_rank_conserving(*args)`

  Similar to cut, but the rank is conserved by not eliminating any dimension (whose length could be one).

#### `exclude(dim_or_dimname)`

  Returns a Grid in which an axis is eliminated from self.

  ARGUMENTS

  - dim_or_dimname (String or Integer) to specify an axis.

  RETURN VALUE

  - a Grid

#### `change_axis(dim, axis)`

  Replaces an axis. (Returns a new object)

  ARGUMENTS

  - dim_or_dimname (String or Integer) to specify an axis.
  - axis (Axis)

  RETURN VALUE

  - a Grid

#### `change_axis!(dim_or_dimname, axis)`

  Replaces an axis. (overwrites self)

  ARGUMENTS

  - dim_or_dimname (String or Integer) to specify an axis.
  - axis (Axis)

  RETURN VALUE

  - self

#### `insert_axis(dim_or_dimname, axis)`

  Inserts an axis. (Returns a new object)

  ARGUMENTS

  - dim_or_dimname (String or Integer) to specify an axis.
  - axis (Axis)

  RETURN VALUE

  - a Grid

#### `insert_axis!(dim_or_dimname, axis)`

  Inserts an axis. (overwrites self)

  ARGUMENTS

  - dim_or_dimname (String or Integer) to specify an axis.
  - axis (Axis)

  RETURN VALUE

  - self

#### `transpose( *dims )`

  Transpose.

  ARGUMENTS

  - dims (integers) : for example, [1,0] to transpose a 2D object. For 3D objects, [1,0,2], [2,1,0], etc.etc.

  RETURN VALUE

  - a Grid