Package ucar.nc2.dt

Examples of ucar.nc2.dt.TrajectoryObsDatatype


  private VerticalCT makeWRFEtaVerticalCoordinateTransform(NetcdfDataset ds, CoordinateSystem cs) {
    if ((null == ds.findVariable("PH")) || (null == ds.findVariable("PHB")) ||
        (null == ds.findVariable("P")) || (null == ds.findVariable("PB")))
      return null;

    WRFEtaTransformBuilder builder = new WRFEtaTransformBuilder(cs);
    return (VerticalCT) builder.makeCoordinateTransform(ds, null);
  }
View Full Code Here


  }
*/

  static private NetcdfFile acquireDODS(FileCache cache, FileFactory factory, Object hashKey,
                                        String location, int buffer_size, ucar.nc2.util.CancelTask cancelTask, Object spiObject) throws IOException {
    if (cache == null) return new DODSNetcdfFile(location, cancelTask);

    if (factory == null) factory = new DodsFactory();
    return (NetcdfFile) cache.acquire(factory, hashKey, location, buffer_size, cancelTask, spiObject);
  }
View Full Code Here

    return (NetcdfFile) cache.acquire(factory, hashKey, location, buffer_size, cancelTask, spiObject);
  }

  static private class DodsFactory implements FileFactory {
    public NetcdfFile open(String location, int buffer_size, ucar.nc2.util.CancelTask cancelTask, Object spiObject) throws IOException {
      return new DODSNetcdfFile(location, cancelTask);
    }
View Full Code Here

    Date startDate = trajDs.getStartDate();
    Date endDate = trajDs.getEndDate();
    System.out.println( "Dataset start date=" + startDate );
    System.out.println( "Dataset end date  =" + endDate );
    TrajectoryObsDatatype traj = trajDs.getTrajectory( "trajectory data");
    Date trajEndDate;
    Array presArray;
    try
    {
      trajEndDate = traj.getTime( traj.getNumberPoints() - 1);
      presArray = traj.getData( traj.getNumberPoints() - 1, "HADS_A");
    }
    catch ( IOException e )
    {
      assertTrue( "Failed to read last time or pressure from <" + testDataFileOut + ">: " + e.getMessage(),
                  false );
      return;
    }
    System.out.println( "Traj end date  =" + trajEndDate );
    System.out.println( "Pressure end value=" + presArray.getFloat( presArray.getIndex()));


    try
    {
      Thread.sleep( 10000 );
    }
    catch ( InterruptedException e )
    {
    }

    if ( ! trajDs.syncExtend() )
      System.out.println( "File not extended." );
    else
      System.out.println( "File extended" );

    startDate = trajDs.getStartDate();
    endDate = trajDs.getEndDate();
    System.out.println( "Start date=" + startDate );
    System.out.println( "End date  =" + endDate );

    try
    {
      trajEndDate = traj.getTime( traj.getNumberPoints() - 1 );
      presArray = traj.getData( traj.getNumberPoints() - 1, "HADS_A" );
    }
    catch ( IOException e )
    {
      assertTrue( "Failed to read last time or pressure from <" + testDataFileOut + ">: " + e.getMessage(),
                  false );
View Full Code Here

    // Check trajectory stuff.
    List trajNames = trajDs.getTrajectoryIds();
    assertTrue( "Number of trajectory names <" + trajNames.size() + "> more than expected <" + trajDsInfo.getNumTrajs() + ">.",
                trajNames.size() == trajDsInfo.getNumTrajs() );
    TrajectoryObsDatatype traj1 = trajDs.getTrajectory( trajDsInfo.getExTrajId() );
    assertTrue( "Trajectory name <" + traj1.getId() + "> not as expected <" + trajDsInfo.getExTrajId() + ">.",
                ( trajDsInfo.getExTrajId() == null
                  ? traj1.getId() == null
                  : trajDsInfo.getExTrajId().equals( traj1.getId() ) ) );

    assertTrue( "Trajectory description <" + traj1.getDescription() + "> not as expected <" + trajDsInfo.getExTrajDesc() + ">.",
                ( trajDsInfo.getExTrajDesc() == null
                  ? traj1.getDescription() == null
                  : trajDsInfo.getExTrajDesc().equals( traj1.getDescription() ) ) );

    assertTrue( "Number of points in trajectory <" + traj1.getNumberPoints() + "> not as expected <" + trajDsInfo.getExTrajNumPoints() + ">.",
                traj1.getNumberPoints() == trajDsInfo.getExTrajNumPoints() );

    // Check start and end values of time, lat, lon, and elev.
    Date startDate = null, endDate = null;
    double startLat = 0, startLon = 0, startElev = 0;
    double endLat = 0, endLon = 0, endElev = 0;

    try
    {
      startDate = traj1.getTime( 0 );
      startLat = traj1.getLatitude( 0 );
      startLon = traj1.getLongitude( 0 );
      startElev = traj1.getElevation( 0 );
      endDate = traj1.getTime( traj1.getNumberPoints() - 1 );
      endLat = traj1.getLatitude( traj1.getNumberPoints() - 1 );
      endLon = traj1.getLongitude( traj1.getNumberPoints() - 1 );
      endElev = traj1.getElevation( traj1.getNumberPoints() - 1 );
    }
    catch ( IOException e )
    {
      assertTrue( "Couldn't read first/last time, lat, lon, elev from trajectory.", false );
    }
    assertTrue( "Traj start date <" + startDate + " - " + startDate.getTime() + "> not as expected <" + trajDsInfo.getStartDateLong() + ">.",
                startDate.getTime() == trajDsInfo.getStartDateLong() );
    assertTrue( "Traj end date <" + endDate + " - " + endDate.getTime() + "> not as expected <" + trajDsInfo.getEndDateLong() + ">.",
                endDate.getTime() == trajDsInfo.getEndDateLong() );

    assertTrue( "Start latitude <" + startLat + "> not as expected <" + trajDsInfo.getExampleTrajStartLat() + ">.",
                doubleWithinEpsilon( startLat, trajDsInfo.getExampleTrajStartLat(), 0.0001 ) );
    assertTrue( "End latitude <" + endLat + "> not as expected <" + trajDsInfo.getExampleTrajEndLat() + ">.",
                doubleWithinEpsilon( endLat, trajDsInfo.getExampleTrajEndLat(), 0.0001 ) );

    assertTrue( "Start longitude <" + startLon + "> not as expected <" + trajDsInfo.getExampleTrajStartLon() + ">.",
                doubleWithinEpsilon( startLon, trajDsInfo.getExampleTrajStartLon(), 0.0001 ) );
    assertTrue( "End longitude <" + endLon + "> not as expected <" + trajDsInfo.getExampleTrajEndLon() + ">.",
                doubleWithinEpsilon( endLon, trajDsInfo.getExampleTrajEndLon(), 0.0001 ) );

    assertTrue( "Start elevation <" + startElev + "> not as expected <" + trajDsInfo.getExampleTrajStartElev() + ">.",
                doubleWithinEpsilon( startElev, trajDsInfo.getExampleTrajStartElev(), 0.0001 ) );
    assertTrue( "End elevation <" + endElev + "> not as expected <" + trajDsInfo.getExampleTrajEndElev() + ">.",
                doubleWithinEpsilon( endElev, trajDsInfo.getExampleTrajEndElev(), 0.0001 ) );

    // Check the first and last values of the example variable.
    Object exampleVarStartVal = null;
    Object exampleVarEndVal = null;
    try
    {
      Array array = traj1.getData( 0, trajDsInfo.getExampleVarName() );
      exampleVarStartVal = array.getObject( array.getIndex());
      array = traj1.getData( traj1.getNumberPoints() - 1, trajDsInfo.getExampleVarName() );
      exampleVarEndVal = array.getObject( array.getIndex());
    }
    catch ( Exception e )
    {
      assertTrue( "Failed to read start and end values of " + trajDsInfo.getExampleVarName() + ": " + e.getMessage(),
                  false );
    }
    assertTrue( "Example variable \"" + trajDsInfo.getExampleVarName()
                + "\" start value <" + exampleVarStartVal + "> not as expected <" + trajDsInfo.getExampleVarStartVal() + "> or " +
                "end value <" + exampleVarEndVal + "> not as expected <" + trajDsInfo.getExampleVarEndVal() + ">.",
                doubleWithinEpsilon( ((Float) trajDsInfo.getExampleVarStartVal()).doubleValue(), ((Float) exampleVarStartVal).doubleValue(), 0.0001)
                && doubleWithinEpsilon( ((Float) trajDsInfo.getExampleVarEndVal()).doubleValue(), ((Float) exampleVarEndVal).doubleValue(), 0.0001 ) );
//    assertTrue( "Variables' first two values <" + windSpd[0] + "," + windSpd[1] + "> not as expected <" + varVals[0] + "," + varVals[1] + ">.",
//                windSpd[0] == varVals[0] && windSpd[1] == varVals[1] );

    // Test with getPointObsData()
    PointObsDatatype pointOb;
    try
    {
      pointOb = (PointObsDatatype) traj1.getPointObsData( 0 );
    }
    catch ( IOException e )
    {
      assertTrue( "IOException on call to getPointObsData(0): " + e.getMessage(),
                  false);
      return;
    }
    assertTrue( "Start time (getPointObsData) <" + pointOb.getNominalTimeAsDate().getTime() + "> not as expected <" + trajDsInfo.getStartDateLong() + ">.",
                pointOb.getNominalTimeAsDate().getTime() == trajDsInfo.getStartDateLong() );
    assertTrue( "Start lat (getPointObsData) <" + pointOb.getLocation().getLatitude() + "> not as expected <" + trajDsInfo.getExampleTrajStartLat() + ">.",
                doubleWithinEpsilon( pointOb.getLocation().getLatitude(), trajDsInfo.getExampleTrajStartLat(), 0.0001 ) );
    assertTrue( "Start lon (getPointObsData) <" + pointOb.getLocation().getLongitude() + "> not as expected <" + trajDsInfo.getExampleTrajStartLon() + ">.",
                doubleWithinEpsilon( pointOb.getLocation().getLongitude(), trajDsInfo.getExampleTrajStartLon(), 0.0001 ) );
    assertTrue( "Start alt (getPointObsData) <" + pointOb.getLocation().getAltitude() + "> not as expected <" + trajDsInfo.getExampleTrajStartElev() + ">.",
                doubleWithinEpsilon( pointOb.getLocation().getAltitude(), trajDsInfo.getExampleTrajStartElev(), 0.0001 ) );

    // Test with
    StructureData sdata;
    try
    {
      sdata = traj1.getData( 0);
    }
    catch ( IOException e )
    {
      assertTrue( "IOException on getData(0): " + e.getMessage(),
                  false);
      return;
    }
    catch ( InvalidRangeException e )
    {
      assertTrue( "InvalidRangeException on getData(0): " + e.getMessage(),
                  false );
      return;
    }
    assertTrue( "Null StructureData from getData(0).",
                sdata != null);

    // Test with getDataIterator()
    DataIterator it;
    try
    {
      it = traj1.getDataIterator( 0);
    }
    catch ( IOException e )
    {
      assertTrue( "IOException on call to trajectory.getDataIterator(): " + e.getMessage(),
                  false);
View Full Code Here

                    numTrajs, exampleTrajId, exampleTrajDesc, exampleTrajNumPoints,
                    exampleTrajStartLat, exampleTrajEndLat, exampleTrajStartLon, exampleTrajEndLon, exampleTrajStartElev, exampleTrajEndElev);

    TestTrajectoryObsDataset.testTrajInfo( me, trajDsInfo );

    TrajectoryObsDatatype traj = me.getTrajectory( exampleTrajId);

    // Test that "alt" units gets changed to "meters"
    // ... from getPointObsData(0)
    PointObsDatatype pointOb;
    try
    {
      pointOb = (PointObsDatatype) traj.getPointObsData( 0 );
    }
    catch ( IOException e )
    {
      assertTrue( "IOException on call to getPointObsData(0): " + e.getMessage(),
                  false );
      return;
    }
    StructureData sdata;
    try
    {
      sdata = pointOb.getData();
    }
    catch ( IOException e )
    {
      assertTrue( "IOException on getData(): " + e.getMessage(),
                  false);
      return;
    }

    String u = sdata.findMember( "alt").getUnitsString();
    assert u.equals( "meters") : "traj.getPointObsData().getData().findMember( \"alt\") units <" + u + "> not as expected";
    //assertTrue( "traj.getPointObsData().getData().findMember( \"alt\") units <" + u + "> not as expected <meters>.",
    //            u.equals( "meters") );

    // ... from getData(0)
    try
    {
      sdata = traj.getData( 0 );
    }
    catch ( IOException e )
    {
      assertTrue( "IOException on getData(0): " + e.getMessage(),
                  false );
View Full Code Here

  public GridCoordSys getGridCoordSys(VariableEnhanced ve) {
    List<CoordinateSystem> csList = ve.getCoordinateSystems();
    for (CoordinateSystem cs : csList) {
      if (GridCoordSys.isGridCoordSys(null, cs, ve)) {
        return new GridCoordSys(cs, null);
      }
    }
    return null;
  }
View Full Code Here

    List<CoordinateSystem> csList = ds.getCoordinateSystems();
    for (CoordinateSystem cs : csList) {
      Element csElem;
      if (GridCoordSys.isGridCoordSys(null, cs, null)) {
        GridCoordSys gcs = new GridCoordSys(cs, null);
        csElem = new Element("gridCoordSystem");
        csElem.setAttribute("name", cs.getName());
        csElem.setAttribute("horizX", gcs.getXHorizAxis().getFullName());
        csElem.setAttribute("horizY", gcs.getYHorizAxis().getFullName());
        if (gcs.hasVerticalAxis())
          csElem.setAttribute("vertical", gcs.getVerticalAxis().getFullName());
        if (gcs.hasTimeAxis())
          csElem.setAttribute("time", cs.getTaxis().getFullName());
      } else {
        csElem = new Element("coordSystem");
        csElem.setAttribute("name", cs.getName());
      }

      List<CoordinateTransform> coordTransforms = cs.getCoordinateTransforms();
      for (CoordinateTransform ct : coordTransforms) {
        Element ctElem = new Element("coordTransform");
        csElem.addContent(ctElem);
        ctElem.setAttribute("name", ct.getName());
        ctElem.setAttribute("type", ct.getTransformType().toString());
      }

      rootElem.addContent(csElem);
    }

    List<CoordinateTransform> coordTransforms = ds.getCoordinateTransforms();
    for (CoordinateTransform ct : coordTransforms) {
      Element ctElem = new Element("coordTransform");
      rootElem.addContent(ctElem);

      ctElem.setAttribute("name", ct.getName());
      ctElem.setAttribute("type", ct.getTransformType().toString());
      List<Parameter> params = ct.getParameters();
      for (Parameter pp : params) {
        Element ppElem = new Element("param");
        ctElem.addContent(ppElem);
        ppElem.setAttribute("name", pp.getName());
        ppElem.setAttribute("value", pp.getStringValue());
      }
    }

    for (Variable var : ds.getVariables()) {
      VariableEnhanced ve = (VariableEnhanced) var;
      if (ve instanceof CoordinateAxis) continue;
      GridCoordSys gcs = getGridCoordSys(ve);
      if (null != gcs) {
        nDataVariables++;
        Element gridElem = new Element("grid");
        rootElem.addContent(gridElem);

        gridElem.setAttribute("name", ve.getFullName());
        gridElem.setAttribute("decl", getDecl(ve));
        if (ve.getUnitsString() != null) {
          gridElem.setAttribute("units", ve.getUnitsString());
          gridElem.setAttribute("udunits", isUdunits(ve.getUnitsString()));
        }
        gridElem.setAttribute("coordSys", gcs.getName());
      }
    }

    for (Variable var : ds.getVariables()) {
      VariableEnhanced ve =  (VariableEnhanced) var;
      if (ve instanceof CoordinateAxis) continue;
      GridCoordSys gcs = getGridCoordSys(ve);
      if (null == gcs) {
        nOtherVariables++;
        Element elem = new Element("variable");
        rootElem.addContent(elem);
View Full Code Here

    try
    {
      File dir = new File( getDiskCache().getRootDirectory() );
      File ncFile = File.createTempFile( "WCS", ".nc", dir );

      NetcdfCFWriter writer = new NetcdfCFWriter();
      writer.makeFile( ncFile.getPath(), dataset,
                       Collections.singletonList( identifier ), null, null,
  //                     Collections.singletonList( req.getCoverage() ),
  //                     req.getBoundingBox(), dateRange,
                       true, 1, 1, 1 );
      return ncFile;
View Full Code Here

     * @param args filename
     *
     * @throws IOException  problem reading file
     */
    public static void main(String[] args) throws IOException {
        IOServiceProvider mciosp = new McIDASGridServiceProvider();
        RandomAccessFile  rf     = new RandomAccessFile(args[0], "r", 2048);
        NetcdfFile ncfile = new MakeNetcdfFile(mciosp, rf, args[0], null);
    }
View Full Code Here

TOP

Related Classes of ucar.nc2.dt.TrajectoryObsDatatype

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.