Class DataUtil

java.lang.Object
ucar.unidata.data.DataUtil

public class DataUtil extends Object
A class to hold general utility functions for manipulating data
Version:
$Revision: 1.8 $
Author:
IDV development team
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    flag for standard atmosphere coordinate system class
    static final String
    flag for Vis5D pressure to height coordinate system class
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    absoluteValue(float[][] originalValues, float[][] newValues, int[] indexArray)
    copy the originalValues to the new values.
    static void
    average(float[][] originalValues, float[][] newValues, int[] indexArray)
    set newValues to be the average of the original values in the index array
    static String
    Make a valid VisAD RealType name from the string.
    static float[][]
    cloneArray(float[][] a)
    clone the array
    static void
    Write a csv file for a time series point data
    static List
    output a list for a time series point data
    static FlatField
    This method find the flat field somewhere in the given data
    Get the appropriate vertical coordinate system
    static Date
    makeDate(ucar.nc2.time.CalendarDate cdate)
    Make a date object corresponding the the calendar date
    static ucar.visad.data.CalendarDateTime
    makeDateTime(ucar.nc2.time.CalendarDate cdate)
    Make a CalendarDateTime object corresponding the the calendar date
    static List<ucar.visad.data.CalendarDateTime>
    makeDateTimes(ucar.nc2.dataset.CoordinateAxis1DTime timeAxis)
    Make a List of CalendarDateTime objects from the times in the timeAxis
    static List<ucar.visad.data.CalendarDateTime>
    makeDateTimes(ucar.nc2.ft2.coverage.CoverageCoordAxis1D timeAxis)
    Make a List of CalendarDateTime objects from the times in the timeAxis
    static float[][]
    makeFloatArray(int rows, int cols, float value)
    Make a float array of the sizes indicated with the value
    static RealType
    makeRealType(String name, Unit unit)
    Try to create a RealType from the name and unit.
    static String
    makeSamplingLabel(int xStride, int yStride, String pointType)
    Make a label for the stride/sampling
    static TextType
    Try to create a TextType from the name.
    static void
    max(float[][] originalValues, float[][] newValues, int[] indexArray, float value)
    Copy the values in originalValues[indexArray] that are greater than the given value to newValues
    static void
    min(float[][] originalValues, float[][] newValues, int[] indexArray, float value)
    If the originalValues invalid input: '<' given value then set the newValues = value
    static Unit
    parseUnit(String unitString)
    Tries to parse the string.
    static boolean
    pointInside(float[][] pts, float x, float y)
    Determine if the given point is inside the given polygon Code originally taken from: http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html Copyright (c) 1970-2003, Wm.
    static List<Date>
    selectDatesFromList(List sourceTimes, List<DateTime> driverTimes)
    Select the dates from sourceTimes that most closely match the selectionTimes;
    static List<DateTime>
    selectTimesFromList(List sourceTimes, List<DateTime> selectionTimes)
    Select the times from sourceTimes that most closely match the selectionTimes;
    static void
    setValue(float[][] originalValues, float[][] newValues, int[] indexArray, float value)
    set the values in the indices in newValues = the given value
    static char[]
    toCharArray(ucar.ma2.Array arr)
    Get the 1D values for an array as chars.
    static double[]
    toDoubleArray(ucar.ma2.Array arr)
    Get the 1D values for an array as doubles.
    static float[]
    toFloatArray(ucar.ma2.Array arr)
    Get the 1D values for an array as floats.
    static float[]
    toFloatArray(ucar.ma2.Array[] arr)
    Get the 1D values for an array as floats.
    static String[]
    toStringArray(ucar.ma2.Array arr)
    Get the 1D values for an array as Strings.
    static void
    writeCsv(String filename, List rows)
    Write a csv file.
    static void
    writeXls(String filename, List rows)
    Write to an excel spreadsheet
    static void
    writeXls(String filename, List<List> rowsList, List<String> names)
    Write to an excel spreadsheet
    static String
    xlsToCsv(String filename)
    Convert excel to csv
    static String
    xlsToCsv(String filename, boolean skipToFirstNumeric, SimpleDateFormat sdf)
    Convert excel to csv

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • STD_ATMOSPHERE

      public static final String STD_ATMOSPHERE
      flag for standard atmosphere coordinate system class
      See Also:
    • VIS5D_VERTICALCS

      public static final String VIS5D_VERTICALCS
      flag for Vis5D pressure to height coordinate system class
      See Also:
  • Constructor Details

    • DataUtil

      public DataUtil()
  • Method Details

    • toFloatArray

      public static float[] toFloatArray(ucar.ma2.Array arr)
      Get the 1D values for an array as floats.
      Parameters:
      arr - Array of values
      Returns:
      float representation
    • toFloatArray

      public static float[] toFloatArray(ucar.ma2.Array[] arr)
      Get the 1D values for an array as floats.
      Parameters:
      arr - Array of values
      Returns:
      float representation
    • toDoubleArray

      public static double[] toDoubleArray(ucar.ma2.Array arr)
      Get the 1D values for an array as doubles.
      Parameters:
      arr - Array of values
      Returns:
      double representation
    • toStringArray

      public static String[] toStringArray(ucar.ma2.Array arr)
      Get the 1D values for an array as Strings.
      Parameters:
      arr - Array of values
      Returns:
      String representation
    • toCharArray

      public static char[] toCharArray(ucar.ma2.Array arr)
      Get the 1D values for an array as chars.
      Parameters:
      arr - Array of values
      Returns:
      chars representation
    • parseUnit

      public static Unit parseUnit(String unitString)
      Tries to parse the string. If an exception occurs just return null.
      Parameters:
      unitString - The unit string
      Returns:
      The parsed unit or null if an error occurs
    • makeTextType

      public static TextType makeTextType(String name)
      Try to create a TextType from the name.
      Parameters:
      name - name of type
      Returns:
      TextType or null
    • makeRealType

      public static RealType makeRealType(String name, Unit unit)
      Try to create a RealType from the name and unit.
      Parameters:
      name - name of type
      unit - can be null
      Returns:
      RealType or null
    • cleanName

      public static String cleanName(String name)
      Make a valid VisAD RealType name from the string. Remove spaces, "." and parens.
      Parameters:
      name - name to clean
      Returns:
      cleaned up name
    • getPressureToHeightCS

      public static CoordinateSystem getPressureToHeightCS(String type) throws VisADException
      Get the appropriate vertical coordinate system
      Parameters:
      type - type of pressure to height cs
      Returns:
      the corresponding CS
      Throws:
      VisADException - couldn't create the CS
    • makeFloatArray

      public static float[][] makeFloatArray(int rows, int cols, float value)
      Make a float array of the sizes indicated with the value
      Parameters:
      rows - number of arrays
      cols - number of values in each row
      value - fill value
      Returns:
      the filled in array
    • cloneArray

      public static float[][] cloneArray(float[][] a)
      clone the array
      Parameters:
      a - incoming array
      Returns:
      cloned array
    • absoluteValue

      public static void absoluteValue(float[][] originalValues, float[][] newValues, int[] indexArray)
      copy the originalValues to the new values. Set all values to be positive
      Parameters:
      originalValues - original values
      newValues - new values
      indexArray - The indices to change
    • max

      public static void max(float[][] originalValues, float[][] newValues, int[] indexArray, float value)
      Copy the values in originalValues[indexArray] that are greater than the given value to newValues
      Parameters:
      originalValues - original values
      newValues - new Values
      indexArray - indices
      value - the threshold value
    • setValue

      public static void setValue(float[][] originalValues, float[][] newValues, int[] indexArray, float value)
      set the values in the indices in newValues = the given value
      Parameters:
      originalValues - originalValues
      newValues - newValues
      indexArray - indices
      value - value
    • min

      public static void min(float[][] originalValues, float[][] newValues, int[] indexArray, float value)
      If the originalValues invalid input: '<' given value then set the newValues = value
      Parameters:
      originalValues - originalValues
      newValues - newValues
      indexArray - indices
      value - value
    • average

      public static void average(float[][] originalValues, float[][] newValues, int[] indexArray)
      set newValues to be the average of the original values in the index array
      Parameters:
      originalValues - original values
      newValues - new value
      indexArray - indices
    • getFlatField

      public static FlatField getFlatField(Data field) throws VisADException, RemoteException
      This method find the flat field somewhere in the given data
      Parameters:
      field - field
      Returns:
      a flat field or null
      Throws:
      RemoteException - on badness
      VisADException - on badness
    • exportCsvAllTimes

      public static void exportCsvAllTimes(FieldImpl field, String filename)
      Write a csv file for a time series point data
      Parameters:
      field - data
      filename - file to write to
    • fieldToRows

      public static List fieldToRows(FieldImpl field)
      output a list for a time series point data
      Parameters:
      field - data
    • writeCsv

      public static void writeCsv(String filename, List rows)
      Write a csv file. The rows list contains lists. We take the toString value of each list element
      Parameters:
      filename - file to write to
      rows - data
    • writeXls

      public static void writeXls(String filename, List rows) throws Exception
      Write to an excel spreadsheet
      Parameters:
      filename - file
      rows - data
      Throws:
      Exception - On badness
    • writeXls

      public static void writeXls(String filename, List<List> rowsList, List<String> names) throws Exception
      Write to an excel spreadsheet
      Parameters:
      filename - file
      rowsList - data
      names - sheet names
      Throws:
      Exception - On badness
    • xlsToCsv

      public static String xlsToCsv(String filename) throws Exception
      Convert excel to csv
      Parameters:
      filename - excel file
      Returns:
      csv
      Throws:
      Exception - On badness
    • xlsToCsv

      public static String xlsToCsv(String filename, boolean skipToFirstNumeric, SimpleDateFormat sdf) throws Exception
      Convert excel to csv
      Parameters:
      filename - excel file
      skipToFirstNumeric - if true, skip to first numeric
      sdf - If non null then use this to format any date cells
      Returns:
      csv
      Throws:
      Exception - On badness
    • pointInside

      public static boolean pointInside(float[][] pts, float x, float y)
      Determine if the given point is inside the given polygon Code originally taken from: http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html Copyright (c) 1970-2003, Wm. Randolph Franklin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers. 2. Redistributions in binary form must reproduce the above copyright notice in the documentation and/or other materials provided with the distribution. 3. The name of W. Randolph Franklin may not be used to endorse or promote products derived from this Software without specific prior written permission. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
      Parameters:
      pts - the xy outline points
      x - x value
      y - y value
      Returns:
      true if inside
    • selectDatesFromList

      public static List<Date> selectDatesFromList(List sourceTimes, List<DateTime> driverTimes) throws Exception
      Select the dates from sourceTimes that most closely match the selectionTimes;
      Parameters:
      sourceTimes - set of available times
      driverTimes - times we want to match
      Returns:
      the matching times as Dates
      Throws:
      Exception - problem creating times
    • selectTimesFromList

      public static List<DateTime> selectTimesFromList(List sourceTimes, List<DateTime> selectionTimes) throws Exception
      Select the times from sourceTimes that most closely match the selectionTimes;
      Parameters:
      sourceTimes - set of available times
      selectionTimes - times we want to match
      Returns:
      the matching times
      Throws:
      Exception - problem creating times
    • makeDateTime

      public static ucar.visad.data.CalendarDateTime makeDateTime(ucar.nc2.time.CalendarDate cdate) throws VisADException
      Make a CalendarDateTime object corresponding the the calendar date
      Parameters:
      cdate - the CalendarDate
      Returns:
      the corresponding DateTime
      Throws:
      VisADException - problem parsing cdate
    • makeDateTimes

      public static List<ucar.visad.data.CalendarDateTime> makeDateTimes(ucar.nc2.dataset.CoordinateAxis1DTime timeAxis) throws VisADException
      Make a List of CalendarDateTime objects from the times in the timeAxis
      Parameters:
      timeAxis - the time axis
      Returns:
      List of DateTimes
      Throws:
      VisADException - problem parsing timeAxis calendar dates
    • makeDateTimes

      public static List<ucar.visad.data.CalendarDateTime> makeDateTimes(ucar.nc2.ft2.coverage.CoverageCoordAxis1D timeAxis) throws VisADException
      Make a List of CalendarDateTime objects from the times in the timeAxis
      Parameters:
      timeAxis - the time axis
      Returns:
      List of DateTimes
      Throws:
      VisADException - problem parsing timeAxis calendar dates
    • makeDate

      public static Date makeDate(ucar.nc2.time.CalendarDate cdate) throws VisADException
      Make a date object corresponding the the calendar date
      Parameters:
      cdate - the CalendarDate
      Returns:
      the corresponding Date
      Throws:
      VisADException - problem parsing cdate
    • makeSamplingLabel

      public static String makeSamplingLabel(int xStride, int yStride, String pointType)
      Make a label for the stride/sampling
      Parameters:
      xStride - the x stride
      yStride - the y stride
      pointType - the name for the point type
      Returns: