Skip to content

Commit fa321c2

Browse files
authored
Merge pull request #1362 from haileyajohnson/dsgSubsetWriters
Dsg subset writers
2 parents 4ff1c8e + 18a8d99 commit fa321c2

File tree

5 files changed

+22
-48
lines changed

5 files changed

+22
-48
lines changed

cdm/core/src/main/java/ucar/nc2/ft/point/writer/CFPointWriter.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,26 +266,31 @@ private static int writeStationProfileFeatureCollection(FeatureDatasetPoint data
266266
List<Variable> extraVariables = new ArrayList<>();
267267
List<StationFeature> flattenFeatures = new ArrayList<>();
268268

269+
int countProfiles = 0;
270+
int name_strlen = 0;
269271
for (DsgFeatureCollection dsgFeatures : dataset.getPointFeatureCollectionList()) {
270272
extraVariables.addAll(dsgFeatures.getExtraVariables());
271273
flattenFeatures.addAll(((StationProfileFeatureCollection) dsgFeatures).getStationFeatures());
274+
for (StationProfileFeature station : (StationProfileFeatureCollection) dsgFeatures) {
275+
name_strlen = Math.max(name_strlen, station.getName().length());
276+
for (ProfileFeature fp : station) {
277+
countProfiles++;
278+
}
279+
}
272280
}
273281

274282
cfWriter.setExtraVariables(extraVariables);
275283
cfWriter.setStations(flattenFeatures);
276-
cfWriter.setFeatureAuxInfo(0, 0);
284+
cfWriter.setFeatureAuxInfo(countProfiles, name_strlen);
277285
cfWriter.writeHeader(flattenFeatures);
278286

279287
int count = 0;
280288
for (DsgFeatureCollection featureCollection : dataset.getPointFeatureCollectionList()) {
281-
cfWriter.resetObsIndex();
282-
for (StationFeature station : ((StationProfileFeatureCollection) featureCollection).getStationFeatures()) {
283-
StationProfileFeature spf = (StationProfileFeature) station;
284-
cfWriter.resetProfileIndex();
285-
for (ProfileFeature pf : spf) {
289+
for (StationProfileFeature station : (StationProfileFeatureCollection) featureCollection) {
290+
for (ProfileFeature pf : station) {
286291
if (pf.getTime() == null)
287292
continue; // assume this means its an "incomplete multidimensional"
288-
count += cfWriter.writeProfile(spf, pf);
293+
count += cfWriter.writeProfile(station, pf);
289294
if (debug && count % 100 == 0)
290295
logger.debug(String.format("%d ", count));
291296
if (debug && count % 1000 == 0)

cdm/core/src/main/java/ucar/nc2/ft/point/writer/WriterCFStationCollection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void writeHeader(List<StationFeature> stns, @Nullable StationPointFeature
109109

110110
llbb = CFPointWriterUtils.getBoundingBox(stnList); // gets written in super.finish();
111111

112-
altitudeCoordinateName = altName;
112+
altitudeCoordinateName = stationAltName;
113113
coords.add(VariableSimpleBuilder
114114
.makeScalar(stationIndexName, "station index for this observation record", null, DataType.INT)
115115
.addAttribute(CF.INSTANCE_DIMENSION, stationDimName).build());

cdm/core/src/main/java/ucar/nc2/ft/point/writer/WriterCFStationProfileCollection.java

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package ucar.nc2.ft.point.writer;
77

88
import com.google.common.collect.ImmutableList;
9-
import com.google.common.collect.Iterables;
109
import org.slf4j.Logger;
1110
import org.slf4j.LoggerFactory;
1211
import ucar.ma2.*;
@@ -94,11 +93,16 @@ public int writeProfile(StationProfileFeature spf, ProfileFeature profile) throw
9493
writeObsData(pf);
9594
count++;
9695
}
96+
Integer stnIndex = stationIndexMap.get(spf.getName());
97+
if (stnIndex == null) {
98+
log.warn("BAD station {}", spf.getName());
99+
} else {
100+
writeProfileData(stnIndex, profile, count);
101+
}
97102
return count;
98103
}
99104

100105
public void writeHeader(List<StationFeature> stations) throws IOException {
101-
102106
List<VariableSimpleIF> obsCoords = new ArrayList<>();
103107
List<PointFeatureCollection> flattenStations = new ArrayList<>();
104108
List<StructureData> featureData = new ArrayList<>();
@@ -133,35 +137,10 @@ public void writeHeader(List<StationFeature> stations) throws IOException {
133137
for (StationFeature sf : stnList) {
134138
writeStationData(sf);
135139
stationIndexMap.put(sf.getName(), count);
136-
for (ProfileFeature p : (StationProfileFeature) sf) {
137-
int countPoints = 0;
138-
if (p.size() >= 0) {
139-
countPoints += p.size();
140-
} else {
141-
countPoints += Iterables.size(p);
142-
}
143-
writeProfileData(count, p, countPoints);
144-
}
145140
count++;
146141
}
147142
}
148143

149-
@Override
150-
public void setFeatureAuxInfo(int nfeatures, int id_strlen) {
151-
int countProfiles = 0;
152-
int name_strlen = 0;
153-
for (StationFeature s : stnList) {
154-
name_strlen = Math.max(name_strlen, s.getName().length());
155-
if (((StationProfileFeature) s).size() >= 0)
156-
countProfiles += ((StationProfileFeature) s).size();
157-
else {
158-
countProfiles += Iterables.size(((StationProfileFeature) s));
159-
}
160-
}
161-
this.nfeatures = countProfiles;
162-
this.id_strlen = name_strlen;
163-
}
164-
165144
protected void makeFeatureVariables(List<StructureData> stnDataStructs, boolean isExtended) {
166145
// add the dimensions : extended model can use an unlimited dimension
167146
// Dimension stationDim = isExtended ? writer.addDimension(null, stationDimName, 0, true, true, false) :
@@ -265,10 +244,6 @@ protected void makeMiddleVariables(List<StructureData> profileDataStructs, boole
265244

266245
private int profileRecno;
267246

268-
protected void resetProfileIndex() {
269-
profileRecno = 0;
270-
}
271-
272247
public void writeProfileData(int stnIndex, ProfileFeature profile, int nobs) throws IOException {
273248
trackBB(profile.getLatLon(), profile.getTime());
274249

@@ -292,10 +267,6 @@ public void writeProfileData(int stnIndex, ProfileFeature profile, int nobs) thr
292267

293268
private int obsRecno;
294269

295-
protected void resetObsIndex() {
296-
obsRecno = 0;
297-
}
298-
299270
public void writeObsData(PointFeature pf) throws IOException {
300271
StructureMembers.Builder smb = StructureMembers.builder().setName("Coords");
301272
smb.addMemberScalar(pf.getFeatureCollection().getTimeName(), null, null, DataType.DOUBLE, pf.getObservationTime());

cdm/core/src/main/java/ucar/nc2/ft/point/writer2/WriterCFPointAbstract.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ protected void writeHeader(List<VariableSimpleIF> obsCoords,
218218

219219
Formatter coordNames = new Formatter().format("%s %s %s", stnFeature.getTimeName(), latName, lonName);
220220
if (!Double.isNaN(pointFeat.getLocation().getAltitude())) {
221-
coordNames.format(" %s", stnFeature.getAltName());
221+
coordNames.format(" %s", altitudeCoordinateName);
222222
}
223223
if (isExtendedModel) {
224224
addDataVariablesExtended(recordb, obsData, coordNames.toString());

cdm/core/src/main/java/ucar/nc2/ft/point/writer2/WriterCFStationProfileCollection.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,8 @@ protected void writeHeader(List<StationFeature> stations) throws IOException {
139139
stationIndexMap.put(sf.getName(), count);
140140
for (ProfileFeature p : (StationProfileFeature) sf) {
141141
int countPoints = 0;
142-
if (p.size() >= 0) {
143-
countPoints += p.size();
144-
} else {
145-
countPoints += Iterables.size(p);
142+
for (PointFeature pf : p) {
143+
countPoints++;
146144
}
147145
writeProfileData(count, p, countPoints);
148146
}

0 commit comments

Comments
 (0)