Skip to content

Commit 82a64f3

Browse files
Tara Drwenskihaileyajohnson
authored andcommitted
For time intervals, use interval midpoint as coordinate value
1 parent 9646500 commit 82a64f3

3 files changed

Lines changed: 11 additions & 20 deletions

File tree

grib/src/main/java/ucar/nc2/grib/collection/GribIosp.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -780,12 +780,7 @@ private Array makeLazyTime2Darray(Variable coord, Time2Dinfo info) {
780780
CoordinateTimeIntv timeIntv = (CoordinateTimeIntv) time2D.getTimeCoordinate(runIdx);
781781
int timeIdx = 0;
782782
for (TimeCoordIntvValue tinv : timeIntv.getTimeIntervals()) {
783-
data[runIdx * ntimes + timeIdx] = timeUnit.getValue() * tinv.getBounds2() + time2D.getOffset(runIdx); // use
784-
// upper
785-
// bounds
786-
// for
787-
// coord
788-
// value
783+
data[runIdx * ntimes + timeIdx] = timeUnit.getValue() * tinv.getCoordValue() + time2D.getOffset(runIdx);
789784
timeIdx++;
790785
}
791786
}
@@ -796,8 +791,7 @@ private Array makeLazyTime2Darray(Variable coord, Time2Dinfo info) {
796791
for (int runIdx = 0; runIdx < nruns; runIdx++) {
797792
CoordinateTimeIntv timeIntv = (CoordinateTimeIntv) time2D.getTimeCoordinate(runIdx);
798793
for (TimeCoordIntvValue tinv : timeIntv.getTimeIntervals()) {
799-
data[count++] = timeUnit.getValue() * tinv.getBounds2() + time2D.getOffset(runIdx); // use upper bounds for
800-
// coord value
794+
data[count++] = timeUnit.getValue() * tinv.getCoordValue() + time2D.getOffset(runIdx);
801795
}
802796
}
803797
break;
@@ -910,9 +904,8 @@ private void makeTimeCoordinate1D(NetcdfFile ncfile, Group g, CoordinateTimeIntv
910904
double[] data = new double[ntimes];
911905
int count = 0;
912906

913-
// use upper bounds for coord value
914907
for (TimeCoordIntvValue tinv : coordTime.getTimeIntervals()) {
915-
data[count++] = tinv.getBounds2();
908+
data[count++] = tinv.getCoordValue();
916909
}
917910
v.setCachedData(Array.factory(DataType.DOUBLE, new int[] {ntimes}, data));
918911

grib/src/main/java/ucar/nc2/grib/collection/GribIospBuilder.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -580,12 +580,7 @@ private Array makeLazyTime2Darray(Variable coord, Time2Dinfo info) {
580580
CoordinateTimeIntv timeIntv = (CoordinateTimeIntv) time2D.getTimeCoordinate(runIdx);
581581
int timeIdx = 0;
582582
for (TimeCoordIntvValue tinv : timeIntv.getTimeIntervals()) {
583-
data[runIdx * ntimes + timeIdx] = timeUnit.getValue() * tinv.getBounds2() + time2D.getOffset(runIdx); // use
584-
// upper
585-
// bounds
586-
// for
587-
// coord
588-
// value
583+
data[runIdx * ntimes + timeIdx] = timeUnit.getValue() * tinv.getCoordValue() + time2D.getOffset(runIdx);
589584
timeIdx++;
590585
}
591586
}
@@ -596,8 +591,7 @@ private Array makeLazyTime2Darray(Variable coord, Time2Dinfo info) {
596591
for (int runIdx = 0; runIdx < nruns; runIdx++) {
597592
CoordinateTimeIntv timeIntv = (CoordinateTimeIntv) time2D.getTimeCoordinate(runIdx);
598593
for (TimeCoordIntvValue tinv : timeIntv.getTimeIntervals()) {
599-
data[count++] = timeUnit.getValue() * tinv.getBounds2() + time2D.getOffset(runIdx); // use upper bounds for
600-
// coord value
594+
data[count++] = timeUnit.getValue() * tinv.getCoordValue() + time2D.getOffset(runIdx);
601595
}
602596
}
603597
break;
@@ -715,9 +709,8 @@ private void makeTimeCoordinate1D(Group.Builder g, CoordinateTimeIntv coordTime)
715709
double[] data = new double[ntimes];
716710
int count = 0;
717711

718-
// use upper bounds for coord value
719712
for (TimeCoordIntvValue tinv : coordTime.getTimeIntervals()) {
720-
data[count++] = tinv.getBounds2();
713+
data[count++] = tinv.getCoordValue();
721714
}
722715
v.setCachedData(Array.factory(DataType.DOUBLE, new int[] {ntimes}, data), false);
723716

grib/src/main/java/ucar/nc2/grib/coord/TimeCoordIntvValue.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public int getIntervalSize() {
2828
return Math.abs(b2 - b1);
2929
}
3030

31+
public double getCoordValue() {
32+
// Choose interval midpoint as the coordinate value
33+
return (b1 + b2) / 2.0;
34+
}
35+
3136
public TimeCoordIntvValue convertReferenceDate(CalendarDate fromDate, CalendarPeriod fromUnit, CalendarDate toDate,
3237
CalendarPeriod toUnit) {
3338
CalendarDate start = fromDate.add(fromUnit.multiply(b1));

0 commit comments

Comments
 (0)