1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
|
<a name="main"> </a>
<h2>1. Introduction</h2>
<p>
The ENVISAT Product Reader API for C (<code>epr-c-api</code>) is a library of data
structures and functions for simple access to MERIS, AATSR and ASAR products. You can use
them in your programs to retrieve directly the geophysically coded values, e.g.
such as the chlorophyll concentration in mg/m³, in a data matrix.
<p>
The <code>epr-c-api</code> is generic, i.e. it has no instrument specific functions
but utilises the generic ENVISAT product format. However, it is not necessary for a user of the
<code>epr-c-api</code> to know the ENVISAT product format - the
<code>epr-c-api</code> knows it, and that's sufficient.
<p>
All a user of the <code>epr-c-api</code> has to know are a few functions and the name
of the geophysical variable he wants to get. In fact, the <code>epr-c-api</code> can
do more: all information stored in ENVISAT products can be retrieved in a unique way, just by
requesting it identified by its name, without worrying too much where and how it is stored in the
world of the ENVISAT product format.
<p>
Now, here's the tricky bit: there are many different products and the number of items stored
in each product is huge. Therefore a
<a href="http://www.brockmann-consult.de/beam/doc/help/general/envisat-products/index.html">
ENVISAT Data Products
</a> documentation is included in the BEAM software homepage, which describes the internal
structure of each supported product. In order to access a certain item such as a dataset,
record, band or flag you have to consult the data product documentation for he correct
name or ID for the dataset, record, band or flag you want to access.
<h2>2. Using the API in your own C-Programs</h2>
<p>
The <code>epr-c-api</code> is written in pure ANSI C and should compile with
every ANSI conformant C-compiler:
<ol>
<li>Copy all <code>*.h</code> <code>*.c</code> files contained in the
distribution's <code>src</code> folder to your own source folder of your project
and include them in your development environment (makefile or IDE).</li>
<li>Include the public API header <code>epr-api.h</code> in your C source files.</li>
<li>Optionally refer to the example code in <code>src/examples</code> directory</li>
</ol>
<h2>3. API Design</h2>
<h3>3.1 Basic Concepts</h3>
<p>Given here are some of the basic concepts of the API.
<ul>
<li>The API works exclusively with pointers to dynamically allocated structures.
For every structure type in the API a constructor/desctructor function pair always exists:
<code>X epr_create_X(...)</code> and <code>void epr_free_X(X)</code>. Example: For the type
<code>EPR_SRecord*</code> these functions are <code>EPR_SRecord* epr_create_record(...)</code>
and <code>void epr_free_record(EPR_SRecord*)</code>.
</li>
<li>
In most cases, the first parameter is the object on which the function is operating.
For example, <code>uint epr_get_num_fields(const EPR_SRecord* record)</code>.
</li>
<li>Access functions exist for all important members of structures. So, the
user of the API should not need to work directly with the API structures but
with functions to get values. For example, if you use the <code>epr_get_pixel_as_float</code>
to access a pixel value of raster, your code is less dependent on API changes as if
you would have directly accessed a structure member.
</li>
<li>A central concept is that all items, which can be retrieved from ENVISAT
products, are identified by name. For example, to access the MERIS L1B radiance
of band 1, you have to call <code>epr_get_dataset_id(product_id, "Radiance_1")</code>
But how do you know, what name you should use for the data you want to retrieve? There are three
possibilities:
<ol>
<li>
The
<a href="http://www.brockmann-consult.de/beam/doc/help/general/envisat-products/index.html">
ENVISAT Data Products
</a>
documentation provides all valid names used in the all supported data products.
All tables in the documentation have a similar structure, the first column is
always contains the longed-for name.
</li>
<li>
One can use VISAT to open a product. The names shown in VISAT in the product
browser are the same as in the ENVISAT data product tables documentation and
are hence those needed.
</li>
<li>
One can open a product using the <code>epr-c-api</code>, scan all datasets in a look
and print the names of the datasets and records by the access function.
The same can be done with all fields of a record.
</li>
</ol>
</li>
</ul>
<h3>3.2 Data Access Types</h3>
<p>The API provides two access types for ENVISAT data:
<ol>
<li>
Access of data as it is stored in the product (we call this basic or raw data access) and
</li>
<li>
Access to the geophysical raster data (what we call this geophysical data access).
</li>
</ol>
<p>
The difference between the two is how they treat the measurement data: Access type
(1) returns the data in its native data product structure: as datasets, records and fields.
This gives a direct read access to the raw data as it is stored in the data product,
without any interpretation of the content.
For example, the MERIS L1B measurement data set MDS 15 stores chlorophyll, vegetation index
or cloud top height in the same byte. The content has to be interpreted depending
on the surface type, which itself is coded in MDS 20. To get the true geophysical
value one needs to retrieve the proper scaling factors from a certain GADS. Access type
(2) decodes all this and provides, for example, a data matrix with the chlorophyll
concentration in a float variable in its geophysical units, i.e. mg/m³. The data of the
measurement datasets and the tie-point values, i.e. geometry, geo-location and meteorological data,
are available by this method. The tie-point data are interpolated to the corresponding
image grid.
<h3>3.3 Working with the Basic/Raw Data Access</h3>
<div align="center">
<table width="95%">
<tr>
<td class="indexkey">
Level
</td>
<td class="indexkey">
Correspondence in ENVISAT product
</td>
</tr>
<tr>
<td class="indexvalue">
Product
</td>
<td class="indexvalue">
ENVISAT product file
</td>
</tr>
<tr>
<td class="indexvalue">
Dataset
</td>
<td class="indexvalue">
Dataset, e.g. Main Product Header MPH, or a Measurement Data Set MDS.
A dataset contains records. For example, the MERIS L1b MDS1 contains many
records with radiance values.
</td>
</tr>
<tr>
<td class="indexvalue">
Record
</td>
<td class="indexvalue">
A single record within a dataset. A record contains many fields. For
example, a record within the MERIS L1b MDS1 contains a time-stamp field,
a quality flag field and then a field with as many radiance values as
contained in the width of the image.
</td>
</tr>
<tr>
<td class="indexvalue">
Field
</td>
<td class="indexvalue">
A field within a record. Fields can be a scalar or a vector. In the
example, the time stamp and quality flag are scalars while the radiance
field is a vector of the length of an image line.
</td>
</tr>
<tr>
<td class="indexvalue">
Element
</td>
<td class="indexvalue">
Optional. If a field is a vector, these are the elements of that vector.
In the example each element of the radiance field is the radiance of a
certain pixel.
</td>
</tr>
</table>
</div>
<div align="left">
<p>
On each level of the hierarchy, functions exist to point to
a certain instance of it, e.g. a certain product, dataset or record and so
on. That function generally requires the name of the item to be retrieved.
All possible names can be found in the
<a href="http://www.brockmann-consult.de/beam/doc/help/general/envisat-products/index.html">
DDDB
</a>,
and the name of the most important items are listed here. The function returns
an identifier of that instance. The identifier is not the instance but a pointer
to it. It is used to get the values of the instance by using access functions.
<p>
For example,
<p class="code">
my_product_id = epr_open_product("my_MERIS_product");
<p>
returns the identifier to the <code>my_product_id</code>
which points to the product contained in the file "my_MERIS_product".
<p class="code">
rad1_id = epr_get_dataset_id(my_product_id, "Radiance_1");
<p>
This <code>my_product_id</code> is used
get the identifier <code>rad1_id</code>
which points to the <code>Radiance_1</code>
dataset. Now, one can call
<p class="code">
num_rec = epr_get_num_records(rad1_id);
<p>
to get the number of records which this dataset contains. Finally one
can loop over all records and gets its fields and elements. See the examples
to get a complete code example.
</div>
<h3>3.4 Working with Geophysical Data Access</h3>
<p>
To work with geophysical data is easier than the basic access. No such deep
hierarchy exists. Instead of accessing datasets, so called bands will be accessed.
A band directly includes one single geophysical variable.
<p>
For example,
<p class="code">
my_product_id = epr_open_product(my_product_file_path);
<br>
my_chl_id = epr_create_band_id(my_product_id, "algal_1");
<p>
returns the identifier to a band containing the chlorophyll product. Now, the
actual data are read into a raster.
<p class="code">
chl_raster = epr_create_compatible_raster(my_chl_id, ...);
<br>
status = epr_read_band_raster(chl_raster, ...);
<p>
The raster
<code>chl_raster</code> now contains the data as two dimensional
matrix of pixel. To get the value of a pixel at a certain index
<code>(i,j)</code>, one should use the access function:
<p class="code">
chl_pixel = epr_get_pixel_as_float(chl_raster, i, j);
<p>
(See also the examples <code>ndvi.c</code> for complete example codes.)
<p>
The concept of the raster allows spatial subsets and undersampling: A certain
portion of the ENVISAT product will be read into the raster. This is called
the source. The complete ENVISAT product can be much greater than the source.
One can move the raster over the complete ENVISAT product and read in turn different
parts - always of the size of the source - of it into the raster.
<p>
A typical example is a processing in blocks. Lets say, a block has 64x32 pixel.
Then, the source has a width of 64 pixel and a height of 32 pixel. Another example
is a processing of complete image lines. Then, the source has a widths of the
complete product (for example 1121 for a MERIS RR product), and a height of
1. One can loop over all blocks or image lines, read into the raster and process
it. It is, of course, also possible to define a raster of the size of the complete
product.
<p>
In addition, it is possible to define a subsampling step for a raster. This
means, that the source is not read 1:1 into the raster, but that only every
2nd or 3rd pixel is read. This step can be set differently for the across track
and along track directions.
<h3>3.5 Bit masks</h3>
<p>
MERIS and AATSR provide many so called flags, which are binary information
indicating a certain state of a pixel. For example, this can be a quality indicator,
which, if set, indicates that the value of the pixel is invalid. Other example
are a cloud flag, indicating that this pixel is a measurement above a cloud,
or a coastline flag. The flags are stored in a packed format inside the ENVISAT
products, but the <code>epr-c-api</code> provides a function to easily
access the flags.
It returns a bit-mask, which is a byte array that matches the corresponding
image raster and is 1 where the flag is set and 0 elsewhere. Even more, this
functions permits to formulate a bit-mask expression to combine any number of
flags in a logical expression and returns the resulting combined bit-mask:
<p class="code">
bm_expr = "flags.LAND OR flags.CLOUD";
<br>
status = epr_read_bitmask_raster(product_id, bm_expr, ..., bm_raster);
<p>
This is an example to get a bit-mask which masks out all land and cloud pixels.
The names of the flags are found in the
<a href="http://www.brockmann-consult.de/beam/doc/help/general/envisat-products/index.html">DDDB</a>.
The <code>epr_read_bitmask_raster</code> function read from product,
identified by <code>product_id</code>, the flags and stores the resulting
bit-mask in the raster <code>bm_raster</code>.
See the examples for the complete code.
<h2>4. API Function Group Index</h2>
<p>The <code>epr-c-api</code> provides the following group of functions:
<div align="center">
<table width="95%">
<tr valign="top">
<td class="indexvalue">(1)</td>
<td class="indexvalue"><a href="group__INIT.html">Initialisation</a></td>
<td class="indexvalue">Functions for setting up the environment of the API and releasing
memory when the API is closed.</td>
</tr>
<tr valign="top">
<td class="indexvalue">(2)</td>
<td class="indexvalue"><a href="group__LOGGING.html">Logging</a></td>
<td class="indexvalue">Functions to manage logging information</td>
</tr>
<tr valign="top">
<td class="indexvalue">(3)</td>
<td class="indexvalue"><a href="group__ERROR.html">Error handling</a></td>
<td class="indexvalue">Functions for determining the behaviour of the API in case
of errors, and of getting information about runtime errors</td>
</tr>
<tr valign="top">
<td class="indexvalue">(4)</td>
<td class="indexvalue"><a href="group__IO.html">Input / Output</a></td>
<td class="indexvalue">Opening and closing ENVISAT products and writing data to a
file or stdout. </td>
</tr>
<tr valign="top">
<td class="indexvalue">(5)</td>
<td class="indexvalue"><a href="group__DA.html">Basic data access</a></td>
<td class="indexvalue">Functions to retrieve raw data as stored in ENVISAT products
</td>
</tr>
<tr valign="top">
<td class="indexvalue">(6)</td>
<td class="indexvalue"><a href="group__GDA.html">Geophysical data access</a></td>
<td class="indexvalue">Functions to retrieve geophysically interpreted data in a
raster matrix</td>
</tr>
<tr valign="top">
<td class="indexvalue">(7)</td>
<td class="indexvalue"><a href="group__BM.html">Bit masks</a></td>
<td class="indexvalue">Functions for generating bit masks from the flags included
in ENVISAT products. </td>
</tr>
</table>
</div>
|