Skip to content
Snippets Groups Projects
Commit d65fdd02 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Added resolution support for the grid

parent 1424b281
No related branches found
No related tags found
No related merge requests found
...@@ -331,6 +331,22 @@ public class WeatherProxyService { ...@@ -331,6 +331,22 @@ public class WeatherProxyService {
} }
} }
/**
* This is a real memory hog, use only if you know how!!
* Sample test with wget:
* wget --header='Accept-Encoding: gzip' "http://logic.vips.nibio.no/rest/weather/proxy/metno/thredds/grid?elementMeasurementTypes=Q0&north=57.91&south=54.36&west=8.04&east=12.83&startDate=2017-03-01&endDate=2017-10-06&timeZone=Europe/Oslo" -O ./denmark_q0.gz
* @param north
* @param south
* @param east
* @param west
* @param timeZoneStr
* @param startDateStr
* @param startTimeStr
* @param endDateStr
* @param endTimeStr
* @param elementMeasurementTypes
* @return
*/
@GET @GET
@Path("metno/thredds/grid/") @Path("metno/thredds/grid/")
@GZIP @GZIP
...@@ -364,7 +380,7 @@ public class WeatherProxyService { ...@@ -364,7 +380,7 @@ public class WeatherProxyService {
// Creating an envelope with the given bounds // Creating an envelope with the given bounds
Envelope envelope = new Envelope(west, east, south, north); Envelope envelope = new Envelope(west, east, south, north);
GeometryFactory gf = new GeometryFactory(); GeometryFactory gf = new GeometryFactory();
List<PointWeatherObservationList> retVal = dp.getGridData(gf.toGeometry(envelope), startDate, endDate, Arrays.asList(elementMeasurementTypes)); List<PointWeatherObservationList> retVal = dp.getGridData(gf.toGeometry(envelope), 10.0, startDate, endDate, Arrays.asList(elementMeasurementTypes));
return Response.ok().entity(retVal).build(); return Response.ok().entity(retVal).build();
} }
catch(ParseException pe) catch(ParseException pe)
......
...@@ -63,7 +63,7 @@ public class MetNoThreddsDataParser { ...@@ -63,7 +63,7 @@ public class MetNoThreddsDataParser {
private final String BASE_URL = "http://thredds.met.no/thredds/"; private final String BASE_URL = "http://thredds.met.no/thredds/";
private final String NCSS_URL = BASE_URL + "ncss/"; private final String NCSS_URL = BASE_URL + "ncss/";
private final String MEPS25_PATH = "meps25detarchive/"; private final String MEPS25_PATH = "meps25epsarchive/";
private final String MEPS25_FILEBASENAME = "meps_mbr0_extracted_2_5km_"; private final String MEPS25_FILEBASENAME = "meps_mbr0_extracted_2_5km_";
private final String NETCDF_EXT = ".nc"; private final String NETCDF_EXT = ".nc";
private final String STANDARD_PARAMS = "?accept=netcdf&temporal=all&&horizStride=1&disableLLSubset=on&timeStride=1"; private final String STANDARD_PARAMS = "?accept=netcdf&temporal=all&&horizStride=1&disableLLSubset=on&timeStride=1";
...@@ -93,7 +93,7 @@ public class MetNoThreddsDataParser { ...@@ -93,7 +93,7 @@ public class MetNoThreddsDataParser {
this.fileTimeStampFormat.setTimeZone(TimeZone.getTimeZone("UTC")); this.fileTimeStampFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
} }
public List<PointWeatherObservationList> getGridData(Geometry geometry, Date dateFrom, Date dateTo, List<String> VIPSWeatherParameters) public List<PointWeatherObservationList> getGridData(Geometry geometry, Double resolution, Date dateFrom, Date dateTo, List<String> VIPSWeatherParameters)
{ {
Set<String> metParamNames = VIPSWeatherParameters.stream().map( Set<String> metParamNames = VIPSWeatherParameters.stream().map(
param -> paramInfo.getProperty(param) param -> paramInfo.getProperty(param)
...@@ -139,9 +139,12 @@ public class MetNoThreddsDataParser { ...@@ -139,9 +139,12 @@ public class MetNoThreddsDataParser {
ArrayDouble.D2 latitude = (ArrayDouble.D2) ncFile.findVariable("lat").read(); ArrayDouble.D2 latitude = (ArrayDouble.D2) ncFile.findVariable("lat").read();
int[] latLonShape = longitude.getShape(); // Assuming they're identical! int[] latLonShape = longitude.getShape(); // Assuming they're identical!
Coordinate[][] coords = new Coordinate[latLonShape[0]][latLonShape[1]]; Coordinate[][] coords = new Coordinate[latLonShape[0]][latLonShape[1]];
for(int y=0;y<latLonShape[0];y++) // Depending on the resolution, we determine the steps
int step = (int) Math.floor(resolution / 2.5 - resolution % 2.5);
//System.out.println("Step="+step);
for(int y=0;y<latLonShape[0];y=y+step)
{ {
for(int x=0;x<latLonShape[1];x++) for(int x=0;x<latLonShape[1];x=x+step)
{ {
double lat = latitude.get(y, x); double lat = latitude.get(y, x);
double lon = longitude.get(y,x); double lon = longitude.get(y,x);
...@@ -169,9 +172,9 @@ public class MetNoThreddsDataParser { ...@@ -169,9 +172,9 @@ public class MetNoThreddsDataParser {
{ {
continue; continue;
} }
for(int y=0;y<latLonShape[0];y++) for(int y=0;y<latLonShape[0];y=y+step)
{ {
for(int x=0;x<latLonShape[1];x++) for(int x=0;x<latLonShape[1];x=x+step)
{ {
Map<Long, WeatherObservation> obsMapForPoint = tempRetVal.get(coords[y][x]); Map<Long, WeatherObservation> obsMapForPoint = tempRetVal.get(coords[y][x]);
if(obsMapForPoint == null) if(obsMapForPoint == null)
......
...@@ -89,7 +89,7 @@ public class MetNoThreddsDataParserTest { ...@@ -89,7 +89,7 @@ public class MetNoThreddsDataParserTest {
Date dateTo = cal.getTime(); Date dateTo = cal.getTime();
List<PointWeatherObservationList> result = instance.getGridData(pol, dateFrom, dateTo, weatherParameters); List<PointWeatherObservationList> result = instance.getGridData(pol, 10.0, dateFrom, dateTo, weatherParameters);
assertNotNull(result); assertNotNull(result);
Long timeSpent = new Date().getTime() - start.getTime(); Long timeSpent = new Date().getTime() - start.getTime();
System.out.println("Time spent=" + (new Double(timeSpent)/1000) + " seconds"); System.out.println("Time spent=" + (new Double(timeSpent)/1000) + " seconds");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment