Java Code Examples for ucar.ma2.ArrayDouble#D1
The following examples show how to use
ucar.ma2.ArrayDouble#D1 .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WRFEta.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Get the 1D vertical coordinate array for this time step and point * * @param timeIndex the time index. Ignored if !isTimeDependent(). * @param xIndex the x index * @param yIndex the y index * @return vertical coordinate array * @throws java.io.IOException problem reading data * @throws ucar.ma2.InvalidRangeException _more_ */ public D1 getCoordinateArray1D(int timeIndex, int xIndex, int yIndex) throws IOException, InvalidRangeException { ArrayDouble.D3 data = getCoordinateArray(timeIndex); int[] origin = new int[3]; int[] shape = new int[3]; origin[0] = 0; origin[1] = yIndex; origin[2] = xIndex; shape[0] = data.getShape()[0]; shape[1] = 1; shape[2] = 1; Array tmp = data.section(origin, shape); return (ArrayDouble.D1) tmp.reduce(); }
Example 2
Source File: AtmosSigma.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Get the 1D vertical coordinate array for this time step and point * * (needds test!!!) * * @param timeIndex the time index. Ignored if !isTimeDependent(). * @param xIndex the x index * @param yIndex the y index * @return vertical coordinate array * @throws java.io.IOException problem reading data * @throws ucar.ma2.InvalidRangeException _more_ */ public D1 getCoordinateArray1D(int timeIndex, int xIndex, int yIndex) throws IOException, InvalidRangeException { Array ps = readArray(psVar, timeIndex); Index psIndex = ps.getIndex(); int nz = sigma.length; ArrayDouble.D1 result = new ArrayDouble.D1(nz); double psVal = ps.getDouble(psIndex.set(yIndex, xIndex)); for (int z = 0; z < nz; z++) { result.set(z, ptop + sigma[z] * (psVal - ptop)); } return result; }
Example 3
Source File: FmrcDataset.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
private VariableDS makeOffsetCoordinate(NetcdfDataset result, Group group, String dimName, CalendarDate base, double[] values) { DataType dtype = DataType.DOUBLE; VariableDS timeVar = new VariableDS(result, group, null, dimName + "_offset", dtype, dimName, null, null); // LOOK // could // just // make a // CoordinateAxis1D timeVar.addAttribute(new Attribute(CDM.LONG_NAME, "offset hour from start of run for coordinate = " + dimName)); timeVar.addAttribute(new ucar.nc2.Attribute("standard_name", "forecast_period")); timeVar.addAttribute(new ucar.nc2.Attribute(CF.CALENDAR, base.getCalendar().name())); timeVar.addAttribute(new ucar.nc2.Attribute(CDM.UNITS, "hours since " + base)); timeVar.addAttribute(new ucar.nc2.Attribute(CDM.MISSING_VALUE, Double.NaN)); // construct the values int ntimes = values.length; ArrayDouble.D1 timeCoordVals = (ArrayDouble.D1) Array.factory(DataType.DOUBLE, new int[] {ntimes}, values); timeVar.setCachedData(timeCoordVals); group.addVariable(timeVar); return timeVar; }
Example 4
Source File: M3IOConvention.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void makeZCoordAxis(String dimName, String levelsName, String unitName) { Dimension dimz = rootGroup.findDimension(dimName).get(); int nz = dimz.getLength(); ArrayDouble.D1 dataLev = new ArrayDouble.D1(nz); ArrayDouble.D1 dataLayers = new ArrayDouble.D1(nz + 1); // layer values are a numeric global attribute array !! Attribute layers = rootGroup.getAttributeContainer().findAttribute(levelsName); for (int i = 0; i <= nz; i++) dataLayers.set(i, layers.getNumericValue(i).doubleValue()); for (int i = 0; i < nz; i++) { double midpoint = (dataLayers.get(i) + dataLayers.get(i + 1)) / 2; dataLev.set(i, midpoint); } CoordinateAxis.Builder v = CoordinateAxis1D.builder().setName("level").setDataType(DataType.DOUBLE) .setParentGroupBuilder(rootGroup).setDimensionsByName(dimName).setUnits(unitName) .setDesc("synthesized coordinate from " + levelsName + " global attributes"); v.setCachedData(dataLev, true); v.addAttribute(new Attribute("positive", "down")); v.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.GeoZ.toString())); // layer edges String edge_name = "layer"; Dimension lay_edge = new Dimension(edge_name, nz + 1); rootGroup.addDimension(lay_edge); CoordinateAxis.Builder vedge = CoordinateAxis1D.builder().setName(edge_name).setDataType(DataType.DOUBLE) .setParentGroupBuilder(rootGroup).setDimensionsByName(edge_name).setUnits(unitName) .setDesc("synthesized coordinate from " + levelsName + " global attributes"); vedge.setCachedData(dataLayers, true); v.setBoundary(edge_name); datasetBuilder.replaceCoordinateAxis(rootGroup, v); datasetBuilder.replaceCoordinateAxis(rootGroup, vedge); }
Example 5
Source File: FmrcDataset.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
private VariableDS makeRunTimeCoordinate(NetcdfDataset result, Group group, String dimName, CalendarDate base, double[] values) { DataType dtype = DataType.DOUBLE; VariableDS timeVar = new VariableDS(result, group, null, dimName + "_run", dtype, dimName, null, null); // LOOK // could // just make // a // CoordinateAxis1D timeVar.addAttribute(new Attribute(CDM.LONG_NAME, "run times for coordinate = " + dimName)); timeVar.addAttribute(new ucar.nc2.Attribute("standard_name", "forecast_reference_time")); timeVar.addAttribute(new ucar.nc2.Attribute(CF.CALENDAR, base.getCalendar().name())); // timeVar.addAttribute(new ucar.nc2.Attribute(CDM.UNITS, "hours since " + base)); timeVar.addAttribute(new ucar.nc2.Attribute(CDM.UNITS, "hours since " + base.getTimeUnits())); timeVar.addAttribute(new ucar.nc2.Attribute(CDM.MISSING_VALUE, Double.NaN)); timeVar.addAttribute(new ucar.nc2.Attribute(_Coordinate.AxisType, AxisType.RunTime.toString())); // if theres // already a time // coord, dont put // in coordSys - // too complicated // construct the values int ntimes = values.length; ArrayDouble.D1 timeCoordVals = (ArrayDouble.D1) Array.factory(DataType.DOUBLE, new int[] {ntimes}, values); timeVar.setCachedData(timeCoordVals); group.addVariable(timeVar); return timeVar; }
Example 6
Source File: CEDRICRadarConvention.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void augmentDataset(NetcdfDataset ncDataset, CancelTask cancelTask) throws IOException { /* * float lat = 40.45f; * float lon = -104.64f; * ProjectionImpl projection = new FlatEarth(lat, lon); * * Variable ct = new Variable( ncDataset, null, null, projection.getClassName()); * ct.setDataType( DataType.CHAR); * ct.setDimensions( ""); * * ct.addAttribute( new Attribute("grid_mapping_name", "flat_earth")); * ct.addAttribute( new Attribute(_Coordinate.TransformType, "Projection")); * ct.addAttribute( new Attribute(_Coordinate.Axes, "GeoX GeoY")); * ncDataset.addVariable(null, ct); */ NcMLReader.wrapNcMLresource(ncDataset, CoordSysBuilder.resourcesDir + "CEDRICRadar.ncml", cancelTask); Variable lat = ncDataset.findVariable("radar_latitude"); Variable lon = ncDataset.findVariable("radar_longitude"); float latv = (float) lat.readScalarDouble(); float lonv = (float) lon.readScalarDouble(); Variable pv = ncDataset.findVariable("Projection"); pv.addAttribute(new Attribute("longitude_of_projection_origin", lonv)); pv.addAttribute(new Attribute("latitude_of_projection_origin", latv)); Variable tvar = ncDataset.findVariable("time"); /* * Date dt = null; * Variable sdate = ncDataset.findVariable("start_date"); * Variable stime = ncDataset.findVariable("start_time"); * String dateStr = sdate.readScalarString(); * String timeStr = stime.readScalarString(); * try { * dt = DateUtil.parse(dateStr + " " + timeStr); * } catch (Exception e) {} */ int nt = 1; ArrayDouble.D1 data = new ArrayDouble.D1(nt); // fake data.setDouble(0, 0); // data.setDouble(0, dt.getTime()/1000); tvar.setCachedData(data, false); super.augmentDataset(ncDataset, cancelTask); }
Example 7
Source File: WRFConvention.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Nullable private CoordinateAxis.Builder makeZCoordAxis(String axisName, String dimName) { Optional<Dimension> dimOpt = rootGroup.findDimension(dimName); if (!dimOpt.isPresent()) { return null; } Dimension dim = dimOpt.get(); String fromWhere = axisName.endsWith("stag") ? "ZNW" : "ZNU"; CoordinateAxis.Builder v = CoordinateAxis1D.builder().setName(axisName).setDataType(DataType.DOUBLE).setParentGroupBuilder(rootGroup) .setDimensionsByName(dim.getShortName()).setUnits("").setDesc("eta values from variable " + fromWhere); v.addAttribute(new Attribute(CF.POSITIVE, CF.POSITIVE_DOWN)); // eta coordinate is 1.0 at bottom, 0 at top v.setAxisType(AxisType.GeoZ); v.addAttribute(new Attribute(_Coordinate.AxisType, "GeoZ")); if (!axisName.equals(dim.getShortName())) v.addAttribute(new Attribute(_Coordinate.AliasForDimension, dim.getShortName())); // create eta values from file variables: ZNU, ZNW // But they are a function of time though the values are the same in the sample file // NOTE: Use first time sample assuming all are the same!! Optional<Variable.Builder<?>> etaVarOpt = rootGroup.findVariableLocal(fromWhere); if (!etaVarOpt.isPresent()) { return makeFakeCoordAxis(axisName, dim); } else { VariableDS.Builder<?> etaVarDS = (VariableDS.Builder<?>) etaVarOpt.get(); Variable etaVar = etaVarDS.orgVar; int n = etaVar.getShape(1); // number of eta levels int[] origin = {0, 0}; int[] shape = {1, n}; try { Array array = etaVar.read(origin, shape);// read first time slice ArrayDouble.D1 newArray = new ArrayDouble.D1(n); IndexIterator it = array.getIndexIterator(); int count = 0; while (it.hasNext()) { double d = it.getDoubleNext(); newArray.set(count++, d); } v.setCachedData(newArray, true); } catch (Exception e) { e.printStackTrace(); } // ADD: error? return v; } }
Example 8
Source File: VerticalTransformSubset.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Get the 1D vertical coordinate array for this time step and point * * @param timeIndex the time index. Ignored if !isTimeDependent(). * @param xIndex the x index * @param yIndex the y index * @return vertical coordinate array * @throws java.io.IOException problem reading data * @throws ucar.ma2.InvalidRangeException _more_ */ public D1 getCoordinateArray1D(int timeIndex, int xIndex, int yIndex) throws IOException, InvalidRangeException { ArrayDouble.D3 data = original.getCoordinateArray(timeIndex); int[] origin = new int[3]; int[] shape = new int[3]; shape[0] = subsetList.get(0).length(); shape[1] = 1; shape[2] = 1; origin[0] = timeIndex; if (isTimeDependent() && (t_range != null)) { origin[0] = t_range.element(timeIndex); } origin[1] = yIndex; origin[2] = xIndex; Array section = data.section(origin, shape); return (ArrayDouble.D1) section.reduce(); }
Example 9
Source File: TestVerticalTransformWithUnitsConversion.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 3 votes |
private double[] getVertTransformationForPoint(ProjectionPoint point, int timeIndex, GeoGrid grid) throws IOException, InvalidRangeException { VerticalTransform vt = grid.getCoordinateSystem().getVerticalTransform(); // System.out.println(vt.isTimeDependent()); int[] pointIndices = new int[] {0, 0}; grid.getCoordinateSystem().findXYindexFromCoord(point.getX(), point.getY(), pointIndices); ArrayDouble.D1 dataArr = vt.getCoordinateArray1D(timeIndex, pointIndices[0], pointIndices[1]); return (double[]) dataArr.copyTo1DJavaArray(); }
Example 10
Source File: VerticalTransform.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Get the 1D vertical coordinate array for this time step and * the specified X,Y index for Lat-Lon point. * * @param timeIndex the time index. Ignored if !isTimeDependent(). * @param xIndex the x index * @param yIndex the y index * @return vertical coordinate array * @throws java.io.IOException problem reading data * @throws ucar.ma2.InvalidRangeException _more_ */ ArrayDouble.D1 getCoordinateArray1D(int timeIndex, int xIndex, int yIndex) throws IOException, InvalidRangeException;