private void removeConstantTimeDim(NetcdfDataset ds, Variable v) { int[] shape = v.getShape(); if (v.getRank() == 3 && shape[0] == 1) { // remove time dependcies - MAJOR KLUDGE Variable view; try { view = v.slice(0, 0); } catch (InvalidRangeException e) { log.error("Cant remove first dimension in variable {}", v); return; } ds.removeVariable(null, v.getShortName()); ds.addVariable(null, view); } }
private void createNewVariables(NetcdfDataset ds, Variable ncVar, List<Dimension> newDims, Dimension levelDim) throws InvalidRangeException { List<Dimension> dims = ncVar.getDimensions(); int newDimIndex = dims.indexOf(levelDim); //String shapeS = ncVar.getShapeS(); int[] origin = new int[ncVar.getRank()]; int[] shape = ncVar.getShape(); int count = 0; for (Dimension dim : newDims) { String name = ncVar.getShortName() + "-" + dim.getShortName(); origin[newDimIndex] = count; shape[newDimIndex] = dim.getLength(); Variable varNew = ncVar.section(new Section(origin, shape)); varNew.setName(name); varNew.setDimension(newDimIndex, dim); // synthesize long name String long_name = ds.findAttValueIgnoreCase(ncVar, CDM.LONG_NAME, ncVar.getShortName()); long_name = long_name + "-" + dim.getShortName(); ds.addVariableAttribute(varNew, new Attribute(CDM.LONG_NAME, long_name)); ds.addVariable(null, varNew); parseInfo.format("Created New Variable as section = "); varNew.getNameAndDimensions(parseInfo, true, false); parseInfo.format("%n"); count += dim.getLength(); } }
protected void promoteGlobalAttributes(DatasetOuterDimension typicalDataset) throws IOException { for (CacheVar cv : cacheList) { if (!(cv instanceof PromoteVar)) continue; PromoteVar pv = (PromoteVar) cv; Array data = pv.read(typicalDataset); if (data == null) throw new IOException("cant read "+typicalDataset); pv.dtype = DataType.getType(data); VariableDS promotedVar = new VariableDS(ncDataset, null, null, pv.varName, pv.dtype, dimName, null, null); /* if (data.getSize() > 1) { // LOOK case of non-scalar global attribute not delat with Dimension outer = ncDataset.getRootGroup().findDimension(dimName); Dimension inner = new Dimension("", (int) data.getSize(), false); //anonymous List<Dimension> dims = new ArrayList<Dimension>(2); dims.add(outer); dims.add(inner); promotedVar.setDimensions(dims); } */ ncDataset.addVariable(null, promotedVar); promotedVar.setProxyReader( this); promotedVar.setSPobject(pv); } }
private void createNewVariables(NetcdfDataset ds, Variable ncVar, List<Dimension> newDims, Dimension levelDim) throws InvalidRangeException { List<Dimension> dims = ncVar.getDimensions(); int newDimIndex = dims.indexOf(levelDim); //String shapeS = ncVar.getShapeS(); int[] origin = new int[ncVar.getRank()]; int[] shape = ncVar.getShape(); int count = 0; for (Dimension dim : newDims) { String name = ncVar.getShortName() + "-" + dim.getShortName(); origin[newDimIndex] = count; shape[newDimIndex] = dim.getLength(); Variable varNew = ncVar.section(new Section(origin, shape)); varNew.setName(name); varNew.setDimension(newDimIndex, dim); // synthesize long name String long_name = ds.findAttValueIgnoreCase(ncVar, CDM.LONG_NAME, ncVar.getShortName()); long_name = long_name + "-" + dim.getShortName(); ds.addVariableAttribute(varNew, new Attribute(CDM.LONG_NAME, long_name)); ds.addVariable(null, varNew); parseInfo.format("Created New Variable as section = "); varNew.getNameAndDimensions(parseInfo, true, false); parseInfo.format("%n"); count += dim.getLength(); } }
private Projection makeLCProjection(NetcdfDataset ds) { Attribute latLonOrigin = projVar.findAttributeIgnoreCase("latLonOrigin"); if (latLonOrigin == null) throw new IllegalStateException(); double centralLon = latLonOrigin.getNumericValue(0).doubleValue(); double centralLat = latLonOrigin.getNumericValue(1).doubleValue(); double par1 = findAttributeDouble( "stdParallelOne"); double par2 = findAttributeDouble( "stdParallelTwo"); LambertConformal lc = new LambertConformal(centralLat, centralLon, par1, par2); // make Coordinate Transform Variable ProjectionCT ct = new ProjectionCT("lambertConformalProjection", "FGDC", lc); VariableDS ctVar = makeCoordinateTransformVariable(ds, ct); ctVar.addAttribute( new Attribute(_Coordinate.Axes, "xCoord yCoord")); ds.addVariable(null, ctVar); return lc; }
private void createNewVariables(NetcdfDataset ds, Variable ncVar, List<Dimension> newDims, Dimension levelDim) throws InvalidRangeException { List<Dimension> dims = ncVar.getDimensions(); int newDimIndex = dims.indexOf(levelDim); //String shapeS = ncVar.getShapeS(); int[] origin = new int[ncVar.getRank()]; int[] shape = ncVar.getShape(); int count = 0; for (Dimension dim : newDims) { String name = ncVar.getShortName() + "-" + dim.getShortName(); origin[newDimIndex] = count; shape[newDimIndex] = dim.getLength(); Variable varNew = ncVar.section(new Section(origin, shape)); varNew.setName(name); varNew.setDimension(newDimIndex, dim); // synthesize long name String long_name = ds.findAttValueIgnoreCase(ncVar, CDM.LONG_NAME, ncVar.getShortName()); long_name = long_name + "-" + dim.getShortName(); ds.addVariableAttribute(varNew, new Attribute(CDM.LONG_NAME, long_name)); ds.addVariable(null, varNew); parseInfo.format("Created New Variable as section = "); varNew.getNameAndDimensions(parseInfo, true, false); parseInfo.format("\n"); count += dim.getLength(); } }
private Projection makeLCProjection(NetcdfDataset ds) { Attribute latLonOrigin = projVar.findAttributeIgnoreCase("latLonOrigin"); if (latLonOrigin == null) throw new IllegalStateException(); double centralLon = latLonOrigin.getNumericValue(0).doubleValue(); double centralLat = latLonOrigin.getNumericValue(1).doubleValue(); double par1 = findAttributeDouble( "stdParallelOne"); double par2 = findAttributeDouble( "stdParallelTwo"); LambertConformal lc = new LambertConformal(centralLat, centralLon, par1, par2); // make Coordinate Transform Variable ProjectionCT ct = new ProjectionCT("lambertConformalProjection", "FGDC", lc); VariableDS ctVar = makeCoordinateTransformVariable(ds, ct); ctVar.addAttribute( new Attribute(_Coordinate.Axes, "xCoord yCoord")); ds.addVariable(null, ctVar); return lc; }
protected void promoteGlobalAttributes(DatasetOuterDimension typicalDataset) throws IOException { for (CacheVar cv : cacheList) { if (!(cv instanceof PromoteVar)) continue; PromoteVar pv = (PromoteVar) cv; Array data = pv.read(typicalDataset); if (data == null) throw new IOException("cant read "+typicalDataset); pv.dtype = DataType.getType(data.getElementType()); VariableDS promotedVar = new VariableDS(ncDataset, null, null, pv.varName, pv.dtype, dimName, null, null); /* if (data.getSize() > 1) { // LOOK case of non-scalar global attribute not delat with Dimension outer = ncDataset.getRootGroup().findDimension(dimName); Dimension inner = new Dimension("", (int) data.getSize(), false); //anonymous List<Dimension> dims = new ArrayList<Dimension>(2); dims.add(outer); dims.add(inner); promotedVar.setDimensions(dims); } */ ncDataset.addVariable(null, promotedVar); promotedVar.setProxyReader( this); promotedVar.setSPobject(pv); } }
private Projection makeLCProjection(NetcdfDataset ds) { Attribute latLonOrigin = projVar.findAttributeIgnoreCase("latLonOrigin"); double centralLon = latLonOrigin.getNumericValue(0).doubleValue(); double centralLat = latLonOrigin.getNumericValue(1).doubleValue(); double par1 = findAttributeDouble( "stdParallelOne"); double par2 = findAttributeDouble( "stdParallelTwo"); LambertConformal lc = new LambertConformal(centralLat, centralLon, par1, par2); // make Coordinate Transform Variable ProjectionCT ct = new ProjectionCT("lambertConformalProjection", "FGDC", lc); VariableDS ctVar = makeCoordinateTransformVariable(ds, ct); ctVar.addAttribute( new Attribute(_Coordinate.Axes, "xCoord yCoord")); ds.addVariable(null, ctVar); return lc; }
public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) { projCT = makeProjectionCT(ds); if (projCT != null) { VariableDS v = makeCoordinateTransformVariable(ds, projCT); ds.addVariable(null, v); String xname = findCoordinateName(ds, AxisType.GeoX); String yname = findCoordinateName(ds, AxisType.GeoY); if (xname != null && yname != null) v.addAttribute(new Attribute(_Coordinate.Axes, xname + " " + yname)); } ds.finish(); }
public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) { projCT = makeProjectionCT(ds); if (projCT != null) { VariableDS v = makeCoordinateTransformVariable(ds, projCT); ds.addVariable(null, v); String xname = findCoordinateName(ds, AxisType.GeoX); String yname = findCoordinateName(ds, AxisType.GeoY); if (xname != null && yname != null) v.addAttribute(new Attribute(_Coordinate.Axes, xname + " " + yname)); } ds.finish(); }
public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) { projCT = makeProjectionCT(ds); if (projCT != null) { VariableDS v = makeCoordinateTransformVariable(ds, projCT); ds.addVariable(null, v); String xname = findCoordinateName(ds, AxisType.GeoX); String yname = findCoordinateName(ds, AxisType.GeoY); if (xname != null && yname != null) v.addAttribute(new Attribute(_Coordinate.Axes, xname + " " + yname)); } ds.finish(); }
public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) { projCT = makeProjectionCT(ds); if (projCT != null) { VariableDS v = makeCoordinateTransformVariable(ds, projCT); ds.addVariable(null, v); String xname = findCoordinateName(ds, AxisType.GeoX); String yname = findCoordinateName(ds, AxisType.GeoY); if (xname != null && yname != null) v.addAttribute(new Attribute(_Coordinate.Axes, xname + " " + yname)); } ds.finish(); }
public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) { projCT = makeProjectionCT(ds); if (projCT != null) { VariableDS v = makeCoordinateTransformVariable(ds, projCT); ds.addVariable(null, v); String xname = findCoordinateName(ds, AxisType.GeoX); String yname = findCoordinateName(ds, AxisType.GeoY); if (xname != null && yname != null) v.addAttribute(new Attribute(_Coordinate.Axes, xname + " " + yname)); } ds.finish(); }
public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) { projCT = makeProjectionCT(ds); if (projCT != null) { VariableDS v = makeCoordinateTransformVariable(ds, projCT); ds.addVariable(null, v); String xname = findCoordinateName(ds, AxisType.GeoX); String yname = findCoordinateName(ds, AxisType.GeoY); if (xname != null && yname != null) v.addAttribute(new Attribute(_Coordinate.Axes, xname + " " + yname)); } ds.finish(); }
protected void promoteGlobalAttributes(DatasetOuterDimension typicalDataset) throws IOException { for (CacheVar cv : cacheList) { if (!(cv instanceof PromoteVar)) continue; PromoteVar pv = (PromoteVar) cv; Array data = pv.read(typicalDataset); pv.dtype = DataType.getType(data.getElementType()); VariableDS promotedVar = new VariableDS(ncDataset, null, null, pv.varName, pv.dtype, dimName, null, null); /* if (data.getSize() > 1) { // LOOK case of non-scalar global attribute not delat with Dimension outer = ncDataset.getRootGroup().findDimension(dimName); Dimension inner = new Dimension("", (int) data.getSize(), false); //anonymous List<Dimension> dims = new ArrayList<Dimension>(2); dims.add(outer); dims.add(inner); promotedVar.setDimensions(dims); } */ ncDataset.addVariable(null, promotedVar); promotedVar.setProxyReader( this); promotedVar.setSPobject(pv); } }
/** * Add a CoordinateAxis to the dataset, by turning the VariableDS into a CoordinateAxis (if needed). * Also adds it to the list of variables. Replaces any existing Variable and CoordinateAxis with the same name. * * @param v make this VariableDS into a CoordinateAxis * @return the CoordinateAxis */ public CoordinateAxis addCoordinateAxis(VariableDS v) { if (v == null) return null; CoordinateAxis oldVar = findCoordinateAxis(v.getFullName()); if (oldVar != null) coordAxes.remove(oldVar); CoordinateAxis ca = (v instanceof CoordinateAxis) ? (CoordinateAxis) v : CoordinateAxis.factory(this, v); coordAxes.add(ca); if (v.isMemberOfStructure()) { Structure parentOrg = v.getParentStructure(); // gotta be careful to get the wrapping parent Structure parent = (Structure) findVariable(parentOrg.getFullNameEscaped()); parent.replaceMemberVariable(ca); } else { removeVariable(v.getParentGroup(), v.getShortName()); // remove by short name if it exists addVariable(ca.getParentGroup(), ca); } return ca; }
/** * Add a CoordinateAxis to the dataset, by turning the VariableDS into a CoordinateAxis (if needed). * Also adds it to the list of variables. Replaces any existing Variable and CoordinateAxis with the same name. * * @param v make this VariableDS into a CoordinateAxis * @return the CoordinateAxis */ public CoordinateAxis addCoordinateAxis(VariableDS v) { if (v == null) return null; CoordinateAxis oldVar = findCoordinateAxis(v.getFullName()); if (oldVar != null) coordAxes.remove(oldVar); CoordinateAxis ca = (v instanceof CoordinateAxis) ? (CoordinateAxis) v : CoordinateAxis.factory(this, v); coordAxes.add(ca); if (v.isMemberOfStructure()) { Structure parentOrg = v.getParentStructure(); // gotta be careful to get the wrapping parent Structure parent = (Structure) findVariable(parentOrg.getFullNameEscaped()); parent.replaceMemberVariable(ca); } else { removeVariable(v.getParentGroup(), v.getShortName()); // remove by short name if it exists addVariable(ca.getParentGroup(), ca); } return ca; }
/** * Add a CoordinateAxis to the dataset, by turning the VariableDS into a CoordinateAxis (if needed). * Also adds it to the list of variables. Replaces any existing Variable and CoordinateAxis with the same name. * * @param v make this VariableDS into a CoordinateAxis * @return the CoordinateAxis */ public CoordinateAxis addCoordinateAxis(VariableDS v) { if (v == null) return null; CoordinateAxis oldVar = findCoordinateAxis(v.getFullName()); if (oldVar != null) coordAxes.remove(oldVar); CoordinateAxis ca = (v instanceof CoordinateAxis) ? (CoordinateAxis) v : CoordinateAxis.factory(this, v); coordAxes.add(ca); if (v.isMemberOfStructure()) { Structure parentOrg = v.getParentStructure(); // gotta be careful to get the wrapping parent Structure parent = (Structure) findVariable(parentOrg.getFullNameEscaped()); parent.replaceMemberVariable(ca); } else { removeVariable(v.getParentGroup(), v.getShortName()); // remove by short name if it exists addVariable(ca.getParentGroup(), ca); } return ca; }
VariableDS v = makeCoordinateTransformVariable(ds, projCT); v.addAttribute( new Attribute(_Coordinate.Axes, "x y")); ds.addVariable(null, v);