NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

[netcdf-java] how to write unsigned data ?

Hello,

I am trying to aggregate some NetCDF-4 or HDF-5 files and extract a window
from them into a single NetCDF-4 file.
In one of these files I have got a variable for zenithal angles that is
packed into signed ints. I the aggregated file, I want to reduce the
precision of this variable and pack it into signed shorts in the range
0-36000 degrees. But I do not manage...
I have not found any recipe in the docs I have read  (I may not have found
the good one !), so if someone can help me, it would save my day !

Concretely, this is how I proceed (this is certainly not the easiest
way...), with NetCDF-java 4-3 (I have not yet planned to update):
I open a NcML file (without enhancement because I have to change only one
variable). This aggregates the whole input files.
*ncml = NetcdfDataset.openDataset(ncmlFile, false, -1, null, null);*

Then, I create a new NetCDF file to host the extracted window, some
modifications on global or variable attributes and so on.

*chunker = new Nc4ChunkingStrategyFromAttribute(deflate, shuffle);ncWriter
= NetcdfFileWriter.createNew(version, outFile, chunker);*

*// do some stuff*
*ncWriter.create();*

Then, I fill the data in this file. For my zenithal angles, I read the data
in the variable from the aggregated file (called var below), extract the
desired window and create an Array object containing the precision-reduced
data that is finally written:









*Array tmp = (ArrayInt.D2)(var.read().section(origin,
shape).copy());varData = Array.factory(DataType.SHORT,
shape);var.setUnsigned(true);Index2D idx = new Index2D(shape);for (i = 0; i
< shape[0]; i++) {    for (j = 0; j < shape[1]; j++) {        idx.set(i,
j);        varData.setShort(idx,
(short)Math.round(tmp.getInt(idx)/100.));    }}*
*ncWriter.write(ncWriter.findVariable(var.getShortName()), varData);*


This is an extract of the NcML file, relative to this variable:











*    <variable name="sat_azi_ang" shape="ny nx" type="short">
<attribute name="standard_name" value="platform_azimuth_angle" />
<attribute name="long_name" value="horizontal angle between the line of
sight from the observation point to the platform and a reference direction
at the observation point, which is due north" />        <attribute
name="units" value="degrees" />        <attribute name="scale_factor"
type="double" value="1.0E-2" />        <attribute name="add_offset"
type="double" value="0.0" />        <attribute name="valid_min"
type="short" value="0" />        <attribute name="valid_max" type="short"
value="36000" />        <attribute name="_FillValue" type="short"
value="65535" />        <attribute name="grid_mapping" value="geos" />
    <attribute name="_Unsigned" value="true" />*
*    </variable>*

As a result, I get a NetCDF file where the data for this variable do not
seem to be unsigned:












*   short sat_azi_ang(ny=700, nx=1150);     :standard_name =
"platform_azimuth_angle";     :long_name = "horizontal angle between the
line of sight from the observation point to the platform and a reference
direction at the observation point, which is due north";     :units =
"degrees";     :scale_factor = 0.01; // double     :add_offset = 0.0; //
double     :valid_min = 0S; // short     :valid_max = -29536S; // short
:_FillValue = -1S; // short     :grid_mapping = "GeosCoordinateSystem";
:_Unsigned = "true";     :_ChunkSize = 700, 1150; // int*
  • 2015 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: