-
Notifications
You must be signed in to change notification settings - Fork 16
IRSA-629 and IRSA-630: add generic way to get downloader in time series tool #421
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
Changes from 2 commits
5a1133e
dcc2f44
ac798cb
11f4baa
f9431eb
eff30bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
/* | ||
* License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt | ||
*/ | ||
package edu.caltech.ipac.firefly.server.query.lc; | ||
|
||
import edu.caltech.ipac.astro.IpacTableException; | ||
import edu.caltech.ipac.firefly.data.DownloadRequest; | ||
import edu.caltech.ipac.firefly.data.FileInfo; | ||
import edu.caltech.ipac.firefly.data.ServerRequest; | ||
import edu.caltech.ipac.firefly.server.ServerContext; | ||
import edu.caltech.ipac.firefly.server.packagedata.FileGroup; | ||
import edu.caltech.ipac.firefly.server.query.DataAccessException; | ||
import edu.caltech.ipac.firefly.server.query.FileGroupsProcessor; | ||
import edu.caltech.ipac.firefly.server.query.SearchManager; | ||
import edu.caltech.ipac.firefly.server.query.SearchProcessorImpl; | ||
import edu.caltech.ipac.firefly.server.query.ptf.PtfFileRetrieve; | ||
import edu.caltech.ipac.firefly.server.query.ptf.PtfIbeResolver; | ||
import edu.caltech.ipac.firefly.server.util.Logger; | ||
import edu.caltech.ipac.firefly.server.util.ipactable.DataGroupPart; | ||
import edu.caltech.ipac.firefly.server.util.ipactable.IpacTableParser; | ||
import edu.caltech.ipac.util.StringUtils; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.MalformedURLException; | ||
import java.util.*; | ||
|
||
/** | ||
* Created with IntelliJ IDEA. User: wmi Date: 10/8/13 Time: 4:30 PM To change this template use File | Settings | File | ||
* Templates. | ||
*/ | ||
|
||
@SearchProcessorImpl(id = "PtfLcDownload") | ||
public class PtfFileGroupsProcessor extends FileGroupsProcessor { | ||
|
||
private static final Logger.LoggerImpl logger = Logger.getLogger(); | ||
private final int L2_FITS_SIZE = 33586560; | ||
private final int L2_ANSI_SIZE = 16781760; | ||
|
||
public List<FileGroup> loadData(ServerRequest request) throws IOException, DataAccessException { | ||
assert (request instanceof DownloadRequest); | ||
try { | ||
return computeFileGroup((DownloadRequest) request); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
throw new DataAccessException(e.getMessage()); | ||
} | ||
} | ||
|
||
private List<FileGroup> computeFileGroup(DownloadRequest request) throws IOException, IpacTableException, DataAccessException { | ||
// create unique list of filesystem-based and url-based files | ||
Set<String> zipFiles = new HashSet<String>(); | ||
|
||
Collection<Integer> selectedRows = request.getSelectedRows(); | ||
DataGroupPart dgp = new SearchManager().getDataGroup(request.getSearchRequest()); | ||
|
||
ArrayList<FileInfo> fiArr = new ArrayList<FileInfo>(); | ||
long fgSize = 0; | ||
|
||
// values = cut or orig | ||
String dlCutouts = request.getParam("dlCutouts"); | ||
boolean doCutout = dlCutouts != null && dlCutouts.equalsIgnoreCase("cut"); | ||
|
||
// values = folder or flat | ||
String zipType = request.getParam("zipType"); | ||
boolean doFolders = zipType != null && zipType.equalsIgnoreCase("folder"); | ||
|
||
List<String> types = new ArrayList<String>(); | ||
|
||
IpacTableParser.MappedData dgData = IpacTableParser.getData(new File(dgp.getTableDef().getSource()), | ||
selectedRows, "oid", "pfilename", "fid", "pid", "ccdid", "ra", "dec"); | ||
|
||
if (request.getParam("ProductLevel") == null) { | ||
request.setParam("ProductLevel", "l1"); | ||
} | ||
String subSize = request.getSafeParam("cutoutSize"); | ||
double sizeD = StringUtils.isEmpty(subSize) ? 0 : Double.parseDouble(subSize); | ||
String sizeAsecStr = String.valueOf((int) (sizeD * 3600)); | ||
|
||
Map<String, String> cookies = ServerContext.getRequestOwner().getIdentityCookies(); | ||
for (int rowIdx : selectedRows) { | ||
FileInfo fi = null; | ||
String pidstr = dgData.get(rowIdx, "pid").toString(); | ||
long pid = Long.parseLong(pidstr); | ||
|
||
String pfilename = null; | ||
if (pidstr != null) { | ||
try { | ||
pfilename = new PtfIbeResolver().getListPfilenames(new long[]{pid})[0]; | ||
} catch (InterruptedException e) { | ||
//PID didn't work | ||
throw new DataAccessException("PID " + pid + " didn't give any result ", e); | ||
} | ||
} else { | ||
pfilename = (String) dgData.get(rowIdx, "pfilename"); | ||
} | ||
|
||
String baseUrl = getBaseURL(request); | ||
|
||
String fileName = pfilename;//createBaseFileString_l2(fieldDir, fieldId, fId, ccdId); | ||
|
||
logger.briefInfo("filename=" + fileName); | ||
|
||
File f = new File(fileName); | ||
String extName = doFolders ? fileName : f.getName(); | ||
if (doCutout) { | ||
// look for in_ra and in_dec returned by IBE | ||
String subLon = dgData.get(rowIdx, "in_ra") != null ? String.format("%.4f", (Double) dgData.get(rowIdx, "in_ra")) : null; | ||
if (StringUtils.isEmpty(subLon)) { | ||
subLon = String.format("%.4f", (Double) dgData.get(rowIdx, "ra")); | ||
} | ||
|
||
// look for in_ra and in_dec returned by IBE | ||
String subLat = dgData.get(rowIdx, "in_dec") != null ? String.format("%.4f", (Double) dgData.get(rowIdx, "in_dec")) : null; | ||
if (StringUtils.isEmpty(subLat)) { | ||
// if it fails, try using crval2 | ||
subLat = String.format("%.4f", (Double) dgData.get(rowIdx, "dec")); | ||
} | ||
String cutoutInfo = "_ra" + subLon + "_dec" + subLat + "_asec" + sizeAsecStr; | ||
|
||
extName = extName.replace(".fits",cutoutInfo+".fits"); | ||
String url = createCutoutURLString_l2(baseUrl, pfilename, subLon, subLat, subSize); | ||
logger.briefInfo("cutout url: " + url); | ||
|
||
|
||
// // strip out filename when using file resolver | ||
// if (doFolders) { | ||
// int idx = extName.lastIndexOf("/"); | ||
// idx = idx < 0 ? 0 : idx; | ||
// extName = extName.substring(0, idx) + "/"; | ||
// } else { | ||
// extName = null; | ||
// } | ||
|
||
fi = new FileInfo(url, extName, 100000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume 100000 is an arbitrary number. I think if you don't know what the size of the file should be, just put 0. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be '0' actually but it works seamlessly i think. Will change it. |
||
} else { | ||
String url = baseUrl + fileName; | ||
fi = new FileInfo(url, extName, 100000); | ||
} | ||
if (fi != null) { | ||
fi.setCookies(cookies); | ||
fiArr.add(fi); | ||
fgSize += fi.getSizeInBytes(); | ||
} | ||
} | ||
|
||
FileGroup fg = new FileGroup(fiArr, null, fgSize, "PTF Download Files"); | ||
ArrayList<FileGroup> fgArr = new ArrayList<FileGroup>(); | ||
fgArr.add(fg); | ||
return fgArr; | ||
} | ||
|
||
static String createCutoutURLString_l2(String baseUrl, String baseFile, String lon, String lat, String size) { | ||
|
||
//http://irsa.ipac.caltech.edu/ibe/data/ptf/images/level1/{$pfilename}?center=${ra},${dec}&size=${cutoutSizeInDeg}&gzip=false | ||
|
||
String url = baseUrl + baseFile; | ||
url += "?center=" + lon + "," + lat; | ||
if (!StringUtils.isEmpty(size)) { | ||
url += "&size=" + size; | ||
} | ||
url += "&gzip=" + false; | ||
|
||
return url; | ||
} | ||
|
||
// static String getBaseURL(ServerRequest sr) { | ||
// | ||
// String host = sr.getSafeParam("host") != null ? sr.getSafeParam("host") : PtfIbeResolver.PTF_IBE_HOST; | ||
// | ||
// return QueryUtil.makeUrlBase(host) + "/data/ptf/images/level1/"; | ||
// } | ||
|
||
private static String getBaseURL(ServerRequest sr) throws MalformedURLException { | ||
// build service | ||
return new PtfFileRetrieve().getBaseURL(sr); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is PtfFileRetrieve().getBaseURL(sr) not a static method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. left from previous code introduced in different access, can be static now. Will change. |
||
|
||
} | ||
} | ||
|
||
|
||
/* | ||
* THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE CALIFORNIA | ||
* INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. GOVERNMENT CONTRACT WITH | ||
* THE NATIONAL AERONAUTICS AND SPACE ADMINISTRATION (NASA). THE SOFTWARE | ||
* IS TECHNOLOGY AND SOFTWARE PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS | ||
* AND IS PROVIDED AS-IS TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, | ||
* INCLUDING ANY WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR | ||
* A PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC 2312- 2313) | ||
* OR FOR ANY PURPOSE WHATSOEVER, FOR THE SOFTWARE AND RELATED MATERIALS, | ||
* HOWEVER USED. | ||
* | ||
* IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA BE LIABLE | ||
* FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT LIMITED TO, INCIDENTAL | ||
* OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING ECONOMIC DAMAGE OR INJURY TO | ||
* PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE | ||
* ADVISED, HAVE REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. | ||
* | ||
* RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE SOFTWARE | ||
* AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY CALTECH AND NASA FOR | ||
* ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS OF RECIPIENT IN THE USE | ||
* OF THE SOFTWARE. | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt | ||
*/ | ||
package edu.caltech.ipac.firefly.server.query.ptf; | ||
|
||
import edu.caltech.ipac.firefly.data.ServerRequest; | ||
import edu.caltech.ipac.firefly.server.query.SearchProcessorImpl; | ||
import edu.caltech.ipac.firefly.server.query.URLFileInfoProcessor; | ||
import edu.caltech.ipac.firefly.server.util.Logger; | ||
import edu.caltech.ipac.util.AppProperties; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
|
||
/** | ||
* Created by IntelliJ IDEA. User: wmi | ||
*/ | ||
|
||
|
||
@SearchProcessorImpl(id = "PtfFileRetrieve") | ||
public class PtfFileRetrieve extends URLFileInfoProcessor { | ||
static final String IBE_HOST = AppProperties.getProperty("ptf.ibe.host", "https://irsa.ipac.caltech.edu/ibe"); | ||
|
||
public URL getURL(ServerRequest sr) throws MalformedURLException { | ||
String productLevel = sr.getSafeParam("ProductLevel"); | ||
|
||
if (productLevel.equalsIgnoreCase("l2")) { | ||
PtfRefimsFileRetrieve l2FileRetrieve = new PtfRefimsFileRetrieve(); | ||
|
||
return l2FileRetrieve.getURL(sr); | ||
} else if (productLevel.equalsIgnoreCase("l1")) { | ||
PtfProcimsFileRetrieve l1FileRetrieve = new PtfProcimsFileRetrieve(); | ||
|
||
return l1FileRetrieve.getURL(sr); | ||
} else { | ||
Logger.warn("cannot find param: productLevel or the param returns null"); | ||
throw new MalformedURLException("Can not find the file"); | ||
} | ||
|
||
} | ||
public String getBaseURL(ServerRequest sr) throws MalformedURLException { | ||
String productLevel = sr.getSafeParam("ProductLevel"); | ||
|
||
if (productLevel.equalsIgnoreCase("l2")) { | ||
return PtfRefimsFileRetrieve.getBaseURL(sr); | ||
} else if (productLevel.equalsIgnoreCase("l1")) { | ||
return PtfProcimsFileRetrieve.getBaseURL(sr); | ||
} else { | ||
Logger.warn("cannot find param: productLevel or the param returns null"); | ||
throw new MalformedURLException("Can not find the file"); | ||
} | ||
|
||
} | ||
@Override | ||
protected boolean identityAware() { | ||
return true; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this assignment should be in initialize(). It awkward to see assignment in one constructor, but not in the others. After looking at it, the empty constructor and initialize() should be combined as a static creator. But, maybe next time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is only one constructor. is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. I will add it to setupDs() which is called by initialize anyway.