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

fix xml serialization for CAOM-2.4 #183

Merged
merged 2 commits into from
Nov 7, 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
1 change: 0 additions & 1 deletion caom2-viz/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
plugins {
id 'maven'
id 'maven-publish'
id 'com.jfrog.bintray' version '1.7.1'
id 'application'
id 'checkstyle'
}
Expand Down
2 changes: 1 addition & 1 deletion caom2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ sourceCompatibility = 1.8

group = 'org.opencadc'

version = '2.4.8'
version = '2.4.9'

description = 'OpenCADC CAOM library'
def git_url = 'https://github.com/opencadc/caom2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ protected void addPlanes(Set<Plane> planes, Element parent,
plane.metrics = getMetrics(planeElement, namespace, rc);
plane.quality = getQuality(planeElement, namespace, rc);

plane.observable = getObservable(planeElement, namespace, rc);
plane.position = getPosition(planeElement, namespace, rc);
plane.energy = getEnergy(planeElement, namespace, rc);
plane.time = getTime(planeElement, namespace, rc);
Expand Down
33 changes: 33 additions & 0 deletions caom2/src/main/java/ca/nrc/cadc/caom2/xml/ObservationWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
import ca.nrc.cadc.caom2.Environment;
import ca.nrc.cadc.caom2.Instrument;
import ca.nrc.cadc.caom2.Metrics;
import ca.nrc.cadc.caom2.Observable;
import ca.nrc.cadc.caom2.Observation;
import ca.nrc.cadc.caom2.ObservationURI;
import ca.nrc.cadc.caom2.Part;
Expand Down Expand Up @@ -765,6 +766,7 @@ protected void addPlanesElement(Set<Plane> planes, Element parent,
addElement("calibrationLevel", String.valueOf(plane.calibrationLevel.getValue()), planeElement);
}
addProvenanceElement(plane.provenance, planeElement, dateFormat);
addObservableElement(plane.observable, planeElement);
addMetricsElement(plane.metrics, planeElement, dateFormat);
addQuaility(plane.quality, planeElement, dateFormat);

