Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.esa.snap.core.gpf.annotations.OperatorMetadata;
import org.esa.snap.core.gpf.annotations.Parameter;
import org.esa.snap.core.gpf.annotations.SourceProduct;
import org.esa.snap.core.gpf.annotations.TargetProduct;
import org.esa.snap.core.gpf.pointop.PixelOperator;
import org.esa.snap.core.gpf.pointop.ProductConfigurer;
import org.esa.snap.core.gpf.pointop.Sample;
Expand Down Expand Up @@ -59,6 +60,9 @@ public class Biophysical10mOp extends PixelOperator {
@SourceProduct(alias = "source", description = "The source product.")
private Product sourceProduct;

@TargetProduct
private Product targetProduct;

@Parameter(defaultValue = "S2A_10m", label = "Sensor", description = "Sensor", valueSet = {"S2A_10m", "S2B_10m"})
private String sensor;

Expand Down Expand Up @@ -168,13 +172,13 @@ protected void configureTargetProduct(ProductConfigurer productConfigurer) {
productConfigurer.copyMetadata();
productConfigurer.copyMasks();

Product tp = productConfigurer.getTargetProduct();
targetProduct = productConfigurer.getTargetProduct();
// todo setDescription

for (BiophysicalVariable biophysicalVariable : BiophysicalVariable.values()) {
if (BiophysicalModel.S2A_10m.computesVariable(biophysicalVariable) && isComputed(biophysicalVariable)) {
// Add biophysical variable band
final Band biophysicalVariableBand = tp.addBand(biophysicalVariable.getBandName(), ProductData.TYPE_FLOAT32);
final Band biophysicalVariableBand = targetProduct.addBand(biophysicalVariable.getBandName(), ProductData.TYPE_FLOAT32);
biophysicalVariableBand.setDescription(biophysicalVariable.getDescription());
biophysicalVariableBand.setUnit(biophysicalVariable.getUnit());
// todo better setDescription
Expand All @@ -185,18 +189,18 @@ protected void configureTargetProduct(ProductConfigurer productConfigurer) {

// Add corresponding flag band
String flagBandName = String.format("%s_flags", biophysicalVariable.getBandName());
final Band biophysicalVariableFlagBand = tp.addBand(flagBandName, ProductData.TYPE_UINT8);
final Band biophysicalVariableFlagBand = targetProduct.addBand(flagBandName, ProductData.TYPE_UINT8);
final FlagCoding biophysicalVariableFlagCoding = new FlagCoding(flagBandName);
for (BiophysicalFlag flagDef : BiophysicalFlag.values()) {
biophysicalVariableFlagCoding.addFlag(flagDef.getName(), flagDef.getFlagValue(), flagDef.getDescription());
}
tp.getFlagCodingGroup().add(biophysicalVariableFlagCoding);
targetProduct.getFlagCodingGroup().add(biophysicalVariableFlagCoding);
biophysicalVariableFlagBand.setSampleCoding(biophysicalVariableFlagCoding);

// Add a mask for each flag
for (BiophysicalFlag flagDef : BiophysicalFlag.values()) {
String maskName = String.format("%s_%s", biophysicalVariable.getBandName(), flagDef.getName().toLowerCase());
tp.addMask(maskName,
targetProduct.addMask(maskName,
String.format("%s.%s", flagBandName, flagDef.getName()),
flagDef.getDescription(),
flagDef.getColor(), flagDef.getTransparency());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.esa.snap.core.gpf.annotations.OperatorMetadata;
import org.esa.snap.core.gpf.annotations.Parameter;
import org.esa.snap.core.gpf.annotations.SourceProduct;
import org.esa.snap.core.gpf.annotations.TargetProduct;
import org.esa.snap.core.gpf.pointop.PixelOperator;
import org.esa.snap.core.gpf.pointop.ProductConfigurer;
import org.esa.snap.core.gpf.pointop.Sample;
Expand Down Expand Up @@ -56,6 +57,9 @@ public class BiophysicalLandsatOp extends PixelOperator {

private Map<BiophysicalVariable, BiophysicalAlgo> algos = new HashMap<>();

@TargetProduct
private Product targetProduct;

@SourceProduct(alias = "source", description = "The source product.")
private Product sourceProduct;

Expand Down Expand Up @@ -167,13 +171,13 @@ protected void configureTargetProduct(ProductConfigurer productConfigurer) {
productConfigurer.copyMetadata();
productConfigurer.copyMasks();

Product tp = productConfigurer.getTargetProduct();
targetProduct = productConfigurer.getTargetProduct();
// todo setDescription

for (BiophysicalVariable biophysicalVariable : BiophysicalVariable.values()) {
if (BiophysicalModel.LANDSAT8.computesVariable(biophysicalVariable) && isComputed(biophysicalVariable)) {
// Add biophysical variable band
final Band biophysicalVariableBand = tp.addBand(biophysicalVariable.getBandName(), ProductData.TYPE_FLOAT32);
final Band biophysicalVariableBand = targetProduct.addBand(biophysicalVariable.getBandName(), ProductData.TYPE_FLOAT32);
biophysicalVariableBand.setDescription(biophysicalVariable.getDescription());
biophysicalVariableBand.setUnit(biophysicalVariable.getUnit());
// todo better setDescription
Expand All @@ -184,18 +188,18 @@ protected void configureTargetProduct(ProductConfigurer productConfigurer) {

// Add corresponding flag band
String flagBandName = String.format("%s_flags", biophysicalVariable.getBandName());
final Band biophysicalVariableFlagBand = tp.addBand(flagBandName, ProductData.TYPE_UINT8);
final Band biophysicalVariableFlagBand = targetProduct.addBand(flagBandName, ProductData.TYPE_UINT8);
final FlagCoding biophysicalVariableFlagCoding = new FlagCoding(flagBandName);
for (BiophysicalFlag flagDef : BiophysicalFlag.values()) {
biophysicalVariableFlagCoding.addFlag(flagDef.getName(), flagDef.getFlagValue(), flagDef.getDescription());
}
tp.getFlagCodingGroup().add(biophysicalVariableFlagCoding);
targetProduct.getFlagCodingGroup().add(biophysicalVariableFlagCoding);
biophysicalVariableFlagBand.setSampleCoding(biophysicalVariableFlagCoding);

// Add a mask for each flag
for (BiophysicalFlag flagDef : BiophysicalFlag.values()) {
String maskName = String.format("%s_%s", biophysicalVariable.getBandName(), flagDef.getName().toLowerCase());
tp.addMask(maskName,
targetProduct.addMask(maskName,
String.format("%s.%s", flagBandName, flagDef.getName()),
flagDef.getDescription(),
flagDef.getColor(), flagDef.getTransparency());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.esa.snap.core.gpf.annotations.OperatorMetadata;
import org.esa.snap.core.gpf.annotations.Parameter;
import org.esa.snap.core.gpf.annotations.SourceProduct;
import org.esa.snap.core.gpf.annotations.TargetProduct;
import org.esa.snap.core.gpf.pointop.PixelOperator;
import org.esa.snap.core.gpf.pointop.ProductConfigurer;
import org.esa.snap.core.gpf.pointop.Sample;
Expand Down Expand Up @@ -60,6 +61,9 @@ public class BiophysicalOp extends PixelOperator {
@SourceProduct(alias = "source", description = "The source product.")
private Product sourceProduct;

@TargetProduct
private Product targetProduct;

@Parameter(defaultValue = "S2A", label = "Sensor", description = "Sensor", valueSet = {"S2A", "S2B"})
private String sensor;

Expand Down Expand Up @@ -182,13 +186,13 @@ protected void configureTargetProduct(ProductConfigurer productConfigurer) {
productConfigurer.copyMetadata();
productConfigurer.copyMasks();

Product tp = productConfigurer.getTargetProduct();
targetProduct = productConfigurer.getTargetProduct();
// todo setDescription

for (BiophysicalVariable biophysicalVariable : BiophysicalVariable.values()) {
if (BiophysicalModel.S2A.computesVariable(biophysicalVariable) && isComputed(biophysicalVariable)) {
// Add biophysical variable band
final Band biophysicalVariableBand = tp.addBand(biophysicalVariable.getBandName(), ProductData.TYPE_FLOAT32);
final Band biophysicalVariableBand = targetProduct.addBand(biophysicalVariable.getBandName(), ProductData.TYPE_FLOAT32);
biophysicalVariableBand.setDescription(biophysicalVariable.getDescription());
biophysicalVariableBand.setUnit(biophysicalVariable.getUnit());
// todo better setDescription
Expand All @@ -199,18 +203,18 @@ protected void configureTargetProduct(ProductConfigurer productConfigurer) {

// Add corresponding flag band
String flagBandName = String.format("%s_flags", biophysicalVariable.getBandName());
final Band biophysicalVariableFlagBand = tp.addBand(flagBandName, ProductData.TYPE_UINT8);
final Band biophysicalVariableFlagBand = targetProduct.addBand(flagBandName, ProductData.TYPE_UINT8);
final FlagCoding biophysicalVariableFlagCoding = new FlagCoding(flagBandName);
for (BiophysicalFlag flagDef : BiophysicalFlag.values()) {
biophysicalVariableFlagCoding.addFlag(flagDef.getName(), flagDef.getFlagValue(), flagDef.getDescription());
}
tp.getFlagCodingGroup().add(biophysicalVariableFlagCoding);
targetProduct.getFlagCodingGroup().add(biophysicalVariableFlagCoding);
biophysicalVariableFlagBand.setSampleCoding(biophysicalVariableFlagCoding);

// Add a mask for each flag
for (BiophysicalFlag flagDef : BiophysicalFlag.values()) {
String maskName = String.format("%s_%s", biophysicalVariable.getBandName(), flagDef.getName().toLowerCase());
tp.addMask(maskName,
targetProduct.addMask(maskName,
String.format("%s.%s", flagBandName, flagDef.getName()),
flagDef.getDescription(),
flagDef.getColor(), flagDef.getTransparency());
Expand Down