Skip to content

Commit

Permalink
caom2-compute: make timesys-ctype combinations/usage consistent with …
Browse files Browse the repository at this point in the history
…spec
  • Loading branch information
pdowler committed May 29, 2023
1 parent 124ca87 commit 4903bcd
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 5 deletions.
2 changes: 1 addition & 1 deletion caom2-compute/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ sourceCompatibility = 1.8

group = 'org.opencadc'

version = '2.4.9'
version = '2.4.10'

description = 'OpenCADC CAOM compute library'
def git_url = 'https://github.com/opencadc/caom2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public final class TimeUtil {
// sort of a hack: we assume absolute MJD values in the TimeWCS which
// is the default if MJDREF, JDREF, and DATEREF are all absent = 0.0 in FITS
private static final String TARGET_TIMESYS = "UTC";
private static final String TARGET_CTYPE = "TIME";
private static final String COMPAT_CTYPE = "TIME";
private static final String TARGET_CUNIT = "d";
public static double DEFAULT_UNION_SCALE = 0.10;
private static final String TAI_TIMESYS = "TAI";
Expand Down Expand Up @@ -430,13 +430,16 @@ static Interval toInterval(TemporalWCS wcs, CoordFunction1D func) {
private static void validateWCS(TemporalWCS wcs) {
StringBuilder sb = new StringBuilder();
String ctype = wcs.getAxis().getAxis().getCtype();
if (ctype.equals(TARGET_CTYPE) && (wcs.timesys == null || SUPPORTED_TIMESYS.contains(wcs.timesys))) {
if (wcs.timesys != null && SUPPORTED_TIMESYS.contains(wcs.timesys)
&& (ctype.equals(wcs.timesys) || ctype.equals(COMPAT_CTYPE))) {
// OK
} else if (ctype.equals(TARGET_TIMESYS) && wcs.timesys == null) {
} else if (wcs.timesys == null && SUPPORTED_TIMESYS.contains(ctype)) {
// OK
} else {
sb.append("unexpected TIMESYS, CTYPE: ").append(wcs.timesys).append(",").append(ctype);
}

// TODO: with wcs.mjdref != null, CUNIT could be in alt units (eg sec)
String cunit = wcs.getAxis().getAxis().cunit;
if (!TARGET_CUNIT.equals(cunit)) {
sb.append("unexpected CUNIT: ").append(cunit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,101 @@ public void testSkippableCompute() {
Assert.fail("unexpected exception: " + unexpected);
}
}

@Test
public void testComputeTimesysCtypeCunit() {

String[] timeSys = new String[] { "UTC", "TT", "TAI" };

CoordAxis1D[] ctypeOnly = new CoordAxis1D[] {
new CoordAxis1D(new Axis("UTC", "d")),
new CoordAxis1D(new Axis("TT", "d")),
new CoordAxis1D(new Axis("TAI", "d"))
};
CoordAxis1D time = new CoordAxis1D(new Axis("TIME", "d"));

try {
Plane plane = new Plane("foo");
Artifact a = new Artifact(URI.create("cadc:FOO/bar"), ProductType.SCIENCE, ReleaseType.DATA);
plane.getArtifacts().add(a);
Part p = new Part(1);
a.getParts().add(p);
Chunk c = new Chunk();
p.getChunks().add(c);

c.naxis = 1;
c.timeAxis = 1;
// allowed: CTYPE only
for (CoordAxis1D ca : ctypeOnly) {
c.time = new TemporalWCS(ca);
c.time.getAxis().range = new CoordRange1D(new RefCoord(0.5, 54321.0), new RefCoord(1.5, 54321.1));

log.info("timesys: " + c.time.timesys + " axis: " + c.time.getAxis());
Time actual = TimeUtil.compute(plane.getArtifacts());
log.info("testComputeTimesysCtypeCunit: " + actual);

Assert.assertNotNull(actual);
Assert.assertNotNull(actual.bounds);
}
// allowed: CTYPE=TIME && TIMESYS
for (String ts : timeSys) {
c.time = new TemporalWCS(time);
c.time.timesys = ts;
c.time.getAxis().range = new CoordRange1D(new RefCoord(0.5, 54321.0), new RefCoord(1.5, 54321.1));

log.info("timesys: " + c.time.timesys + " axis: " + c.time.getAxis());
Time actual = TimeUtil.compute(plane.getArtifacts());
log.info("testComputeTimesysCtypeCunit: " + actual);

Assert.assertNotNull(actual);
Assert.assertNotNull(actual.bounds);
}

// allowed: CTYPE and redundant TIMESYS
for (CoordAxis1D ca : ctypeOnly) {
c.time = new TemporalWCS(ca);
c.time.timesys = ca.getAxis().getCtype();
c.time.getAxis().range = new CoordRange1D(new RefCoord(0.5, 54321.0), new RefCoord(1.5, 54321.1));

log.info("timesys: " + c.time.timesys + " axis: " + c.time.getAxis());
Time actual = TimeUtil.compute(plane.getArtifacts());
log.info("testComputeTimesysCtypeCunit: " + actual);

Assert.assertNotNull(actual);
Assert.assertNotNull(actual.bounds);
}

// not allowed: CTYPE=TIME only
try {
c.time = new TemporalWCS(time);
c.time.timesys = null;
c.time.getAxis().range = new CoordRange1D(new RefCoord(0.5, 54321.0), new RefCoord(1.5, 54321.1));

log.info("timesys: " + c.time.timesys + " axis: " + c.time.getAxis());
Time actual = TimeUtil.compute(plane.getArtifacts());
Assert.fail("expected UnsupportedOperationException, got: " + actual);
} catch (UnsupportedOperationException ex) {
log.info("caught expected: " + ex);
}

// not allowed: CUNIT other than d (days)
try {
CoordAxis1D ta = new CoordAxis1D(new Axis("UTC", "sec"));
c.time = new TemporalWCS(ta);
c.time.timesys = null;
c.time.getAxis().range = new CoordRange1D(new RefCoord(0.5, 54321.0), new RefCoord(1.5, 54321.1));

log.info("timesys: " + c.time.timesys + " axis: " + c.time.getAxis());
Time actual = TimeUtil.compute(plane.getArtifacts());
Assert.fail("expected UnsupportedOperationException, got: " + actual);
} catch (UnsupportedOperationException ex) {
log.info("caught expected: " + ex);
}
} catch (Exception unexpected) {
log.error("unexpected exception", unexpected);
Assert.fail("unexpected exception: " + unexpected);
}
}

@Test
public void testComputeFromRange() {
Expand Down Expand Up @@ -244,7 +339,7 @@ public void testMultiSampleComputeFromBounds() {

c.naxis = 1;
c.timeAxis = 1;
c.time = new TemporalWCS(new CoordAxis1D(new Axis("TIME", "d")));
c.time = new TemporalWCS(new CoordAxis1D(new Axis("UTC", "d")));
c.time.getAxis().bounds = new CoordBounds1D();
c.time.getAxis().bounds.getSamples().add(new CoordRange1D(new RefCoord(0.5, 54321.0), new RefCoord(1.5, 54321.1)));
c.time.getAxis().bounds.getSamples().add(new CoordRange1D(new RefCoord(0.5, 54321.2), new RefCoord(1.5, 54321.3)));
Expand Down

0 comments on commit 4903bcd

Please sign in to comment.