Skip to content
Snippets Groups Projects
Commit 4dddc8c1 authored by Robert Butora's avatar Robert Butora
Browse files

implements PIXELS param (cfitsio extSyntax [1:10,1:50,1:1000:10]) has...

implements PIXELS param (cfitsio extSyntax [1:10,1:50,1:1000:10]) has precedense over POS,BAND,POL,TIME
parent f2aa74eb
Branches
Tags
No related merge requests found
...@@ -14,11 +14,13 @@ import vo.parameter.*; ...@@ -14,11 +14,13 @@ import vo.parameter.*;
public interface Cutout public interface Cutout
{ {
public void doStream(String relPathname, int hdunum, Pos pos, Band band, Time time, Pol pol, public void doStream(String relPathname, int hdunum,
Pos pos, Band band, Time time, Pol pol, String pixels,
OutputStream outputStream) throws IOException, InterruptedException; OutputStream outputStream) throws IOException, InterruptedException;
public CutResult doFile(String relPathname, int hdunum, Pos pos, Band band, Time time, Pol pol, public CutResult doFile(String relPathname, int hdunum,
Pos pos, Band band, Time time, Pol pol, String pixels,
boolean countNullValues, FitsCard[] extraCards) boolean countNullValues, FitsCard[] extraCards)
throws IOException, InterruptedException; throws IOException, InterruptedException;
......
...@@ -94,11 +94,20 @@ class CutoutImpl implements Cutout ...@@ -94,11 +94,20 @@ class CutoutImpl implements Cutout
return region; return region;
} }
public void doStream(String relPathname, int hdunum, Pos pos, Band band, Time time, Pol pol, public void doStream(String relPathname, int hdunum,
Pos pos, Band band, Time time, Pol pol, String pixels,
OutputStream outputStream) throws IOException, InterruptedException OutputStream outputStream) throws IOException, InterruptedException
{ {
Instant start = Instant.now(); Instant start = Instant.now();
boolean has_overlap = false;
boolean pixels_valid = (pixels != null);
String boundsString = "";
String absPathname = settings.fitsPaths.surveys() + "/" + relPathname;
if( !pixels_valid )
{
ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream();
if(bos == null) if(bos == null)
throw new AssertionError("byte output stream for bounds was not created, is null"); throw new AssertionError("byte output stream for bounds was not created, is null");
...@@ -112,8 +121,6 @@ class CutoutImpl implements Cutout ...@@ -112,8 +121,6 @@ class CutoutImpl implements Cutout
String coordString = jReq.toString(); String coordString = jReq.toString();
LOGGER.info("coordString: " + coordString); LOGGER.info("coordString: " + coordString);
String absPathname = settings.fitsPaths.surveys() + "/" + relPathname;
/* calc bounds */ /* calc bounds */
String[] cmdBounds = new String[4]; String[] cmdBounds = new String[4];
...@@ -126,27 +133,32 @@ class CutoutImpl implements Cutout ...@@ -126,27 +133,32 @@ class CutoutImpl implements Cutout
execBounds.doRun(bos, cmdBounds); execBounds.doRun(bos, cmdBounds);
LOGGER.info("execBounds exitValue: " + execBounds.exitValue); LOGGER.info("execBounds exitValue: " + execBounds.exitValue);
bos.close();
boolean has_result = (execBounds.exitValue == 0); boolean has_result = (execBounds.exitValue == 0);
Instant boundsDone = Instant.now();
LOGGER.info("EXECTIME boundsDone: " + Duration.between(start, boundsDone));
if(has_result) if(has_result)
{ {
String boundsString = new String(bos.toByteArray()); boundsString = new String(bos.toByteArray());
// remove end-of-line (was added by vlkb_ast.cpp: cout << ... << endl) // remove end-of-line (was added by vlkb_ast.cpp: cout << ... << endl)
String lineSeparator = System.lineSeparator(); String lineSeparator = System.lineSeparator();
boundsString = boundsString.replace(lineSeparator, ""); boundsString = boundsString.replace(lineSeparator, "");
LOGGER.info("BOUNDS: " + boundsString); LOGGER.info("BOUNDS: " + boundsString);
if((boundsString != null) && boundsString.trim().isEmpty()) has_overlap = !((boundsString != null) && boundsString.trim().isEmpty());
if( !has_overlap )
{ {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"region in file does not overlap with region defined by SODA parameters"); "region in file does not overlap with region defined by SODA parameters");
} }
else }
bos.close();
Instant boundsDone = Instant.now();
LOGGER.info("EXECTIME boundsDone: " + Duration.between(start, boundsDone));
}
if(has_overlap || pixels_valid)
{ {
/* cutout -> outputStream */ /* cutout -> outputStream */
...@@ -155,7 +167,7 @@ class CutoutImpl implements Cutout ...@@ -155,7 +167,7 @@ class CutoutImpl implements Cutout
cmdCut[1] = "imcopy"; cmdCut[1] = "imcopy";
cmdCut[2] = absPathname; cmdCut[2] = absPathname;
cmdCut[3] = String.valueOf(hdunum-1); cmdCut[3] = String.valueOf(hdunum-1);
cmdCut[4] = boundsString; cmdCut[4] = pixels_valid ? pixels : boundsString;
cmdCut[5] = settings.fitsPaths.cutouts(); cmdCut[5] = settings.fitsPaths.cutouts();
if(outputStream == null) if(outputStream == null)
...@@ -167,7 +179,6 @@ class CutoutImpl implements Cutout ...@@ -167,7 +179,6 @@ class CutoutImpl implements Cutout
Instant cutDone = Instant.now(); Instant cutDone = Instant.now();
LOGGER.info("EXECTIME cutDone: " + Duration.between(start, cutDone)); LOGGER.info("EXECTIME cutDone: " + Duration.between(start, cutDone));
} }
}
else else
{ {
throw new IllegalArgumentException( throw new IllegalArgumentException(
...@@ -226,7 +237,7 @@ class CutoutImpl implements Cutout ...@@ -226,7 +237,7 @@ class CutoutImpl implements Cutout
public CutResult doFile(String relPathname, int hdunum, public CutResult doFile(String relPathname, int hdunum,
Pos pos, Band band, Time time, Pol pol, Pos pos, Band band, Time time, Pol pol, String pixels,
boolean countNullValues, FitsCard[] extraCards) boolean countNullValues, FitsCard[] extraCards)
throws IOException, InterruptedException throws IOException, InterruptedException
{ {
...@@ -245,7 +256,7 @@ class CutoutImpl implements Cutout ...@@ -245,7 +256,7 @@ class CutoutImpl implements Cutout
OutputStream fileOutputStream = new FileOutputStream( new File(absSubimgPathname) ); OutputStream fileOutputStream = new FileOutputStream( new File(absSubimgPathname) );
doStream(relPathname, hdunum, pos, band, time, pol, fileOutputStream); doStream(relPathname, hdunum, pos, band, time, pol, pixels, fileOutputStream);
// engine returns absPathname see common/cutout.cpp::do_cutout_file() // engine returns absPathname see common/cutout.cpp::do_cutout_file()
cutResult.filename = absSubimgPathname; cutResult.filename = absSubimgPathname;
...@@ -271,6 +282,9 @@ class CutoutImpl implements Cutout ...@@ -271,6 +282,9 @@ class CutoutImpl implements Cutout
jReq.add(band); jReq.add(band);
jReq.add(time); jReq.add(time);
jReq.add(pol); jReq.add(pol);
// jReq.add(pixels), FIXME implement to supoort PIXLES in vlkb-legacy by AMQP
jReq.add(countNullValues); jReq.add(countNullValues);
jReq.add(extraCards); jReq.add(extraCards);
......
...@@ -88,6 +88,7 @@ public class ServletCutout extends javax.servlet.http.HttpServlet ...@@ -88,6 +88,7 @@ public class ServletCutout extends javax.servlet.http.HttpServlet
+ "<PARAM name=\"BAND\" ucd=\"stat.interval\" unit=\"m\" datatype=\"double\" arraysize=\"2\" xtype=\"interval\" value=\"\"/>" + "<PARAM name=\"BAND\" ucd=\"stat.interval\" unit=\"m\" datatype=\"double\" arraysize=\"2\" xtype=\"interval\" value=\"\"/>"
+ "<PARAM name=\"TIME\" ucd=\"time.interval;obs.exposure\" unit=\"d\" datatype=\"double\" arraysize=\"2\" xtype=\"interval\" value=\"\"/>" + "<PARAM name=\"TIME\" ucd=\"time.interval;obs.exposure\" unit=\"d\" datatype=\"double\" arraysize=\"2\" xtype=\"interval\" value=\"\"/>"
+ "<PARAM name=\"POL\" ucd=\"meta.code;phys.polarization\" datatype=\"char\" arraysize=\"*\" value=\"\"/>" + "<PARAM name=\"POL\" ucd=\"meta.code;phys.polarization\" datatype=\"char\" arraysize=\"*\" value=\"\"/>"
+ "<PARAM name=\"PIXELS\" ucd=\"instr.pixel;meta.dataset\" datatype=\"char\" arraysize=\"*\" value=\"\"/>"
+ "<PARAM name=\"RESPONSEFORMAT\" ucd=\"meta.code.mime\" datatype=\"char\" arraysize=\"*\" value=\"application/fits\"/>" + "<PARAM name=\"RESPONSEFORMAT\" ucd=\"meta.code.mime\" datatype=\"char\" arraysize=\"*\" value=\"application/fits\"/>"
+ "<PARAM name=\"POSSYS\" ucd=\"pos.frame\" datatype=\"char\" arraysize=\"*\" value=\"\">" + "<PARAM name=\"POSSYS\" ucd=\"pos.frame\" datatype=\"char\" arraysize=\"*\" value=\"\">"
...@@ -114,7 +115,7 @@ public class ServletCutout extends javax.servlet.http.HttpServlet ...@@ -114,7 +115,7 @@ public class ServletCutout extends javax.servlet.http.HttpServlet
} }
protected void doCutoutStream(String id, Pos pos, Band band, Time time, Pol pol, protected void doCutoutStream(String id, Pos pos, Band band, Time time, Pol pol, String pixels,
OutputStream respOutputStream) throws IOException, InterruptedException OutputStream respOutputStream) throws IOException, InterruptedException
{ {
LOGGER.info("trace" + pos); LOGGER.info("trace" + pos);
...@@ -122,12 +123,12 @@ public class ServletCutout extends javax.servlet.http.HttpServlet ...@@ -122,12 +123,12 @@ public class ServletCutout extends javax.servlet.http.HttpServlet
Resolver rsl = new ResolverFromId(); Resolver rsl = new ResolverFromId();
rsl.resolve(id); rsl.resolve(id);
cutout.doStream(rsl.relPathname(), rsl.hdunum(), pos, band, time, pol, respOutputStream); cutout.doStream(rsl.relPathname(), rsl.hdunum(), pos, band, time, pol, pixels, respOutputStream);
} }
protected DataLink doCutoutFile(String id, Pos pos, Band band, Time time, Pol pol, protected DataLink doCutoutFile(String id, Pos pos, Band band, Time time, Pol pol, String pixels,
boolean countNullValues, String respFormat) boolean countNullValues, String respFormat)
throws IOException, InterruptedException throws IOException, InterruptedException
{ {
...@@ -166,11 +167,11 @@ public class ServletCutout extends javax.servlet.http.HttpServlet ...@@ -166,11 +167,11 @@ public class ServletCutout extends javax.servlet.http.HttpServlet
final String DEFAULT_TIME_SYSTEM = "MJD_UTC"; // FIXME take from confif file final String DEFAULT_TIME_SYSTEM = "MJD_UTC"; // FIXME take from confif file
if(pos != null) pos.setSystem(DEFAULT_SKY_SYSTEM); //if(pos != null) pos.setSystem(DEFAULT_SKY_SYSTEM);
if(band != null) band.setSystem(DEFAULT_SPEC_SYSTEM); //if(band != null) band.setSystem(DEFAULT_SPEC_SYSTEM);
if(time != null) time.setSystem(DEFAULT_TIME_SYSTEM); //if(time != null) time.setSystem(DEFAULT_TIME_SYSTEM);
CutResult cutResult = cutout.doFile(relPathname, hdunum, pos, band, time, pol, false, null); CutResult cutResult = cutout.doFile(relPathname, hdunum, pos, band, time, pol, pixels, false, null);
DataLink dlk = new DataLink(); DataLink dlk = new DataLink();
...@@ -292,22 +293,24 @@ public class ServletCutout extends javax.servlet.http.HttpServlet ...@@ -292,22 +293,24 @@ public class ServletCutout extends javax.servlet.http.HttpServlet
Band band = Band.parseBand(params, DEFAULT_SPEC_SYSTEM); Band band = Band.parseBand(params, DEFAULT_SPEC_SYSTEM);
Time time = Time.parseTime(params, DEFAULT_TIME_SYSTEM); Time time = Time.parseTime(params, DEFAULT_TIME_SYSTEM);
Pol pol = Pol.parsePol(params); Pol pol = Pol.parsePol(params);
String pixels = SingleStringParam.parseSingleStringParam(params, "PIXELS");
String respFormat = sodaReq_getResponseFormat(request, DEFAULT_RESPONSEFORMAT); String respFormat = sodaReq_getResponseFormat(request, DEFAULT_RESPONSEFORMAT);
LOGGER.info("responseFormat: " + respFormat); LOGGER.info("responseFormat: " + respFormat);
if(respFormat.equals("application/fits")) if(respFormat.startsWith("application/fits"))
{ {
response.setContentType(respFormat); response.setContentType(respFormat);
doCutoutStream(id, pos, band, time, pol, respOutputStream); doCutoutStream(id, pos, band, time, pol, pixels, respOutputStream);
} }
else if(respFormat.equals("application/x-vlkb+xml")) else if(respFormat.startsWith("application/x-vlkb+xml"))
{ {
boolean countNullValues = vlkbReq_getNullValues(request); boolean countNullValues = vlkbReq_getNullValues(request);
response.setContentType(respFormat); response.setContentType(respFormat);
DataLink respDataLink = doCutoutFile(id, pos, band, time, pol, countNullValues, respFormat); DataLink respDataLink = doCutoutFile(id, pos, band, time, pol, pixels, countNullValues,
respFormat);
/* FIXME errors from engine not checked - cut-file might not have been created */ /* FIXME errors from engine not checked - cut-file might not have been created */
LOGGER.info("DataLink - id:" + respDataLink.id + " url: " + respDataLink.accessUrl ); LOGGER.info("DataLink - id:" + respDataLink.id + " url: " + respDataLink.accessUrl );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment