Package ucar.unidata.data
Class DataUtil
java.lang.Object
ucar.unidata.data.DataUtil
A class to hold general utility functions for manipulating data
- Version:
- $Revision: 1.8 $
- Author:
- IDV development team
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 arraystatic String
Make a valid VisAD RealType name from the string.static float[][]
cloneArray
(float[][] a) clone the arraystatic void
exportCsvAllTimes
(FieldImpl field, String filename) Write a csv file for a time series point datastatic List
fieldToRows
(FieldImpl field) output a list for a time series point datastatic FlatField
getFlatField
(Data field) This method find the flat field somewhere in the given datastatic CoordinateSystem
getPressureToHeightCS
(String type) Get the appropriate vertical coordinate systemstatic Date
makeDate
(ucar.nc2.time.CalendarDate cdate) Make a date object corresponding the the calendar datestatic ucar.visad.data.CalendarDateTime
makeDateTime
(ucar.nc2.time.CalendarDate cdate) Make a CalendarDateTime object corresponding the the calendar datestatic List
<ucar.visad.data.CalendarDateTime> makeDateTimes
(ucar.nc2.dataset.CoordinateAxis1DTime timeAxis) Make a List of CalendarDateTime objects from the times in the timeAxisstatic List
<ucar.visad.data.CalendarDateTime> makeDateTimes
(ucar.nc2.ft2.coverage.CoverageCoordAxis1D timeAxis) Make a List of CalendarDateTime objects from the times in the timeAxisstatic float[][]
makeFloatArray
(int rows, int cols, float value) Make a float array of the sizes indicated with the valuestatic 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/samplingstatic TextType
makeTextType
(String name) 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 newValuesstatic void
min
(float[][] originalValues, float[][] newValues, int[] indexArray, float value) If the originalValues invalid input: '<' given value then set the newValues = valuestatic Unit
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.selectDatesFromList
(List sourceTimes, List<DateTime> driverTimes) Select the dates from sourceTimes that most closely match the selectionTimes;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 valuestatic 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
Write a csv file.static void
Write to an excel spreadsheetstatic void
Write to an excel spreadsheetstatic String
Convert excel to csvstatic String
xlsToCsv
(String filename, boolean skipToFirstNumeric, SimpleDateFormat sdf) Convert excel to csv
-
Field Details
-
STD_ATMOSPHERE
flag for standard atmosphere coordinate system class- See Also:
-
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
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
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
Try to create a TextType from the name.- Parameters:
name
- name of type- Returns:
- TextType or null
-
makeRealType
Try to create a RealType from the name and unit.- Parameters:
name
- name of typeunit
- can be null- Returns:
- RealType or null
-
cleanName
Make a valid VisAD RealType name from the string. Remove spaces, "." and parens.- Parameters:
name
- name to clean- Returns:
- cleaned up name
-
getPressureToHeightCS
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 arrayscols
- number of values in each rowvalue
- 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 valuesnewValues
- new valuesindexArray
- 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 valuesnewValues
- new ValuesindexArray
- indicesvalue
- 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
- originalValuesnewValues
- newValuesindexArray
- indicesvalue
- 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
- originalValuesnewValues
- newValuesindexArray
- indicesvalue
- 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 valuesnewValues
- new valueindexArray
- indices
-
getFlatField
This method find the flat field somewhere in the given data- Parameters:
field
- field- Returns:
- a flat field or null
- Throws:
RemoteException
- on badnessVisADException
- on badness
-
exportCsvAllTimes
Write a csv file for a time series point data- Parameters:
field
- datafilename
- file to write to
-
fieldToRows
output a list for a time series point data- Parameters:
field
- data
-
writeCsv
Write a csv file. The rows list contains lists. We take the toString value of each list element- Parameters:
filename
- file to write torows
- data
-
writeXls
Write to an excel spreadsheet- Parameters:
filename
- filerows
- 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
- filerowsList
- datanames
- sheet names- Throws:
Exception
- On badness
-
xlsToCsv
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 fileskipToFirstNumeric
- if true, skip to first numericsdf
- 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 pointsx
- x valuey
- 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 timesdriverTimes
- 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 timesselectionTimes
- 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
Make a date object corresponding the the calendar date- Parameters:
cdate
- the CalendarDate- Returns:
- the corresponding Date
- Throws:
VisADException
- problem parsing cdate
-
makeSamplingLabel
Make a label for the stride/sampling- Parameters:
xStride
- the x strideyStride
- the y stridepointType
- the name for the point type- Returns:
-