[visad] Convert Netcdf content to visad object in order generate contours coordinates

  • To: Tom Whittaker <whittaker@xxxxxxxx>
  • Subject: [visad] Convert Netcdf content to visad object in order generate contours coordinates
  • From: Jose Carro <joandca@xxxxxxxxx>
  • Date: Wed, 3 Jul 2013 23:16:53 -0300
Hi Tom
Using the below Jython code I was able to draw contours for 3,5,7....24
degrees Celsius.
Now I have to identify points that are inside each contours to apply
specific functions depending on the contour they are.
Do you know how I can get contour coordinates?
If you think I should do it in a different way please let me know.
Regards
Jose

import ucar.visad.display.ContourLines as cLines
import visad.ContourControl as ContourControl
import ucar.visad.display.Contour2DDisplayable as Contour2DDisplayable
import ucar.unidata.util.ContourInfo as ContourInfo
import visad.Contour2D as Contour2D

filename = 'd:/mymodel.nc'
file_opener = 'file.grid'
variable = 'sst'
ds = makeDataSource(filename, file_opener)
display_type = 'planviewcontour'
image_dimensions = (800, 600)
setOffScreen(1)
idv.getStateManager().setViewSize(java.awt.Dimension(image_dimensions[0],
image_dimensions[1]))
temperaturas = getData(ds.getName(), variable)
dc=createDisplay(display_type, temperaturas)
cInfo =
ContourInfo('3.0;5.0;7.0;10.0;12.0;15.0;18.0;20.0;22.0;24.0',0.0,0.0,24.0,1,0,1,1.0)
dc.setContourInfo(cInfo)


