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 @@ -113,7 +113,8 @@ public void onChange(ChangeEvent event) {
l3ConfigForm.compositingPeriodLength.setValue(30);

outputParametersForm = new OutputParametersForm(portalContext);
outputParametersForm.setAvailableOutputFormats("BEAM-DIMAP", "NetCDF", "NetCDF4", "GeoTIFF", "BigGeoTiff");
outputParametersForm.setAvailableOutputFormats("BEAM-DIMAP", "NetCDF", "NetCDF4", "NetCDF4-SEAGrid",
"GeoTIFF", "BigGeoTiff");

l2ConfigForm.setProductSet(productSetSelectionForm.getSelectedProductSet());
updateTemporalParameters(productSetFilterForm.getValueMap());
Expand Down Expand Up @@ -279,4 +280,4 @@ public void setProductionParameters(Map<String, String> parameters) {
l3ConfigForm.setValues(parameters);
outputParametersForm.setValues(parameters);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
*/
public class ProductFormatter {

public static final String FORMAT_NETCDF4_SEAGRID = "NetCDF4-SEAGrid";

private static final Logger LOG = CalvalusLogger.getLogger();

private final String outputFormat;
Expand Down Expand Up @@ -91,6 +93,12 @@ public ProductFormatter(String productName, String outputFormat, String desiredO
outputExtension = ".nc";
outputCompression = ""; // no further compression required
outputFormat = "NetCDF4-BEAM"; // use NetCDF with BEAM extensions
} else if (outputFormat.equalsIgnoreCase(FORMAT_NETCDF4_SEAGRID)) {
outputExtension = ".nc";
outputCompression = ""; // already written as NetCDF-4
// L3Formatter uses the dedicated binning FormatterPlugin; ProductFormatter
// only provides the temporary file and HDFS copy, so no ProductWriterPlugIn
// is required.
} else if (outputFormat.equals("GeoTIFF")) {
outputExtension = ".tif";
outputCompression = desiredOutputCompression;
Expand All @@ -107,20 +115,22 @@ public ProductFormatter(String productName, String outputFormat, String desiredO
} else {
outputCompression = desiredOutputCompression;
}
// test if writer for output format exists
ProductIOPlugInManager registry = ProductIOPlugInManager.getInstance();
Iterator it = registry.getWriterPlugIns(outputFormat);
if(it.hasNext()) {
ProductWriterPlugIn plugIn = (ProductWriterPlugIn) it.next();
if (outputExtension.isEmpty()) {
// get output extension from writer
String[] defaultFileExtensions = plugIn.getDefaultFileExtensions();
if (defaultFileExtensions != null && defaultFileExtensions.length > 0) {
outputExtension = defaultFileExtensions[0];
if (!FORMAT_NETCDF4_SEAGRID.equalsIgnoreCase(outputFormat)) {
// test if writer for output format exists
ProductIOPlugInManager registry = ProductIOPlugInManager.getInstance();
Iterator it = registry.getWriterPlugIns(outputFormat);
if(it.hasNext()) {
ProductWriterPlugIn plugIn = (ProductWriterPlugIn) it.next();
if (outputExtension.isEmpty()) {
// get output extension from writer
String[] defaultFileExtensions = plugIn.getDefaultFileExtensions();
if (defaultFileExtensions != null && defaultFileExtensions.length > 0) {
outputExtension = defaultFileExtensions[0];
}
}
} else {
throw new IllegalArgumentException("Unsupported output format: " + outputFormat);
}
} else {
throw new IllegalArgumentException("Unsupported output format: " + outputFormat);
}

if ("zip".equals(outputCompression)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.bc.ceres.binding.ConversionException;
import com.bc.ceres.binding.Converter;
import com.bc.ceres.binding.ConverterRegistry;
import org.esa.snap.binning.operator.formatter.Formatter;
import org.esa.snap.binning.operator.formatter.FormatterFactory;
import org.esa.snap.binning.support.IsinPlanetaryGrid;
import org.locationtech.jts.geom.Geometry;
Expand All @@ -36,7 +37,6 @@
import org.esa.snap.binning.PlanetaryGrid;
import org.esa.snap.binning.TemporalBinSource;
import org.esa.snap.binning.operator.BinningConfig;
import org.esa.snap.binning.operator.formatter.Formatter;
import org.esa.snap.binning.operator.formatter.FormatterConfig;
import org.esa.snap.core.datamodel.MetadataElement;
import org.esa.snap.core.datamodel.Product;
Expand Down Expand Up @@ -89,25 +89,39 @@ private L3Formatter(String dateStart, String dateStop, String outputFile, String
metadataSerializer = new MetadataSerializer();
}

private void format(TemporalBinSource temporalBinSource, String regionName, String regionWKT) throws Exception {
Geometry regionGeometry = GeometryUtils.createGeometry(regionWKT);
final String processingHistoryXml = configuration.get(JobConfigNames.PROCESSING_HISTORY);
final MetadataElement processingGraphMetadata = metadataSerializer.fromXml(processingHistoryXml);
// TODO maybe replace region information in metadata if overwritten in formatting request
org.esa.snap.binning.operator.formatter.Formatter formatter;
if (planetaryGrid instanceof IsinPlanetaryGrid) {
private void format(TemporalBinSource temporalBinSource,
String regionName,
String regionWKT) throws Exception {
boolean useSeaGridNetcdfFormatter =
usesSeaGridNetcdfFormatter(formatterConfig.getOutputFormat());
Formatter formatter;
if (useSeaGridNetcdfFormatter) {
// SNAP's default formatter maps planetary grids to rectangular raster products.
// Select the Calvalus plugin by output format, not just by grid type, because
// existing SEA-grid requests may still require a standard raster product.
formatter = FormatterFactory.get(SeaGridFormatterPlugin.NAME);
} else if (planetaryGrid instanceof IsinPlanetaryGrid) {
formatter = FormatterFactory.get("isin");
} else {
formatter = FormatterFactory.get("default");
}

Geometry regionGeometry = null;
if (!useSeaGridNetcdfFormatter) {
regionGeometry = GeometryUtils.createGeometry(regionWKT);
}
final String processingHistoryXml = configuration.get(JobConfigNames.PROCESSING_HISTORY);
final MetadataElement processingGraphMetadata = metadataSerializer.fromXml(processingHistoryXml);
// TODO maybe replace region information in metadata if overwritten in formatting request
MetadataElement[] metadataElements = new MetadataElement[]{processingGraphMetadata};
formatter.format(planetaryGrid,
temporalBinSource,
featureNames,
formatterConfig,
regionGeometry,
startTime,
endTime,
processingGraphMetadata);
metadataElements);
}

private static ProductData.UTC parseTime(String timeString) {
Expand Down Expand Up @@ -174,6 +188,10 @@ public static void write(TaskInputOutputContext context, TemporalBinSource tempo
}
}

static boolean usesSeaGridNetcdfFormatter(String outputFormat) {
return ProductFormatter.FORMAT_NETCDF4_SEAGRID.equalsIgnoreCase(outputFormat);
}

private static class ProductConverter implements Converter<Product> {

private final Configuration conf;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (C) 2010 Brockmann Consult GmbH (info@brockmann-consult.de)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see http://www.gnu.org/licenses/
*/

package com.bc.calvalus.processing.l3;

import com.bc.calvalus.commons.CalvalusLogger;
import com.bc.calvalus.processing.l2.ProductFormatter;
import org.esa.snap.binning.PlanetaryGrid;
import org.esa.snap.binning.TemporalBinSource;
import org.esa.snap.binning.operator.formatter.Formatter;
import org.esa.snap.binning.operator.formatter.FormatterConfig;
import org.esa.snap.binning.support.SEAGrid;
import org.esa.snap.core.datamodel.MetadataElement;
import org.esa.snap.core.datamodel.ProductData;
import org.locationtech.jts.geom.Geometry;

import java.io.File;
import java.util.logging.Logger;

/**
* Formats a SNAP {@link SEAGrid} as the flattened NetCDF layout required by
* {@link ProductFormatter#FORMAT_NETCDF4_SEAGRID}.
*/
final class SeaGridFormatter implements Formatter {

private static final Logger LOG = CalvalusLogger.getLogger();

@Override
public void format(PlanetaryGrid planetaryGrid,
TemporalBinSource temporalBinSource,
String[] featureNames,
FormatterConfig formatterConfig,
Geometry regionGeometry,
ProductData.UTC startTime,
ProductData.UTC endTime,
MetadataElement... metadataElements) throws Exception {
if (!(planetaryGrid instanceof SEAGrid)) {
throw new IllegalArgumentException(
ProductFormatter.FORMAT_NETCDF4_SEAGRID +
" requires org.esa.snap.binning.support.SEAGrid, but the request uses " +
planetaryGrid.getClass().getName());
}

LOG.info("Using flattened SEAGrid NetCDF formatter for output format " +
ProductFormatter.FORMAT_NETCDF4_SEAGRID + '.');
SeaGridNetcdfFormatter.write(new File(formatterConfig.getOutputFile()),
(SEAGrid) planetaryGrid,
temporalBinSource,
featureNames,
startTime,
endTime,
metadataElements);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2010 Brockmann Consult GmbH (info@brockmann-consult.de)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see http://www.gnu.org/licenses/
*/

package com.bc.calvalus.processing.l3;

import org.esa.snap.binning.operator.formatter.Formatter;
import org.esa.snap.binning.operator.formatter.FormatterPlugin;

/**
* Makes the Calvalus flattened SEA-grid formatter available to SNAP's
* {@code FormatterFactory}.
*/
public final class SeaGridFormatterPlugin implements FormatterPlugin {

static final String NAME = "seagrid";

@Override
public String getName() {
return NAME;
}

@Override
public Formatter create() {
return new SeaGridFormatter();
}
}
Loading