Greetings all,
I have a basic netCDF file with data:
(Latitude, Longitude) -> Altitude.
The output in this format looks like this:
http://www.cimms.ou.edu/~kmanross/VCPRPE/kiwaTerrain2D.gif
Using the BoM package's Radar2DCoordinateSystem, I want to change the
domain of the netCDF file from (Latitude, Longitude) to (Azimuth, Range)
for easier overall computation.
I realize that the output from the
Radar2DCoordinateSystem.fromReference() method is in (Range, Azimuth).
Additionally, I found out that when obtaining the DomainSet samples from
the original netCDF files, they actually come as (Longitude, Latitude)
and I have rearranged these for input to the Radar2DCoordinateSystem method.
When I do this, my output looks like this:
http://www.cimms.ou.edu/~kmanross/VCPRPE/kiwaTerrain2D-polar.gif
and when displaying the coordinates by clicking the middle mouse button,
I find that the 0 degree azimuth is along the right side of the display.
This makes some sense as the image appears to be "flipped over" and
rotated 90 degreesclockwise.
My code is attached below and I have been trying almost anything I can
think of to correct this problem. I would greatly appreciate any help
on this! If you want to run the script, the netCDF file can be found at:
(Shift + Right Click the link below)
http://www.cimms.ou.edu/~kmanross/VCPRPE/kiwaTerrain-test.nc
Thank you very much!
-kevin
########################################################################
import visad.*;
import visad.java3d.*;
import visad.data.netcdf.Plain;
import visad.bom.Radar2DCoordinateSystem;
import java.rmi.RemoteException;
import java.io.IOException;
import java.awt.*;
import javax.swing.*;
public class displayTerrain_v2
{
protected static final float cLat = 33.289f;
protected static final float cLon = -111.67f;
public static void main(String[] args) throws VisADException,
RemoteException,
IOException
{
Radar2DCoordinateSystem radarCoords = new
Radar2DCoordinateSystem(cLat, cLon);
// netCDF reader
Plain ncReader = new Plain();
// read the netCDF file into a data object (FlatField)
FlatField terrainData_ff = (FlatField)
ncReader.open("kiwaTerrain-test.nc");
// Get domain data
float d[][] = terrainData_ff.getDomainSet().getSamples();
/*
// Attempt to get domain data in exact order
float d[][] = terrainData_ff.getDomainSet().indexToValue(
terrainData_ff.getDomainSet().getWedge() );
*/
// Note: Domain data extracted from FlatField is lon/lat
// even though data in *.nc file are lat/lon.
// Radar2DCoordinateSystem.fromReference() requires lat/lon
// Switch order below
float[][] dom = new float[2][ d[0].length ];
dom[0] = d[1];
dom[1] = d[0];
// Get range (alt) data from FlatField
float ran[][] = terrainData_ff.getFloats();
// Feed lat/lon from FlatField domain into Radar2DCoordinateSystem
to get
// domain now in polar coords (range/azimuth)
float[][] azRanDomain = radarCoords.fromReference(dom);
// Create RealTypes
RealType azimuth = RealType.getRealType("Azimuth",
CommonUnit.degree, null);
RealType range = RealType.getRealType("Range", CommonUnit.meter, null);
RealType altitude = RealType.getRealType("Alititude",
CommonUnit.meter, null);
// Create RealTupleType
// Note: order (ran/az) since this is the order of the
Radar2DCoordinateSystem
// output
RealTupleType azRanTT = new RealTupleType(range, azimuth);
Gridded2DSet azRanSet = new Gridded2DSet(azRanTT, azRanDomain,
azRanDomain[0].length);
// Create new FunctionType for new FlatField: (range, azimuth) ->
altitude
FunctionType azRanFType = new FunctionType(azRanTT, altitude);
FlatField azRan_ff = new FlatField(azRanFType, azRanSet);
azRan_ff.setSamples(ran);
DataReferenceImpl refTerrainData = new
DataReferenceImpl("TerrainData");
refTerrainData.setData(azRan_ff);
// create a simple display for viewing the data
DisplayImplJ3D display = new DisplayImplJ3D("TerrainDisplay",
new TwoDDisplayRendererJ3D());
display.clearMaps();
// Show axis labels
GraphicsModeControl dispGMC =
(GraphicsModeControl)display.getGraphicsModeControl();
dispGMC.setScaleEnable(true);
// Create ScalarMaps
ScalarMap azMap = new ScalarMap(azimuth, Display.Longitude);
ScalarMap ranMap = new ScalarMap(range, Display.Radius);
ScalarMap altMap = new ScalarMap(altitude, Display.RGB);
// Add ScalarMaps to display
display.addMap(azMap);
display.addMap(ranMap);
display.addMap(altMap);
// Add DataReference to display
display.addReference(refTerrainData);
// create a JFrame
JFrame frame = new JFrame("Terrain");
// link the display to the frame
frame.getContentPane().add(display.getComponent());
// set size of frame and make it visible
frame.setSize(600, 600);
frame.setVisible(true);
}
}
##################################################################
--
+------------------------------------------------------------+
Kevin L. Manross [KD5MYD] (405)-366-0557
CIMMS Research Associate kevin.manross@xxxxxxxx
[NSSL-WRDD/SWATN] http://www.cimms.ou.edu/~kmanross
"My opinions are my own and not representative of CIMMS, NSSL,
NOAA or any affiliates"
+------------------------------------------------------------+