# 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

#### `coord_dim_indices(coordname)`

  Coordinate name --> dimension indices.

  ARGUMENT

  - coordname (String) : Name of a coordinate

  RETURN VALUE

  - Array of Integer or nil -- If the coordinate is present it is an Array containing dimension indices (If the coordinate is 1D, the lengthof the array is 1.)

#### `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).

#### `cut_assoccoord(hasharg)`

  Cut with respect to the asscoated coordinates. Similar to cut, when the argeuemnt is a Hash, but hash keys are the names of the asscoated coordinates.

#### `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

#### `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