Skip to content

Commit 1392c3b

Browse files
authored
Merge pull request #7 from bcdev/SE_ReaderSlstrSubset_CCI+SST_COO-02
Se reader slstr subset cci+sst coo 02
2 parents d018064 + 3c88a14 commit 1392c3b

30 files changed

+1641
-115
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
### Updates from version 1.5.5 to 1.5.6
2+
* added support for SLSTR regridded subseted data in safe format
23
* corrected TAI 1993 to UTC conversion for MODIS data
34
* updated H2 database driver
45
* added support for MODIS MxD035 cloud data

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

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,25 @@
11
package com.bc.fiduceo.reader.modis;
22

3+
import com.bc.fiduceo.util.NetCDFUtils;
34
import com.bc.fiduceo.util.VariableProxy;
45
import org.esa.snap.core.datamodel.TiePointGrid;
56
import ucar.ma2.Array;
67
import ucar.ma2.DataType;
78
import ucar.ma2.InvalidRangeException;
89
import ucar.ma2.MAMath;
9-
import ucar.nc2.Attribute;
10-
import ucar.nc2.AttributeContainer;
1110
import ucar.nc2.Variable;
1211

1312
import java.io.IOException;
14-
import java.util.ArrayList;
1513

16-
import static com.bc.fiduceo.util.NetCDFUtils.CF_ADD_OFFSET_NAME;
17-
import static com.bc.fiduceo.util.NetCDFUtils.CF_FILL_VALUE_NAME;
1814
import static com.bc.fiduceo.util.NetCDFUtils.CF_SCALE_FACTOR_NAME;
19-
import static com.bc.fiduceo.util.NetCDFUtils.CF_VALID_RANGE_NAME;
2015

