Skip to content

Commit

Permalink
Merge pull request #1253 from mnlerman/cf-point-writer-touchups
Browse files Browse the repository at this point in the history
Changes to prevent impacts on TDS code before it's ready
  • Loading branch information
haileyajohnson authored Oct 26, 2023
2 parents 0560755 + eedc29e commit 9449937
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ protected DsgCollectionImpl(String name, CalendarDateUnit timeUnit, String altUn
protected DsgCollectionImpl(String name, String timeName, CalendarDateUnit timeUnit, String altName,
String altUnits) {
this.name = name;
this.timeName = timeName;
// this.timeName = timeName;
this.timeUnit = timeUnit;
this.altName = altName;
// this.altName = altName;
this.altUnits = altUnits;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,8 @@ record = (Structure) writer.addVariable(null, recordName, DataType.STRUCTURE, re

StructureData obsData = pointFeat.getFeatureData();

timeName = pointFeat.getFeatureCollection().getTimeName();

Formatter coordNames = new Formatter().format("%s %s %s", timeName, latName, lonName);
Formatter coordNames =
new Formatter().format("%s %s %s", pointFeat.getFeatureCollection().getTimeName(), latName, lonName);
if (!Double.isNaN(pointFeat.getLocation().getAltitude())) {
coordNames.format(" %s", altitudeCoordinateName);
}
Expand Down Expand Up @@ -692,7 +691,8 @@ protected void addDataVariablesExtended(StructureData obsData, String coordVars)
continue;

// skip duplicates
// if (record.findVariable(oldVar.getShortName()) != null) continue;
if (record.findVariable(oldVar.getShortName()) != null)
continue;

// make dimension list
StringBuilder dimNames = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ public WriterCFPointCollection(String fileOut, List<Attribute> globalAtts, List<

public void writeHeader(PointFeature pf) throws IOException {
List<VariableSimpleIF> coords = new ArrayList<>();
coords.add(VariableSimpleBuilder.makeScalar(timeName, "time of measurement", timeUnit.getUdUnit(), DataType.DOUBLE)
.addAttribute(CF.CALENDAR, timeUnit.getCalendar().toString()).build());
coords.add(VariableSimpleBuilder.makeScalar(pf.getFeatureCollection().getTimeName(), "time of measurement",
timeUnit.getUdUnit(), DataType.DOUBLE).addAttribute(CF.CALENDAR, timeUnit.getCalendar().toString()).build());

coords.add(
VariableSimpleBuilder.makeScalar(latName, "latitude of measurement", CDM.LAT_UNITS, DataType.DOUBLE).build());
coords.add(
VariableSimpleBuilder.makeScalar(lonName, "longitude of measurement", CDM.LON_UNITS, DataType.DOUBLE).build());
Formatter coordNames = new Formatter().format("%s %s %s", timeName, latName, lonName);
Formatter coordNames =
new Formatter().format("%s %s %s", pf.getFeatureCollection().getTimeName(), latName, lonName);
if (altUnits != null) {
coords.add(VariableSimpleBuilder.makeScalar(altName, "altitude of measurement", altUnits, DataType.DOUBLE)
.addAttribute(CF.POSITIVE, CF1Convention.getZisPositive(altName, altUnits)).build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,16 @@ public void writeHeader(List<StationFeature> stns, StationPointFeature spf) thro
StructureData obsData = spf.getFeatureData();

List<VariableSimpleIF> coords = new ArrayList<>();
coords.add(VariableSimpleBuilder.makeScalar(timeName, "time of measurement", timeUnit.getUdUnit(), DataType.DOUBLE)
.addAttribute(CF.CALENDAR, timeUnit.getCalendar().toString()).build());
coords.add(VariableSimpleBuilder.makeScalar(spf.getFeatureCollection().getTimeName(), "time of measurement",
timeUnit.getUdUnit(), DataType.DOUBLE).addAttribute(CF.CALENDAR, timeUnit.getCalendar().toString()).build());

coords.add(VariableSimpleBuilder
.makeScalar(stationIndexName, "station index for this observation record", null, DataType.INT)
.addAttribute(CF.INSTANCE_DIMENSION, stationDimName).build());


Formatter coordNames = new Formatter().format("%s %s %s", timeName, latName, lonName);
Formatter coordNames =
new Formatter().format("%s %s %s", spf.getFeatureCollection().getTimeName(), latName, lonName);
if (useAlt)
coordNames.format(" %s", stationAltName);

Expand Down Expand Up @@ -233,8 +234,9 @@ public void writeRecord(Station s, PointFeature sobs, StructureData sdata) throw
writeRecord(dsgStation.getName(), dsgStation.getTimeName(), sobs.getObservationTime(),
sobs.getObservationTimeAsCalendarDate(), dsgStation.getAltName(), sobs.getLocation().getAltitude(), sdata);
} else {
writeRecord(s.getName(), timeName, sobs.getObservationTime(), sobs.getObservationTimeAsCalendarDate(),
this.altitudeCoordinateName, sobs.getLocation().getAltitude(), sdata);
writeRecord(s.getName(), sobs.getFeatureCollection().getTimeName(), sobs.getObservationTime(),
sobs.getObservationTimeAsCalendarDate(), this.altitudeCoordinateName, sobs.getLocation().getAltitude(),
sdata);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ public int writeTrajectory(TrajectoryFeature traj) throws IOException {
private void writeHeader(TrajectoryFeature feature, PointFeature obs) throws IOException {
// obs data
List<VariableSimpleIF> coords = new ArrayList<>();
coords.add(VariableSimpleBuilder.makeScalar(timeName, "time of measurement", timeUnit.getUdUnit(), DataType.DOUBLE)
.addAttribute(CF.CALENDAR, timeUnit.getCalendar().toString()).build());
coords.add(VariableSimpleBuilder.makeScalar(obs.getFeatureCollection().getTimeName(), "time of measurement",
timeUnit.getUdUnit(), DataType.DOUBLE).addAttribute(CF.CALENDAR, timeUnit.getCalendar().toString()).build());

coords.add(
VariableSimpleBuilder.makeScalar(latName, "latitude of measurement", CDM.LAT_UNITS, DataType.DOUBLE).build());
coords.add(
VariableSimpleBuilder.makeScalar(lonName, "longitude of measurement", CDM.LON_UNITS, DataType.DOUBLE).build());
Formatter coordNames = new Formatter().format("%s %s %s", timeName, latName, lonName);
Formatter coordNames =
new Formatter().format("%s %s %s", obs.getFeatureCollection().getTimeName(), latName, lonName);
if (altUnits != null) {
coords.add(VariableSimpleBuilder.makeScalar(altName, "altitude of measurement", altUnits, DataType.DOUBLE)
.addAttribute(CF.POSITIVE, CF1Convention.getZisPositive(altName, altUnits)).build());
Expand Down Expand Up @@ -126,7 +127,7 @@ public void writeObsData(PointFeature pf) throws IOException {
trackBB(loc.getLatLon(), timeUnit.makeCalendarDate(pf.getObservationTime()));

StructureMembers.Builder smb = StructureMembers.builder().setName("Coords");
smb.addMemberScalar(timeName, null, null, DataType.DOUBLE, pf.getObservationTime());
smb.addMemberScalar(pf.getFeatureCollection().getTimeName(), null, null, DataType.DOUBLE, pf.getObservationTime());
smb.addMemberScalar(latName, null, null, DataType.DOUBLE, loc.getLatitude());
smb.addMemberScalar(lonName, null, null, DataType.DOUBLE, loc.getLongitude());
if (altUnits != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ class WriterCFPointCollection extends WriterCFPointAbstract {

void writeHeader(PointFeature pf) throws IOException {
List<VariableSimpleIF> coords = new ArrayList<>();
coords.add(VariableSimpleBuilder.makeScalar(timeName, "time of measurement", timeUnit.getUdUnit(), DataType.DOUBLE)
.addAttribute(CF.CALENDAR, timeUnit.getCalendar().toString()).build());
coords.add(VariableSimpleBuilder.makeScalar(pf.getFeatureCollection().getTimeName(), "time of measurement",
timeUnit.getUdUnit(), DataType.DOUBLE).addAttribute(CF.CALENDAR, timeUnit.getCalendar().toString()).build());

coords.add(
VariableSimpleBuilder.makeScalar(latName, "latitude of measurement", CDM.LAT_UNITS, DataType.DOUBLE).build());
coords.add(
VariableSimpleBuilder.makeScalar(lonName, "longitude of measurement", CDM.LON_UNITS, DataType.DOUBLE).build());
Formatter coordNames = new Formatter().format("%s %s %s", timeName, latName, lonName);
Formatter coordNames =
new Formatter().format("%s %s %s", pf.getFeatureCollection().getTimeName(), latName, lonName);
if (altUnits != null) {
coords.add(VariableSimpleBuilder.makeScalar(altName, "altitude of measurement", altUnits, DataType.DOUBLE)
.addAttribute(CF.POSITIVE, CF1Convention.getZisPositive(altName, altUnits)).build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,15 @@ int writeTrajectory(TrajectoryFeature traj) throws IOException {
private void writeHeader(TrajectoryFeature feature, PointFeature obs) throws IOException {
// obs data
List<VariableSimpleIF> coords = new ArrayList<>();
coords.add(VariableSimpleBuilder.makeScalar(timeName, "time of measurement", timeUnit.getUdUnit(), DataType.DOUBLE)
.addAttribute(CF.CALENDAR, timeUnit.getCalendar().toString()).build());
coords.add(VariableSimpleBuilder.makeScalar(obs.getFeatureCollection().getTimeName(), "time of measurement",
timeUnit.getUdUnit(), DataType.DOUBLE).addAttribute(CF.CALENDAR, timeUnit.getCalendar().toString()).build());

coords.add(
VariableSimpleBuilder.makeScalar(latName, "latitude of measurement", CDM.LAT_UNITS, DataType.DOUBLE).build());
coords.add(
VariableSimpleBuilder.makeScalar(lonName, "longitude of measurement", CDM.LON_UNITS, DataType.DOUBLE).build());
Formatter coordNames = new Formatter().format("%s %s %s", timeName, latName, lonName);
Formatter coordNames =
new Formatter().format("%s %s %s", obs.getFeatureCollection().getTimeName(), latName, lonName);
if (altUnits != null) {
coords.add(VariableSimpleBuilder.makeScalar(altName, "altitude of measurement", altUnits, DataType.DOUBLE)
.addAttribute(CF.POSITIVE, CF1Convention.getZisPositive(altName, altUnits)).build());
Expand Down Expand Up @@ -143,7 +144,7 @@ private void writeObsData(PointFeature pf) throws IOException {
trackBB(loc.getLatLon(), timeUnit.makeCalendarDate(pf.getObservationTime()));

StructureMembers.Builder smb = StructureMembers.builder().setName("Coords");
smb.addMemberScalar(timeName, null, null, DataType.DOUBLE, pf.getObservationTime());
smb.addMemberScalar(pf.getFeatureCollection().getTimeName(), null, null, DataType.DOUBLE, pf.getObservationTime());
smb.addMemberScalar(latName, null, null, DataType.DOUBLE, loc.getLatitude());
smb.addMemberScalar(lonName, null, null, DataType.DOUBLE, loc.getLongitude());
if (altUnits != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.junit.Assert.assertThrows;

import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import ucar.ma2.Array;
import ucar.nc2.constants.FeatureType;
Expand Down Expand Up @@ -85,6 +86,7 @@ public void testVarFeatureTypes() throws IOException {
}

@Test
@Ignore
public void testCoverageAsPoint() throws IOException {
double[] vals = Arrays.copyOfRange(expected, 0, 1);
// test single point (no time)
Expand Down Expand Up @@ -129,6 +131,7 @@ public void testExceptionThrownForPointOutsideCoverage() {
}

@Test
@Ignore
public void testCoverageAsProfile() throws IOException {
// test single profile (no time)
List<String> varNames = new ArrayList<>();
Expand Down Expand Up @@ -252,7 +255,7 @@ private void readCoverageAsPoint(List<String> varNames, SubsetParams params, dou

private void readCoverageAsProfile(List<String> varNames, SubsetParams params, double[] alt, double[] time,
double[] expected) throws IOException {
readCoverageAsProfile(varNames, params, alt, time, expected, 0, "time", "z");
readCoverageAsProfile(varNames, params, alt, time, expected, 0, "time", "altitude");
}

private void readCoverageAsProfile(List<String> varNames, SubsetParams params, double[] alt, double[] time,
Expand Down

0 comments on commit 9449937

Please sign in to comment.