Skip to content

DM-7162: adding first skeleton and test for lightcurve handler #161

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

Merged
merged 3 commits into from
Sep 9, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package edu.caltech.ipac.firefly.server.query;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please include on top of file the caltech/ipac license's information. See other source file for example.


/**
* Created by ejoliet on 8/22/16.
*/
public enum AlgorithmDefinition {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class name is too generic. Could be inner static of Periodogram.


LS("Lomb-Scargle");

String name = null;
int nParameters = 0;

AlgorithmDefinition(String name) {
this.name = name;
}

AlgorithmDefinition(String name, int npars) {
this.name = name;
this.nParameters = npars;
}

public int getNParameters() {
return this.nParameters;
}

public String getName() {
return this.name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt
*/
package edu.caltech.ipac.firefly.server.query;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to find a better place to put these classes.


import edu.caltech.ipac.astro.IpacTableWriter;
import edu.caltech.ipac.firefly.server.ServerContext;
import edu.caltech.ipac.util.DataGroup;
import edu.caltech.ipac.util.VoTableUtil;
import edu.caltech.ipac.util.download.FailedRequestException;
import edu.caltech.ipac.util.download.URLDownload;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;


/**
* .
* Should handle the LC transformations to get files out of the API result VOtable xml
*
* @author ejoliet
* @see PeriodogramAPIRequest
*/
public class IrsaLightCurveHandler extends NexsciLcApiHandler {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for subclassing? I don't see multiple versions of nexsci handlers.


public File getPeriodogramTable(PeriodogramAPIRequest request) {

return ipacTableFromAPI(request, RESULT_TABLES_IDX.PERIODOGRAM);

}


/**
* @return peaks table (default: 50 rows)
*/
public File getPeaksTable(PeriodogramAPIRequest request) {

return ipacTableFromAPI(request, RESULT_TABLES_IDX.PEAKS);
}

/**
* Return a phase folded curve form original light-curve
*
* @param tbl orginal lc table
* @param period period for phase folding the lc curve
* @return phase folded curve (x2 original input table 0,2 phase)
*/
public File toPhaseFoldedTable(File tbl, float period) {
//get raw lcTable and phase fold on time/period
//for now, return same table.
//TODO change it with the implementation DM-7165
return tbl;
}


protected File extractTblFrom(File votableResult, NexsciLcApiHandler.RESULT_TABLES_IDX resultTable) {
File resultTblFile = null;
try {
resultTblFile = makeResultTempFile(resultTable);
DataGroup[] dataGroups = VoTableUtil.voToDataGroups(votableResult.getAbsolutePath());

IpacTableWriter.save(resultTblFile, dataGroups[resultTable.ordinal()]);
return resultTblFile;
} catch (IOException e) {
e.printStackTrace();
}
return resultTblFile;
}

protected File ipacTableFromAPI(PeriodogramAPIRequest request, RESULT_TABLES_IDX resultTable) {
File tempFile = null;
try {
/**
* @see edu.caltech.ipac.firefly.server.query.LightCurveProcessor#computePeriodogram(edu.caltech.ipac.firefly.server.query.PeriodogramAPIRequest, java.lang.String)
*/
URL url = buildUrl(request);

File apiResult = apiDownlaod(url);

tempFile = extractTblFrom(apiResult, resultTable);

} catch (IOException e) {
e.printStackTrace();
} catch (FailedRequestException e) {
e.printStackTrace();
}
return tempFile;
}

protected File apiDownlaod(URL url) throws IOException, FailedRequestException {

File apiResultTempFile = makeApiResultTempFile();

URLConnection aconn = URLDownload.makeConnection(url);
aconn.setRequestProperty("Accept", "*/*");
URLDownload.getDataToFile(aconn, apiResultTempFile); //TODO Get from cache

return apiResultTempFile;
}


protected File makeResultTempFile(RESULT_TABLES_IDX resultTable) throws IOException {
String prefix = "error";
switch (resultTable) {
case PERIODOGRAM:
prefix = "periodogram-";
break;
case PEAKS:
prefix = "peaks-";
break;
}

return File.createTempFile(prefix, ".tbl", ServerContext.getTempWorkDir());
}

protected File makeApiResultTempFile() throws IOException {
return File.createTempFile("lc-api-result-", ".xml", ServerContext.getTempWorkDir());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package edu.caltech.ipac.firefly.server.query;

import java.io.File;

/**
* Created by ejoliet on 8/22/16.
* API handler to deal with result from calling LC API.
* Result is a file or several that contain the power vs period and peaks table
* The prefered output is votable containing those 2 tables
*/
public abstract class LightCurveAPIHandler implements LightCurveHandler {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not used. Not sure what the usage of this would be.


/**
* return a periodogram table
*
* @return
*/
public abstract File getPeriodogramTable();

/**
* @return
*/
public abstract File getPeaksTable();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt
*/
package edu.caltech.ipac.firefly.server.query;

import java.io.File;

/**
* Class should handle the input user parameter to
* call an API to
* get at least the periodogram and peaks table
* out of a raw time changin flux curve
*
* @author ejoliet
* @see PeriodogramAPIRequest
*/
public interface LightCurveHandler {
/**
* return a periodogram table from a request
*
* @return periodogram (power vs period) file
*/
public File getPeriodogramTable(PeriodogramAPIRequest request);

/**
* Return the table which contains N peaks, N integer from request object
*
* @return peaks table
* @see PeriodogramAPIRequest#getNumberPeaks()
*/
public File getPeaksTable(PeriodogramAPIRequest request);

/**
* TODO add extra output parameters getter that might be interesting
*/
}
Loading