Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SEADAS: seadas reader fixes (master) #119

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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 @@ -31,14 +31,7 @@ public class L1AHawkeyeFileReader extends SeadasFileReader {
@Override
public Product createProduct() throws ProductIOException {

String historyName = getStringAttribute("history");
String productName = "SEAHAWK1_HAWKEYE20210319T084332.L1A.nc";
if (historyName != null) {
int indexSEAHAWK = historyName.indexOf("SEAHAWK");
int indexL1Anc = historyName.indexOf("L1A.nc");
productName = historyName.substring(indexSEAHAWK, (indexL1Anc + 6));
}

String productName = productReader.getInputFile().getName();
numPixels = getDimension("number_of_pixels");
numScans = getDimension("number_of_scans");
title = getStringAttribute("title");
Expand Down Expand Up @@ -108,7 +101,7 @@ public void addGeocoding(final Product product) throws ProductIOException {
lats = geoNcFile.findVariable("geolocation_data/latitude");
lons = geoNcFile.findVariable("geolocation_data/longitude");

//Use lat/lon with PixelGeoCoding
//Use lat/lon with TiePointGeoCoding
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change in the comment is not correct. In the end still a PixelGeoCoding is created.

By the way, the GeoCodingFactory should not be used anymore. It is better to use the ComponentGeoCoding. Probably we will soon change the implementation of GeoCodingFactory or maybe remove it at all. The new one is faster and more accurate.

int[] dims = lats.getShape();
float[] latTiePoints;
float[] lonTiePoints;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,11 @@ private Map<Band, Variable> addOciBands(Product product, List<Variable> variable

private WvlType getWvlType(String productName) {
WvlType wvltype = null;
if (productName.equals("Lt_blue")) {
if (productName.equals("Lt_blue") || productName.equals("rhot_blue")) {
wvltype = WvlType.BLUE;
} else if (productName.equals("Lt_red")) {
} else if (productName.equals("Lt_red") || productName.equals("rhot_red")) {
wvltype = WvlType.RED;
} else if (productName.equals("Lt_SWIR")) {
} else if (productName.equals("Lt_SWIR") || productName.equals("rhot_SWIR")) {
wvltype = WvlType.SWIR;
}
return wvltype;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,11 @@ private Map<Band, Variable> addOciBands(Product product, List<Variable> variable

private WvlType getWvlType(String productName) {
WvlType wvltype = null;
if (productName.equals("Lt_blue")) {
if (productName.equals("Lt_blue") || productName.equals("rhot_blue")) {
wvltype = WvlType.BLUE;
} else if (productName.equals("Lt_red")) {
} else if (productName.equals("Lt_red") || productName.equals("rhot_red")) {
wvltype = WvlType.RED;
} else if (productName.equals("Lt_SWIR")) {
} else if (productName.equals("Lt_SWIR") || productName.equals("rhot_SWIR")) {
wvltype = WvlType.SWIR;
}
return wvltype;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
package gov.nasa.gsfc.seadas.dataio;

import org.esa.snap.core.dataio.DecodeQualification;
import org.esa.snap.core.dataio.ProductReader;
import org.esa.snap.core.util.io.SnapFileFilter;
import org.esa.snap.dataio.netcdf.GenericNetCdfReaderPlugIn;
import org.esa.snap.dataio.netcdf.util.NetcdfFileOpener;
import ucar.nc2.Attribute;
import ucar.nc2.NetcdfFile;
import ucar.nc2.iosp.hdf5.H5iosp;
import ucar.nc2.util.DebugFlags;
import ucar.nc2.util.DebugFlagsImpl;

import java.io.File;
import java.io.IOException;
import java.util.Locale;

public class L1CPaceProductReaderPlugIn extends GenericNetCdfReaderPlugIn {

// Set to "true" to output debugging information.
// Don't forget to setback to "false" in production code!
//
private static final boolean DEBUG = false;

private static final String DEFAULT_FILE_EXTENSION = ".nc";

public static final String READER_DESCRIPTION = "PACE OCIS L1C Products";
public static final String FORMAT_NAME = "PACE-L1C";


/**
* Checks whether the given object is an acceptable input for this product reader and if so, the method checks if it
* is capable of decoding the input's content.
*/
@Override
public DecodeQualification getDecodeQualification(Object input) {
final File file = SeadasProductReader.getInputFile(input);
if (file == null) {
return DecodeQualification.UNABLE;
}
if (!file.exists()) {
if (DEBUG) {
System.out.println("# File not found: " + file);
}
return DecodeQualification.UNABLE;
}
if (!file.isFile()) {
if (DEBUG) {
System.out.println("# Not a file: " + file);
}
return DecodeQualification.UNABLE;
}
NetcdfFile ncfile = null;
H5iosp.setDebugFlags(new DebugFlagsImpl("HdfEos/turnOff"));

try {
ncfile = NetcdfFileOpener.open(file.getPath());
if (ncfile != null) {
Attribute scene_title = ncfile.findGlobalAttributeIgnoreCase("Title");

if (scene_title != null) {
if (scene_title.toString().contains("PACE OCI Level-1C Data")
|| scene_title.toString().contains("PACE SPEXone Level-1C Data")
|| scene_title.toString().contains("HARP2 Level-1C Data")){
if (DEBUG) {
System.out.println(file);
}
ncfile.close();
DebugFlags debugFlags = new DebugFlagsImpl("HdfEos/turnOff");
debugFlags.set("HdfEos/turnOff", false);
H5iosp.setDebugFlags(debugFlags);
return DecodeQualification.INTENDED;
} else {
if (DEBUG) {
System.out.println("# Unrecognized scene title =[" + scene_title + "]: " + file);
}
}
} else {
if (DEBUG) {
System.out.println("# Missing scene title attribute': " + file);
}
}
} else {
if (DEBUG) {
System.out.println("# Can't open as NetCDF: " + file);
}
}
} catch (Exception ignore) {
if (DEBUG) {
System.out.println("# I/O exception caught: " + file);
}
} finally {
DebugFlags debugFlags = new DebugFlagsImpl("HdfEos/turnOff");
debugFlags.set("HdfEos/turnOff", false);
H5iosp.setDebugFlags(debugFlags);
if (ncfile != null) {
try {
ncfile.close();
} catch (IOException ignore) {
}
}
}
return DecodeQualification.UNABLE;
}

/**
* Returns an array containing the classes that represent valid input types for this reader.
* <p/>
* <p> Intances of the classes returned in this array are valid objects for the <code>setInput</code> method of the
* <code>ProductReader</code> interface (the method will not throw an <code>InvalidArgumentException</code> in this
* case).
*
* @return an array containing valid input types, never <code>null</code>
*/
@Override
public Class[] getInputTypes() {
return new Class[]{String.class, File.class};
}

/**
* Creates an instance of the actual product reader class. This method should never return <code>null</code>.
*
* @return a new reader instance, never <code>null</code>
*/
@Override
public ProductReader createReaderInstance() {
return new SeadasProductReader(this);
}

@Override
public SnapFileFilter getProductFileFilter() {
String[] formatNames = getFormatNames();
String formatName = "";
if (formatNames.length > 0) {
formatName = formatNames[0];
}
return new SnapFileFilter(formatName, getDefaultFileExtensions(), getDescription(null));
}

/**
* Gets the default file extensions associated with each of the format names returned by the <code>{@link
* #getFormatNames}</code> method. <p>The string array returned shall always have the same length as the array
* returned by the <code>{@link #getFormatNames}</code> method. <p>The extensions returned in the string array shall
* always include a leading colon ('.') character, e.g. <code>".hdf"</code>
*
* @return the default file extensions for this product I/O plug-in, never <code>null</code>
*/
@Override
public String[] getDefaultFileExtensions() {
// todo: return regular expression to clean up the extensions.
return new String[]{
DEFAULT_FILE_EXTENSION
};
}

/**
* Gets a short description of this plug-in. If the given locale is set to <code>null</code> the default locale is
* used.
* <p/>
* <p> In a GUI, the description returned could be used as tool-tip text.
*
* @param locale the local for the given decription string, if <code>null</code> the default locale is used
* @return a textual description of this product reader/writer
*/
@Override
public String getDescription(Locale locale) {
return READER_DESCRIPTION;
}

/**
* Gets the names of the product formats handled by this product I/O plug-in.
*
* @return the names of the product formats handled by this product I/O plug-in, never <code>null</code>
*/
@Override
public String[] getFormatNames() {
return new String[]{FORMAT_NAME};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public DecodeQualification getDecodeQualification(Object input) {
ncfile.close();
return DecodeQualification.UNABLE;
}
if(title.matches(".*Level-3 Standard Mapped Image")){
if(title.matches("(.*)Level-3 Standard Mapped Image") || title.matches("(.*)Level-3 Equidistant Cylindrical Mapped Image")){
if (DEBUG) {
System.out.println(file);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public Product createProduct() throws ProductIOException {
Dimension tileSize = new Dimension(640, 320);
product.setPreferredTileSize(tileSize);
}
product.setAutoGrouping("Rrs:nLw:Lt:La:Lr:Lw:L_q:L_u:Es:TLg:rhom:rhos:rhot:Taua:Kd:aot:adg:aph_:bbp:vgain:BT:tg_sol:tg_sen");
return product;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,21 @@ protected void addFlagsAndMasks(Product product) {
product.getSceneRasterWidth(),
product.getSceneRasterHeight(), "l2_flags.PRODFAIL",
FailRed, 0.1));
product.getMaskGroup().add(Mask.BandMathsType.create("Quality_L2", "Product could be computed (l2_flags composite)",
product.getSceneRasterWidth(),

product.getSceneRasterHeight(), "!(l2_flags.ATMFAIL or l2_flags.LAND or l2_flags.HILT or l2_flags.STRAYLIGHT or l2_flags.CLDICE or l2_flags.NAVFAIL)",
DarkGreen, 0.0));

product.getMaskGroup().add(Mask.BandMathsType.create("Quality_L3", "Best quality (l2_flags composite)",
product.getSceneRasterWidth(),

product.getSceneRasterHeight(), "!(l2_flags.ATMFAIL or l2_flags.LAND or l2_flags.HIGLINT or l2_flags.HILT or l2_flags.STRAYLIGHT or l2_flags.CLDICE or l2_flags.COCCOLITH or l2_flags.HISOLZEN or l2_flags.LOWLW or l2_flags.CHLFAIL or l2_flags.NAVWARN or l2_flags.MAXAERITER or l2_flags.CHLWARN or l2_flags.ATMWARN or l2_flags.NAVFAIL or l2_flags.FILTER)",
Color.GREEN, 0.0));
product.getMaskGroup().add(Mask.BandMathsType.create("Water", "Not land (l2_flags.LAND)",
product.getSceneRasterWidth(),
product.getSceneRasterHeight(), "!l2_flags.LAND",
Color.BLUE, 0.0));

}
Band QFBandSST = product.getBand("flags_sst");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ enum ProductType {
Level1B_OCM2("OCM2_L1B"),
Level1B_PaceOCI("PaceOCI_L1B"),
Level1B_PaceOCIS("PaceOCIS_L1B"),
Level1C_Pace("Pace_L1C"),
Level2("Level 2"),
Level2_DscovrEpic("DscovrEpic Level 2"),
Level2_PaceOCI("OCI Level-2"),
Expand Down Expand Up @@ -153,6 +154,9 @@ protected Product readProductNodesImpl() throws IOException {
case Level1B_PaceOCIS:
seadasFileReader = new L1BPaceOcisFileReader(this);
break;
case Level1C_Pace:
seadasFileReader = new L1CPaceFileReader(this);
break;
case Level3_Bin:
seadasFileReader = new L3BinFileReader(this);
break;
Expand Down Expand Up @@ -338,6 +342,10 @@ public ProductType findProductType() throws ProductIOException {
return ProductType.Level1B_PaceOCI;
} else if (title.contains("PACE OCIS Level-1B Data")) {
return ProductType.Level1B_PaceOCIS;
} else if (title.contains("PACE OCI Level-1C Data")
|| title.contains("PACE SPEXone Level-1C Data")
|| title.contains("HARP2 Level-1C Data")) {
return ProductType.Level1C_Pace;
} else if (title.equals("OCIS Level-2 Data")) {
return ProductType.Level2_PaceOCIS;
} else if (title.equals("OCI Level-2 Data")) {
Expand Down Expand Up @@ -368,7 +376,7 @@ public ProductType findProductType() throws ProductIOException {
return ProductType.ANCNRT2;
} else if (title.equals("SeaWiFS Climatological Ancillary Data")) {
return ProductType.ANCCLIM;
} else if (title.contains("Level-3 Standard Mapped Image")) {
} else if (title.matches("(.*)Level-3 Standard Mapped Image") || title.matches("(.*)Level-3 Equidistant Cylindrical Mapped Image")) {
return ProductType.SMI;
} else if (title.contains("Level-3 Binned Data") || title.contains("level-3_binned_data")) {
return ProductType.Level3_Bin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ gov.nasa.gsfc.seadas.dataio.L3ProductReaderPlugIn
gov.nasa.gsfc.seadas.dataio.BrowseProductReaderPlugIn
gov.nasa.gsfc.seadas.dataio.L1BViirsProductReaderPlugin
gov.nasa.gsfc.seadas.dataio.L1BPaceProductReaderPlugIn
gov.nasa.gsfc.seadas.dataio.L1CPaceProductReaderPlugIn
gov.nasa.gsfc.seadas.dataio.L2DscovrEpicProductReaderPlugIn