From 91819eeb2e7c521efb33de397cfccd24cffff8a5 Mon Sep 17 00:00:00 2001 From: Dustin Jenkins Date: Wed, 14 Aug 2024 15:33:01 -0700 Subject: [PATCH] Update test to do reverse striding properly. --- .../main/java/org/opencadc/fits/slice/WCSCutoutUtil.java | 5 ++--- .../src/test/java/org/opencadc/fits/FitsTest.java | 8 +++++++- .../org/opencadc/fits/slice/NDimensionalSlicerTest.java | 4 ++-- .../java/org/opencadc/fits/slice/WCSCutoutUtilTest.java | 5 ++++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/cadc-data-ops-fits/src/main/java/org/opencadc/fits/slice/WCSCutoutUtil.java b/cadc-data-ops-fits/src/main/java/org/opencadc/fits/slice/WCSCutoutUtil.java index f25c4bf3..31557e05 100644 --- a/cadc-data-ops-fits/src/main/java/org/opencadc/fits/slice/WCSCutoutUtil.java +++ b/cadc-data-ops-fits/src/main/java/org/opencadc/fits/slice/WCSCutoutUtil.java @@ -151,10 +151,10 @@ static void adjustHeaders(final Header header, final int dimensionLength, final // CRPIX values are not set automatically. Adjust them here, if present. for (int i = 0; i < dimensionLength; i++) { final HeaderCard crPixCard = header.findCard(Standard.CRPIXn.n(i + 1)); + final int stepValue = steps[steps.length - i - 1]; if (crPixCard != null) { // Need to run backwards (reverse order) to match the dimensions. final double nextValue = corners[corners.length - i - 1]; - final int stepValue = steps[steps.length - i - 1]; final double crPixValue = Double.parseDouble(crPixCard.getValue()) - nextValue; if (stepValue > 1) { @@ -175,7 +175,6 @@ static void adjustHeaders(final Header header, final int dimensionLength, final final HeaderCard cDeltCard = header.findCard(Standard.CDELTn.n(i + 1)); if (cDeltCard != null) { final double cDeltValue = Double.parseDouble(cDeltCard.getValue()); - final int stepValue = steps[steps.length - i - 1]; cDeltCard.setValue(cDeltValue * (double) stepValue); } @@ -184,7 +183,7 @@ static void adjustHeaders(final Header header, final int dimensionLength, final final HeaderCard cdMatrixCard = header.findCard(String.format("CD%d_%d", i + 1, j + 1)); if (cdMatrixCard != null) { final double cdMatrixValue = Double.parseDouble(cdMatrixCard.getValue()); - cdMatrixCard.setValue(cdMatrixValue * (double) steps[i]); + cdMatrixCard.setValue(cdMatrixValue * (double) stepValue); } } } diff --git a/cadc-data-ops-fits/src/test/java/org/opencadc/fits/FitsTest.java b/cadc-data-ops-fits/src/test/java/org/opencadc/fits/FitsTest.java index a857235e..86e5ef63 100644 --- a/cadc-data-ops-fits/src/test/java/org/opencadc/fits/FitsTest.java +++ b/cadc-data-ops-fits/src/test/java/org/opencadc/fits/FitsTest.java @@ -92,7 +92,7 @@ public class FitsTest { private static final IFitsHeader[] HEADER_CARD_KEYS_TO_CHECK = new IFitsHeader[]{ Standard.BITPIX, Standard.NAXIS, Standard.EXTNAME, Standard.XTENSION, Standard.SIMPLE, Standard.EXTVER, - Standard.BSCALE, Standard.BUNIT, NOAOExt.CD1_1, Standard.CDELTn.n(1), Standard.CRPIXn.n(1) + Standard.BSCALE, Standard.BUNIT, NOAOExt.CD1_1, NOAOExt.CD1_2, Standard.CDELTn.n(1), Standard.CRPIXn.n(1) }; public static void assertFitsEqual(final Fits expected, final Fits result) { @@ -132,6 +132,12 @@ public static void assertHeadersEqual(final Header expectedHeader, final Header Assert.assertEquals("Header " + headerCardKey.key() + " has the wrong value.", Double.parseDouble(expectedCard.getValue()), Double.parseDouble(resultCard.getValue()), 1.0e-5D); + } else if (valueType == Integer.class) { + // Expected type has been declared as Integer, but result may have been converted to Float (i.e. 0 == 0e0), so + // allow some robustness here. + Assert.assertEquals("Header " + headerCardKey.key() + " has the wrong value.", + Integer.parseInt(expectedCard.getValue()), + Math.round(Float.parseFloat(resultCard.getValue()))); } else { Assert.assertEquals("Header " + headerCardKey.key() + " has the wrong value.", expectedCard.getValue(), resultCard.getValue()); diff --git a/cadc-data-ops-fits/src/test/java/org/opencadc/fits/slice/NDimensionalSlicerTest.java b/cadc-data-ops-fits/src/test/java/org/opencadc/fits/slice/NDimensionalSlicerTest.java index e090c6b6..c730e44b 100644 --- a/cadc-data-ops-fits/src/test/java/org/opencadc/fits/slice/NDimensionalSlicerTest.java +++ b/cadc-data-ops-fits/src/test/java/org/opencadc/fits/slice/NDimensionalSlicerTest.java @@ -103,11 +103,11 @@ public class NDimensionalSlicerTest { } @Test - @Ignore("Requires larger ALMA file. Useful for running locally.") + @Ignore("Requires a larger file to cut from. Here to illustrate test input.") public void testIncorrectWCS() throws Exception { ExtensionSliceFormat fmt = new ExtensionSliceFormat(); List slices = new ArrayList<>(); - slices.add(fmt.parse("[*:4,*:5,*:4]")); + slices.add(fmt.parse("[*:4,*:6,*:6]")); final Cutout cutout = new Cutout(); cutout.pixelCutouts = slices; diff --git a/cadc-data-ops-fits/src/test/java/org/opencadc/fits/slice/WCSCutoutUtilTest.java b/cadc-data-ops-fits/src/test/java/org/opencadc/fits/slice/WCSCutoutUtilTest.java index 93f9d8e1..33311ee3 100644 --- a/cadc-data-ops-fits/src/test/java/org/opencadc/fits/slice/WCSCutoutUtilTest.java +++ b/cadc-data-ops-fits/src/test/java/org/opencadc/fits/slice/WCSCutoutUtilTest.java @@ -136,8 +136,11 @@ public void testMultipleWCS() throws Exception { public void testWCSAdjustment() throws Exception { final String headerFileName = "test-blast-header-1.txt"; final File testFile = FileUtil.getFileFromResource(headerFileName, CircleCutoutTest.class); + + // Corners and striding values MUST be in reverse order as per what nom-tam-fits provides. This accurately + // represents the use case. final int[] corners = new int[]{0, 0}; - final int[] stridingValues = new int[]{1, 5}; + final int[] stridingValues = new int[]{5, 1}; try (final InputStream inputStream = Files.newInputStream(testFile.toPath()); final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream))) {