@Deprecated public class TLcdGRIB1ModelDecoder extends Object implements ILcdModelDecoder, ILcdInputStreamFactoryCapable
Each GRIB file contains the values of a single meteorological parameter (e.g., temperature, pressure...) at different grid points. The parameter values in the file are not the actual values, but internal values to eliminate redundancy and negative or broken values. These internal values are decoded as unsigned shorts.
The actual value of a parameter can be calculated with the formula:
Y * 10D = R + (X*2E)
where
File | Required | Entry point | Description |
---|---|---|---|
*.grb *.grib *.dat |
x | x | GRIB file containing the meteorological raster |
inputStreamFactory
of this decoder.ILcd2DBoundsIndexedModel
.TLcdGRIBModelDescriptor
. Among other information about
the GRIB data, it contains the values of D, R and E. For convenience,
it already provides methods to calculate actual values from internal
values, and vice versa:
getActualValue
and
getInternalValue
.addParameterTable(ILcdGRIBParameterTable)
and
addParameterTable(ILcdGRIBParameterTable,boolean)
.
The most convenient way to create parameter tables is by decoding them
from files, using the class TLcdGRIB1ParameterTableDecoder
.ILcdRaster
. The raster has a single tile with unsigned shorts
that represent the internal values of the parameter.colorModel
allows to override the default
16-bits index color that is attached to the decoded rasters, since
GRIB files don't contain any color information. Note that the indexing
must be based on the internal GRIB values, not on the actual values.
TLcdGRIB1ModelDecoder decoder = new TLcdGRIB1ModelDecoder();
ILcdModel model = decoder.decode("data.grb");
In some cases, you may want to combine related parameters from to decoded
models into a single representation, for instance the u-component and the
v-component of the wind speed. You can do this as follows:
TLcdGRIB1ModelDecoder decoder = new TLcdGRIB1ModelDecoder();
ILcdModel u_model = decoder.decode("u_component.grb");
ILcdModel v_model = decoder.decode("v_component.grb");
ILcdRaster[] uv_rasters = {
(ILcdRaster)u_model.elements().nextElement(),
(ILcdRaster)v_model.elements().nextElement()
};
ILcdMultiValuedRaster raster = new TLcdMultivaluedRaster(rasters);
TLcdRasterModelDescriptor[] descriptors = {
(TLcdRasterModelDescriptor)u_model.getModelDescriptor(),
(TLcdRasterModelDescriptor)v_model.getModelDescriptor()
};
ILcdModelDescriptor uv_descriptor =
new TLcdMultivaluedRasterModelDescriptor(u_model.getModelDescriptor().getSourceName(),
u_model.getModelDescriptor().getDisplayName(),
u_model.getModelDescriptor().getTypeName(),
descriptors);
TLcd2DBoundsIndexedModel uv_model = new TLcd2DBoundsIndexedModel();
uv_model.setModelDescriptor(uv_descriptor);
uv_model.setModelReference(u_model.getModelReference());
uv_model.addElement(uv_raster, ILcdFireEventMode.NO_EVENT);
TLcdGRIB1ParameterTableDecoder
Constructor and Description |
---|
TLcdGRIB1ModelDecoder()
Deprecated.
Creates a new
TLcdGRIB1ModelDecoder , with a globally shared
buffer for caching tiles. |
TLcdGRIB1ModelDecoder(ILcdBuffer aBuffer)
Deprecated.
Creates a new
TLcdGRIB1ModelDecoder . |
Modifier and Type | Method and Description |
---|---|
void |
addParameterTable(ILcdGRIBParameterTable aParameterTable)
Deprecated.
Adds a parameter table.
|
void |
addParameterTable(ILcdGRIBParameterTable aParameterTable,
boolean aMatchCenter)
Deprecated.
Adds a parameter table.
|
boolean |
canDecodeSource(String aSourceName)
Deprecated.
Checks whether this model decoder can decode the specified data source.
|
ILcdModel |
decode(String aSourceName)
Deprecated.
Creates a new model from the given data source.
|
ColorModel |
getColorModel()
Deprecated.
Returns the color model that is attached by default to the decoded rasters.
|
String |
getDefaultExtension()
Deprecated.
Gets the default file extension of GRIB messages.
|
String |
getDisplayName()
Deprecated.
Returns a short, displayable name for the format that is decoded by this
ILcdModelDecoder . |
ILcdInputStreamFactory |
getInputStreamFactory()
Deprecated.
Returns the input stream factory that is be used for creating input streams
given source names.
|
int |
getSampleStrategy()
Deprecated.
Returns the sampling strategy that is used for displaying raster data.
|
void |
removeParameterTable(ILcdGRIBParameterTable aParameterTable)
Deprecated.
Removes a parameter table.
|
void |
setColorModel(ColorModel aColorModel)
Deprecated.
Sets the color model that is attached by default to the decoded rasters.
|
void |
setInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory)
Deprecated.
Sets the input stream factory that will be used for creating input streams
given source names.
|
void |
setSampleStrategy(int aSampleStrategy)
Deprecated.
Sets the sampling strategy that is used for displaying raster data.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
canDecodeSource, decodeModelMetadata, decodeModelMetadata, decodeSource, discoverDataSources
public TLcdGRIB1ModelDecoder()
TLcdGRIB1ModelDecoder
, with a globally shared
buffer for caching tiles.TLcdSharedBuffer.getBufferInstance()
public TLcdGRIB1ModelDecoder(ILcdBuffer aBuffer)
TLcdGRIB1ModelDecoder
.aBuffer
- the shared buffer that decoded models will use.public void setInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory)
setInputStreamFactory
in interface ILcdInputStreamFactoryCapable
aInputStreamFactory
- The input stream factory to be used.getInputStreamFactory()
public ILcdInputStreamFactory getInputStreamFactory()
getInputStreamFactory
in interface ILcdInputStreamFactoryCapable
setInputStreamFactory(com.luciad.io.ILcdInputStreamFactory)
public void addParameterTable(ILcdGRIBParameterTable aParameterTable)
The decoder will first try to use the parameter table with a matching table version, center ID, and subcenter ID. If it can't find it, it it will fall back on the parameter table that only matches the table version.
aParameterTable
- the parameter table to add.addParameterTable(ILcdGRIBParameterTable,boolean)
public void addParameterTable(ILcdGRIBParameterTable aParameterTable, boolean aMatchCenter)
The decoder will first try to use the parameter table with a matching table version, center ID, and subcenter ID. If it can't find it, it it will fall back on the parameter table that only matches the table version, if non-exact matches are allowed.
aParameterTable
- the parameter table to add.aMatchCenter
- a boolean flag that indicates if the center ID and
subcenter ID have to match in order for this table
to be used.public void removeParameterTable(ILcdGRIBParameterTable aParameterTable)
aParameterTable
- the parameter table to remove.public void setColorModel(ColorModel aColorModel)
null
.aColorModel
- an 8-bit or 16-bit IndexColorModel that is compatible
with the GRIB data to be decoded.getColorModel()
public ColorModel getColorModel()
setColorModel(java.awt.image.ColorModel)
public void setSampleStrategy(int aSampleStrategy)
aSampleStrategy
- one of
getSampleStrategy()
public int getSampleStrategy()
setSampleStrategy(int)
public String getDefaultExtension()
public String getDisplayName()
ILcdModelDecoder
ILcdModelDecoder
.getDisplayName
in interface ILcdModelDecoder
public boolean canDecodeSource(String aSourceName)
ILcdModelDecoder
true
for a source name while decode
throws an exception for that same source name.
For performance reasons, we strongly recommend that this will only be a simple test. For example: check the file extension of a file, but not that the file exists or contains expected content.
canDecodeSource
in interface ILcdModelDecoder
aSourceName
- the data source to be verified; typically a file name or a URL.true
if the given file name has extension "grb", "grib", or "dat"
(possibly extended with ".gz" or ".zip").ILcdModelDecoder.decode(String)
,
ILcdModelDecoder.decodeModelMetadata(String)
public ILcdModel decode(String aSourceName) throws IOException
ILcdModelDecoder
decode
in interface ILcdModelDecoder
aSourceName
- the data source to be decoded; typically a file name or a URL.null
is allowed, implementors are advised to throw an error instead.IOException
- for any exceptions caused by IO problems or invalid data. Since decoding invalid data almost
always results in RunTimeExceptions (NullPointerException, IndexOutOfBoundsException,
IllegalArgumentException, ...) on unexpected places, implementations are advised to catch
RuntimeExceptions in their decode() method, and wrap them into an IOException, as illustrated
in the code snippet below.
public ILcdModel decode( String aSourceName ) throws IOException {
try (InputStream input = fInputStreamFactory.createInputStream(aSourceName)) {
// Perform decoding ...
} catch (RuntimeException e) {
throw new IOException(e);
}
}
InterruptedIOException
- When the thread on which this method is called is interrupted: it is recommended to stop the decoding
and throw an InterruptedIOException
.
This same exception can also be used if the decoder shows UI to the user, and the user cancels the decoding
through the UI.ILcdModelDecoder.canDecodeSource(String)