John et al.
I thought I'd toss this up here just in case someone else wanted to do this
in the future. I came up with a solution for renaming Coordinate Variables
(axes) prior to writing them to a local netcdf file. Here's the code:
**Obtain the axis of interest from the GridCoordSystem**
**Let's say I'd like this axis to be named "lon"***
//get the coordinate dimension from the old axis
Dimension dim = axis.getCoordinateDimension();
//change the name to the desired name
dim.setName("lon");
//create a new coordinate axis based on the original but using the renamed
//dimension and the desired name for the name of the axis
CoordinateAxis replacementAxis = new CoordinateAxis(your_NetcdfDataset,
null, "lon", axis.getDataType(), dim.getName(), axis.getUnitsString(),
axis.getDescription());
//fill the new axis with the old data
replacementAxis.setCachedData(axis.read(), axis.isMetadata());
**then either use the replacementAxis or set the original axis =
replacementAxis**
Hopefully someone else will find this useful at some point!! Helps to get
rid of those whacky variable names (i.e. "xu_bem_ard", which is actually
"lon")!!
Chris
--
Christopher Mueller | Scientist
Applied Science Associates
70 Dean Knauss Drive | Narragansett, RI 02882 USA
p: +1 401-789-6224 | f: +1 401-789-1932
e: cmueller@xxxxxxxxxxxxxx | www.asascience.com
ASA | Science. Services. Solutions
Imagination is everything. It is the preview of life's coming attractions.
- Albert Einstein
Whether you think you can or think you can't, either way you are right. -
Henry Ford
> From: John Caron <caron@xxxxxxxxxxxxxxxx>
> Date: Sat, 26 Jan 2008 12:48:23 -0700
> To: Christopher Mueller <cmueller@xxxxxxxxxxxxxx>
> Cc: Java NetCDF <netcdf-java@xxxxxxxxxxxxxxxx>
> Subject: Re: [netcdf-java] Renaming CoordinateAxis
>
> Hi Chris:
>
> You cannot currently rename on output, but you can rename when reading the
> input with NcML:
>
> http://www.unidata.ucar.edu/software/netcdf/ncml/v2.2/Tutorial.html
>
> Christopher Mueller wrote:
>> Hi All,
>>
>> I¹m working with gridded datasets (for now) and am interested in
>> ³renaming² the coordinate axes for certain datasets. For example a
>> particular dataset has a ³latitude² coordinate axis called ³yu_ocean²
>> and a ³longitude² axis called ³xu_ocean². Is there a way to rename
>> these axes to ³lat² and ³lon² without completely rebuilding the nc file?
>> I¹m currently using:
>> FileWriter.writeVariables(List<Variable>); FileWriter.finish();
>>
>> To write the file and would like to do the ³rename² prior to these calls
>> when I am building the List<Variable> to pass to
>> FileWriter.writeVariables()....
>>
>> Is this possible?
>>
>> Thanks,
>> Chris
>>
>> --
>> *Christopher Mueller* | Scientist
>> Applied Science Associates
>> 70 Dean Knauss Drive | Narragansett, RI 02882 USA
>> p: +1 401-789-6224 | f: +1 401-789-1932
>> e: cmueller@xxxxxxxxxxxxxx | www.asascience.com
>>
>> *ASA **| Science. Services. Solutions
>> *
>> Imagination is everything. It is the preview of life's coming
>> attractions. - Albert Einstein
>>
>> Whether you think you can or think you can't, either way you are right.
>> - Henry Ford
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> netcdf-java mailing list
>> netcdf-java@xxxxxxxxxxxxxxxx
>> For list information or to unsubscribe, visit:
>> http://www.unidata.ucar.edu/mailing_lists/