2116
public class MxD35BowTieVariable extends VariableProxy {
2217

2318
private final Variable _variable;
2419
private TiePointGrid[] grids;
2520

2621
public MxD35BowTieVariable(Variable variable, int width, int height) throws IOException {
27-
super(variable.getShortName(), DataType.FLOAT, getAttributes(variable));
22+
super(variable.getShortName(), DataType.FLOAT, NetCDFUtils.getAttributes(variable));
2823
setShape(new int[]{height, width});
2924
this._variable = variable;
3025
init();
@@ -54,35 +49,6 @@ public Array read() throws IOException {
5449
return targetArray;
5550
}
5651

57-
private static ArrayList<Attribute> getAttributes(Variable variable) {
58-
final AttributeContainer inAtts = variable.attributes();
59-
final double scaling = inAtts.findAttributeDouble(CF_SCALE_FACTOR_NAME, 1.0);
60-
final double offset = inAtts.findAttributeDouble(CF_ADD_OFFSET_NAME, 0.0);
61-
final Attribute fillAtt = inAtts.findAttribute(CF_FILL_VALUE_NAME);
62-
final Number newFill;
63-
if (fillAtt != null && (scaling != 1.0 || offset != 0.0)) {
64-
final Number value = fillAtt.getNumericValue();
65-
newFill = value.doubleValue() * scaling + offset;
66-
} else {
67-
newFill = null;
68-
}
69-
70-
final ArrayList<Attribute> attributes = new ArrayList<>();
71-
inAtts.forEach(attribute -> {
72-
final String name = attribute.getShortName();
73-
if (CF_SCALE_FACTOR_NAME.equals(name)) {
74-
attributes.add(new Attribute(CF_SCALE_FACTOR_NAME, 1.0F));
75-
} else if (CF_ADD_OFFSET_NAME.equals(name)) {
76-
attributes.add(new Attribute(CF_ADD_OFFSET_NAME, 0.0F));
77-
} else if (newFill != null && CF_FILL_VALUE_NAME.equals(name)) {
78-
attributes.add(new Attribute(CF_FILL_VALUE_NAME, newFill.floatValue()));
79-
} else if (!(name.contains("_Swath_Sampling") || CF_VALID_RANGE_NAME.equals(name))) {
80-
attributes.add(attribute);
81-
}
82-
});
83-
return attributes;
84-
}
85-
8652
private void init() throws IOException {
8753
final int[] shape = getShape();
8854
final int[] tiePointShape = _variable.getShape();

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.bc.fiduceo.geometry.Polygon;
3131
import com.bc.fiduceo.hdf.HdfEOSUtil;
3232
import com.bc.fiduceo.location.PixelLocator;
33+
import com.bc.fiduceo.location.PixelLocatorFactory;
3334
import com.bc.fiduceo.reader.AcquisitionInfo;
3435
import com.bc.fiduceo.reader.BoundingPolygonCreator;
3536
import com.bc.fiduceo.reader.Geometries;
@@ -77,6 +78,7 @@ public class MxD35_Reader extends NetCDFReader {
7778
private static final int SMALLEST_DIM_IDX = 0;
7879
private static final int SMALLEST_DIM_SIZE = 1;
7980
private static final HashMap<String, FlagDefinition> FLAG_DEFINITIONS = new HashMap<>();
81+
private BoundingPolygonCreator boundingPolygonCreator;
8082

8183
{
8284
final FlagDefinition cloudMaskFlagDef = new FlagDefinition();
@@ -356,7 +358,13 @@ public PixelLocator getPixelLocator() throws IOException {
356358

357359
@Override
358360
public PixelLocator getSubScenePixelLocator(Polygon sceneGeometry) throws IOException {
359-
return getPixelLocator();
361+
final Dimension productSize = getProductSize();
362+
final int height = productSize.getNy();
363+
final int width = productSize.getNx();
364+
final int subsetHeight = boundingPolygonCreator.getSubsetHeight(height, 250);
365+
final PixelLocator pixelLocator = getPixelLocator();
366+
367+
return PixelLocatorFactory.getSubScenePixelLocator(sceneGeometry, width, height, subsetHeight, pixelLocator);
360368
}
361369

362370
@Override
@@ -606,7 +614,7 @@ private int[] findSlicingConditions(Variable variable) {
606614
}
607615

608616
private void extractGeometries(AcquisitionInfo acquisitionInfo) throws IOException {
609-
final BoundingPolygonCreator boundingPolygonCreator = new BoundingPolygonCreator(new Interval(250, 250), geometryFactory);
617+
boundingPolygonCreator = new BoundingPolygonCreator(new Interval(250, 250), geometryFactory);
610618
final Array longitude = arrayCache.get(GEOLOCATION_GROUP, LONGITUDE_VAR_NAME);
611619
final Array latitude = arrayCache.get(GEOLOCATION_GROUP, LATITUDE_VAR_NAME);
612620
final Geometry boundingGeometry = boundingPolygonCreator.createBoundingGeometry(longitude, latitude);

core/src/main/java/com/bc/fiduceo/reader/slstr/SlstrReader.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import com.bc.fiduceo.reader.AcquisitionInfo;
99
import com.bc.fiduceo.reader.ReaderContext;
1010
import com.bc.fiduceo.reader.ReaderUtils;
11-
import com.bc.fiduceo.reader.time.TimeLocator;
1211
import com.bc.fiduceo.reader.snap.SNAP_Reader;
1312
import com.bc.fiduceo.reader.snap.VariableProxy;
13+
import com.bc.fiduceo.reader.time.TimeLocator;
1414
import com.bc.fiduceo.reader.time.TimeLocator_MicrosSince2000;
1515
import com.bc.fiduceo.util.NetCDFUtils;
1616
import com.bc.fiduceo.util.TimeUtils;
@@ -20,7 +20,6 @@
2020
import ucar.ma2.Array;
2121
import ucar.ma2.ArrayInt;
2222
import ucar.ma2.DataType;
23-
import ucar.ma2.Index;
2423
import ucar.nc2.Variable;
2524

2625
import java.io.File;
@@ -213,7 +212,6 @@ public Array readRaw(int centerX, int centerY, Interval interval, String variabl
213212

214213
final VariableType variableType = variableNames.getVariableType(variableName);
215214
final Transform transform = transformFactory.get(variableType);
216-
final Dimension rasterSize = transform.getRasterSize();
217215

218216
final RasterDataNode dataNode = getRasterDataNode(variableName);
219217

@@ -225,7 +223,6 @@ public Array readRaw(int centerX, int centerY, Interval interval, String variabl
225223
final int height = mappedInterval.getY();
226224
final int[] shape = getShape(mappedInterval);
227225
final Array readArray = Array.factory(targetDataType, shape);
228-
final Array targetArray = NetCDFUtils.create(targetDataType, shape, noDataValue);
229226

230227
final int mappedX = (int) (transform.mapCoordinate_X(centerX) + 0.5);
231228
final int mappedY = (int) (transform.mapCoordinate_Y(centerY) + 0.5);

0 commit comments

Comments
 (0)