Skip to content

Commit

Permalink
Merge pull request #150 from pdowler/master
Browse files Browse the repository at this point in the history
update caom2 TAP to use DALI-1.2 xtypes
  • Loading branch information
pdowler authored May 9, 2024
2 parents cfa7522 + d82847e commit 7ad37d1
Show file tree
Hide file tree
Showing 10 changed files with 257 additions and 102 deletions.
3 changes: 2 additions & 1 deletion caom2-tap-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ sourceCompatibility = 1.8

group = 'org.opencadc'

version = '1.2.11'
version = '1.2.12'

description = 'OpenCADC CAOM2 TAP server library'
def git_url = 'https://github.com/opencadc/caom2service'
Expand All @@ -34,6 +34,7 @@ dependencies {
compile 'org.opencadc:cadc-tap-server-pg:[1.1.0,)'
compile 'org.opencadc:cadc-tap-schema:[1.1.6,)'
compile 'org.opencadc:cadc-adql:[1.1.14,)'
compile 'org.opencadc:caom2:[2.4.8,)'
compile 'org.opencadc:caom2-artifact-resolvers:[1.2.3,)'

compile 'org.opencadc:cadc-gms:[1.0.0,)'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,27 @@
package ca.nrc.cadc.tap.caom2;


import ca.nrc.cadc.caom2.types.SegmentType;
import ca.nrc.cadc.dali.MultiPolygon;
import ca.nrc.cadc.dali.Point;
import ca.nrc.cadc.dali.Polygon;
import ca.nrc.cadc.dali.util.MultiPolygonFormat;
import ca.nrc.cadc.tap.writer.format.AbstractResultSetFormat;
import ca.nrc.cadc.tap.writer.format.DoubleArrayFormat;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.log4j.Logger;

/**
* Format position_bounds_samples as a xtype="caom2:multipolygon".
* Format position_bounds_samples as a xtype="multipolygon".
*
* @author pdowler
*/
public class PositionBoundsSamplesFormat extends AbstractResultSetFormat {
private static final Logger log = Logger.getLogger(PositionBoundsSamplesFormat.class);

private DoubleArrayFormat daf = new DoubleArrayFormat();
private MultiPolygonFormat mpf = new MultiPolygonFormat();

public PositionBoundsSamplesFormat() {
}
Expand All @@ -94,6 +100,25 @@ public Object extract(ResultSet resultSet, int columnIndex) throws SQLException

@Override
public String format(Object o) {
return daf.format(o);
if (o == null) {
return "";
}
double[] arr = daf.unwrap(o);
MultiPolygon mp = new MultiPolygon();
// caom2 MP has longitude,latitide,segmentType
Polygon poly = new Polygon();
for (int i = 0; i < arr.length; i += 3) {
double cv1 = arr[i];
double cv2 = arr[i + 1];
SegmentType st = SegmentType.toValue((int) arr[i + 2]);
if (SegmentType.CLOSE.equals(st)) {
mp.getPolygons().add(poly);
poly = new Polygon();
} else {
poly.getVertices().add(new Point(cv1, cv2));
}
}

return mpf.format(mp);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
************************************************************************
******************* CANADIAN ASTRONOMY DATA CENTRE *******************
************** CENTRE CANADIEN DE DONNÉES ASTRONOMIQUES **************
*
* (c) 2019. (c) 2019.
* Government of Canada Gouvernement du Canada
* National Research Council Conseil national de recherches
* Ottawa, Canada, K1A 0R6 Ottawa, Canada, K1A 0R6
* All rights reserved Tous droits réservés
*
* NRC disclaims any warranties, Le CNRC dénie toute garantie
* expressed, implied, or énoncée, implicite ou légale,
* statutory, of any kind with de quelque nature que ce
* respect to the software, soit, concernant le logiciel,
* including without limitation y compris sans restriction
* any warranty of merchantability toute garantie de valeur
* or fitness for a particular marchande ou de pertinence
* purpose. NRC shall not be pour un usage particulier.
* liable in any event for any Le CNRC ne pourra en aucun cas
* damages, whether direct or être tenu responsable de tout
* indirect, special or general, dommage, direct ou indirect,
* consequential or incidental, particulier ou général,
* arising from the use of the accessoire ou fortuit, résultant
* software. Neither the name de l'utilisation du logiciel. Ni
* of the National Research le nom du Conseil National de
* Council of Canada nor the Recherches du Canada ni les noms
* names of its contributors may de ses participants ne peuvent
* be used to endorse or promote être utilisés pour approuver ou
* products derived from this promouvoir les produits dérivés
* software without specific prior de ce logiciel sans autorisation
* written permission. préalable et particulière
* par écrit.
*
* This file is part of the Ce fichier fait partie du projet
* OpenCADC project. OpenCADC.
*
* OpenCADC is free software: OpenCADC est un logiciel libre ;
* you can redistribute it and/or vous pouvez le redistribuer ou le
* modify it under the terms of modifier suivant les termes de
* the GNU Affero General Public la “GNU Affero General Public
* License as published by the License” telle que publiée
* Free Software Foundation, par la Free Software Foundation
* either version 3 of the : soit la version 3 de cette
* License, or (at your option) licence, soit (à votre gré)
* any later version. toute version ultérieure.
*
* OpenCADC is distributed in the OpenCADC est distribué
* hope that it will be useful, dans l’espoir qu’il vous
* but WITHOUT ANY WARRANTY; sera utile, mais SANS AUCUNE
* without even the implied GARANTIE : sans même la garantie
* warranty of MERCHANTABILITY implicite de COMMERCIALISABILITÉ
* or FITNESS FOR A PARTICULAR ni d’ADÉQUATION À UN OBJECTIF
* PURPOSE. See the GNU Affero PARTICULIER. Consultez la Licence
* General Public License for Générale Publique GNU Affero
* more details. pour plus de détails.
*
* You should have received Vous devriez avoir reçu une
* a copy of the GNU Affero copie de la Licence Générale
* General Public License along Publique GNU Affero avec
* with OpenCADC. If not, see OpenCADC ; si ce n’est
* <http://www.gnu.org/licenses/>. pas le cas, consultez :
* <http://www.gnu.org/licenses/>.
*
************************************************************************
*/

package ca.nrc.cadc.tap.caom2;


import ca.nrc.cadc.tap.writer.format.AbstractResultSetFormat;
import ca.nrc.cadc.tap.writer.format.DoubleArrayFormat;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.log4j.Logger;

/**
* Format position_bounds_samples as a xtype="caom2:multipolygon".
*
* @author pdowler
*/
public class PositionBoundsSamplesInternalFormat extends AbstractResultSetFormat {
private static final Logger log = Logger.getLogger(PositionBoundsSamplesFormat.class);

private DoubleArrayFormat daf = new DoubleArrayFormat();

public PositionBoundsSamplesInternalFormat() {
}

@Override
public Object extract(ResultSet resultSet, int columnIndex) throws SQLException {
return daf.extract(resultSet, columnIndex);
}

@Override
public String format(Object o) {
return daf.format(o);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,21 @@ public Object extract(ResultSet resultSet, int columnIndex)

@Override
public String format(Object o) {
if (o == null)
if (o == null) {
return "";

}

double[] dd = daf.unwrap(o);
StringBuilder sb = new StringBuilder();

if (dd.length == 3)
if (dd.length == 3) {
sb.append("circle ");
else if (dd.length >= 6)
} else if (dd.length >= 6) {
sb.append("polygon ");
else
} else {
throw new RuntimeException("CONTENT: unexpected position_bounds length: " + dd.length);

}

sb.append(daf.format(dd));

return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ protected Format<Object> getShapeFormat(TapSelectItem columnDesc) {
|| columnDesc.utype.equals("obscore:Char.SpatialAxis.Coverage.Support.Area"))) {
return new PositionBoundsShapeFormat();
}
// default to pgsphere formatters
return super.getShapeFormat(columnDesc);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public class InitCaomTapSchemaContent extends InitDatabase {
private static final Logger log = Logger.getLogger(InitCaomTapSchemaContent.class);

public static final String MODEL_NAME = "caom-schema";
public static final String MODEL_VERSION = "1.2.8";
public static final String MODEL_VERSION = "1.2.12";

// the SQL is tightly coupled to cadc-tap-schema table names (for TAP-1.1)
static String[] CREATE_SQL = new String[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ insert into tap_schema.columns11 (table_name,column_name,description,utype,ucd,u
( 'caom2.Plane', 'observable_ucd', 'UCD (Universal Content Descriptor) for the observed/measure quantity', 'caom2:Plane.observable.ucd', NULL, NULL, 'char', '64*', NULL, 0,0,0 , 40),
( 'caom2.Plane', 'quality_flag', 'flag describing the data quality (possible values: junk)', 'caom2:Plane.quality.flag', NULL, NULL, 'char', '16*', NULL, 0,0,0 , 41),

( 'caom2.Plane', 'position_bounds', 'positional coverage of the data', 'caom2:Plane.position.bounds', NULL, 'deg', 'char', '*', 'caom2:shape', 0,0,0 , 50),
( 'caom2.Plane', 'position_bounds_samples', 'positional coverage of the data', 'caom2:Plane.position.bounds.samples', NULL, 'deg', 'double', '*', 'caom2:multipolygon', 0,0,0 , 50),
( 'caom2.Plane', 'position_bounds', 'positional coverage of the data', 'caom2:Plane.position.bounds', NULL, 'deg', 'char', '*', 'shape', 0,0,0 , 50),
( 'caom2.Plane', 'position_bounds_samples', 'positional coverage of the data', 'caom2:Plane.position.bounds.samples', NULL, 'deg', 'double', '*', 'multipolygon', 0,0,0 , 50),
( 'caom2.Plane', 'position_bounds_size', 'size of the polygon bounds (diameter of minimum spanning circle)', 'caom2:Plane.position.bounds.size', NULL, 'deg', 'double', NULL, NULL, 0,0,0 , 51),
( 'caom2.Plane', 'position_resolution', 'median spatial resolution (FWHM)', 'caom2:Plane.position.resolution', NULL, 'arcsec', 'double', NULL, NULL, 0,0,0 , 52),
( 'caom2.Plane', 'position_resolutionBounds', 'range of spatial resolution (FWHM) [new in 2.4]', 'caom2:Plane.position.resolutionBounds', NULL, 'arcsec', 'double', '2', 'interval', 0,0,0 , 52),
Expand All @@ -159,7 +159,7 @@ insert into tap_schema.columns11 (table_name,column_name,description,utype,ucd,u
( 'caom2.Plane', 'position_timeDependent', 'flag indicating that the position is time-dependent (0=false, 1=true)', 'caom2:Plane.position.timeDependent', NULL, NULL, 'int', NULL, NULL, 0,0,0 , 56),

( 'caom2.Plane', 'energy_bounds', 'energy coverage (barycentric wavelength)', 'caom2:Plane.energy.bounds', NULL, 'm', 'double', '2','interval', 0,1,0 , 61),
( 'caom2.Plane', 'energy_bounds_samples', 'detailed energy coverage (barycentric wavelength)', 'caom2:Plane.energy.bounds.samples', NULL, 'm', 'double', '*', 'caom2:multiinterval', 0,0,0 , 61),
( 'caom2.Plane', 'energy_bounds_samples', 'detailed energy coverage (barycentric wavelength)', 'caom2:Plane.energy.bounds.samples', NULL, 'm', 'double', '2x*', 'interval', 0,0,0 , 61),
( 'caom2.Plane', 'energy_bounds_lower', 'lower bound on energy axis (barycentric wavelength)', 'caom2:Plane.energy.bounds.lower', NULL, 'm', 'double', NULL, NULL, 0,1,0 , 62),
( 'caom2.Plane', 'energy_bounds_upper', 'upper bound on energy axis (barycentric wavelength)', 'caom2:Plane.energy.bounds.upper', NULL, 'm', 'double', NULL, NULL, 0,1,0 , 63),
( 'caom2.Plane', 'energy_bounds_width', 'width of the energy bounds', 'caom2:Plane.energy.bounds.width', NULL, 'm', 'double', NULL, NULL, 0,0,0 , 64),
Expand All @@ -179,7 +179,7 @@ insert into tap_schema.columns11 (table_name,column_name,description,utype,ucd,u
( 'caom2.Plane', 'energy_restwav', 'rest wavelength of target spectral feature (barycentric)', 'caom2:Plane.energy.restwav', NULL, 'm', 'double', NULL, NULL, 0,1,0 , 75),

( 'caom2.Plane', 'time_bounds', 'time coverage (Modified Julian Day)', 'caom2:Plane.time.bounds', NULL, 'd', 'double', '2', 'interval', 0,1,0 , 80),
( 'caom2.Plane', 'time_bounds_samples', 'detailed time coverage (Modified Julian Day)', 'caom2:Plane.time.bounds.samples', NULL, 'd', 'double', '*', 'caom2:multiinterval', 0,0,0 , 81),
( 'caom2.Plane', 'time_bounds_samples', 'detailed time coverage (Modified Julian Day)', 'caom2:Plane.time.bounds.samples', NULL, 'd', 'double', '2x*', 'interval', 0,0,0 , 81),
( 'caom2.Plane', 'time_bounds_lower', 'lower bound on time axis (Modified Julian Day)', 'caom2:Plane.time.bounds.lower', NULL, 'd', 'double', NULL, NULL, 0,1,0 , 81),
( 'caom2.Plane', 'time_bounds_upper', 'upper bound on time axis (Modified Julian Day)', 'caom2:Plane.time.bounds.upper', NULL, 'd', 'double', NULL, NULL, 0,1,0 , 82),
( 'caom2.Plane', 'time_bounds_width', 'width of the time bounds', 'caom2:Plane.time.bounds.width', NULL, 'd', 'double', NULL, NULL, 0,1,0 , 83),
Expand All @@ -194,7 +194,7 @@ insert into tap_schema.columns11 (table_name,column_name,description,utype,ucd,u

( 'caom2.Plane', 'custom_ctype', 'coordinate type for custom axis [new in 2.4]', 'caom2:Plane.custom.ctype', NULL, NULL, 'char', '32*', NULL, 0,0,0 , 100),
( 'caom2.Plane', 'custom_bounds', 'custom axis coverage [new in 2.4]', 'caom2:Plane.custom.bounds', NULL, NULL, 'double', '2', 'interval', 0,0,0 , 101),
( 'caom2.Plane', 'custom_bounds_samples', 'detailed custom axis coverage [new in 2.4]', 'caom2:Plane.custom.bounds.samples', NULL, NULL, 'double', '*', 'caom2:multiinterval', 0,0,0 , 102),
( 'caom2.Plane', 'custom_bounds_samples', 'detailed custom axis coverage [new in 2.4]', 'caom2:Plane.custom.bounds.samples', NULL, NULL, 'double', '2x*', 'interval', 0,0,0 , 102),
( 'caom2.Plane', 'custom_bounds_lower', 'lower bound on custom axis [new in 2.4]', 'caom2:Plane.custom.bounds.lower', NULL, NULL, 'double', NULL, NULL, 0,0,0 , 103),
( 'caom2.Plane', 'custom_bounds_upper', 'upper bound on custom axis [new in 2.4]', 'caom2:Plane.custom.bounds.upper', NULL, NULL, 'double', NULL, NULL, 0,0,0 , 104),
( 'caom2.Plane', 'custom_bounds_width', 'width of the custom bounds [new in 2.4]', 'caom2:Plane.custom.bounds.width', NULL, NULL, 'double', NULL, NULL, 0,0,0 , 105),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ insert into tap_schema.tables11 (schema_name,table_name,table_type,description,t

insert into tap_schema.columns11 (table_name,column_name,utype,description,ucd,unit,datatype,arraysize,xtype,principal,indexed,std,column_index,id) values
( 'ivoa.ObsCore', 'obs_publisher_did', 'obscore:Curation.PublisherDID',
'publisher dataset identifier', 'meta.ref.ivoid', NULL, 'char', '256*',NULL, 1,1,1,1, 'caomPublisherID')
'publisher dataset identifier', 'meta.ref.ivoid', NULL, 'char', '256*','uri', 1,1,1,1, 'caomPublisherID')
;
insert into tap_schema.columns11 (table_name,column_name,utype,description,ucd,unit,datatype,arraysize,xtype,principal,indexed,std, column_index) values
( 'ivoa.ObsCore', 'obs_collection', 'obscore:DataID.Collection',
Expand Down
2 changes: 1 addition & 1 deletion caom2-tap/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ sourceCompatibility = 1.8

group = 'org.opencadc'

version = '1.8.0'
version = '1.8.1'

description = 'OpenCADC CAOM2 TAP client library'
def git_url = 'https://github.com/opencadc/caom2service'
Expand Down
Loading

0 comments on commit 7ad37d1

Please sign in to comment.