Skip to content

Commit 8889f03

Browse files
authored
Merge pull request #1449 from lesserwhirls/numericAggBug
Enable joinNew agg with numericTimeSettings
2 parents 7d6f10e + 414544d commit 8889f03

5 files changed

Lines changed: 60 additions & 7 deletions

File tree

cdm/core/src/main/java/ucar/nc2/internal/ncml/AggregationNew.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import ucar.nc2.Group;
1515
import ucar.nc2.NetcdfFile;
1616
import ucar.nc2.Variable;
17+
import ucar.nc2.constants.CF;
1718
import ucar.nc2.constants._Coordinate;
1819
import ucar.nc2.dataset.CoordinateAxis;
1920
import ucar.nc2.dataset.NetcdfDataset;
@@ -60,8 +61,13 @@ protected void buildNetcdfDataset(CancelTask cancelTask) throws IOException {
6061
.setParentGroupBuilder(root).setDimensionsByName(dimName);
6162
root.addVariable(joinAggCoordVar);
6263
joinAggCoordVar.setProxyReader(this);
63-
if (isDate)
64+
if (isDate) {
6465
joinAggCoordVar.addAttribute(new Attribute(_Coordinate.AxisType, "Time"));
66+
String coordUnits = ((AggDatasetOuter) typicalDataset).coordUdunit;
67+
if (coordUnits != null && !coordUnits.isEmpty()) {
68+
joinAggCoordVar.addAttribute(new Attribute(CF.UNITS, coordUnits));
69+
}
70+
}
6571

6672
// if speced externally, this variable will get replaced
6773
// LOOK was CacheVar cv = new CoordValueVar(joinAggCoordVar.getFullName(), joinAggCoordVar.dataType,

cdm/core/src/main/java/ucar/nc2/ncml/AggregationNew.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package ucar.nc2.ncml;
77

8+
import ucar.nc2.constants.CF;
89
import ucar.nc2.dataset.NetcdfDataset;
910
import ucar.nc2.dataset.VariableDS;
1011
import ucar.nc2.dataset.DatasetConstructor;
@@ -55,8 +56,14 @@ protected void buildNetcdfDataset(CancelTask cancelTask) throws IOException {
5556
joinAggCoord = new VariableDS(ncDataset, null, null, dimName, coordType, dimName, null, null);
5657
ncDataset.addVariable(null, joinAggCoord);
5758
joinAggCoord.setProxyReader(this);
58-
if (isDate)
59+
if (isDate) {
5960
joinAggCoord.addAttribute(new ucar.nc2.Attribute(_Coordinate.AxisType, "Time"));
61+
String coordUnits = ((DatasetOuterDimension) typicalDataset).coordUdunit;
62+
if (coordUnits != null && !coordUnits.isEmpty()) {
63+
joinAggCoord.addAttribute(new Attribute(CF.UNITS, coordUnits));
64+
}
65+
}
66+
6067

6168
// if speced externally, this variable will get replaced
6269
CacheVar cv =
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2">
3+
<aggregation dimName="time2" type="joinNew" recheckEvery="4 sec">
4+
<scan dateFormatMark="CG#yyyyDDD_HHmmss"
5+
location="nc/cg/"
6+
suffix=".nc"
7+
subdirs="false"/>
8+
</aggregation>
9+
</netcdf>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2">
3+
<aggregation dimName="time2" type="joinNew" recheckEvery="4 sec">
4+
<scan dateFormatMark="CG#yyyyDDD_HHmmss"
5+
location="nc/cg/"
6+
suffix=".nc"
7+
subdirs="false"
8+
numericTimeSettings="int seconds since 2006-06-07T11:00:00Z"/>
9+
</aggregation>
10+
</netcdf>

cdm/core/src/test/java/ucar/nc2/ncml/TestAggScanNumericTime.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import ucar.nc2.Variable;
1616
import ucar.nc2.dataset.NetcdfDataset;
1717
import ucar.nc2.dataset.NetcdfDatasets;
18+
import ucar.nc2.internal.ncml.NcmlReader;
1819
import ucar.nc2.time.Calendar;
1920
import ucar.nc2.time.CalendarDate;
2021
import ucar.nc2.time.CalendarDateFormatter;
@@ -30,7 +31,7 @@ public void testNumericTime() throws IOException, InvalidRangeException, Interru
3031

3132
try (NetcdfDataset ncStr = NetcdfDataset.openDataset(aggStringTime);
3233
NetcdfDataset ncNum = NetcdfDataset.openDataset(aggNumericTime)) {
33-
compareTimes(ncStr, ncNum);
34+
compareTimes(ncStr, ncNum, "time");
3435
}
3536
}
3637

@@ -41,14 +42,34 @@ public void testNumericTimeWithBuilders() throws IOException, InvalidRangeExcept
4142

4243
try (NetcdfDataset ncStr = NetcdfDatasets.openDataset(aggStringTime);
4344
NetcdfDataset ncNum = NetcdfDatasets.openDataset(aggNumericTime)) {
44-
compareTimes(ncStr, ncNum);
45+
compareTimes(ncStr, ncNum, "time");
4546
}
4647
}
4748

48-
void compareTimes(NetcdfDataset ncStr, NetcdfDataset ncNum) throws IOException {
49-
Variable isoTimeVar = ncStr.findVariable("time");
49+
@Test
50+
public void testNumericTimeNcmlReader() throws IOException, InvalidRangeException, InterruptedException {
51+
String aggStringTime = "file:./" + TestNcmlRead.topDir + "aggNewOne.xml";
52+
String aggNumericTime = "file:./" + TestNcmlRead.topDir + "aggNewOneNumericTime.xml";
53+
try (NetcdfDataset ncStr = NcMLReader.readNcML(aggStringTime, null);
54+
NetcdfDataset ncNum = NcMLReader.readNcML(aggNumericTime, null)) {
55+
compareTimes(ncStr, ncNum, "time2");
56+
}
57+
}
58+
59+
@Test
60+
public void testNumericTimeNcmlReaderWithBuilders() throws IOException, InvalidRangeException, InterruptedException {
61+
String aggStringTime = "file:./" + TestNcmlRead.topDir + "aggNewOne.xml";
62+
String aggNumericTime = "file:./" + TestNcmlRead.topDir + "aggNewOneNumericTime.xml";
63+
try (NetcdfDataset ncStr = NcmlReader.readNcml(aggStringTime, null, null).build();
64+
NetcdfDataset ncNum = NcmlReader.readNcml(aggNumericTime, null, null).build()) {
65+
compareTimes(ncStr, ncNum, "time2");
66+
}
67+
}
68+
69+
void compareTimes(NetcdfDataset ncStr, NetcdfDataset ncNum, String timeVarName) throws IOException {
70+
Variable isoTimeVar = ncStr.findVariable(timeVarName);
5071
assertThat(isoTimeVar != null).isTrue();
51-
Variable numericTimeVar = ncNum.findVariable("time");
72+
Variable numericTimeVar = ncNum.findVariable(timeVarName);
5273
assertThat(numericTimeVar != null).isTrue();
5374
Array isoTime = isoTimeVar.read();
5475
Array numericTime = numericTimeVar.read();

0 commit comments

Comments
 (0)