ucar.nc2.Dimension Java Examples
The following examples show how to use
ucar.nc2.Dimension.
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: SimpleGeometryCSBuilder.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public String toString() { Formatter f2 = new Formatter(); f2.format("%s", type == null ? "" : type.toString()); if (type == null) { f2.close(); return ""; } f2.format("}"); f2.format("%n allAxes=("); for (CoordinateAxis axis : allAxes) f2.format("%s, ", axis.getShortName()); f2.format(") {"); for (Dimension dim : CoordinateSystem.makeDomain(allAxes)) f2.format("%s, ", dim.getShortName()); f2.format("}%n"); String stringRepres = f2.toString(); f2.close(); return stringRepres; }
Example #2
Source File: DMSPHeader.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Parse the file header information about the file (e.g., file ID, dataset ID, * record size, number of records) and create netCDF attributes and dimensions * where appropriate. * * @throws IOException if any problems reading the file (or validating the file). */ private void handleFileInformation() throws IOException { fileIdAtt = new Attribute(this.fileIdAttName, headerInfo.get(HeaderInfoTitle.FILE_ID.toString())); datasetIdAtt = new Attribute(this.datasetIdAttName, headerInfo.get(HeaderInfoTitle.DATA_SET_ID.toString())); recordSizeInBytes = Integer.parseInt(headerInfo.get(HeaderInfoTitle.RECORD_BYTES.toString())); numRecords = Integer.parseInt(headerInfo.get(HeaderInfoTitle.NUM_RECORDS.toString())); numHeaderRecords = Integer.parseInt(headerInfo.get(HeaderInfoTitle.NUM_HEADER_RECORDS.toString())); numDataRecords = Integer.parseInt(headerInfo.get(HeaderInfoTitle.NUM_DATA_RECORDS.toString())); numDataRecordsDim = new Dimension(this.numDataRecordsDimName, numDataRecords, true, true, false); numArtificialDataRecords = Integer.parseInt(headerInfo.get(HeaderInfoTitle.NUM_ARTIFICIAL_DATA_RECORDS.toString())); this.headerSizeInBytes = this.numHeaderRecords * this.recordSizeInBytes; if (numRecords * ((long) this.recordSizeInBytes) != this.actualSize) { throw new IOException("Invalid DMSP file: the number of records <" + this.numRecords + "> times the record size <" + this.recordSizeInBytes + "> does not equal the size of the file <" + this.actualSize + ">."); } }
Example #3
Source File: WRFConvention.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Nullable private CoordinateAxis.Builder makeXCoordAxis(String axisName, String dimName) { Optional<Dimension> dimOpt = rootGroup.findDimension(dimName); if (!dimOpt.isPresent()) { return null; } Dimension dim = dimOpt.get(); double dx = findAttributeDouble("DX") / 1000.0; // km ya just gotta know int nx = dim.getLength(); double startx = centerX - dx * (nx - 1) / 2; // ya just gotta know CoordinateAxis.Builder v = CoordinateAxis1D.builder().setName(axisName).setDataType(DataType.DOUBLE) .setParentGroupBuilder(rootGroup).setDimensionsByName(dim.getShortName()).setUnits("km") .setDesc("synthesized GeoX coordinate from DX attribute"); v.setAutoGen(startx, dx); v.setAxisType(AxisType.GeoX); v.addAttribute(new Attribute(_Coordinate.AxisType, "GeoX")); if (!axisName.equals(dim.getShortName())) v.addAttribute(new Attribute(_Coordinate.AliasForDimension, dim.getShortName())); if (gridE) v.addAttribute(new Attribute(_Coordinate.Stagger, CDM.ARAKAWA_E)); return v; }
Example #4
Source File: DatasetTreeView.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
void makeChildren() { children = new ArrayList<>(); List dims = group.getDimensions(); for (Object dim : dims) { children.add(new DimensionNode(this, (Dimension) dim)); } for (Variable var : group.getVariables()) { children.add(new VariableNode(this, var)); } List groups = group.getGroups(); for (Object group1 : groups) { children.add(new GroupNode(this, (Group) group1)); } }
Example #5
Source File: WriterCFTrajectoryProfileCollection.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override void makeFeatureVariables(StructureData trajData, boolean isExtended) { // add the dimensions : extended model can use an unlimited dimension Dimension trajDim = writerb.addDimension(trajDimName, ntraj); List<VariableSimpleIF> trajVars = new ArrayList<>(); trajVars.add(VariableSimpleBuilder.makeString(trajIdName, "trajectory identifier", null, traj_strlen) .addAttribute(CF.CF_ROLE, CF.TRAJECTORY_ID).build()); for (StructureMembers.Member m : trajData.getMembers()) { if (findDataVar(m.getName()) != null) trajVars.add(VariableSimpleBuilder.fromMember(m).build()); } if (isExtended) { Structure.Builder structb = writerb.addStructure(trajStructName, trajDimName); addCoordinatesExtended(structb, trajVars); } else { addCoordinatesClassic(trajDim, trajVars, trajVarMap); } }
Example #6
Source File: TestChunkingIndex.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testChunkingStrategy() { Dimension d2 = new Dimension("2", 2); Dimension d10 = new Dimension("10", 10); Dimension d20 = new Dimension("20", 20); Dimension dun = new Dimension("u", 0, true, true, false); testOneStrategy(new Dimension[] {dun, d10, d20}, 50, 40); testOneStrategy(new Dimension[] {dun, d10, d20}, 500, 400); testOneStrategy(new Dimension[] {dun}, 500, 500); testOneStrategy(new Dimension[] {dun, d2}, 101, 100); testOneStrategy(new Dimension[] {dun, d10}, 777, 770); testOneStrategy(new Dimension[] {dun, dun}, 100, 100); testOneStrategy(new Dimension[] {dun, d10, dun}, 100, 90); testOneStrategy(new Dimension[] {dun, dun, d2}, 100, 98); testOneStrategy(new Dimension[] {dun, dun, d2}, 400, 392); testOneStrategy(new Dimension[] {dun, dun, dun}, 400, 343); }
Example #7
Source File: H5headerNew.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
private String addDimension(Group.Builder parent, H5Group h5group, String name, int length, boolean isUnlimited) { int pos = name.lastIndexOf('/'); String dimName = (pos >= 0) ? name.substring(pos + 1) : name; Dimension d = h5group.dimMap.get(dimName); // first look in current group if (d == null) { // create if not found d = Dimension.builder().setName(name).setIsUnlimited(isUnlimited).setLength(length).build(); h5group.dimMap.put(dimName, d); h5group.dimList.add(d); parent.addDimension(d); if (debugDimensionScales) { log.debug("addDimension name=" + name + " dim= " + d + " to group " + parent.shortName); } } else { // check has correct length if (d.getLength() != length) throw new IllegalStateException( "addDimension: DimScale has different length than dimension it references dimScale=" + dimName); } return d.getShortName(); }
Example #8
Source File: CFpointObsExt.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override protected boolean identifyEncodingProfile(NetcdfDataset ds, EncodingInfo info, Formatter errlog) { Evaluator.VarAtt varatt = Evaluator.findVariableWithAttribute(ds, CF.SAMPLE_DIMENSION); if (varatt == null) return false; String dimName = varatt.att.getStringValue(); Dimension obsDim = ds.findDimension(dimName); Structure profile = info.lat.getParentStructure(); if (profile.getRank() == 0) { // could be scalar info.set(Encoding.single, null, obsDim); } Dimension profileDim = profile.getDimension(0); // now find the child structure info.childStruct = Evaluator.findStructureWithDimensions(ds, obsDim, null); // the raggeds if (identifyRaggeds(ds, info, profileDim, obsDim, errlog)) return true; errlog.format("CFpointObsExt: %s only supports ragged array representation%n", CF.FeatureType.profile); return false; }
Example #9
Source File: NcStream.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
private static NcStreamProto.Structure.Builder encodeStructure(Structure s) throws IOException { NcStreamProto.Structure.Builder builder = NcStreamProto.Structure.newBuilder(); builder.setName(s.getShortName()); builder.setDataType(convertDataType(s.getDataType())); for (Dimension dim : s.getDimensions()) builder.addShape(encodeDim(dim)); for (Attribute att : s.attributes()) builder.addAtts(encodeAtt(att)); for (Variable v : s.getVariables()) { if (v instanceof Structure) builder.addStructs(NcStream.encodeStructure((Structure) v)); else builder.addVars(NcStream.encodeVar(v, -1)); } return builder; }
Example #10
Source File: H5headerNew.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
private String extendDimension(Group.Builder parent, H5Group h5group, String name, int length) { int pos = name.lastIndexOf('/'); String dimName = (pos >= 0) ? name.substring(pos + 1) : name; Dimension d = h5group.dimMap.get(dimName); // first look in current group if (d == null) { d = parent.findDimension(dimName).orElse(null); // then look in parent groups } if (d != null) { if (d.isUnlimited() && (length > d.getLength())) { parent.replaceDimension(d.toBuilder().setLength(length).build()); } if (!d.isUnlimited() && (length != d.getLength())) { throw new IllegalStateException( "extendDimension: DimScale has different length than dimension it references dimScale=" + dimName); } return d.getShortName(); } return dimName; }
Example #11
Source File: RafNimbus.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
public TableConfig getConfig(FeatureType wantFeatureType, NetcdfDataset ds, Formatter errlog) { TableConfig topTable = new TableConfig(Table.Type.Top, "singleTrajectory"); CoordinateAxis coordAxis = CoordSysEvaluator.findCoordByType(ds, AxisType.Time); if (coordAxis == null) { errlog.format("Cant find a time coordinate"); return null; } Dimension innerDim = coordAxis.getDimension(0); boolean obsIsStruct = Evaluator.hasNetcdf3RecordStructure(ds) && innerDim.isUnlimited(); TableConfig obsTable = new TableConfig(Table.Type.Structure, innerDim.getShortName()); obsTable.dimName = innerDim.getShortName(); obsTable.time = coordAxis.getFullName(); obsTable.structName = obsIsStruct ? "record" : innerDim.getShortName(); obsTable.structureType = obsIsStruct ? TableConfig.StructureType.Structure : TableConfig.StructureType.PsuedoStructure; CoordSysEvaluator.findCoords(obsTable, ds, axis -> innerDim.equals(axis.getDimension(0))); topTable.addChild(obsTable); return topTable; }
Example #12
Source File: NetcdfUtils.java From OpenDA with GNU Lesser General Public License v3.0 | 6 votes |
/** * Creates metadata and data variables for the given exchangeItems and/or ensembleExchangeItems in the given netcdfFile, if not present yet. * Each exchangeItem stores a scalar timeseries for a single location (and a single ensemble member). * All exchangeItems must use the same ensemble member indices. */ public static void createMetadataAndDataVariablesForScalars(NetcdfFileWriter netcdfFileWriter, List<IExchangeItem> exchangeItems, Map<String, Map<Integer, IExchangeItem>> ensembleExchangeItems, Map<ITimeInfo, Dimension> timeInfoTimeDimensionMap, String stationNameVarName, String stationDimensionVarName, int stationCount, int ensembleMemberCount) { //create stations variable. Dimension stationDimension = createStationsVariable(netcdfFileWriter, stationNameVarName, stationDimensionVarName, stationCount); //create realization variable. Dimension realizationDimension = null; if (ensembleMemberCount > 0) { realizationDimension = createRealizationVariable(netcdfFileWriter, ensembleMemberCount); } //create data variables. NetcdfUtils.createDataVariables(netcdfFileWriter, exchangeItems, ensembleExchangeItems, realizationDimension, stationDimension, timeInfoTimeDimensionMap, null); }
Example #13
Source File: TestChunkingIndex.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void testOneStrategy(Dimension[] shape, int maxChunkElems, long expectSize) { List<Dimension> dims = Arrays.asList(shape); show("shape", dims); System.out.printf(" max = %d%n", maxChunkElems); Nc4ChunkingDefault chunker = new Nc4ChunkingDefault(); chunker.setDefaultChunkSize(maxChunkElems); chunker.setMinChunksize(maxChunkElems); int[] result = chunker.computeUnlimitedChunking(dims, 1); show("chunk", result); long shapeSize = new Section(result).computeSize(); System.out.printf(" size = %d%n%n", shapeSize); assert shapeSize <= maxChunkElems; assert shapeSize >= maxChunkElems / 2; assert shapeSize == expectSize : shapeSize + " != " + expectSize; }
Example #14
Source File: CFpointObs.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
EncodingInfo set(Encoding encoding, Dimension parentDim, Dimension childDim, Dimension grandChildDim) { this.encoding = encoding; this.parentDim = parentDim; this.childDim = childDim; this.grandChildDim = grandChildDim; return this; }
Example #15
Source File: CDLWriter.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void writeCDL(Dimension dim, Indent indent) { String name = strict ? NetcdfFiles.makeValidCDLName(dim.getShortName()) : dim.getShortName(); out.format("%s%s", indent, name); if (dim.isUnlimited()) out.format(" = UNLIMITED; // (%d currently)", dim.getLength()); else if (dim.isVariableLength()) out.format(" = UNKNOWN;"); else out.format(" = %d;", dim.getLength()); }
Example #16
Source File: WriterCFPointAbstract.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void addDataVariablesClassic(Dimension recordDim, StructureData stnData, HashSet<String> varSet, String coordVars) { addDimensionsClassic(dataVars); for (StructureMembers.Member m : stnData.getMembers()) { VariableSimpleIF oldVar = findDataVar(m.getName()); if (oldVar == null) continue; List<Dimension> dims = makeDimensionList(oldVar.getDimensions()); dims.add(0, recordDim); Variable.Builder newVar; if (oldVar.getDataType() == DataType.STRING && !isExtendedModel) { // What should the string length be ?? String name = oldVar.getShortName(); Dimension strlen = new Dimension(name + "_strlen", defaultStringLength); newVar = Variable.builder().setName(name).setDataType(DataType.CHAR).setDimensions(dims).addDimension(strlen); writerb.getRootGroup().addDimensionIfNotExists(strlen); } else { newVar = Variable.builder().setName(oldVar.getShortName()).setDataType(oldVar.getDataType()).setDimensions(dims); } if (writerb.getRootGroup().replaceVariable(newVar)) { logger.warn("Variable was already added =" + oldVar.getShortName()); } for (Attribute att : oldVar.attributes()) { String attName = att.getShortName(); if (!reservedVariableAtts.contains(attName) && !attName.startsWith("_Coordinate")) newVar.addAttribute(att); } newVar.addAttribute(new Attribute(CF.COORDINATES, coordVars)); varSet.add(oldVar.getShortName()); } }
Example #17
Source File: FmrcDataset.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
private VariableDS makeTimeCoordinate(NetcdfDataset result, Group group, String dimName, CalendarDate base, FmrcInvLite.ValueB valueb) { DataType dtype = DataType.DOUBLE; VariableDS timeVar = new VariableDS(result, group, null, dimName, dtype, dimName, null, null); // LOOK could just // make a // CoordinateAxis1D timeVar.addAttribute(new Attribute(CDM.LONG_NAME, "Forecast time for ForecastModelRunCollection")); timeVar.addAttribute(new ucar.nc2.Attribute("standard_name", "time")); timeVar.addAttribute(new ucar.nc2.Attribute(CF.CALENDAR, base.getCalendar().name())); // timeVar.addAttribute(new ucar.nc2.Attribute(CDM.UNITS, "hours since " + base)); // Ensure a valid udunit 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.Time.toString())); // construct the values int ntimes = valueb.offset.length; timeVar.setCachedData(Array.factory(DataType.DOUBLE, new int[] {ntimes}, valueb.offset)); group.addVariable(timeVar); if (valueb.bounds != null) { String bname = timeVar.getShortName() + "_bounds"; timeVar.addAttribute(new ucar.nc2.Attribute("bounds", bname)); Dimension bd = ucar.nc2.dataset.DatasetConstructor.getBoundsDimension(result); VariableDS boundsVar = new VariableDS(result, group, null, bname, dtype, dimName + " " + bd.getShortName(), null, null); boundsVar.addAttribute(new Attribute(CDM.LONG_NAME, "bounds for " + timeVar.getShortName())); boundsVar.setCachedData(Array.factory(DataType.DOUBLE, new int[] {ntimes, 2}, valueb.bounds)); group.addVariable(boundsVar); } return timeVar; }
Example #18
Source File: WriterCFPointAbstract.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void addDataVariablesExtended(Structure.Builder<?> recordb, StructureData obsData, String coordNames) { for (StructureMembers.Member m : obsData.getMembers()) { VariableSimpleIF oldVar = findDataVar(m.getName()); if (oldVar == null) continue; // make dimension list StringBuilder dimNames = new StringBuilder(); for (Dimension d : oldVar.getDimensions()) { if (d.isUnlimited()) continue; if (d.getShortName() == null || !d.getShortName().equals(recordDimName)) dimNames.append(" ").append(d.getLength()); // anonymous } Variable.Builder newVar = Variable.builder().setName(oldVar.getShortName()).setDataType(oldVar.getDataType()) .setParentGroupBuilder(writerb.getRootGroup()).setDimensionsByName(dimNames.toString()); recordb.addMemberVariable(newVar); // TODO /* * Variable newVar = * writer.addStructureMember(record, oldVar.getShortName(), oldVar.getDataType(), dimNames.toString()); * if (newVar == null) { * logger.warn("Variable already exists =" + oldVar.getShortName()); // LOOK barf * continue; * } */ for (Attribute att : oldVar.attributes()) { String attName = att.getShortName(); if (!reservedVariableAtts.contains(attName) && !attName.startsWith("_Coordinate")) newVar.addAttribute(att); } newVar.addAttribute(new Attribute(CF.COORDINATES, coordNames)); } }
Example #19
Source File: PointConfigXML.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void makeMultidimInner(NetcdfDataset ds, TableConfig parentTable, TableConfig childTable) { Dimension parentDim = ds.findDimension(parentTable.dimName); Dimension childDim = ds.findDimension(childTable.innerName); // divide up the variables between the parent and the child List<String> obsVars; List<Variable> vars = ds.getVariables(); List<String> parentVars = new ArrayList<>(vars.size()); obsVars = new ArrayList<>(vars.size()); for (Variable orgV : vars) { if (orgV instanceof Structure) continue; Dimension dim0 = orgV.getDimension(0); if ((dim0 != null) && dim0.equals(parentDim)) { if ((orgV.getRank() == 1) || ((orgV.getRank() == 2) && orgV.getDataType() == DataType.CHAR)) { parentVars.add(orgV.getShortName()); } else { Dimension dim1 = orgV.getDimension(1); if ((dim1 != null) && dim1.equals(childDim)) obsVars.add(orgV.getShortName()); } } } parentTable.vars = parentVars; childTable.vars = obsVars; }
Example #20
Source File: NdbcNetcdf4.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public TableConfig getConfig(FeatureType wantFeatureType, NetcdfDataset ds, Formatter errlog) { Dimension obsDim = ds.findDimension("time"); if (obsDim == null) { CoordinateAxis axis = CoordSysEvaluator.findCoordByType(ds, AxisType.Time); if ((axis != null) && axis.isScalar()) obsDim = axis.getDimension(0); } if (obsDim == null) { errlog.format("Must have an Observation dimension: unlimited dimension, or from Time Coordinate"); return null; } boolean hasStruct = Evaluator.hasNetcdf3RecordStructure(ds); // otherwise, make it a Station TableConfig nt = new TableConfig(Table.Type.Top, "station"); nt.featureType = FeatureType.STATION; nt.lat = CoordSysEvaluator.findCoordNameByType(ds, AxisType.Lat); nt.lon = CoordSysEvaluator.findCoordNameByType(ds, AxisType.Lon); nt.stnId = ds.getRootGroup().findAttributeString("station_name", null); nt.stnWmoId = ds.getRootGroup().findAttributeString("wmo_id", null); nt.stnDesc = ds.getRootGroup().findAttributeString("description", null); if (nt.stnDesc == null) nt.stnDesc = ds.getRootGroup().findAttributeString("comment", null); TableConfig obs = new TableConfig(Table.Type.Structure, hasStruct ? "record" : obsDim.getShortName()); obs.structName = "record"; obs.structureType = hasStruct ? TableConfig.StructureType.Structure : TableConfig.StructureType.PsuedoStructure; obs.dimName = obsDim.getShortName(); obs.time = CoordSysEvaluator.findCoordNameByType(ds, AxisType.Time); nt.addChild(obs); return nt; }
Example #21
Source File: NcStream.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static Variable.Builder decodeVar(NcStreamProto.Variable var) { DataType varType = convertDataType(var.getDataType()); Variable.Builder ncvar = Variable.builder().setName(var.getName()).setDataType(varType); if (varType.isEnum()) { ncvar.setEnumTypeName(var.getEnumType()); } // The Dimensions are stored redunantly in the Variable. // If shared, they must also exist in a parent Group. However, we dont yet have the Groups wired together, // so that has to wait until build(). List<Dimension> dims = new ArrayList<>(6); Section.Builder section = Section.builder(); for (ucar.nc2.stream.NcStreamProto.Dimension dim : var.getShapeList()) { dims.add(decodeDim(dim)); section.appendRange((int) dim.getLength()); } ncvar.addDimensions(dims); for (ucar.nc2.stream.NcStreamProto.Attribute att : var.getAttsList()) ncvar.addAttribute(decodeAtt(att)); if (!var.getData().isEmpty()) { // LOOK may mess with ability to change var size later. ByteBuffer bb = ByteBuffer.wrap(var.getData().toByteArray()); Array data = Array.factory(varType, section.build().getShape(), bb); ncvar.setCachedData(data, true); } return ncvar; }
Example #22
Source File: TestGribEnsembles.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testEcmwfEns() throws Exception { String filename = TestDir.cdmUnitTestDir + "ft/grid/ensemble/jitka/ECME_RIZ_201201101200_00600_GB"; System.out.printf("Open %s%n", filename); try (NetcdfFile datafile = NetcdfFiles.open(filename)) { NetcdfDataset netcdfDataset = new NetcdfDataset(datafile); GridDataset gridDataset = new GridDataset(netcdfDataset); String requiredName = "Total_precipitation_surface"; GridDatatype gridDatatype = gridDataset.findGridDatatype(requiredName); assertNotNull(gridDatatype); assertEquals(requiredName, gridDatatype.getFullName()); Dimension ensDimension = gridDatatype.getEnsembleDimension(); assertNotNull(ensDimension); // fails in 4.3 , null returned assertEquals(51, ensDimension.getLength()); // is 2 in 4.2, however it should be 51 (incl. control forecast) Dimension timeDimension = gridDatatype.getTimeDimension(); assertEquals(1, timeDimension.getLength()); // ok in both versions Dimension xDimension = gridDatatype.getXDimension(); assertEquals(31, xDimension.getLength()); // ok in both versions Dimension yDimension = gridDatatype.getYDimension(); assertEquals(21, yDimension.getLength()); // ok in both versions } }
Example #23
Source File: NetcdfFormatWriter.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** Add a Variable to the root group. */ public Variable.Builder addVariable(String shortName, DataType dataType, List<Dimension> dims) { if (!isNewFile && !useJna) { throw new UnsupportedOperationException("Cant add variable to existing netcdf-3 files"); } Variable.Builder vb = Variable.builder().setName(shortName).setDataType(dataType).setParentGroupBuilder(rootGroup) .setDimensions(dims); rootGroup.addVariable(vb); return vb; }
Example #24
Source File: NsslRadialAdapter.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public Object isMine(FeatureType wantFeatureType, NetcdfDataset ncd, Formatter errlog) { String format = ncd.getRootGroup().findAttributeString("format", null); if (format != null) { if (format.startsWith("nssl/netcdf")) return this; } Dimension az = ncd.findDimension("Azimuth"); Dimension gt = ncd.findDimension("Gate"); if ((null != az) && (null != gt)) { return this; } return null; }
Example #25
Source File: Nc4ChunkingDefault.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public int[] computeUnlimitedChunking(List<Dimension> dims, int elemSize) { int maxElements = defaultChunkSize / elemSize; int[] result = fillRightmost(convertUnlimitedShape(dims), maxElements); long resultSize = new Section(result).computeSize(); if (resultSize < minChunksize) { maxElements = minChunksize / elemSize; result = incrUnlimitedShape(dims, result, maxElements); } return result; }
Example #26
Source File: GridTable.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
Row(GridDatatype gg) { this.gg = gg; Formatter f = new Formatter(); for (Dimension dim : gg.getDimensions()) f.format("%s ", dim.getShortName()); dims = f.toString(); }
Example #27
Source File: TableConfigurerImpl.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected String matchAxisTypeAndDimension(NetcdfDataset ds, AxisType type, Dimension outer, Dimension inner) { Variable var = CoordSysEvaluator.findCoordByType(ds, type, axis -> ((axis.getRank() == 2) && outer.equals(axis.getDimension(0)) && inner.equals(axis.getDimension(1)))); if (var == null) return null; return var.getShortName(); }
Example #28
Source File: AWIPSConvention.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected AxisType getAxisType(NetcdfDataset ds, VariableEnhanced ve) { Variable v = (Variable) ve; String vname = v.getShortName(); if (vname.equalsIgnoreCase("x")) return AxisType.GeoX; if (vname.equalsIgnoreCase("lon")) return AxisType.Lon; if (vname.equalsIgnoreCase("y")) return AxisType.GeoY; if (vname.equalsIgnoreCase("lat")) return AxisType.Lat; if (vname.equalsIgnoreCase("record")) return AxisType.Time; Dimension dim = v.getDimension(0); if ((dim != null) && dim.getShortName().equalsIgnoreCase("record")) return AxisType.Time; String unit = ve.getUnitsString(); if (unit != null) { if (SimpleUnit.isCompatible("millibar", unit)) return AxisType.Pressure; if (SimpleUnit.isCompatible("m", unit)) return AxisType.Height; } return AxisType.GeoZ; }
Example #29
Source File: GribCoordsMatchGbx.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
private boolean read(GridDatatype gdt) throws IOException { // if (!gdt.getName().startsWith("Total_pre")) return true; if (showMissing) logger.debug("grid {}", gdt.getName()); countReadsForVariable = 0; gdc = gdt.getCoordinateSystem(); grid = gdt; dtCoords = new SubsetParams(); Dimension rtDim = gdt.getRunTimeDimension(); Dimension tDim = gdt.getTimeDimension(); Dimension zDim = gdt.getZDimension(); try { // loop over runtime if (rtDim != null) { CoordinateAxis1DTime rtcoord = gdc.getRunTimeAxis(); for (int rt = 0; rt < rtDim.getLength(); rt++) { dtCoords.setRunTime(rtcoord.getCalendarDate(rt)); readTime(gdt, rt, tDim, zDim); } } else { readTime(gdt, -1, tDim, zDim); } timeCoord2DBoundsArray = null; } catch (AssertionError e) { e.printStackTrace(); return false; } catch (Throwable t) { t.printStackTrace(); return false; } return true; }
Example #30
Source File: WriterCFTrajectoryProfileCollection.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected void makeMiddleVariables(StructureData profileData, boolean isExtended) { Dimension profileDim = writerb.addDimension(profileDimName, nfeatures); // add the profile Variables using the profile dimension List<VariableSimpleIF> profileVars = new ArrayList<>(); profileVars.add(VariableSimpleBuilder.makeString(profileIdName, "profile identifier", null, id_strlen) .addAttribute(CF.CF_ROLE, CF.PROFILE_ID) // profileId:cf_role = "profile_id"; .addAttribute(CDM.MISSING_VALUE, String.valueOf(idMissingValue)).build()); profileVars .add(VariableSimpleBuilder.makeScalar(latName, "profile latitude", CDM.LAT_UNITS, DataType.DOUBLE).build()); profileVars .add(VariableSimpleBuilder.makeScalar(lonName, "profile longitude", CDM.LON_UNITS, DataType.DOUBLE).build()); profileVars.add(VariableSimpleBuilder .makeScalar(profileTimeName, "nominal time of profile", timeUnit.getUdUnit(), DataType.DOUBLE) .addAttribute(CF.CALENDAR, timeUnit.getCalendar().toString()).build()); profileVars.add( VariableSimpleBuilder.makeScalar(trajectoryIndexName, "trajectory index for this profile", null, DataType.INT) .addAttribute(CF.INSTANCE_DIMENSION, trajDimName).build()); profileVars .add(VariableSimpleBuilder.makeScalar(numberOfObsName, "number of obs for this profile", null, DataType.INT) .addAttribute(CF.SAMPLE_DIMENSION, recordDimName).build()); for (StructureMembers.Member m : profileData.getMembers()) { VariableSimpleIF dv = findDataVar(m.getName()); if (dv != null) profileVars.add(dv); } if (isExtended) { Structure.Builder structb = writerb.addStructure(profileStructName, profileDimName); addCoordinatesExtended(structb, profileVars); } else { addCoordinatesClassic(profileDim, profileVars, profileVarMap); } }