2013/7/3 Tom Whittaker <whittaker@xxxxxxxx>
>
>> Hi Jose...
>>
>> Thanks for the background information.
>>
>> Have you considered writing your formula using Jython (Python)?  It is
>> very well integrated into the IDV and there are many, many functions
>> available that would allow you to, for example, obtain the latitude
>> and longitude of the grid points, and get an array of the data where
>> you could apply the algorithm and fill up a 3D array with values,
>> which you would then have to use to create a new FlatField.
>>
>> Even if you code this in Java, I would still recommend that you
>> consider using the IDV to read the data and then call your method
>> to do the computations and create the new data field for display.
>>
>> The "netCDF file adapter" in the VisAD library uses a very old version of
>> the netCDF library and may not understand the structure of the data in
>> your file.  We do not have the resources to re-write that code.
>>
>> Good luck.
>>
>> tom
>>
>> On Tue, Jul 2, 2013 at 3:27 PM, Jose Carro <joandca@xxxxxxxxx> wrote:
>> > Hi Tom
>> >
>> > Thanks for your quick response.
>> > I already tested my nc file in IDV and I was able to draw beautiful
>> > contours.
>> >
>> > The problem is that for my region (South America), specifically coast of
>> > Uruguay and Argentine, we have sea surface temperature data but missing
>> > measures for different depths.
>> >
>> > I am working with a local professor who developed a formula function,
>> where
>> > he can get the approximate temperature for different depths based on SST
>> > isotherms.
>> >
>> > I am trying to develop a Java application using Visad libraries. This
>> > program should read the 2D Netcdf. Calculate the contours for different
>> > temperatures and depending on the lat.lon of each point I would apply a
>> > specific formula. That’s why I need the contours coordinates (each point
>> > lat,lon) for each coordinate in order to apply different formulas for
>> > different points depending between what contours they are. (I understand
>> > that class Conrourd2D can provide x,y for each points of the contours)
>> >
>> > With a new 3d array I plan to create a 3D Netcdf in order to be
>> imported to
>> > IDV.
>> >
>> > I hope it clarifies my requirements.
>> >
>> > I will investigate the information you provided me.
>> >
>> > Thanks
>> >
>> > Jose
>> >
>> >
>> >
>> > 2013/7/2 Tom Whittaker <whittaker@xxxxxxxx>
>> >>
>> >> Hello Jose...
>> >>
>> >> Unless you need to write Java code, you might consider using a
>> >> higher-level application like McIDAS-V (which is based on the
>> >> IDV...which, in turn, uses the VisAD library for it's data model and
>> >> display).  If your file is truly CF-compliant, then either of these
>> >> applications would be able to display contour lines.  Both
>> >> applications are freely available -- for McIDAS-V, go to:
>> >> <http://www.ssec.wisc.edu/mcidas/software/v/download.html>.  The IDV
>> >> homepage is: <http://www.unidata.ucar.edu/software/idv/>.
>> >>
>> >> If you must write your own code, you can look in the examples in the
>> >> VisAD library in the various "File Adapters", or in some of the
>> >> "field" methods defined in the JPythonMethods which create FlatFields,
>> >> for examples.  In addition, the VisAD Develooper's Guide and the Data
>> >> Tutorial will be helpful.
>> >>
>> >> tom
>> >>
>> >>
>> >> On Tue, Jul 2, 2013 at 10:49 AM, Jose Carro <joandca@xxxxxxxxx> wrote:
>> >> > Dear visad group
>> >> > I am totally new in visad library and netcdf manipulation.
>> >> > The file I am trying to manipulate has this features:
>> >> >
>> >> > Netcdfile follows the convention CF-1.0
>> >> > type: Time -> ((Longitude, Latitude, zlev) -> (sst, anom, err, ice)
>> >> > It is 2D because zlev is 0.
>> >> >
>> >> > I wrote a small java program where I can read a Netcdf file and list
>> >> > values
>> >> > following some examples from netcdf library,
>> >> > My question is how can I transform this array into a format that
>> visad
>> >> > can
>> >> > understand. As instance FieldImpl.
>> >> > My goal is to get isotherms (contours) lat,lon using some visad
>> contour
>> >> > class.
>> >> > Thanks in advance
>> >> > Jose
>> >> > code:
>> >> >
>> >> > dataFile=NetcdfFile.open("d:/mymodel.nc");
>> >> > Variable tempVar = dataFile.findVariable("sst");
>> >> > if (tempVar == null) {
>> >> > System.out.println("Cant find Variable sst");
>> >> > return;
>> >> > }else{
>> >> > // read variable
>> >> > int [] shape = tempVar.getShape();
>> >> >   int recLen = shape[0]; // number of times
>> >> >   int[] origin = new int[4];
>> >> >    shape[0] = 1; // only one rec per read
>> >> >
>> >> >    // loop over the rec dimension
>> >> >    for (int rec = 0; rec < recLen; rec++) {
>> >> >     origin[0] = rec;  // read this index
>> >> >     // Get the lat/lon data from the file.
>> >> >     ArrayShort.D2 tempArray = null;
>> >> >     try {
>> >> > tempArray = (ArrayShort.D2) (tempVar.read(origin, shape).reduce());
>> >> > } catch (InvalidRangeException e) {
>> >> > // TODO Auto-generated catch block
>> >> > e.printStackTrace();
>> >> > }
>> >> >
>> >> >
>> >> >     // now checking the value
>> >> >     for (int lvl = 0; lvl < NLVL; lvl++)
>> >> >     for (int lat = 0; lat < NLAT; lat++)
>> >> >     for (int lon = 0; lon < NLON; lon++) {
>> >> >     // System.out.println(tempArray.get(1,1, lat, lon));
>> >> >     System.out.println("Longitude:" + lon);
>> >> >     System.out.println("Latitude:" + lat);
>> >> >     System.out.println("Temp:" + Float.toString(tempArray.get(lat,
>> >> > lon)));
>> >> >     }
>> >> >    }
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > _______________________________________________
>> >> > visad mailing list
>> >> > visad@xxxxxxxxxxxxxxxx
>> >> > For list information, to unsubscribe, visit:
>> >> > http://www.unidata.ucar.edu/mailing_lists/
>> >>
>> >>
>> >>
>> >> --
>> >> Tom Whittaker
>> >> University of Wisconsin-Madison
>> >> Space Science & Engineering Center (SSEC)
>> >> Cooperative Institute for Meteorological Satellite Studies (CIMSS)
>> >> 1225 W. Dayton Street
>> >> Madison, WI  53706  USA
>> >> ph: +1 608 262 2759
>> >
>> >
>>
>>
>>
>> --
>> Tom Whittaker
>> University of Wisconsin-Madison
>> Space Science & Engineering Center (SSEC)
>> Cooperative Institute for Meteorological Satellite Studies (CIMSS)
>> 1225 W. Dayton Street
>> Madison, WI  53706  USA
>> ph: +1 608 262 2759
>>
>
>
  • 2013 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: