diff --git a/data-discovery/src/main/java/search/DbObstap.java b/data-discovery/src/main/java/search/DbObstap.java index e673210b4023639edee0e950a49814b06457e468..ea50b70d70bf19c4576ccbd13a0b2315c30f37c6 100644 --- a/data-discovery/src/main/java/search/DbObstap.java +++ b/data-discovery/src/main/java/search/DbObstap.java @@ -60,7 +60,6 @@ public class DbObstap Double em_min, em_max, em_res_power; Long em_xel; - boolean em_valid; String o_ucd; @@ -208,7 +207,8 @@ public class DbObstap String dbRegion = toRegionColumnName(pos.system); String theQuery ="SELECT *," - + inputRegion + " <@ " + dbRegion + " AS inputInsideDb, " + + inputRegion + " && " + dbRegion + " AS inputOverlapsDb, " + + inputRegion + " <@ " + dbRegion + " AS inputInsideDb, " + inputRegion + " @> " + dbRegion + " AS dbInsideInput FROM obscore WHERE (obs_publisher_did IN (\'" +commaSepPubdids+"\'))"; @@ -257,9 +257,8 @@ public class DbObstap obstap.t_resolution = this.getDouble(res,"t_resolution"); obstap.t_xel = this.getLong(res,"t_xel"); - obstap.em_min = this.getDouble(res,"em_min"); boolean em_min_valid = !res.wasNull(); - obstap.em_max = this.getDouble(res,"em_max"); boolean em_max_valid = !res.wasNull(); - obstap.em_valid = em_min_valid && em_max_valid;; + obstap.em_min = this.getDouble(res,"em_min"); + obstap.em_max = this.getDouble(res,"em_max"); obstap.em_res_power = this.getDouble(res,"em_res_power"); obstap.em_xel = this.getLong(res,"em_xel"); @@ -274,16 +273,22 @@ public class DbObstap // VLKB extension obstap.s_region_galactic = this.getString(res,"s_region_galactic"); - obstap.vel_min = this.getDouble(res,"vel_min"); //boolean em_min_valid = !res.wasNull(); - obstap.vel_max = this.getDouble(res,"vel_max"); //boolean em_max_valid = !res.wasNull(); + obstap.vel_min = this.getDouble(res,"vel_min"); + obstap.vel_max = this.getDouble(res,"vel_max"); + boolean inputOverlapsDb = res.getBoolean("inputOverlapsDb"); boolean inputInsideDb = res.getBoolean("inputInsideDb"); boolean dbInsideInput = res.getBoolean("dbInsideInput"); - obstap.overlapCodeSky = convertToOverlapCodeSky(inputInsideDb, dbInsideInput); + LOGGER.finest("inpOverlapsDb, inpInsideDb, dbInsideInp : " + + inputOverlapsDb + " " + inputInsideDb + " " + dbInsideInput); - obstap.overlapCodeVel = convertToOverlapCodeVel(band,obstap.em_valid,obstap.em_min,obstap.em_max); + obstap.overlapCodeSky = convertToOverlapCodeSky(inputOverlapsDb, inputInsideDb, dbInsideInput); - obstap.overlapCode = convertToOverlapCode(obstap.overlapCodeSky, obstap.overlapCodeVel); + obstap.overlapCodeVel = convertToOverlapCodeVel(band, + obstap.em_min,obstap.em_max, + obstap.vel_min,obstap.vel_max ); + + obstap.overlapCode = convertToOverlapCode(obstap.overlapCodeSky, obstap.overlapCodeVel); obstapList.add(obstap); @@ -303,24 +308,56 @@ public class DbObstap return cubes; } - /* convert overlap codes */ + /* convert overlap codes (AST definition): + + "0 - The check could not be performed because the second Region could not be mapped into the coordinate system of the first Region.", + "1 - There is no overlap between the two Regions.", + "2 - The first Region is completely inside the second Region.", + "3 - The second Region is completely inside the first Region.", + "4 - There is partial overlap between the two Regions.", + "5 - The Regions are identical to within their uncertainties.", + "6 - The second Region is the exact negation of the first Region to within their uncertainties." + */ + private Integer convertToOverlapCodeSky(boolean inpOverlapsDb, boolean inpInDb, boolean dbInInp) + { + if(inpOverlapsDb) + { + if(!inpInDb && !dbInInp) return 4; + else if( inpInDb && !dbInInp) return 3; + else if(!inpInDb && dbInInp) return 2; + else return 5; + } + else + { + return 1; + } + } + + private boolean intervalOverlap(double amin, double amax, double bmin, double bmax) + { + boolean AoverB + = (amin <= bmin) && (bmin <= amax) + || (amin <= bmax) && (bmax <= amax); - private Integer convertToOverlapCodeSky(boolean inpInDb, boolean dbInInp) - { - if(!inpInDb && !dbInInp) return 4; // parial overlap - else if( inpInDb && !dbInInp) return 3; // input region completely inside fits-datacube - else if(!inpInDb && dbInInp) return 2; // datacube completely inside input-region - else return 5; // exact match: both inpInDb dbInInp are true + boolean BoverA + = (bmin <= amin) && (amin <= bmax) + || (bmin <= amax) && (amax <= bmax); + + return AoverB || BoverA; } - private Integer convertToOverlapCodeVel(Band band, boolean v_valid, double v_min, double v_max) + private Integer convertToOverlapCodeVel(Band band, + Double w_min, Double w_max, // WAVE + Double v_min, Double v_max) // VELO { - if((band != null) && v_valid) + if(band != null) { - if(band.system == Band.System.VELO_LSRK) + boolean v_valid = (v_min != null) && (v_max != null); + boolean w_valid = (w_min != null) && (w_max != null); + + if( v_valid && (band.system == Band.System.VELO_LSRK) ) { - // FIXME assert qArgs: vel_min <= vel_max - // FIXME assert cube: v_min <= v_max + boolean overlap = intervalOverlap(band.min, band.max, v_min, v_max);; boolean dbInInp = (band.min <= v_min) && (v_min <= band.max) && (band.min <= v_max) && (v_max <= band.max); @@ -328,20 +365,44 @@ public class DbObstap boolean inpInDb = (v_min <= band.min) && (band.min <= v_max) && (v_min <= band.max ) && (band.max <= v_max); - return convertToOverlapCodeSky(inpInDb, dbInInp); + // do as in Sky-overlap + return convertToOverlapCodeSky(overlap, inpInDb, dbInInp); + } + else if( w_valid && (band.system == Band.System.WAVE_Barycentric) ) + { + boolean overlap = intervalOverlap(band.min, band.max, w_min, w_max);; + + boolean dbInInp = (band.min <= w_min) && (w_min <= band.max) + && (band.min <= w_max) && (w_max <= band.max); + + boolean inpInDb = (w_min <= band.min) && (band.min <= w_max) + && (w_min <= band.max ) && (band.max <= w_max); + // do as in Sky-overlap + return convertToOverlapCodeSky(overlap, inpInDb, dbInInp); + } + else + { + return null; } - else return null;// FIXME other v_type NotImplemented yet } - - return null; + else + { + return null; + } } private Integer convertToOverlapCode(Integer ovcSky, Integer ovcVel) { - if(ovcVel == null) return ovcSky; // 2D images - else if(ovcSky == ovcVel) return ovcSky; - else return 4;// partial overlap + if(ovcSky == null) return ovcVel; // spectral images or both null + else if(ovcVel == null) return ovcSky; // 2D sky images or both null + else if((ovcSky != null) && (ovcVel != null)) + { + if((ovcSky == 1) || (ovcVel == 1) ) return 1; // no overlap + else if(ovcSky == ovcVel) return ovcSky; + else return 4; + } + else return null; // both null }