Skip to content

Commit

Permalink
added NDBI for bare ice; now process pixel if land or bare ice and op…
Browse files Browse the repository at this point in the history
…tional cloud free; set version to 2.0.7-SNAPSHOT; delivery
  • Loading branch information
dolaf committed Oct 9, 2018
1 parent 8e9dcdb commit a8452a7
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 27 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<groupId>org.esa.s3tbx</groupId>
<artifactId>s3tbx-snow</artifactId>
<version>2.0.6-SNAPSHOT</version>
<version>2.0.7-SNAPSHOT</version>
<packaging>nbm</packaging>
<name>S3TBX Snow Operator</name>
<description>Provides snow properties from OLCI/SLSTR measurements.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public class OlciSnowPropertiesConstants {

public static final double RHO_ICE = 917.0; // in kg*m^-3

public static final double BARE_ICE_THRESH = 1./3.; // AK, 20181001

// define here, we do not want a dependency to Idepix just for this:
public static final String IDEPIX_CLASSIF_BAND_NAME = "pixel_classif_flags";
}
61 changes: 38 additions & 23 deletions src/main/java/org/esa/s3tbx/snow/OlciSnowPropertiesOp.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
authors = "Olaf Danne (Brockmann Consult), Alexander Kokhanovsky (Vitrociset)",
copyright = "(c) 2017, 2018 by ESA, Brockmann Consult",
category = "Optical/Thematic Land Processing",
version = "2.0.6-SNAPSHOT")
version = "2.0.7-SNAPSHOT")