Expand Down Expand Up @@ -850,6 +852,12 @@ protected void addPositionElement(Position comp, Element parent) {
if (comp.resolution != null) {
addNumberElement("resolution", comp.resolution, e);
}
if (comp.resolutionBounds != null) {
Element rb = getCaom2Element("resolutionBounds");
addNumberElement("lower", comp.resolutionBounds.getLower(), rb);
addNumberElement("upper", comp.resolutionBounds.getUpper(), rb);
e.addContent(rb);
}
if (comp.sampleSize != null) {
addNumberElement("sampleSize", comp.sampleSize, e);
}
Expand Down Expand Up @@ -897,6 +905,12 @@ protected void addEnergyElement(Energy comp, Element parent) {
if (comp.resolvingPower != null) {
addNumberElement("resolvingPower", comp.resolvingPower, e);
}
if (comp.resolvingPowerBounds != null) {
Element rb = getCaom2Element("resolvingPowerBounds");
addNumberElement("lower", comp.resolvingPowerBounds.getLower(), rb);
addNumberElement("upper", comp.resolvingPowerBounds.getUpper(), rb);
e.addContent(rb);
}
if (comp.sampleSize != null) {
addNumberElement("sampleSize", comp.sampleSize, e);
}
Expand Down Expand Up @@ -956,6 +970,12 @@ protected void addTimeElement(Time comp, Element parent) {
if (comp.resolution != null) {
addNumberElement("resolution", comp.resolution, e);
}
if (comp.resolutionBounds != null) {
Element rb = getCaom2Element("resolutionBounds");
addNumberElement("lower", comp.resolutionBounds.getLower(), rb);
addNumberElement("upper", comp.resolutionBounds.getUpper(), rb);
e.addContent(rb);
}
if (comp.sampleSize != null) {
addNumberElement("sampleSize", comp.sampleSize, e);
}
Expand Down Expand Up @@ -1064,6 +1084,19 @@ protected void addProvenanceElement(Provenance provenance, Element parent,
parent.addContent(element);
}

protected void addObservableElement(Observable observable, Element parent) {
if (observable == null) {
return;
}

Element obsE = getCaom2Element("observable");
parent.addContent(obsE);

Element ucdE = getCaom2Element("ucd");
ucdE.setText(observable.getUCD());
obsE.addContent(ucdE);
}

protected void addMetricsElement(Metrics metrics, Element parent,
DateFormat dateFormat) {
if (metrics == null) {
Expand Down
10 changes: 6 additions & 4 deletions caom2/src/main/resources/CAOM-2.4.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@
<xs:extension base="caom2:CaomEntity">
<xs:sequence>
<xs:element name="uri" type="xs:anyURI"/>
<xs:element name="productType" type="caom2:ProductType"/>
<xs:element name="productType" type="xs:string"/>
<xs:element name="releaseType" type="caom2:ReleaseType"/>

<xs:element name="contentRelease" type="xs:string" minOccurs="0">
Expand Down Expand Up @@ -481,7 +481,7 @@
<xs:extension base="caom2:CaomEntity">
<xs:sequence>
<xs:element name="name" type="xs:string" minOccurs="1"/>
<xs:element name="productType" type="caom2:ProductType" minOccurs="0"/>
<xs:element name="productType" type="xs:string" minOccurs="0"/>
<xs:element name="chunks" type="caom2:Chunks" minOccurs="0"/>
</xs:sequence>
</xs:extension>
Expand All @@ -500,7 +500,7 @@
<xs:complexContent>
<xs:extension base="caom2:CaomEntity">
<xs:sequence>
<xs:element name="productType" type="caom2:ProductType" minOccurs="0"/>
<xs:element name="productType" type="xs:string" minOccurs="0"/>
<xs:element name="naxis" type="xs:integer" minOccurs="0"/>
<xs:element name="observableAxis" type="xs:integer" minOccurs="0"/>
<xs:element name="positionAxis1" type="xs:integer" minOccurs="0"/>
Expand Down Expand Up @@ -764,6 +764,7 @@
</xs:restriction>
</xs:simpleType>

<!-- open vocabulary in 2.4
<xs:simpleType name="ProductType">
<xs:restriction base="xs:string">
<xs:enumeration value="science"/>
Expand All @@ -777,7 +778,8 @@
<xs:enumeration value="thumbnail"/>
</xs:restriction>
</xs:simpleType>

-->

<!-- open vocabulary in 2.3
<xs:simpleType name="DataProductType">
<xs:restriction base="xs:string">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
import ca.nrc.cadc.caom2.Environment;
import ca.nrc.cadc.caom2.Instrument;
import ca.nrc.cadc.caom2.Metrics;
import ca.nrc.cadc.caom2.Observable;
import ca.nrc.cadc.caom2.ObservationIntentType;
import ca.nrc.cadc.caom2.ObservationURI;
import ca.nrc.cadc.caom2.Part;
Expand Down Expand Up @@ -389,6 +390,7 @@ protected Set<Plane> getPlanes()
p.provenance = getProvenance();
p.metrics = getMetrics();
p.quality = new DataQuality(Quality.JUNK);
p.observable = new Observable("phot.count");

// alphabetical so easier to trace and debug metaChecksum computation

Expand All @@ -397,17 +399,18 @@ protected Set<Plane> getPlanes()
p.energy.bounds = new SampledInterval(400e-6, 900e-6);
p.energy.bounds.getSamples().add(new Interval(400e-6, 500e-6));
p.energy.bounds.getSamples().add(new Interval(800e-6, 900e-6));
p.energy.dimension = 2l;
p.energy.dimension = 2L;
for (EnergyBand eb : EnergyBand.values()) {
p.energy.getEnergyBands().add(eb);
}
p.energy.resolvingPower = 2.0;
p.energy.resolvingPowerBounds = new Interval(2.0, 5.0);
p.energy.restwav = 600e-9;
p.energy.sampleSize = 100e-6;
p.energy.transition = new EnergyTransition("H", "alpha");

p.polarization = new Polarization();
p.polarization.dimension = 3l;
p.polarization.dimension = 3L;
p.polarization.states = new TreeSet<PolarizationState>();
p.polarization.states.add(PolarizationState.I);
p.polarization.states.add(PolarizationState.Q);
Expand All @@ -432,16 +435,18 @@ protected Set<Plane> getPlanes()
}
p.position.dimension = new Dimension2D(1024, 2048);
p.position.resolution = 0.05;
p.position.resolutionBounds = new Interval(0.04, 0.06);
p.position.sampleSize = 0.025;
p.position.timeDependent = false;

p.time = new Time();
p.time.bounds = new SampledInterval(50000.25, 50000.75);
p.time.bounds.getSamples().add(new Interval(50000.25, 50000.40));
p.time.bounds.getSamples().add(new Interval(50000.50, 50000.75));
p.time.dimension = 2l;
p.time.dimension = 2L;
p.time.exposure = 666.0;
p.time.resolution = 0.5;
p.time.resolutionBounds = new Interval(0.5, 0.5);
p.time.sampleSize = 0.15;

p.custom = new CustomAxis("FARADAY");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1105,8 +1105,6 @@ protected void comparePlanes(Set<Plane> expected, Set<Plane> actual) throws NoSu
assertNotNull(expectedPlane);
assertNotNull(actualPlane);

compareEntity(expectedPlane, actualPlane);

assertEquals(expectedPlane.getProductID(), actualPlane.getProductID());
assertEquals(expectedPlane.creatorID, actualPlane.creatorID);
assertEquals(expectedPlane.metaRelease, actualPlane.metaRelease);
Expand All @@ -1118,7 +1116,11 @@ protected void comparePlanes(Set<Plane> expected, Set<Plane> actual) throws NoSu
compare(expectedPlane.metrics, actualPlane.metrics);
compare(expectedPlane.observable, actualPlane.observable);

compareComputed(expectedPlane, actualPlane);
compare(expectedPlane.position, actualPlane.position);
compare(expectedPlane.energy, actualPlane.energy);
compare(expectedPlane.time, actualPlane.time);
compare(expectedPlane.polarization, actualPlane.polarization);
compare(expectedPlane.custom, actualPlane.custom);

compareDataQuality(expectedPlane.quality, actualPlane.quality);
compareProvenance(expectedPlane.provenance, actualPlane.provenance);
Expand Down Expand Up @@ -1176,15 +1178,6 @@ protected void compare(Observable expected, Observable actual)
assertEquals(expected.getUCD(), actual.getUCD());
}

protected void compareComputed(Plane expected, Plane actual)
{
compare(expected.position, actual.position);
compare(expected.energy, actual.energy);
compare(expected.time, actual.time);
compare(expected.polarization, actual.polarization);
compare(expected.custom, actual.custom);
}

protected void compare(Position expected, Position actual)
{
if (expected == null)
Expand Down Expand Up @@ -1381,11 +1374,11 @@ protected void compare(Shape expected, Shape actual) {
}

protected void compare(Interval expected, Interval actual) {
if (expected == null)
{
Assert.assertNull(actual);
if (expected == null && actual == null) {
return;
}
assertNotNull(expected);
assertNotNull(actual);
Assert.assertEquals(expected.getLower(), actual.getLower(), 0.0);
Assert.assertEquals(expected.getUpper(), actual.getUpper(), 0.0);
}
Expand All @@ -1394,7 +1387,6 @@ protected void compareDataQuality(DataQuality expected, DataQuality actual)
{
if (expected == null && actual == null)
return;

assertNotNull(expected);
assertNotNull(actual);

Expand Down
Loading
Loading