Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to latest nom-tam-fits. #103

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cadc-data-ops-fits/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ repositories {
mavenLocal()
}

sourceCompatibility = 1.8
sourceCompatibility = 11
group = 'org.opencadc'
version = '0.3.0'
version = '0.4.0'

description = 'OpenCADC FITS cutout library'
def git_url = 'https://github.com/opencadc/dal'
Expand All @@ -23,7 +23,7 @@ dependencies {
implementation 'org.opencadc:cadc-soda-server:[1.2.1,2.0)'
implementation 'org.opencadc:cadc-wcs:[2.1.4,3.0)'
implementation 'org.opencadc:jsky:[1.0.0,2.0.0)'
implementation 'gov.nasa.gsfc.heasarc:nom-tam-fits:1.18.0'
implementation 'gov.nasa.gsfc.heasarc:nom-tam-fits:1.20.0'

// Use JUnit test framework
testImplementation 'junit:junit:[4.13,5.0)'
Expand Down
17 changes: 1 addition & 16 deletions cadc-data-ops-fits/src/main/java/org/opencadc/fits/CADCExt.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,33 +99,18 @@ public enum CADCExt implements IFitsHeader {
SPECSYS(HDU.IMAGE, VALUE.STRING, ""),

// Temporal values.
MJDREF(HDU.IMAGE, VALUE.REAL, "Reference time in MJD"),
MJDREFI(HDU.IMAGE, VALUE.REAL, "Integer part of reference time in MJD"),
MJDREFF(HDU.IMAGE, VALUE.REAL, "Fractional part of reference time in MJD"),
JDREF(HDU.IMAGE, VALUE.REAL, "Reference time in JD"),
JDREFI(HDU.IMAGE, VALUE.REAL, "Integer part of reference time in JD"),
JDREFF(HDU.IMAGE, VALUE.REAL, "Fractional part of reference time in JD"),
DATEBEG("DATE-BEG", HDU.PRIMARY_EXTENSION, VALUE.REAL, "Start time of data in iso-8601"),
DATEOBS("DATE-OBS", HDU.PRIMARY_EXTENSION, VALUE.REAL, "Time (or start time) of data in iso-8601"),
DATEEND("DATE-END", HDU.PRIMARY_EXTENSION, VALUE.REAL, "Stop time of data in iso-8601"),

JDBEG("JD-BEG", HDU.PRIMARY_EXTENSION, VALUE.REAL, "Start time of data in JD"),
JDOBS("JD-OBS", HDU.PRIMARY_EXTENSION, VALUE.REAL, "Time (or start time) of data in JD"),
JDEND("JD-END", HDU.PRIMARY_EXTENSION, VALUE.REAL, "Stop time of data in JD"),

MJDBEG("MJD-BEG", HDU.PRIMARY_EXTENSION, VALUE.REAL, "Start time of data in MJD"),
MJDOBS("MJD-OBS", HDU.PRIMARY_EXTENSION, VALUE.REAL, "Time (or start time) of data in MJD"),
MJDEND("MJD-END", HDU.PRIMARY_EXTENSION, VALUE.REAL, "Stop time of data in MJD"),

TSTART(HDU.PRIMARY_EXTENSION, VALUE.REAL,
"Start time of data in units of TIMEUNIT relative to MJDREF, JDREF or DATEREF according to TIMESYS."),
TSTOP(HDU.PRIMARY_EXTENSION, VALUE.REAL,
"Stop time of data in units of TIMEUNIT relative to MJDREF, JDREF or DATEREF according to TIMESYS."),

DATEREF(HDU.IMAGE, VALUE.REAL, "Reference time in ISO-8601"),

TIMESYS(HDU.PRIMARY_EXTENSION, VALUE.STRING, "Time scale. Defaults to UTC."),
TIMEUNIT(HDU.ANY, VALUE.STRING, "Unit of elapsed time.");
"Stop time of data in units of TIMEUNIT relative to MJDREF, JDREF or DATEREF according to TIMESYS.");

private final IFitsHeader key;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,16 @@

import ca.nrc.cadc.util.StringUtil;
import ca.nrc.cadc.wcs.WCSKeywords;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import nom.tam.fits.FitsFactory;
import nom.tam.fits.Header;
import nom.tam.fits.HeaderCard;
import nom.tam.fits.HeaderCardException;
import nom.tam.fits.header.DateTime;
import nom.tam.fits.header.Standard;
import nom.tam.fits.header.extra.NOAOExt;
import nom.tam.util.Cursor;
Expand All @@ -103,7 +101,8 @@ public class FITSHeaderWCSKeywords implements WCSKeywords {

/**
* Empty constructor.
* @throws HeaderCardException If cloning the header fails.
*
* @throws HeaderCardException If cloning the header fails.
*/
public FITSHeaderWCSKeywords() throws HeaderCardException {
this(new Header());
Expand Down Expand Up @@ -411,11 +410,12 @@ private Header cloneHeader(final Header source) throws HeaderCardException {
/**
* Copy a header card with some potential modifications. COMMENT and HISTORY cards are truncated to the
* maximum length.
* @param destination The Header to write to.
* @param headerCardKey The current key.
* @param valueType The class type of the value.
* @param comment The comment value for COMMENT or HISTORY values.
* @param value The string value.
*
* @param destination The Header to write to.
* @param headerCardKey The current key.
* @param valueType The class type of the value.
* @param comment The comment value for COMMENT or HISTORY values.
* @param value The string value.
* @throws HeaderCardException
*/
private void cloneHeaderCard(final Header destination, final String headerCardKey, final Class<?> valueType,
Expand Down Expand Up @@ -484,8 +484,8 @@ private void sanitizeHeader(final Header destination) throws HeaderCardException
}

if (x == temporalAxis && !destination.containsKey(CADCExt.CUNITn.n(x))
&& !destination.containsKey(CADCExt.TIMEUNIT)) {
destination.addValue(CADCExt.TIMEUNIT.key(), "s", CADCExt.TIMEUNIT.comment());
&& !destination.containsKey(DateTime.TIMEUNIT)) {
destination.addValue(DateTime.TIMEUNIT.key(), "s", DateTime.TIMEUNIT.comment());
}
}

Expand All @@ -502,6 +502,7 @@ private void sanitizeHeader(final Header destination) throws HeaderCardException

/**
* Obtain the spatial longitude axis value.
*
* @return int axis, or -1 if no spectral axis present.
*/
int getSpatialLongitudeAxis() {
Expand All @@ -510,8 +511,9 @@ int getSpatialLongitudeAxis() {

/**
* Obtain the two spatial axis value.
* @param h The header to check for the axes.
* @return int of longitude axis numbers, or -1 if none found.
*
* @param h The header to check for the axes.
* @return int of longitude axis numbers, or -1 if none found.
*/
int getSpatialLongitudeAxis(final Header h) {
final int naxis = h.getIntValue(Standard.NAXIS);
Expand All @@ -529,6 +531,7 @@ int getSpatialLongitudeAxis(final Header h) {

/**
* Obtain the spatial longitude axis value.
*
* @return int axis, or -1 if no spectral axis present.
*/
int getSpatialLatitudeAxis() {
Expand All @@ -537,8 +540,9 @@ int getSpatialLatitudeAxis() {

/**
* Obtain the two spatial axis value.
* @param h The header to check for the axes.
* @return int of longitude axis numbers, or -1 if none found.
*
* @param h The header to check for the axes.
* @return int of longitude axis numbers, or -1 if none found.
*/
int getSpatialLatitudeAxis(final Header h) {
final int naxis = h.getIntValue(Standard.NAXIS);
Expand Down Expand Up @@ -566,7 +570,7 @@ int getSpectralAxis() {
/**
* Obtain the energy (1-based) axis from the given header. Return -1 if none found that match the Spectral types.
*
* @param h The header to search in
* @param h The header to search in
* @return integer axis, or -1 if not found.
*/
int getSpectralAxis(final Header h) {
Expand Down Expand Up @@ -594,7 +598,7 @@ public int getTemporalAxis() {
/**
* Obtain the time (1-based) axis from the given header. Return -1 if none found that match the Temporal types.
*
* @param h The header to search in
* @param h The header to search in
* @return integer axis, or -1 if not found.
*/
int getTemporalAxis(final Header h) {
Expand Down Expand Up @@ -622,7 +626,7 @@ int getPolarizationAxis() {
/**
* Obtain the time (1-based) axis from the given header. Return -1 if none found that match the Temporal types.
*
* @param h The header to search in
* @param h The header to search in
* @return integer axis, or -1 if not found.
*/
int getPolarizationAxis(final Header h) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@

import nom.tam.fits.Header;
import nom.tam.fits.HeaderCardException;
import nom.tam.fits.header.DateTime;
import org.apache.log4j.Logger;
import org.opencadc.fits.CADCExt;

Expand Down Expand Up @@ -113,21 +114,21 @@ public double getMJDRef() throws ParseException {
&& this.fitsHeaderWCSKeywords.containsKey(CADCExt.MJDREFF.key())) {
mjdRef = this.fitsHeaderWCSKeywords.getIntValue(CADCExt.MJDREFI.key())
+ this.fitsHeaderWCSKeywords.getDoubleValue(CADCExt.MJDREFF.key());
} else if (this.fitsHeaderWCSKeywords.containsKey(CADCExt.MJDREF.key())) {
mjdRef = this.fitsHeaderWCSKeywords.getDoubleValue(CADCExt.MJDREF.key());
} else if (this.fitsHeaderWCSKeywords.containsKey(DateTime.MJDREF.key())) {
mjdRef = this.fitsHeaderWCSKeywords.getDoubleValue(DateTime.MJDREF.key());
} else if (this.fitsHeaderWCSKeywords.containsKey(CADCExt.JDREFI.key())
&& this.fitsHeaderWCSKeywords.containsKey(CADCExt.JDREFF.key())) {
final double jdRef = this.fitsHeaderWCSKeywords.getIntValue(CADCExt.JDREFI.key())
+ this.fitsHeaderWCSKeywords.getDoubleValue(CADCExt.JDREFF.key());
mjdRef = DateUtil.toModifiedJulianDate(jdRef);
} else if (this.fitsHeaderWCSKeywords.containsKey(CADCExt.JDREF.key())) {
mjdRef = DateUtil.toModifiedJulianDate(this.fitsHeaderWCSKeywords.getDoubleValue(CADCExt.JDREF.key()));
} else if (this.fitsHeaderWCSKeywords.containsKey(CADCExt.DATEREF.key())) {
LOGGER.debug("Using DATEREF: " + this.fitsHeaderWCSKeywords.getStringValue(CADCExt.DATEREF.key()));
} else if (this.fitsHeaderWCSKeywords.containsKey(DateTime.JDREF.key())) {
mjdRef = DateUtil.toModifiedJulianDate(this.fitsHeaderWCSKeywords.getDoubleValue(DateTime.JDREF.key()));
} else if (this.fitsHeaderWCSKeywords.containsKey(DateTime.DATEREF.key())) {
LOGGER.debug("Using DATEREF: " + this.fitsHeaderWCSKeywords.getStringValue(DateTime.DATEREF.key()));
final String timeSystem = getSystem();
final TimeZone timeZone = TimeZone.getTimeZone(timeSystem);
final Date date = DateUtil.getDateFormat(DateUtil.ISO8601_DATE_FORMAT_LOCAL, timeZone).parse(
this.fitsHeaderWCSKeywords.getStringValue(CADCExt.DATEREF.key()));
this.fitsHeaderWCSKeywords.getStringValue(DateTime.DATEREF.key()));
mjdRef = DateUtil.toModifiedJulianDate(date, timeZone);
} else {
mjdRef = 0.0D;
Expand All @@ -141,27 +142,27 @@ public double getMJDRef() throws ParseException {
public double getMJDStart() throws ParseException {
final double startMJD;

if (this.fitsHeaderWCSKeywords.containsKey(CADCExt.MJDBEG.key())) {
startMJD = this.fitsHeaderWCSKeywords.getDoubleValue(CADCExt.MJDBEG.key());
} else if (this.fitsHeaderWCSKeywords.containsKey(CADCExt.MJDOBS.key())) {
startMJD = this.fitsHeaderWCSKeywords.getDoubleValue(CADCExt.MJDOBS.key());
if (this.fitsHeaderWCSKeywords.containsKey(DateTime.MJD_BEG.key())) {
startMJD = this.fitsHeaderWCSKeywords.getDoubleValue(DateTime.MJD_BEG.key());
} else if (this.fitsHeaderWCSKeywords.containsKey(DateTime.MJD_OBS.key())) {
startMJD = this.fitsHeaderWCSKeywords.getDoubleValue(DateTime.MJD_OBS.key());
} else if (this.fitsHeaderWCSKeywords.containsKey(CADCExt.JDBEG.key())) {
startMJD = DateUtil.toModifiedJulianDate(
this.fitsHeaderWCSKeywords.getDoubleValue(CADCExt.JDBEG.key()));
} else if (this.fitsHeaderWCSKeywords.containsKey(CADCExt.JDOBS.key())) {
startMJD = DateUtil.toModifiedJulianDate(
this.fitsHeaderWCSKeywords.getDoubleValue(CADCExt.JDOBS.key()));
} else if (this.fitsHeaderWCSKeywords.containsKey(CADCExt.DATEOBS.key())) {
} else if (this.fitsHeaderWCSKeywords.containsKey(DateTime.DATE_OBS.key())) {
final String timeSystem = getSystem();
final TimeZone timeZone = TimeZone.getTimeZone(timeSystem);
final Date date = DateUtil.getDateFormat(DateUtil.ISO8601_DATE_FORMAT_LOCAL, timeZone).parse(
this.fitsHeaderWCSKeywords.getStringValue(CADCExt.DATEOBS.key()));
this.fitsHeaderWCSKeywords.getStringValue(DateTime.DATE_OBS.key()));
startMJD = DateUtil.toModifiedJulianDate(date, timeZone);
} else if (this.fitsHeaderWCSKeywords.containsKey(CADCExt.DATEBEG.key())) {
} else if (this.fitsHeaderWCSKeywords.containsKey(DateTime.DATE_BEG.key())) {
final String timeSystem = getSystem();
final TimeZone timeZone = TimeZone.getTimeZone(timeSystem);
final Date date = DateUtil.getDateFormat(DateUtil.ISO8601_DATE_FORMAT_LOCAL, timeZone).parse(
this.fitsHeaderWCSKeywords.getStringValue(CADCExt.DATEBEG.key()));
this.fitsHeaderWCSKeywords.getStringValue(DateTime.DATE_BEG.key()));
startMJD = DateUtil.toModifiedJulianDate(date, timeZone);
} else if (this.fitsHeaderWCSKeywords.containsKey(CADCExt.TSTART.key())) {
final String unit = getUnit();
Expand All @@ -188,17 +189,19 @@ private double addToMJD(final double mjdValue, final double crval, final String
}

private String getSystem() {
return this.fitsHeaderWCSKeywords.containsKey(CADCExt.TIMESYS.key())
? this.fitsHeaderWCSKeywords.getStringValue(CADCExt.TIMESYS.key()) : DEFAULT_TIME_SYSTEM;
return this.fitsHeaderWCSKeywords.containsKey(DateTime.TIMESYS.key())
? this.fitsHeaderWCSKeywords.getStringValue(DateTime.TIMESYS.key()) : DEFAULT_TIME_SYSTEM;
}

public String getUnit() {
final String unit;
final String cUnitKey = CADCExt.CUNITn.n(this.fitsHeaderWCSKeywords.getTemporalAxis()).key();
final int temporalAxis = this.fitsHeaderWCSKeywords.getTemporalAxis();

if (this.fitsHeaderWCSKeywords.containsKey(CADCExt.TIMEUNIT.key())) {
unit = this.fitsHeaderWCSKeywords.getStringValue(CADCExt.TIMEUNIT.key());
} else if (this.fitsHeaderWCSKeywords.containsKey(cUnitKey)) {
final String cUnitKey = temporalAxis < 0 ? null : CADCExt.CUNITn.n(temporalAxis).key();

if (this.fitsHeaderWCSKeywords.containsKey(DateTime.TIMEUNIT.key())) {
unit = this.fitsHeaderWCSKeywords.getStringValue(DateTime.TIMEUNIT.key());
} else if (cUnitKey != null && this.fitsHeaderWCSKeywords.containsKey(cUnitKey)) {
unit = this.fitsHeaderWCSKeywords.getStringValue(cUnitKey);
} else {
unit = DEFAULT_TIME_UNIT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,8 @@ public static void assertFitsEqual(final Fits expected, final Fits result) throw
final BasicHDU<?> nextExpectedHDU = expectedHDUList[expectedIndex];
final BasicHDU<?> nextResultHDU = resultHDUList[expectedIndex];

try {
FitsTest.assertHDUEqual(nextExpectedHDU, nextResultHDU);
} catch (AssertionError assertionError) {
LOGGER.error("On Extension at index " + expectedIndex);
throw assertionError;
}
LOGGER.debug("On Extension at index " + expectedIndex);
FitsTest.assertHDUEqual(nextExpectedHDU, nextResultHDU);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public void test1DEnergy() throws Exception {
testHeader.addValue(Standard.CRPIXn.n(1), 1.000000000000E+00D);
testHeader.addValue(CADCExt.CUNITn.n(1), "Hz");
testHeader.addValue(CADCExt.PC1_1, 1.000000000000E+00D);
testHeader.addValue(CADCExt.RESTFRQ, 1.152712000000E+11D);
testHeader.addValue(Standard.RESTFRQ, 1.152712000000E+11D);
testHeader.addValue(CADCExt.SPECSYS, "LSRK");
testHeader.addValue(Standard.BSCALE, 1.000000000000E+00D);
testHeader.addValue(Standard.BZERO, 0.000000000000E+00D);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import ca.nrc.cadc.date.DateUtil;
import ca.nrc.cadc.util.Log4jInit;
import nom.tam.fits.Header;
import nom.tam.fits.header.DateTime;
import nom.tam.fits.header.Standard;
import nom.tam.fits.header.extra.NOAOExt;
import org.apache.log4j.Level;
Expand All @@ -89,7 +90,7 @@ public class TimeCutoutTest extends BaseCutoutTest {
}

@Test
public void testSimpleOverlap() throws Exception {
public void testSimpleOverlap() {
final Header testHeader = new Header();
final Calendar calendar = Calendar.getInstance(DateUtil.UTC);
calendar.set(2007, Calendar.SEPTEMBER, 18, 1, 15, 0);
Expand All @@ -102,9 +103,9 @@ public void testSimpleOverlap() throws Exception {
testHeader.addValue(Standard.CRPIXn.n(1), 10.0);
testHeader.addValue(Standard.CDELTn.n(1), 13.3629);
testHeader.addValue(Standard.CTYPEn.n(1), "UTC");
testHeader.addValue(CADCExt.DATEOBS, "2008-10-07T00:39:35.3342");
testHeader.addValue(CADCExt.MJDOBS, 54746.02749237);
testHeader.addValue(CADCExt.MJDREF, 54746.0);
testHeader.addValue(DateTime.DATE_OBS, "2008-10-07T00:39:35.3342");
testHeader.addValue(DateTime.MJD_OBS, 54746.02749237);
testHeader.addValue(DateTime.MJDREF, 54746.0);

final Interval<Number> testInterval = new Interval<>(54746.013D, 54746.058D);
final TimeCutout testSubject = new TimeCutout(testHeader);
Expand All @@ -116,7 +117,7 @@ public void testSimpleOverlap() throws Exception {
}

@Test
public void testSimpleMJDOverlap() throws Exception {
public void testSimpleMJDOverlap() {
final Header testHeader = new Header();

testHeader.setNaxes(3);
Expand All @@ -128,8 +129,8 @@ public void testSimpleMJDOverlap() throws Exception {
testHeader.addValue(Standard.CRPIXn.n(1), 102.0);
testHeader.addValue(Standard.CDELTn.n(1), 0.369);
testHeader.addValue(Standard.CTYPEn.n(1), "UTC");
testHeader.addValue(CADCExt.MJDBEG, 54533.0112D);
testHeader.addValue(CADCExt.MJDEND, 54565.0112D);
testHeader.addValue(DateTime.MJD_BEG, 54533.0112D);
testHeader.addValue(DateTime.MJD_END, 54565.0112D);
testHeader.addValue(CADCExt.MJDREFI, 54468);
testHeader.addValue(CADCExt.MJDREFF, 0.2489D);

Expand All @@ -155,7 +156,7 @@ public void testSimpleMJDOverlap() throws Exception {
}

@Test
public void testNoOverlap() throws Exception {
public void testNoOverlap() {
final Header testHeader = new Header();

testHeader.setNaxes(1);
Expand All @@ -165,10 +166,10 @@ public void testNoOverlap() throws Exception {
testHeader.addValue(Standard.CRPIXn.n(1), 1.0D);
testHeader.addValue(Standard.CDELTn.n(1), 7.0856D);
testHeader.addValue(Standard.CTYPEn.n(1), "TIME");
testHeader.addValue(NOAOExt.TIMESYS, "UTC");
testHeader.addValue(CADCExt.DATEBEG, "1977-11-25T01:21:13.0");
testHeader.addValue(CADCExt.DATEEND, "1977-11-25T03:11:00.0");
testHeader.addValue(CADCExt.MJDREF, 30005.3321D);
testHeader.addValue(DateTime.TIMESYS, "UTC");
testHeader.addValue(DateTime.DATE_BEG, "1977-11-25T01:21:13.0");
testHeader.addValue(DateTime.DATE_END, "1977-11-25T03:11:00.0");
testHeader.addValue(DateTime.MJDREF, 30005.3321D);

final Interval<Number> testInterval = new Interval<>(52644.1D, 52830.33D);
final TimeCutout testSubject = new TimeCutout(testHeader);
Expand Down
Loading
Loading