public class OlciSnowPropertiesOp extends Operator {

Expand All @@ -70,7 +70,7 @@ public class OlciSnowPropertiesOp extends Operator {

private static final String GRAIN_DIAMETER_BAND_NAME = "grain_diameter";
private static final String SNOW_SPECIFIC_AREA_BAND_NAME = "snow_specific_area";
private static final String ICE_FLAG_BAND_NAME = "ice_indicator";
private static final String NDBI_BAND_NAME = "ndbi";
private static final String POLLUTION_MASK_BAND_NAME = "pollution_mask";
private static final String POLLUTION_F_BAND_NAME = "f";
private static final String POLLUTION_L_BAND_NAME = "l";
Expand Down Expand Up @@ -199,7 +199,7 @@ public class OlciSnowPropertiesOp extends Operator {
optional = true)
private Product cloudMaskProduct;

// @Parameter(defaultValue = "false",
// @Parameter(defaultValue = "false",
// label = "Use new algorithm for spectral albedo (AK, 20180404)",
// description = "If selected, new algorithm for spectral albedo (provided by AK, 20180404) is used.")
// private boolean useAlgoApril2018;
Expand All @@ -222,7 +222,7 @@ public class OlciSnowPropertiesOp extends Operator {
private int width;
private int height;

// private SolarSpectrumTable solarSpectrumTable;
// private SolarSpectrumTable solarSpectrumTable;
private SolarSpectrumExtendedTable solarSpectrumExtendedTable;
private RefractiveIndexTable refractiveIndexInterpolatedTable;

Expand Down Expand Up @@ -316,19 +316,41 @@ public void computeTileStack(Map<Band, Tile> targetTiles, Rectangle targetRectan
for (int y = targetRectangle.y; y < targetRectangle.y + targetRectangle.height; y++) {
checkForCancellation();
for (int x = targetRectangle.x; x < targetRectangle.x + targetRectangle.width; x++) {
final boolean pixelIsValid = !l1FlagsTile.getSampleBit(x, y, sensor.getInvalidBit()) &&
(cloudMaskTile == null ||
(cloudMaskTile != null && cloudMaskTile.getSampleDouble(x, y) != 1.0));

double[] rhoToaAlbedo = new double[requiredBrrBandNamesAlbedo.length]; // now always 01, 05, 17, 21
for (int i = 0; i < requiredBrrBandNamesAlbedo.length; i++) {
rhoToaAlbedo[i] = olciGains[i] * rhoToaTilesAlbedo[i].getSampleDouble(x, y);
rhoToaAlbedo[i] = Math.max(0.0, rhoToaAlbedo[i]);
}

double brr400 = rhoToaAlbedo[0];
final double brr865 = rhoToaAlbedo[2];
final double brr1020 = rhoToaAlbedo[3];

double ndbi = Double.NaN;
boolean isBareIce = false;
if (brr400 > 0.0 && brr1020 > 0.0) {
final double iceIndicator = brr400 / brr1020;
ndbi = (iceIndicator - 1) / (iceIndicator + 1);
isBareIce = ndbi > OlciSnowPropertiesConstants.BARE_ICE_THRESH;
}

final boolean l1Valid = !l1FlagsTile.getSampleBit(x, y, sensor.getInvalidBit());
final boolean isLandOrBareIce = l1FlagsTile.getSampleBit(x, y, sensor.getLandBit()) || isBareIce;
final boolean isNotCloud = cloudMaskTile == null ||
(cloudMaskTile != null && cloudMaskTile.getSampleDouble(x, y) != 1.0);

final boolean pixelIsValid = l1Valid && isLandOrBareIce && isNotCloud;

if (pixelIsValid) {
double[] rhoToaAlbedo = new double[requiredBrrBandNamesAlbedo.length]; // now always 01, 05, 17, 21
for (int i = 0; i < requiredBrrBandNamesAlbedo.length; i++) {
rhoToaAlbedo[i] = olciGains[i] * rhoToaTilesAlbedo[i].getSampleDouble(x, y);
rhoToaAlbedo[i] = Math.max(0.0, rhoToaAlbedo[i]);

final Band ndbiBand = targetProduct.getBand(NDBI_BAND_NAME);
if (!Double.isNaN(ndbi)) {
targetTiles.get(ndbiBand).setSample(x, y, SnowUtils.cutTo4DecimalPlaces(ndbi));
} else {
targetTiles.get(ndbiBand).setSample(x, y, ndbi);
}

double brr400 = rhoToaAlbedo[0];
final double brr865 = rhoToaAlbedo[2];
final double brr1020 = rhoToaAlbedo[3];
double ndsi = Double.NaN;
boolean validNdsi = true;
if (considerNdsiSnowMask) {
Expand Down Expand Up @@ -470,14 +492,6 @@ public void computeTileStack(Map<Band, Tile> targetTiles, Rectangle targetRectan
targetTiles.get(snowSpecificAreaBand).setSample(x, y, Double.NaN);
}

final Band iceFlagBand = targetProduct.getBand(ICE_FLAG_BAND_NAME);
if (brr400 > 0.0 && brr1020 > 0.0) {
double iceFlag = brr400 / brr1020;
targetTiles.get(iceFlagBand).setSample(x, y, SnowUtils.cutTo4DecimalPlaces(iceFlag));
} else {
targetTiles.get(iceFlagBand).setSample(x, y, Double.NaN);
}

if (considerSnowPollution) {
final Band pollutionMaskBand = targetProduct.getBand(POLLUTION_MASK_BAND_NAME);
if (brr400 > 0.0 && !Double.isNaN(r0)) {
Expand Down Expand Up @@ -541,7 +555,8 @@ private void createTargetProduct() {

targetProduct.addBand(GRAIN_DIAMETER_BAND_NAME, ProductData.TYPE_FLOAT32);
targetProduct.addBand(SNOW_SPECIFIC_AREA_BAND_NAME, ProductData.TYPE_FLOAT32);
targetProduct.addBand(ICE_FLAG_BAND_NAME, ProductData.TYPE_FLOAT32);
// targetProduct.addBand(ICE_INDICATOR_BAND_NAME, ProductData.TYPE_FLOAT32);
targetProduct.addBand(NDBI_BAND_NAME, ProductData.TYPE_FLOAT32);

if (considerSnowPollution) {
targetProduct.addBand(POLLUTION_MASK_BAND_NAME, ProductData.TYPE_INT16);
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/org/esa/s3tbx/snow/Sensor.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public enum Sensor {

OLCI("OLCI", OLCI_SZA_NAME, OLCI_VZA_NAME, OLCI_SAA_NAME, OLCI_VAA_NAME, OLCI_L1B_FLAGS_NAME,
OLCI_INVALID_BIT, OLCI_TARGET_TPGS);
OLCI_INVALID_BIT, OLCI_LAND_BIT, OLCI_TARGET_TPGS);

private String name;
private String szaName;
Expand All @@ -19,17 +19,19 @@ public enum Sensor {
private String vaaName;
private String l1bFlagsName;
private int invalidBit;
private int landBit;
private String[] targetTpgs;

Sensor(String name, String szaName, String vzaName, String saaName, String vaaName,
String l1bFlagsName, int invalidBit, String[] targetTpgs) {
String l1bFlagsName, int invalidBit, int landBit, String[] targetTpgs) {
this.name = name;
this.szaName = szaName;
this.saaName = saaName;
this.vzaName = vzaName;
this.vaaName = vaaName;
this.l1bFlagsName = l1bFlagsName;
this.invalidBit = invalidBit;
this.landBit = landBit;
this.targetTpgs = targetTpgs;
}

Expand Down Expand Up @@ -61,6 +63,10 @@ public int getInvalidBit() {
return invalidBit;
}

public int getLandBit() {
return landBit;
}

public String[] getTargetTpgs() {
return targetTpgs;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/esa/s3tbx/snow/SensorConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class SensorConstants {
public static final String OLCI_VAA_NAME = "OAA";
public static final String OLCI_L1B_FLAGS_NAME = "quality_flags";
public static final int OLCI_INVALID_BIT = 25;
public static final int OLCI_LAND_BIT = 31;

public final static String OLCI_BRR_BAND_PREFIX = "rBRR";

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/layer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<attr name="delegate" methodvalue="org.esa.snap.core.gpf.ui.DefaultOperatorAction.create"/>
<attr name="operatorName" stringvalue="OLCI.SnowProperties"/>
<attr name="displayName" stringvalue="OLCI Snow Properties"/>
<attr name="dialogTitle" stringvalue="OLCI Snow Properties v2.0.6-SNAPSHOT"/>
<attr name="dialogTitle" stringvalue="OLCI Snow Properties v2.0.7-SNAPSHOT"/>
<attr name="helpId" stringvalue="s3SnowDoc"/> <!--The helpId if help contents is provided-->
<attr name="targetProductNameSuffix" stringvalue="_snow"/>
<attr name="ShortDescription" stringvalue="Provides snow properties from OLCI measurements."/>
Expand Down

0 comments on commit a8452a7

Please sign in to comment.