View Javadoc

1   /*
2    * $Id: SssImagePlugin.java,v 1.2 2005/03/21 18:45:55 mch Exp $
3    *
4    * (C) Copyright Astrogrid...
5    */
6   
7   package org.astrogrid.dataservice.impl.roe;
8   
9   import java.io.IOException;
10  import java.net.URL;
11  import java.security.Principal;
12  import java.util.Vector;
13  import org.astrogrid.dataservice.queriers.DefaultPlugin;
14  import org.astrogrid.dataservice.queriers.ImageResults;
15  import org.astrogrid.dataservice.queriers.Querier;
16  import org.astrogrid.dataservice.queriers.UrlListResults;
17  import org.astrogrid.dataservice.queriers.status.QuerierQuerying;
18  import org.astrogrid.query.Query;
19  import org.astrogrid.query.keyword.KeywordMaker;
20  import org.astrogrid.query.returns.ReturnImage;
21  import org.astrogrid.query.returns.ReturnTable;
22  import org.astrogrid.geom.Angle;
23  
24  /***
25   * A plugin that returns URLs based on the query suitable for accessing the
26   * SuperCOSMOS Sky Survey images.  This is mostly to provide SIAP-compliant
27   * access, though obviously also you get the other interfaces for free.
28   * <p>
29   * The image server is a cutout server here:
30   * http://www-wfau.roe.ac.uk/~sss/cgi-bin/sss_aladin_pix.cgi?
31   *  @author M Hill
32   */
33  
34  public class SssImagePlugin extends DefaultPlugin {
35     
36     //requires waveband=1,2,3,etc   public static final String SSS_URL = "http://www-wfau.roe.ac.uk/~sss/cgi-bin/sss_aladin_pix.cgi?";
37     public static final String SSS_URL = "http://www-wfau.roe.ac.uk/~sss/cgi-bin/sss_topcat_pix.cgi?";
38     
39     public SssImagePlugin() {
40     }
41     
42     /*** Constructs a list of URLs suitable for accessing the images that correspond to the given query
43      */
44     public void askQuery(Principal user, Query query, Querier querier) throws IOException {
45  
46        //extract query to specific keys
47        KeywordMaker maker = new KeywordMaker(query);
48  
49        querier.setStatus(new QuerierQuerying(querier.getStatus(), maker.toString()));
50  
51        Angle ra = Angle.parseAngle(maker.getRequiredValue(maker.RA_KEYWORD));
52        Angle dec = Angle.parseAngle(maker.getRequiredValue(maker.DEC_KEYWORD));
53        Angle radius = Angle.parseAngle(maker.getRequiredValue(maker.RADIUS_KEYWORD));
54        String waveband = maker.getValue("WAVEBAND");
55        if (maker.getRequiredValue(maker.RADIUS_KEYWORD).toString().trim().equals("0")) {
56           radius = new Angle(0.1);//default to 0.1 deg
57        }
58        
59        if (radius.asArcMins()>7.5) {
60           throw new IllegalArgumentException("Maximum Radius is 7.5 arc minutes; Radius given was "+radius.asArcMins()+" arcmins (="+radius.asDegrees()+" deg)");
61        }
62  
63        Angle imageWidth = Angle.fromDegrees(radius.asDegrees()*2);
64        Angle imageHeight = imageWidth;
65        
66        
67        Vector urls = new Vector();
68        //build urls to images depending on if there are any at that wavelength.
69        /*
70        for (int waveband = 0; waveband < 5; waveband++) {
71           if (isCovered(ra, dec, waveband)) {
72              urls.add(SSS_URL+"ra="+ra.asDegrees()+"&dec="+dec.asDegrees()+"&mime-type=image/x-gfits&x="+imageWidth.asArcMins()+"&y="+imageHeight.asArcMins()+"&waveband="+waveband);
73           }
74        }
75         */
76  
77        String redImage = SSS_URL+"ra="+ra.asDegrees()+"&dec="+dec.asDegrees()+"&mime-type=image/x-gfits&x="+imageWidth.asArcMins()+"&y="+imageHeight.asArcMins()+"&waveband=red";
78        String blueImage = SSS_URL+"ra="+ra.asDegrees()+"&dec="+dec.asDegrees()+"&mime-type=image/x-gfits&x="+imageWidth.asArcMins()+"&y="+imageHeight.asArcMins()+"&waveband=blue";
79        
80        if (query.getResultsDef().getFormat().equals(ReturnImage.FITS)) {
81           //send the results back to the caller direct
82           String imageUrl = blueImage;
83           if ((waveband!=null) && (waveband.trim().toLowerCase().equals("red"))) {
84              imageUrl = redImage;
85           }
86           ImageResults results = new ImageResults(querier, new URL(imageUrl));
87           results.send(query.getResultsDef(), user);
88        }
89        else {
90           //assume it's a table
91           
92           //Use the 'red' and 'blue' waveband form which has whole sky coverage and so is much easier
93           urls.add(SSS_URL+"ra="+ra.asDegrees()+"&dec="+dec.asDegrees()+"&mime-type=image/x-gfits&x="+imageWidth.asArcMins()+"&y="+imageHeight.asArcMins()+"&waveband=red");
94           urls.add(SSS_URL+"ra="+ra.asDegrees()+"&dec="+dec.asDegrees()+"&mime-type=image/x-gfits&x="+imageWidth.asArcMins()+"&y="+imageHeight.asArcMins()+"&waveband=blue");
95           
96           
97           UrlListResults results = new UrlListResults(querier, (String[]) urls.toArray(new String[] {} ));
98           results.send(query.getResultsDef(), user);
99        }
100    }
101    
102    /*** Returns true if the given point is covered by the survey at the given
103     * waveband */
104    public boolean isCovered(Angle ra, Angle dec, int waveband) {
105       return true;
106    }
107    
108 
109    /*** Returns just the number of matches rather than the list of matches. Just does
110     * an askQuery and counts the results */
111    public long getCount(Principal user, Query query, Querier querier) throws IOException {
112       return getCountFromResults(user, query, querier);
113    }
114 
115    /*** Returns the formats that this plugin can provide.  Asks the results class; override in subclasse if nec */
116    public String[] getFormats() {
117       return new String[] { ReturnTable.VOTABLE, ReturnTable.CSV, ReturnTable.HTML, ReturnImage.FITS};
118    }
119    
120    
121 }
122 
123 
124 
125 
126 
127