Class GeoGrid

  • All Implemented Interfaces:
    Comparable<GridDatatype>, IsMissingEvaluator, GridDatatype, NamedObject

    public class GeoGrid
    extends Object
    implements NamedObject, GridDatatype
    A georeferencing "gridded" VariableEnhanced, that has a GridCoordSys. In VisAD data model, it is a sampled Field. The dimension are put into canonical order: (rt, e, t, z, y, x).

    Implementation note: If the Horizontal axes are 2D, the x and y dimensions are arbitrarily chosen to be gcs.getXHorizAxis().getDimension(1), gcs.getXHorizAxis().getDimension(0) respectively.

    • Constructor Detail

      • GeoGrid

        public GeoGrid​(GridDataset dataset,
                       VariableDS dsvar,
                       GridCoordSys gcs)
        Constructor.
        Parameters:
        dataset - belongs to this dataset
        dsvar - wraps this Variable
        gcs - has this grid coordinate system
    • Method Detail

      • getDimensions

        public List<Dimension> getDimensions()
        Returns an ArrayList containing the dimensions used by this geoGrid. The dimension are put into canonical order: (rt, e, t, z, y, x). Note that the z and t dimensions are optional. If the Horizontal axes are 2D, the x and y dimensions are arbitrarily chosen to be gcs.getXHorizAxis().getDimension(1), gcs.getXHorizAxis().getDimension(0), respectively.
        Specified by:
        getDimensions in interface GridDatatype
        Returns:
        List with objects of type Dimension, in canonical order.
      • getDimension

        public Dimension getDimension​(int i)
        get the ith dimension
        Specified by:
        getDimension in interface GridDatatype
        Parameters:
        i - : which dimension
        Returns:
        ith Dimension
      • getTimeDimension

        public Dimension getTimeDimension()
        get the time Dimension, if it exists
        Specified by:
        getTimeDimension in interface GridDatatype
        Returns:
        the time Dimension, or null
      • getZDimension

        public Dimension getZDimension()
        get the z Dimension, if it exists
        Specified by:
        getZDimension in interface GridDatatype
        Returns:
        the z Dimension, or null
      • getYDimension

        public Dimension getYDimension()
        get the y Dimension, if it exists
        Specified by:
        getYDimension in interface GridDatatype
        Returns:
        the y Dimension, or null
      • getXDimension

        public Dimension getXDimension()
        get the x Dimension, if it exists
        Specified by:
        getXDimension in interface GridDatatype
        Returns:
        the x Dimension, or null
      • getEnsembleDimension

        public Dimension getEnsembleDimension()
        get the ensemble Dimension, if it exists
        Specified by:
        getEnsembleDimension in interface GridDatatype
        Returns:
        the ensemble Dimension, or null
      • getRunTimeDimension

        public Dimension getRunTimeDimension()
        get the run time Dimension, if it exists
        Specified by:
        getRunTimeDimension in interface GridDatatype
        Returns:
        the runtime Dimension, or null
      • getTimeDimensionIndex

        public int getTimeDimensionIndex()
        get the time Dimension index in the geogrid (canonical order), or -1 if none
        Specified by:
        getTimeDimensionIndex in interface GridDatatype
        Returns:
        the time Dimension index in canonical order, or -1
      • getZDimensionIndex

        public int getZDimensionIndex()
        get the z Dimension index in the geogrid (canonical order), or -1 if none
        Specified by:
        getZDimensionIndex in interface GridDatatype
        Returns:
        the z Dimension index in canonical order, or -1
      • getYDimensionIndex

        public int getYDimensionIndex()
        get the y Dimension index in the geogrid (canonical order)
        Specified by:
        getYDimensionIndex in interface GridDatatype
        Returns:
        the y Dimension index in canonical order, or -1
      • getXDimensionIndex

        public int getXDimensionIndex()
        get the x Dimension index in the geogrid (canonical order)
        Specified by:
        getXDimensionIndex in interface GridDatatype
        Returns:
        the x Dimension index in canonical order, or -1
      • getEnsembleDimensionIndex

        public int getEnsembleDimensionIndex()
        get the ensemble Dimension index in the geogrid (canonical order)
        Specified by:
        getEnsembleDimensionIndex in interface GridDatatype
        Returns:
        the ensemble Dimension index in canonical order, or -1
      • getRunTimeDimensionIndex

        public int getRunTimeDimensionIndex()
        get the runtime Dimension index in the geogrid (canonical order)
        Specified by:
        getRunTimeDimensionIndex in interface GridDatatype
        Returns:
        the runtime Dimension index in canonical order, or -1
      • findAttributeIgnoreCase

        public Attribute findAttributeIgnoreCase​(String name)
        Convenience function; lookup Attribute by name.
        Specified by:
        findAttributeIgnoreCase in interface GridDatatype
        Parameters:
        name - the name of the attribute
        Returns:
        the attribute, or null if not found
      • findAttValueIgnoreCase

        public String findAttValueIgnoreCase​(String attName,
                                             String defaultValue)
        Convenience function; lookup Attribute value by name. Must be String valued
        Specified by:
        findAttValueIgnoreCase in interface GridDatatype
        Parameters:
        attName - name of the attribute
        defaultValue - if not found, use this as the default
        Returns:
        Attribute string value, or default if not found.
      • getRank

        public int getRank()
        get the rank
        Specified by:
        getRank in interface GridDatatype
        Returns:
        the rank
      • getShape

        public int[] getShape()
        get the shape
        Specified by:
        getShape in interface GridDatatype
        Returns:
        the shape (canonical ordering)
      • getVariable

        public VariableDS getVariable()
        Description copied from interface: GridDatatype
        Get the underlying Variable, if it exists.
        Specified by:
        getVariable in interface GridDatatype
        Returns:
        the underlying Variable, if it exists, else null
      • getFullName

        public String getFullName()
        Description copied from interface: GridDatatype
        Get the full, unescaped name of the Grid
        Specified by:
        getFullName in interface GridDatatype
        Returns:
        the full, unescaped name of the Grid
      • getShortName

        public String getShortName()
        Description copied from interface: GridDatatype
        Get the short name of the Grid
        Specified by:
        getShortName in interface GridDatatype
        Returns:
        the short name of the Grid
      • getProjection

        public ProjectionImpl getProjection()
        Deprecated.
        this will return Projection, not ProjectionImpl in 6.
        get the Projection.
        Specified by:
        getProjection in interface GridDatatype
        Returns:
        the Projection, or null
      • getLevels

        @Deprecated
        public List<NamedObject> getLevels()
        Deprecated.
        will move in ver 6
        Returns:
        ArrayList of thredds.util.NamedObject, from the GridCoordSys.
      • getTimes

        @Deprecated
        public List<NamedObject> getTimes()
        Deprecated.
        will move in ver 6
        Returns:
        ArrayList of thredds.util.NamedObject, from the GridCoordSys.
      • getUnitString

        public String getUnitString()
        Deprecated.
        use getUnitsString()
        Returns:
        getUnitsString()
      • hasMissingData

        public boolean hasMissingData()
        true if there may be missing data, see VariableDS.hasMissing()
        Specified by:
        hasMissingData in interface GridDatatype
        Returns:
        true if there may be missing data
      • isMissingData

        public boolean isMissingData​(double val)
        if val is missing data, see VariableDS.isMissingData()
        Specified by:
        isMissingData in interface GridDatatype
        Parameters:
        val - test this value
        Returns:
        true if val is missing data
      • hasMissing

        public boolean hasMissing()
        Description copied from interface: IsMissingEvaluator
        true if there may be missing data
        Specified by:
        hasMissing in interface IsMissingEvaluator
        Returns:
        true if there may be missing data
      • isMissing

        public boolean isMissing​(double val)
        Description copied from interface: IsMissingEvaluator
        if val is a missing data value
        Specified by:
        isMissing in interface IsMissingEvaluator
        Parameters:
        val - test this value
        Returns:
        true if val is missing data
      • setMissingToNaN

        public float[] setMissingToNaN​(float[] values)
        Convert (in place) all values in the given array that are considered as "missing" to Float.NaN, according to isMissingData(val).
        Specified by:
        setMissingToNaN in interface GridDatatype
        Parameters:
        values - input array
        Returns:
        input array, with missing values converted to NaNs.
      • getMinMaxSkipMissingData

        public MAMath.MinMax getMinMaxSkipMissingData​(Array a)
        Get the minimum and the maximum data value of the previously read Array, skipping missing values as defined by isMissingData(double val).
        Specified by:
        getMinMaxSkipMissingData in interface GridDatatype
        Parameters:
        a - Array to get min/max values
        Returns:
        both min and max value.
      • readVolumeData

        public Array readVolumeData​(int t)
                             throws IOException
        Reads in the data "volume" at the given time index. If its a product set, put into canonical order (z-y-x). If not a product set, reorder to (z,i,j), where i, j are from the original
        Specified by:
        readVolumeData in interface GridDatatype
        Parameters:
        t - time index; ignored if no time axis.
        Returns:
        data[z,y,x] or data[y,x] if no z axis.
        Throws:
        IOException - on io error
      • readYXData

        public Array readYXData​(int t,
                                int z)
                         throws IOException
        Reads a Y-X "horizontal slice" at the given time and vertical index. If its a product set, put into canonical order (y-x).
        Parameters:
        t - time index; ignored if no time axis.
        z - vertical index; ignored if no z axis.
        Returns:
        data[y,x]
        Throws:
        IOException - on read error
      • readZYData

        public Array readZYData​(int t,
                                int x)
                         throws IOException
        Reads a Z-Y "vertical slice" at the given time and x index. If its a product set, put into canonical order (z-y).
        Parameters:
        t - time index; ignored if no time axis.
        x - x index; ignored if no x axis.
        Returns:
        data[z,y]
        Throws:
        IOException - on read error
      • getDataSlice

        public Array getDataSlice​(int t,
                                  int z,
                                  int y,
                                  int x)
                           throws IOException
        Deprecated.
        use readDataSlice
        Throws:
        IOException - on read error
      • readDataSlice

        public Array readDataSlice​(int t,
                                   int z,
                                   int y,
                                   int x)
                            throws IOException
        This reads an arbitrary data slice, returning the data in canonical order (t-z-y-x). If any dimension does not exist, ignore it.
        Specified by:
        readDataSlice in interface GridDatatype
        Parameters:
        t - if < 0, get all of time dim; if valid index, fix slice to that value.
        z - if < 0, get all of z dim; if valid index, fix slice to that value.
        y - if < 0, get all of y dim; if valid index, fix slice to that value.
        x - if < 0, get all of x dim; if valid index, fix slice to that value.
        Returns:
        data[t,z,y,x], eliminating missing or fixed dimension.
        Throws:
        IOException - on io error
      • readDataSlice

        public Array readDataSlice​(int rt,
                                   int e,
                                   int t,
                                   int z,
                                   int y,
                                   int x)
                            throws IOException
        This reads an arbitrary data slice, returning the data in canonical order (rt-e-t-z-y-x). If any dimension does not exist, ignore it.
        Specified by:
        readDataSlice in interface GridDatatype
        Parameters:
        rt - if < 0, get all of runtime dim; if valid index, fix slice to that value.
        e - if < 0, get all of ensemble dim; if valid index, fix slice to that value.
        t - if < 0, get all of time dim; if valid index, fix slice to that value.
        z - if < 0, get all of z dim; if valid index, fix slice to that value.
        y - if < 0, get all of y dim; if valid index, fix slice to that value.
        x - if < 0, get all of x dim; if valid index, fix slice to that value.
        Returns:
        data[rt,e,t,z,y,x], eliminating missing or fixed dimension.
        Throws:
        IOException - on io error
      • subset

        public GeoGrid subset​(Range t_range,
                              Range z_range,
                              LatLonRect bbox,
                              int z_stride,
                              int y_stride,
                              int x_stride)
                       throws InvalidRangeException
        Create a new GeoGrid that is a logical subset of this GeoGrid.
        Parameters:
        t_range - subset the time dimension, or null if you want all of it
        z_range - subset the vertical dimension, or null if you want all of it
        bbox - a lat/lon bounding box, or null if you want all x,y
        z_stride - use only if z_range is null, then take all z with this stride (1 means all)
        y_stride - use this stride on the y coordinate (1 means all)
        x_stride - use this stride on the x coordinate (1 means all)
        Returns:
        subsetted GeoGrid
        Throws:
        InvalidRangeException - if bbox does not intersect GeoGrid
      • makeSubset

        public GridDatatype makeSubset​(Range t_range,
                                       Range z_range,
                                       LatLonRect bbox,
                                       int z_stride,
                                       int y_stride,
                                       int x_stride)
                                throws InvalidRangeException
        Description copied from interface: GridDatatype
        Create a new GeoGrid that is a logical subset of this GeoGrid. For backwards compatibility for grids with no runtime or ensemble dimensions.
        Specified by:
        makeSubset in interface GridDatatype
        Parameters:
        t_range - subset the time dimension, or null if you want all of it
        z_range - subset the vertical dimension, or null if you want all of it
        bbox - a lat/lon bounding box, or null if you want all x,y
        z_stride - use only if z_range is null, then take all z with this stride (1 means all)
        y_stride - use this stride on the y coordinate (1 means all)
        x_stride - use this stride on the x coordinate (1 means all)
        Returns:
        subsetted GeoGrid
        Throws:
        InvalidRangeException - if ranges are invlaid
      • subset

        public GeoGrid subset​(Range t_range,
                              Range z_range,
                              Range y_range,
                              Range x_range)
                       throws InvalidRangeException
        Create a new GeoGrid that is a logical subset of this GeoGrid.
        Parameters:
        t_range - subset the time dimension, or null if you want all of it
        z_range - subset the vertical dimension, or null if you want all of it
        y_range - subset the y dimension, or null if you want all of it
        x_range - subset the x dimension, or null if you want all of it
        Returns:
        subsetted GeoGrid
        Throws:
        InvalidRangeException - if any of the ranges are invalid
      • makeSubset

        public GridDatatype makeSubset​(Range rt_range,
                                       Range e_range,
                                       Range t_range,
                                       Range z_range,
                                       Range y_range,
                                       Range x_range)
                                throws InvalidRangeException
        Description copied from interface: GridDatatype
        Create a new GeoGrid that is a logical subset of this GeoGrid.
        Specified by:
        makeSubset in interface GridDatatype
        Parameters:
        rt_range - subset the runtime dimension, or null if you want all of it
        e_range - subset the ensemble dimension, or null if you want all of it
        t_range - subset the time dimension, or null if you want all of it
        z_range - subset the vertical dimension, or null if you want all of it
        y_range - subset the y dimension, or null if you want all of it
        x_range - subset the x dimension, or null if you want all of it
        Returns:
        subsetted GeoGrid
        Throws:
        InvalidRangeException - if ranges are invlaid
      • equals

        public boolean equals​(Object oo)
        Instances which have same name and coordinate system are equal.
        Overrides:
        equals in class Object
      • hashCode

        public int hashCode()
        Override Object.hashCode() to be consistent with equals.
        Overrides:
        hashCode in class Object
      • getInfo

        public String getInfo()
        nicely formatted information
        Specified by:
        getInfo in interface GridDatatype
        Returns:
        human readable information about this Grid.