Skip to content

Commit ad92496

Browse files
authored
Merge pull request #10 from bcdev/TB_windsat
Tb windsat
2 parents d4278dd + 2f96d82 commit ad92496

29 files changed

+2004
-319
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### Updates from version 1.5.6 to 1.5.7
2+
* added support for Windsat Coriolis data
3+
14
### Updates from version 1.5.6 to 1.5.7
25
* added support for SMOS L1C daily aggregated products
36
* added support for SIC-CCI RRDP insitu data

core/src/main/java/com/bc/fiduceo/geometry/GeometryUtil.java

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package com.bc.fiduceo.geometry;
2222

2323

24+
import java.util.ArrayList;
2425
import java.util.List;
2526

2627
public class GeometryUtil {
@@ -33,13 +34,57 @@ public static Geometry[] getSubGeometries(Geometry composedGeometry) {
3334
} else if (composedGeometry instanceof MultiPolygon) {
3435
final MultiPolygon observationMultiPolygon = (MultiPolygon) composedGeometry;
3536
final List<Polygon> polygons = observationMultiPolygon.getPolygons();
36-
geometries = polygons.toArray(new Geometry[polygons.size()]);
37+
geometries = polygons.toArray(new Geometry[0]);
3738
} else {
3839
geometries = new Geometry[]{composedGeometry};
3940
}
4041
return geometries;
4142
}
4243

44+
public static Polygon createPolygonFromMinMax(double[] geoMinMax, GeometryFactory geometryFactory) {
45+
final double lonMin = geoMinMax[0];
46+
final double lonMax = geoMinMax[1];
47+
final double latMin = geoMinMax[2];
48+
final double latMax = geoMinMax[3];
49+
50+
final Point ll = geometryFactory.createPoint(lonMin, latMin);
51+
final Point ul = geometryFactory.createPoint(lonMin, latMax);
52+
final Point ur = geometryFactory.createPoint(lonMax, latMax);
53+
final Point lr = geometryFactory.createPoint(lonMax, latMin);
54+
final ArrayList<Point> polygonPoints = new ArrayList<>();
55+
polygonPoints.add(ll);
56+
polygonPoints.add(lr);
57+
polygonPoints.add(ur);
58+
polygonPoints.add(ul);
59+
polygonPoints.add(ll);
60+
return geometryFactory.createPolygon(polygonPoints);
61+
}
62+
63+
public static MultiLineString createMultiLineStringFromMinMax(double[] geoMinMax, GeometryFactory geometryFactory) {
64+
final double lonMin = geoMinMax[0];
65+
final double lonMax = geoMinMax[1];
66+
67+
final double latMin = geoMinMax[2];
68+
final double latMax = geoMinMax[3];
69+
70+
final List<Point> points = new ArrayList<>();
71+
points.add(geometryFactory.createPoint(lonMin, 0.0));
72+
points.add(geometryFactory.createPoint(lonMax, 0.0));
73+
final LineString we = geometryFactory.createLineString(points);
74+
75+
points.clear();
76+
points.add(geometryFactory.createPoint(0.0, latMax));
77+
points.add(geometryFactory.createPoint(0.0, latMin));
78+
79+
final LineString ns = geometryFactory.createLineString(points);
80+
81+
final List<LineString> lines = new ArrayList<>();
82+
lines.add(we);
83+
lines.add(ns);
84+
85+
return geometryFactory.createMultiLineString(lines);
86+
}
87+
4388
public static String toKml(Polygon polygon) {
4489
final StringBuilder builder = new StringBuilder();
4590

@@ -103,14 +148,14 @@ public static String toKml(float[] lats, float[] lons) {
103148
for (int i = 0; i < lats.length; i++) {
104149
final float lat = lats[i];
105150
final float lon = lons[i];
106-
if (lat != latBefore || lon != lonBefore || i == lats.length -1 ) {
151+
if (lat != latBefore || lon != lonBefore || i == lats.length - 1) {
107152
builder.append(" <Placemark>\n");
108-
builder.append(" <name>"+count+"</name>\n");
153+
builder.append(" <name>" + count + "</name>\n");
109154
builder.append(" <Point><coordinates>");
110155
builder.append(lonBefore);
111156
builder.append(",");
112157
builder.append(latBefore);
113-
// builder.append(",0");
158+
// builder.append(",0");
114159
builder.append("</coordinates>");
115160
builder.append("</Point>\n");
116161
builder.append(" </Placemark>\n");

core/src/main/java/com/bc/fiduceo/reader/smos/RasterPixelLocator.java renamed to core/src/main/java/com/bc/fiduceo/location/RasterPixelLocator.java

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
package com.bc.fiduceo.reader.smos;
2-
3-
import com.bc.fiduceo.location.PixelLocator;
1+
package com.bc.fiduceo.location;
42

53
import java.awt.geom.Point2D;
64
import java.awt.geom.Rectangle2D;
75

8-
class RasterPixelLocator implements PixelLocator {
6+
public class RasterPixelLocator implements PixelLocator {
7+
8+
public static int LON_WEST_EAST = 0;
9+
public static int LON_EAST_WEST = 1;
910

1011
private final float[] lons;
1112
private final float[] lats;
1213
private final Rectangle2D.Float boundary;
14+
private final int lonDirection;
1315

1416
/**
1517
* Pixel locator for rectangular rasters, lon and lat axes supplied as vectors.
@@ -21,10 +23,16 @@ class RasterPixelLocator implements PixelLocator {
2123
* @param lats the latitude axis
2224
* @param boundary the raster boundaries
2325
*/
24-
RasterPixelLocator(float[] lons, float[] lats, Rectangle2D.Float boundary) {
26+
// @todo 1 tb/tb add option to flip axes (at least lon for now) 2022-11-23
27+
public RasterPixelLocator(float[] lons, float[] lats, Rectangle2D.Float boundary) {
28+
this(lons, lats, boundary, LON_WEST_EAST);
29+
}
30+
31+
public RasterPixelLocator(float[] lons, float[] lats, Rectangle2D.Float boundary, int lonDirection) {
2532
this.lons = lons;
2633
this.lats = lats;
2734
this.boundary = boundary;
35+
this.lonDirection = lonDirection;
2836
}
2937

3038
@Override
@@ -53,7 +61,12 @@ public Point2D[] getPixelLocation(double lon, double lat) {
5361
return new Point2D[0];
5462
}
5563

56-
int x_break = getIndexLargerThan(lon, lons);
64+
int x_break;
65+
if (lonDirection == LON_EAST_WEST) {
66+
x_break = getIndexSmallerThan(lon, lons);
67+
} else {
68+
x_break = getIndexLargerThan(lon, lons);
69+
}
5770
x_break = adjustForClosest(x_break, lon, lons);
5871

5972
int y_break = getIndexLargerThan(lat, lats);
@@ -77,7 +90,7 @@ private static int adjustForClosest(int targetIndex, double location, float[] lo
7790
return targetIndex;
7891
}
7992

80-
private static int getIndexLargerThan(double location, float[] locations) {
93+
static int getIndexLargerThan(double location, float[] locations) {
8194
int x_break = -1;
8295
for (int i = 0; i < locations.length; i++) {
8396
if (location <= locations[i]) {
@@ -87,4 +100,17 @@ private static int getIndexLargerThan(double location, float[] locations) {
87100
}
88101
return x_break;
89102
}
103+
104+
static int getIndexSmallerThan(double location, float[] locations) {
105+
int x_break = -1;
106+
107+
for (int i = 0; i < locations.length; i++) {
108+
if (location >= locations[i]) {
109+
x_break = i;
110+
break;
111+
}
112+
}
113+
114+
return x_break;
115+
}
90116
}

core/src/main/java/com/bc/fiduceo/reader/ReaderUtils.java

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,18 @@
2020

2121
package com.bc.fiduceo.reader;
2222

23+
import com.bc.fiduceo.core.Dimension;
24+
import com.bc.fiduceo.core.Interval;
2325
import com.bc.fiduceo.geometry.*;
2426
import com.bc.fiduceo.math.TimeInterval;
27+
import com.bc.fiduceo.reader.time.TimeLocator;
2528
import com.bc.fiduceo.util.NetCDFUtils;
2629
import org.esa.snap.core.datamodel.ProductData;
2730
import org.esa.snap.core.util.io.FileUtils;
31+
import ucar.ma2.Array;
32+
import ucar.ma2.ArrayInt;
2833
import ucar.ma2.DataType;
34+
import ucar.ma2.Index;
2935

3036
import java.io.*;
3137
import java.util.Date;
@@ -111,7 +117,7 @@ public static int getChannelIndex(String variableName) {
111117

112118
public static boolean isCompressed(File file) {
113119
final String extension = FileUtils.getExtension(file);
114-
return extension.equalsIgnoreCase(".gz") || extension.equalsIgnoreCase(".tgz")|| extension.equalsIgnoreCase(".zip");
120+
return extension.equalsIgnoreCase(".gz") || extension.equalsIgnoreCase(".tgz") || extension.equalsIgnoreCase(".zip");
115121
}
116122

117123
/**
@@ -132,4 +138,44 @@ public static void decompress(File gzipFile, File tmpFile) throws IOException {
132138
}
133139
}
134140
}
141+
142+
public static ArrayInt.D2 readAcquisitionTimeFromTimeLocator(int x, int y, Interval interval, Dimension productSize, TimeLocator timeLocator) {
143+
final int height = interval.getY();
144+
final int width = interval.getX();
145+
final int x_offset = x - width / 2;
146+
final int y_offset = y - height / 2;
147+
int[] shape = new int[]{height, width};
148+
149+
final int pWidth = productSize.getNx();
150+
final int pHeight = productSize.getNy();
151+
152+
final int acquisitionTimeFillValue = getDefaultFillValue(ProductData.TYPE_INT32).intValue();
153+
154+
final ArrayInt.D2 acquisitionTime = (ArrayInt.D2) Array.factory(DataType.INT, shape);
155+
final Index index = acquisitionTime.getIndex();
156+
157+
for (int ya = 0; ya < height; ya++) {
158+
final int yRead = y_offset + ya;
159+
160+
for (int xa = 0; xa < width; xa++) {
161+
final int xRead = x_offset + xa;
162+
163+
int acTime;
164+
if (xRead < 0 || xRead >= pWidth || yRead < 0 || yRead >= pHeight) {
165+
acTime = acquisitionTimeFillValue;
166+
} else {
167+
final long pxTime = timeLocator.getTimeFor(xRead, yRead);
168+
if (pxTime < 0) {
169+
acTime = acquisitionTimeFillValue;
170+
} else {
171+
acTime = (int) (pxTime / 1000);
172+
}
173+
}
174+
index.set(ya, xa);
175+
acquisitionTime.setInt(index, acTime);
176+
}
177+
}
178+
179+
return acquisitionTime;
180+
}
135181
}

core/src/main/java/com/bc/fiduceo/reader/modis/MxD021KM_Reader.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import com.bc.fiduceo.reader.time.TimeLocator_TAI1993Scan;
1818
import com.bc.fiduceo.util.NetCDFUtils;
1919
import org.esa.snap.core.util.StringUtils;
20-
import ucar.ma2.*;
2120
import ucar.ma2.DataType;
21+
import ucar.ma2.*;
2222
import ucar.nc2.Attribute;
2323
import ucar.nc2.AttributeContainer;
2424
import ucar.nc2.Structure;
@@ -246,11 +246,7 @@ public List<Variable> getVariables() throws InvalidRangeException, IOException {
246246
}
247247

248248
if (variableName.contains("EV_1KM_RefSB")) {
249-
final ArrayList<Variable> bandVariables = new ArrayList<>(NUM_1KM_REF_CHAN);
250-
251-
addLayered3DVariables(bandVariables, variable, NUM_1KM_REF_CHAN, variableName, new ModisL1ReflectiveExtension());
252-
253-
exportVariables.addAll(bandVariables);
249+
addLayered3DVariables(exportVariables, variable, NUM_1KM_REF_CHAN, variableName, new ModisL1ReflectiveExtension());
254250
continue;
255251
}
256252

0 commit comments

Comments
 (0)