Package com.google.test.metric

Examples of com.google.test.metric.MetricComputerTest$Array


                    gradsDDF.getEnsembleDimension().getEnsembleNames();
                String[] nameArray = new String[names.size()];
                for (int i = 0; i < nameArray.length; i++) {
                    nameArray[i] = names.get(i);
                }
                Array dataArray = Array.factory(DataType.STRING,
                                      new int[] { nameArray.length },
                                      nameArray);
                v.setCachedData(dataArray, false);
            } else {
                double[] vals = dim.getValues();
View Full Code Here


     * @throws InvalidRangeException invalid Range
     */
    public Array readData(Variable v2, Section section)
            throws IOException, InvalidRangeException {

        Array dataArray = Array.factory(DataType.FLOAT, section.getShape());
        GradsVariable gradsVar = findVar(v2);

        // Canonical ordering is ens, time, level, lat, lon
        int           rangeIdx  = 0;
        Range         ensRange  = (gradsDDF.getEnsembleDimension() != null)
                                  ? section.getRange(rangeIdx++)
                                  : new Range(0, 0);
        Range         timeRange = (section.getRank() > 2)
                                  ? section.getRange(rangeIdx++)
                                  : new Range(0, 0);
        Range         levRange  = (gradsVar.getNumLevels() > 0)
                                  ? section.getRange(rangeIdx++)
                                  : new Range(0, 0);
        Range         yRange    = section.getRange(rangeIdx++);
        Range         xRange    = section.getRange(rangeIdx);

        IndexIterator ii        = dataArray.getIndexIterator();

        // loop over ens
        for (int ensIdx = ensRange.first(); ensIdx <= ensRange.last();
                ensIdx += ensRange.stride()) {
            //loop over time
View Full Code Here

    taxis.setDimensions("time");
    taxis.addAttribute( new Attribute("long_name", "time since base date"));
    taxis.addAttribute( new Attribute(_Coordinate.AxisType, AxisType.Time.toString()));
    double [] tdata = new double[1];
    tdata[0] = cal.getTimeInMillis();
    Array dataA = Array.factory(DataType.DOUBLE.getPrimitiveClassType(), new int[] {1}, tdata);
    taxis.setCachedData( dataA, false);
    DateFormatter formatter = new DateFormatter();
    taxis.addAttribute( new Attribute("units", "msecs since "+formatter.toDateTimeStringISO(new Date(0))));
    ncfile.addVariable(null, taxis);

    //att = new Attribute( "Time", dstring);
    //this.ncfile.addAttribute(null, att);
    this.ncfile.addAttribute(null, new Attribute("time_coverage_start", dstring));
    this.ncfile.addAttribute(null, new Attribute("time_coverage_end", dstring));
    bos.get();   /* skip a byte for hundreds of seconds */

    nv   = new Byte ( bos.get());
    att = new Attribute( "ProjIndex", nv);
    this.ncfile.addAttribute(null, att);
    proj = nv.intValue();
    if( proj == 1) {
     att = new Attribute( "ProjName", "MERCATOR");
    } else if (proj == 3) {
     att = new Attribute( "ProjName", "LAMBERT_CONFORNAL");
    } else if (proj == 5) {
     att = new Attribute( "ProjName", "POLARSTEREOGRAPHIC");
    }

    this.ncfile.addAttribute(null, att);

    /*
    ** Get grid dimensions
    */

    byte[] b3 = new byte[3];
    bos.get(b2, 0, 2);
    nx = getInt( b2, 2);
    Integer ni = new Integer(nx);
    att = new Attribute( "NX", ni);
    this.ncfile.addAttribute(null, att);


    bos.get(b2, 0, 2);
    ny = getInt( b2, 2);
    ni = new Integer(ny);
    att = new Attribute( "NY", ni);
    this.ncfile.addAttribute(null, att);

    ProjectionImpl projection = null;
    double dxKm = 0.0, dyKm = 0.0, latin, lonProjectionOrigin ;

    switch( proj ) {

      case 1:                                                    /* Mercator */
        /*
        ** Get the latitude and longitude of first and last "grid" points
        */

        /* Latitude of first grid point */
        bos.get(b3, 0, 3);
        int nn = getInt( b3, 3);
        lat1 = (double) nn / 10000.0;
        Double nd = new Double(lat1);
        att = new Attribute( "Latitude0", nd);
        this.ncfile.addAttribute(null, att);

        bos.get(b3, 0, 3);
        nn = getInt( b3, 3);
        int b33 = (int)(b3[0] & (1<< 7));
      //  if( b33 == 128)      //west longitude
      //      nd = new Double(((double) nn) / 10000.0 * (-1));
      //  else
            nd = new Double(((double) nn) / 10000.0 );
        lon1 = nd.doubleValue();
        att = new Attribute( "Longitude0", nd);
        this.ncfile.addAttribute(null, att);

        /* Longitude of last grid point */
        bos.get(); /* skip one byte */

        bos.get(b3, 0, 3);
        nn = getInt( b3, 3);
        nd = new Double( ((double) nn) / 10000.0);
        lat2 = nd.doubleValue();
        att = new Attribute( "LatitudeN", nd);
        this.ncfile.addAttribute(null, att);

        bos.get(b3, 0, 3);
        nn = getInt( b3, 3);
        b33 = (int)(b3[0] & (1<< 7));
       // if( b33 == 128)      //west longitude
      //      nd = new Double(((double) nn) / 10000.0 * (-1));
      //  else
            nd = new Double(((double) nn) / 10000.0 );
        lon2 = nd.doubleValue();
        att = new Attribute( "LongitudeN", nd);
        this.ncfile.addAttribute(null, att);

        /*
        ** Hack to catch incorrect sign of lon2 in header.
        */

    //    if ( lon1 > 0.0 && lon2 < 0.0 ) lon2 *= -1;
        double lon_1 = lon1;
        double lon_2 = lon2;
        if ( lon1 < 0 ) lon_1 += 360.0;
        if ( lon2 < 0 ) lon_2 += 360.0;

        lonv = lon_1 - (lon_1 - lon_2) / 2.0;

        if ( lonv >  180.0 ) lonv -= 360.0;
        if ( lonv < -180.0 ) lonv += 360.0;
        /*
        ** Get the "Latin" parameter.  The ICD describes this value as:
        ** "Latin - The latitude(s) at which the Mercator projection cylinder
        ** intersects the earth."  It should read that this is the latitude
        ** at which the image resolution is that defined by octet 41.
        */
        bos.getInt(); /* skip 4 bytes */
        bos.get();    /* skip 1 byte */

        bos.get(b3, 0, 3);
        nn = getInt( b3, 3);
        nd = new Double(((double) nn) / 10000.0);

        /* Latitude of proj cylinder intersects */
        att = new Attribute( "LatitudeX", nd);
        latin = nd.doubleValue();
        this.ncfile.addAttribute(null, att);

        latt = 0.0; // this is not corrected  // jc 8/7/08 not used

       // dyKm =  Math.cos( DEG_TO_RAD*latt);
       // dxKm = DEG_TO_RAD * EARTH_RAD_KMETERS * Math.abs((lon_1-lon_2) / (nx-1));
      //  double dy  =  EARTH_RAD_KMETERS * Math.cos(DEG_TO_RAD*latt) / (ny - 1);
      //  dyKm = dy *( Math.log( Math.tan(DEG_TO_RAD*( (lat2-latt)/2.0 + 45.0 ) ) )
      //                  -Math.log( Math.tan(DEG_TO_RAD*( (lat1-latt)/2.0 + 45.0 ) ) ) );
      //  dxKm = DEG_TO_RAD * EARTH_RAD_KMETERS * Math.abs(lon1-lon2) / (ny-1);
        projection = new Mercator( lonv, latin) ;
        break;

      case 3:                               /* Lambert Conformal             */
      case 5:                               /* Polar Stereographic           */
        /*
        ** Get lat/lon of first grid point
        */
        bos.get(b3, 0, 3);
        nn = getInt( b3, 3);
        nd = new Double(((double) nn) / 10000.0);
        lat1 = nd.doubleValue();
        //att = new Attribute( "Lat1", nd);
        //this.ncfile.addAttribute(null, att);
        bos.get(b3, 0, 3);
        nn = getInt( b3, 3);
        nd = new Double(((double) nn) / 10000.0);
        lon1 = nd.doubleValue();
        /*
        ** Get Lov - the orientation of the grid; i.e. the east longitude of
        ** the meridian which is parallel to the y-aixs
        */
        bos.get(); /* skip one byte */

        bos.get(b3, 0, 3);
        nn = getInt( b3, 3);
        nd = new Double(((double) nn) / 10000.0);
        lonv = nd.doubleValue();
        lonProjectionOrigin = lonv;
        att = new Attribute( "Lov", nd);
        this.ncfile.addAttribute(null, att);

        /*
        ** Get distance increment of grid
        */
        bos.get(b3, 0, 3);
        nn = getInt( b3, 3);
        dxKm = ((double) nn) / 10000.0;

        nd = new Double(((double) nn) / 10000.);
        att = new Attribute( "DxKm", nd);
        this.ncfile.addAttribute(null, att);

        bos.get(b3, 0, 3);
        nn = getInt( b3, 3);
        dyKm = ((double) nn) / 10000.0;

        nd = new Double( ((double) nn) / 10000.);
        att = new Attribute( "DyKm", nd);
        this.ncfile.addAttribute(null, att);
        /* calculate the lat2 and lon2 */

        if ( proj == 5 ) {
            latt = 60.0;            /* Fixed for polar stereographic */
            imageScale = (1. + Math.sin(DEG_TO_RAD*latt))/2.;
        }

        lat2 = lat1 + dyKm*(ny-1) / 111.26;


        /* Convert to east longitude */
        if ( lonv < 0. ) lonv += 360.;
        if ( lon1 < 0. ) lon1 += 360.;


        lon2 = lon1 + dxKm*(nx-1) / 111.26 * Math.cos(DEG_TO_RAD*lat1);

        diff_lon = lonv - lon1;

        if ( diff_lon >  180. diff_lon -= 360.;
        if ( diff_lon < -180. diff_lon += 360.;
        /*
        ** Convert to normal longitude to McIDAS convention
        */
        lonv = (lonv > 180.) ? -(360.-lonv) : lonv;
        lon1 = (lon1 > 180.) ? -(360.-lon1) : lon1;
        lon2 = (lon2 > 180.) ? -(360.-lon2) : lon2;
        /*
        ** Check high bit of octet for North or South projection center
        */
        nv= new Byte(bos.get());
        pole = nv.intValue();
        pole = ( pole > 127 ) ? -1 : 1;
        ni = new Integer(pole);
        att = new Attribute( "ProjCenter", ni);
        this.ncfile.addAttribute(null, att);

        bos.get(); /* skip one byte for Scanning mode */

        bos.get(b3, 0, 3);
        nn = getInt( b3, 3);
        latin = (((double) nn) / 10000.);

        nd = new Double(((double) nn) / 10000.);
        att = new Attribute( "Latin", nd);
        this.ncfile.addAttribute(null, att);

        if (proj == 3 )
          projection = new LambertConformal(latin, lonProjectionOrigin, latin, latin);
        else // (proj == 5)
          projection = new Stereographic(90.0, lonv, imageScale);

        break;

      default:
        System.out.println("unimplemented projection");


    }


    this.ncfile.addAttribute(null, new Attribute("title", gini_GetEntityID( ent_id )));
    this.ncfile.addAttribute(null, new Attribute("summary", getPhysElemSummary(phys_elem, ent_id)));
    this.ncfile.addAttribute(null, new Attribute("id", gini_GetSectorID(sec_id)));
    this.ncfile.addAttribute(null, new Attribute("keywords_vocabulary", gini_GetPhysElemID(phys_elem, ent_id)));
    this.ncfile.addAttribute(null, new Attribute("cdm_data_type", FeatureType.GRID.toString()));
    this.ncfile.addAttribute(null, new Attribute("standard_name_vocabulary", getPhysElemLongName(phys_elem, ent_id)));
    this.ncfile.addAttribute(null, new Attribute("creator_name", "UNIDATA"));
    this.ncfile.addAttribute(null, new Attribute("creator_url", "http://www.unidata.ucar.edu/"));
    this.ncfile.addAttribute(null, new Attribute("naming_authority", "UCAR/UOP"));
    this.ncfile.addAttribute(null, new Attribute("geospatial_lat_min", new Float(lat1)));
    this.ncfile.addAttribute(null, new Attribute("geospatial_lat_max", new Float(lat2)));
    this.ncfile.addAttribute(null, new Attribute("geospatial_lon_min", new Float(lon1)));
    this.ncfile.addAttribute(null, new Attribute("geospatial_lon_max", new Float(lon2)));
    //this.ncfile.addAttribute(null, new Attribute("geospatial_vertical_min", new Float(0.0)));
    //this.ncfile.addAttribute(null, new Attribute("geospatial_vertical_max", new Float(0.0)));

    /** Get the image resolution.
    */

    bos.position(41)/* jump to 42 bytes of PDB */
    nv = new Byte( ( bos.get() ) );      /* Res [km] */
    att = new Attribute( "imageResolution", nv);
    this.ncfile.addAttribute(null, att);
   // if(proj == 1)
   //     dyKm = nv.doubleValue()/dyKm;
    /* compression flag 43 byte */

    nv = new Byte( ( bos.get() ));      /* Res [km] */
    att = new Attribute( "compressionFlag", nv );
    this.ncfile.addAttribute(null, att);

    if ( convertunsignedByte2Short( nv.byteValue() ) == 128 )
    {
       Z_type = 2;
       //out.println( "ReadNexrInfo:: This is a Z file ");
    }

   /* new 47 - 60 */
    bos.position(46);
    nv = new Byte( ( bos.get() ) );      /* Cal indicator */
    int navcal = convertunsignedByte2Short(nv);
    int [] calcods = null;
    if(navcal == 128)
        calcods = getCalibrationInfo(bos, phys_elem, ent_id);

    // only one data variable per gini file

    String vname= gini_GetPhysElemID(phys_elem, ent_id);
    Variable var = new Variable( ncfile, ncfile.getRootGroup(), null, vname);
    var.addAttribute( new Attribute("long_name", getPhysElemLongName(phys_elem, ent_id)));
    var.addAttribute( new Attribute("units", getPhysElemUnits(phys_elem, ent_id)));
    // var.addAttribute( new Attribute("missing_value", new Byte((byte) 0))); // ??

      // get dimensions
    int velems;
    boolean isRecord = false;
    ArrayList dims = new ArrayList();

    Dimension dimX  = new Dimension( "x", nx, true, false, false);
    Dimension dimY  = new Dimension( "y", ny, true, false, false);

    ncfile.addDimension( null, dimY);
    ncfile.addDimension( null, dimX);

    velems = dimX.getLength() * dimY.getLength();
    dims.add( dimT);
    dims.add( dimY);
    dims.add( dimX);

    var.setDimensions( dims);

    // size and beginning data position in file
    int vsize = velems;
    long begin = dataStart ;
    if (debug) log.warn(" name= "+vname+" vsize="+vsize+" velems="+velems+" begin= "+begin+" isRecord="+isRecord+"\n");
    if( navcal == 128) {
        var.setDataType( DataType.FLOAT);
        var.setSPobject( new Vinfo (vsize, begin, isRecord, nx, ny, calcods));
     /*   var.addAttribute(new Attribute("_Unsigned", "true"));
        int numer = calcods[0] - calcods[1];
        int denom = calcods[2] - calcods[3];
        float a  = (numer*1.f) / (1.f*denom);
        float b  = calcods[0] - a * calcods[2];
        var.addAttribute( new Attribute("scale_factor", new Float(a)));
        var.addAttribute( new Attribute("add_offset", new Float(b)));
      */
    }
    else  {
        var.setDataType( DataType.BYTE);
        var.addAttribute(new Attribute("_Unsigned", "true"));
        var.addAttribute(new Attribute("_missing_value", new Short((short)255)));
        var.addAttribute( new Attribute("scale_factor", new Short((short)(1))));
        var.addAttribute( new Attribute("add_offset", new Short((short)(0))));
        var.setSPobject( new Vinfo (vsize, begin, isRecord, nx, ny));
    }
    String coordinates = "x y time";
    var.addAttribute( new Attribute(_Coordinate.Axes, coordinates));
    ncfile.addVariable(null, var);

    // add coordinate information. we need:
    // nx, ny, dx, dy,
    // latin, lov, la1, lo1

    // we have to project in order to find the origin
    ProjectionPointImpl start = (ProjectionPointImpl) projection.latLonToProj( new LatLonPointImpl( lat1, lon1));
    if (debug) log.warn("start at proj coord "+start);

    double startx = start.getX();
    double starty = start.getY();

    // create coordinate variables
    Variable xaxis = new Variable( ncfile, null, null, "x");
    xaxis.setDataType( DataType.DOUBLE);
    xaxis.setDimensions( "x");
    xaxis.addAttribute( new Attribute("long_name", "projection x coordinate"));
    xaxis.addAttribute( new Attribute("units", "km"));
    xaxis.addAttribute( new Attribute(_Coordinate.AxisType, "GeoX"));
    double[] data = new double[nx];
    if( proj == 1 ) {
        double lon_1 = lon1;
        double lon_2 = lon2;
        if ( lon1 < 0 ) lon_1 += 360.0;
        if ( lon2 < 0 ) lon_2 += 360.0;
        double dx = (lon_2 - lon_1) /(nx-1);

        for (int i = 0; i < data.length; i++) {
          double ln = lon1 + i * dx;
          ProjectionPointImpl pt = (ProjectionPointImpl) projection.latLonToProj( new LatLonPointImpl( lat1, ln));
          data[i] = pt.getX()// startx + i*dx;
        }
    } else {
        for (int i = 0; i < data.length; i++)
          data[i] = startx + i*dxKm;
    }

    dataA = Array.factory(DataType.DOUBLE.getPrimitiveClassType(), new int[] {nx}, data);
    xaxis.setCachedData( dataA, false);
    ncfile.addVariable(null, xaxis);

    Variable yaxis = new Variable( ncfile, null, null, "y");
    yaxis.setDataType( DataType.DOUBLE);
    yaxis.setDimensions( "y");
    yaxis.addAttribute( new Attribute("long_name", "projection y coordinate"));
    yaxis.addAttribute( new Attribute("units", "km"));
    yaxis.addAttribute( new Attribute(_Coordinate.AxisType, "GeoY"));
    data = new double[ny];
    double endy = starty + dyKm * (data.length - 1); // apparently lat1,lon1 is always the lower ledt, but data is upper left
    if(proj == 1) {
        double dy = (lat2 - lat1 ) / (ny-1);
        for (int i = 0; i < data.length; i++) {
          double la = lat2 - i*dy;
          ProjectionPointImpl pt = (ProjectionPointImpl) projection.latLonToProj( new LatLonPointImpl( la, lon1));
          data[i] = pt.getY()//endyy - i*dy;
        }
    }
    else {
        for (int i = 0; i < data.length; i++)
          data[i] = endy - i*dyKm;
    }
    dataA = Array.factory(DataType.DOUBLE.getPrimitiveClassType(), new int[] {ny}, data);
    yaxis.setCachedData( dataA, false);
    ncfile.addVariable(null, yaxis);

    // coordinate transform variable
    Variable ct = new Variable( ncfile, null, null, projection.getClassName());
    ct.setDataType( DataType.CHAR);
    ct.setDimensions( "");
    List params = projection.getProjectionParameters();
    for (int i = 0; i < params.size(); i++) {
      Parameter p = (Parameter) params.get(i);
      ct.addAttribute( new Attribute(p));
    }
    ct.addAttribute( new Attribute(_Coordinate.TransformType, "Projection"));
    ct.addAttribute( new Attribute(_Coordinate.Axes, "x y "));
    // fake data
    dataA = Array.factory(DataType.CHAR.getPrimitiveClassType(), new int[] {});
    dataA.setChar(dataA.getIndex(), ' ');
    ct.setCachedData(dataA, false);

    ncfile.addVariable(null, ct);
    ncfile.addAttribute( null, new Attribute("Conventions", _Coordinate.Convention));

View Full Code Here

        taxis.setDimensions("time");
        taxis.addAttribute(new Attribute("long_name", "time since base date"));
        taxis.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Time.toString()));
        double[] tdata = new double[1];
        tdata[0] = cal.getTimeInMillis();
        Array dataA = Array.factory(DataType.DOUBLE.getPrimitiveClassType(), new int[]{1}, tdata);
        taxis.setCachedData(dataA, false);
        DateFormatter formatter = new DateFormatter();
        taxis.addAttribute(new Attribute("units", "msecs since " + formatter.toDateTimeStringISO(new Date(0))));
        ncfile.addVariable(null, taxis);
        //  Get dimensions
        Integer ni = new Integer(geoSatelliteSecondHeader.widthOfImage);
        att = new Attribute("NX", ni);
        this.ncfile.addAttribute(null, att);

        ni = new Integer(geoSatelliteSecondHeader.heightOfImage);
        att = new Attribute("NY", ni);
        this.ncfile.addAttribute(null, att);

        vname = getGeoSatelliteProductName(geoSatelliteSecondHeader.channel);
        if (vname == null)
          throw new UnsupportedDatasetException("Unsupported GeoSatellite Procuct Dataset");


        // set projection attribute
        // ? which projection
        ProjectionImpl projection = null;
        double dxKm = 0.0, dyKm = 0.0;
        short nv = geoSatelliteSecondHeader.flagOfProjection;
        att = new Attribute("ProjIndex", nv);
        this.ncfile.addAttribute(null, att);
        int proj = nv;
        if (proj == 2) {
          att = new Attribute("ProjName", "MERCATOR");
          double lat0 = geoSatelliteSecondHeader.centerLatitudeOfProjection;
          double lon0 = geoSatelliteSecondHeader.centerLongitudeOfProjection;
          double par = geoSatelliteSecondHeader.standardLatitude1;
          dxKm = geoSatelliteSecondHeader.horizontalResolution;
          dyKm = geoSatelliteSecondHeader.verticalResolution;
          projection = new Mercator(lon0, par);
        } else if (proj == 1) {
          att = new Attribute("ProjName", "LAMBERT_CONFORNAL");
          double lat0 = geoSatelliteSecondHeader.centerLatitudeOfProjection;
          double lon0 = geoSatelliteSecondHeader.centerLongitudeOfProjection;
          double par1 = geoSatelliteSecondHeader.standardLatitude1;
          double par2 = geoSatelliteSecondHeader.standardLatitude2;
          dxKm = geoSatelliteSecondHeader.horizontalResolution / 100;
          dyKm = geoSatelliteSecondHeader.verticalResolution / 100;
          projection = new LambertConformal(lat0, lon0, par1, par2);
        } else if (proj == 3) {
          att = new Attribute("ProjName", "POLARSTEREOGRAPHIC");
          double latt = geoSatelliteSecondHeader.centerLatitudeOfProjection;
          double lont = geoSatelliteSecondHeader.centerLongitudeOfProjection;
          double scale = (1. + Math.sin(DEG_TO_RAD * latt)) / 2.;
          dxKm = geoSatelliteSecondHeader.horizontalResolution;
          dyKm = geoSatelliteSecondHeader.verticalResolution;
          projection = new Stereographic(90.0, lont, scale);
        } else if (proj == 4) {
          att = new Attribute("ProjName", "LatLonProjection");
          projection = new LatLonProjection();
        }
        this.ncfile.addAttribute(null, att);

        // coordinate transform variable
        if (proj != 4) {

        }
        //double dxKm = 0.0, dyKm = 0.0, latin, lonProjectionOrigin ;

        // deal with projection


        this.ncfile.addAttribute(null, new Attribute("channel", geoSatelliteSecondHeader.channel));

        this.ncfile.addAttribute(null, new Attribute("geospatial_lat_min", new Float(geoSatelliteSecondHeader.latitudeOfSouth)));
        this.ncfile.addAttribute(null, new Attribute("geospatial_lat_max", new Float(geoSatelliteSecondHeader.latitudeOfNorth)));
        this.ncfile.addAttribute(null, new Attribute("geospatial_lon_min", new Float(geoSatelliteSecondHeader.longitudeOfWest)));
        this.ncfile.addAttribute(null, new Attribute("geospatial_lon_max", new Float(geoSatelliteSecondHeader.longitudeOfEast)));
        this.ncfile.addAttribute(null, new Attribute("geospatial_vertical_min", new Float(0.0)));
        this.ncfile.addAttribute(null, new Attribute("geospatial_vertical_max", new Float(0.0)));


        this.ncfile.addAttribute(null, new Attribute("sample_ratio", geoSatelliteSecondHeader.sampleRatio));


        att = new Attribute("horizontal_resolution", geoSatelliteSecondHeader.horizontalResolution);
        this.ncfile.addAttribute(null, att);
        att = new Attribute("vertical_resolution", geoSatelliteSecondHeader.verticalResolution);
        this.ncfile.addAttribute(null, att);


        // only one data variable per awx file

        //  set vname and units according to grid feature

        Variable var = new Variable(ncfile, ncfile.getRootGroup(), null, vname);

        var.addAttribute(new Attribute("long_name", vname));

        // get dimensions
        int velems;
        boolean isRecord = false;


        int nx = geoSatelliteSecondHeader.widthOfImage;
        int ny = geoSatelliteSecondHeader.heightOfImage;


        Dimension dimX;
        Dimension dimY;

        if (proj != 4) {
          dimX = new Dimension("x", nx, true, false, false);
          dimY = new Dimension("y", ny, true, false, false);
        } else {
          dimX = new Dimension("lon", nx, true, false, false);
          dimY = new Dimension("lat", ny, true, false, false);
        }

        ncfile.addDimension(null, dimY);
        ncfile.addDimension(null, dimX);

        int byteAmountofData = 1;
        velems = dimX.getLength() * dimY.getLength() * byteAmountofData;
        ArrayList dims = new ArrayList();
        dims.add(dimT);
        dims.add(dimY);
        dims.add(dimX);


        var.setDimensions(dims);

        // data type
        Class dataType = null;
        switch (byteAmountofData) {
          case 1:
            var.setDataType(DataType.BYTE);
            dataType = DataType.BYTE.getPrimitiveClassType();
            break;
          case 2:
            var.setDataType(DataType.SHORT);
            dataType = DataType.SHORT.getPrimitiveClassType();
            break;
          case 4:
            var.setDataType(DataType.INT);
            dataType = DataType.INT.getPrimitiveClassType();
            break;
          default:
            System.out.println("Unsupported Grid Procuct Dataset!");
            throw new UnsupportedDatasetException("Unsupported Grid Procuct Dataset");

        }

        var.addAttribute(new Attribute("coordinates", "Lon Lat"));

        var.addAttribute(new Attribute("_unsigned", "true"));
        var.addAttribute(new Attribute("units", "percent"));
        // if(var.getDataType() == DataType.BYTE) {
        //     var.addAttribute(new Attribute("_missing_value", new Byte((byte)-1)));
        //     var.addAttribute( new Attribute("scale_factor", new Byte((byte)(1))));
        //     var.addAttribute( new Attribute("add_offset", new Byte((byte)(0))));
        //  } else {
        var.addAttribute(new Attribute("_missing_value", new Short((short) -1)));
        var.addAttribute(new Attribute("scale_factor", new Short((short) (1))));
        var.addAttribute(new Attribute("add_offset", new Short((short) (0))));
        //  }

        // size and beginning data position in file
        int vsize = velems;
        long begin = this.firstHeader.recordsOfHeader * this.firstHeader.recoderLength;
        if (debug)
          log.warn(" name= " + vname + " vsize=" + vsize + " velems=" + velems + " begin= " + begin + " isRecord=" + isRecord + "\n");
        var.setSPobject(new Vinfo(vsize, begin, isRecord, nx, ny, dataType, this.firstHeader.byteOrder));
        String coordinates;
        if (proj != 4) {
          coordinates = "x y time";
        } else {
          coordinates = "Lon Lat time";
        }

        var.addAttribute(new Attribute(_Coordinate.Axes, coordinates));

        ncfile.addVariable(ncfile.getRootGroup(), var);


//          if (debug) System.out.println("start at proj coord "+start);

        LatLonPointImpl startPnt = new LatLonPointImpl(geoSatelliteSecondHeader.latitudeOfNorth, geoSatelliteSecondHeader.longitudeOfWest);
        LatLonPointImpl endPnt = new LatLonPointImpl(geoSatelliteSecondHeader.latitudeOfSouth, geoSatelliteSecondHeader.longitudeOfEast);
        if (debug) System.out.println("start at geo coord :" + startPnt);

        if (proj != 4) {
          // we have to project in order to find the origin
          ProjectionPointImpl start = (ProjectionPointImpl) projection.latLonToProj(
                  new LatLonPointImpl(geoSatelliteSecondHeader.latitudeOfSouth,
                          geoSatelliteSecondHeader.longitudeOfWest));
          double startx = start.getX();
          double starty = start.getY();

          Variable xaxis = new Variable(ncfile, null, null, "x");
          xaxis.setDataType(DataType.DOUBLE);
          xaxis.setDimensions("x");
          xaxis.addAttribute(new Attribute("long_name", "projection x coordinate"));
          xaxis.addAttribute(new Attribute("units", "km"));
          xaxis.addAttribute(new Attribute(_Coordinate.AxisType, "GeoX"));
          double[] data = new double[nx];
          if (proj == 2) {
            double lon_1 = geoSatelliteSecondHeader.longitudeOfEast;
            double lon_2 = geoSatelliteSecondHeader.longitudeOfWest;
            if (lon_1 < 0) lon_1 += 360.0;
            if (lon_2 < 0) lon_2 += 360.0;
            double dx = (lon_1 - lon_2) / (nx - 1);

            for (int i = 0; i < data.length; i++) {
              double ln = lon_2 + i * dx;
              ProjectionPointImpl pt = (ProjectionPointImpl) projection.latLonToProj(
                      new LatLonPointImpl(geoSatelliteSecondHeader.latitudeOfSouth, ln));
              data[i] = pt.getX()// startx + i*dx;
            }
          } else {
            for (int i = 0; i < data.length; i++)
              data[i] = startx + i * dxKm;
          }

          dataA = Array.factory(DataType.DOUBLE.getPrimitiveClassType(), new int[]{nx}, data);
          xaxis.setCachedData(dataA, false);
          ncfile.addVariable(null, xaxis);

          Variable yaxis = new Variable(ncfile, null, null, "y");
          yaxis.setDataType(DataType.DOUBLE);
          yaxis.setDimensions("y");
          yaxis.addAttribute(new Attribute("long_name", "projection y coordinate"));
          yaxis.addAttribute(new Attribute("units", "km"));
          yaxis.addAttribute(new Attribute(_Coordinate.AxisType, "GeoY"));
          data = new double[ny];
          double endy = starty + dyKm * (data.length - 1); // apparently lat1,lon1 is always the lower ledt, but data is upper left
          double lat2 = geoSatelliteSecondHeader.latitudeOfNorth;
          double lat1 = geoSatelliteSecondHeader.latitudeOfSouth;
          if (proj == 2) {
            double dy = (lat2 - lat1) / (ny - 1);
            for (int i = 0; i < data.length; i++) {
              double la = lat2 - i * dy;
              ProjectionPointImpl pt = (ProjectionPointImpl) projection.latLonToProj(
                      new LatLonPointImpl(la, geoSatelliteSecondHeader.longitudeOfWest));
              data[i] = pt.getY()//endyy - i*dy;
            }
          } else {
            for (int i = 0; i < data.length; i++)
              data[i] = endy - i * dyKm;
          }
          dataA = Array.factory(DataType.DOUBLE.getPrimitiveClassType(), new int[]{ny}, data);
          yaxis.setCachedData(dataA, false);
          ncfile.addVariable(null, yaxis);

          // coordinate transform variable
          Variable ct = new Variable(ncfile, null, null, projection.getClassName());
          ct.setDataType(DataType.CHAR);
          ct.setDimensions("");
          List params = projection.getProjectionParameters();
          for (int i = 0; i < params.size(); i++) {
            Parameter p = (Parameter) params.get(i);
            ct.addAttribute(new Attribute(p));
          }
          ct.addAttribute(new Attribute(_Coordinate.TransformType, "Projection"));
          ct.addAttribute(new Attribute(_Coordinate.Axes, "x, y"));
          // fake data
          dataA = Array.factory(DataType.CHAR.getPrimitiveClassType(), new int[]{});
          dataA.setChar(dataA.getIndex(), ' ');
          ct.setCachedData(dataA, false);

          ncfile.addVariable(null, ct);
          ncfile.addAttribute(null, new Attribute("Conventions", _Coordinate.Convention));
        } else {
          Variable yaxis = new Variable(ncfile, null, null, "lat");
          yaxis.setDataType(DataType.DOUBLE);
          yaxis.setDimensions("lat");
          yaxis.addAttribute(new Attribute("long_name", "latitude"));
          yaxis.addAttribute(new Attribute("units", "degree"));
          yaxis.addAttribute(new Attribute(_Coordinate.AxisType, "Lat"));
          double[] data = new double[ny];

          double dy = (endPnt.getLatitude() - startPnt.getLatitude()) / (ny - 1);
          for (int i = 0; i < data.length; i++) {
            data[i] = startPnt.getLatitude() + i * dy; // starty + i*dy;
          }

          dataA = Array.factory(DataType.DOUBLE.getPrimitiveClassType(), new int[]{ny}, data);
          yaxis.setCachedData(dataA, false);
          ncfile.addVariable(null, yaxis);


          // create coordinate variables
          Variable xaxis = new Variable(ncfile, null, null, "lon");
          xaxis.setDataType(DataType.DOUBLE);
          xaxis.setDimensions("lon");
          xaxis.addAttribute(new Attribute("long_name", "longitude"));
          xaxis.addAttribute(new Attribute("units", "degree"));
          xaxis.addAttribute(new Attribute(_Coordinate.AxisType, "Lon"));
          data = new double[nx];

          double dx = (endPnt.getLongitude() - startPnt.getLongitude()) / (nx - 1);
          for (int i = 0; i < data.length; i++) {
            data[i] = startPnt.getLongitude() + i * dx; // startx + i*dx;

          }

          dataA = Array.factory(DataType.DOUBLE.getPrimitiveClassType(), new int[]{nx}, data);
          xaxis.setCachedData(dataA, false);
          ncfile.addVariable(null, xaxis);
        }
        break;
      }
      case AwxFileFirstHeader.AWX_PRODUCT_TYPE_POLARSAT_IMAGE:
        throw new UnsupportedDatasetException();

      case AwxFileFirstHeader.AWX_PRODUCT_TYPE_GRID: {
        AwxFileGridProductSecondHeader gridprocuctSecondHeader = (AwxFileGridProductSecondHeader) this.secondHeader;


        att = new Attribute("satellite_name", gridprocuctSecondHeader.satelliteName);
        this.ncfile.addAttribute(null, att);

        att = new Attribute("grid_feature", gridprocuctSecondHeader.gridFeature);
        this.ncfile.addAttribute(null, att);

        att = new Attribute("byte_amount_of_data", gridprocuctSecondHeader.byteAmountofData);
        this.ncfile.addAttribute(null, att);

        att = new Attribute("data_scale", gridprocuctSecondHeader.dataScale);
        this.ncfile.addAttribute(null, att);

        //        this.ncfile.addAttribute(null, new Attribute("cdm_data_type", thredds.catalog.DataType.GRID.toString()));

        DateFormat dformat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
        dformat.setTimeZone(java.util.TimeZone.getTimeZone("GMT"));
        Calendar cal = Calendar.getInstance();
        cal.set(gridprocuctSecondHeader.startYear,
                gridprocuctSecondHeader.startMonth - 1,
                gridprocuctSecondHeader.startDay,
                gridprocuctSecondHeader.startHour,
                gridprocuctSecondHeader.startMinute, 0);
        cal.setTimeZone(java.util.TimeZone.getTimeZone("GMT"));
        String dstring = dformat.format(cal.getTime());
        this.ncfile.addAttribute(null, new Attribute("time_coverage_start", dstring));
        int nz = 1;
        Dimension dimT = new Dimension("time", nz, true, false, false);
        ncfile.addDimension(null, dimT);

        // set time variable with time_coverage_start
        String timeCoordName = "time";
        Variable taxis = new Variable(ncfile, null, null, timeCoordName);
        taxis.setDataType(DataType.DOUBLE);
        taxis.setDimensions("time");
        taxis.addAttribute(new Attribute("long_name", "time since base date"));
        taxis.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Time.toString()));
        double[] tdata = new double[1];
        tdata[0] = cal.getTimeInMillis();
        Array dataA = Array.factory(DataType.DOUBLE.getPrimitiveClassType(), new int[]{1}, tdata);
        taxis.setCachedData(dataA, false);
        DateFormatter formatter = new DateFormatter();
        taxis.addAttribute(new Attribute("units", "msecs since " + formatter.toDateTimeStringISO(new Date(0))));
        ncfile.addVariable(null, taxis);

View Full Code Here

    units = existingData.getUnitsString();
  }

  public ArrayDouble.D3 getCoordinateArray(int timeIndex)
      throws IOException, InvalidRangeException {
    Array data = readArray(existingData, timeIndex);

    // copy for now - better to just return Array, with promise its rank 3
    int[] shape = data.getShape();
    ArrayDouble.D3 ddata = (ArrayDouble.D3) Array.factory(double.class, shape);
    MAMath.copyDouble(ddata, data);
    return ddata;
  }
View Full Code Here

    Variable dset = g.findVariable("StructMetadata.0");
    assert(null != dset );
    assert(dset.getDataType() == DataType.CHAR);

    // read entire array
    Array A;
    try {
      A = dset.read();
    }
    catch (IOException e) {
      System.err.println("ERROR reading file");
      assert false;
      return;
    }
    assert(A.getRank() == 1);
    assert (A instanceof ArrayChar);

    ArrayChar ca = (ArrayChar) A;
    String sval = ca.getString();
    System.out.println(dset.getFullName());
View Full Code Here

   */
  public ArrayDouble.D3 getCoordinateArray(int timeIndex)
      throws IOException {
    ArrayDouble.D3 array;

    Array pertArray = getTimeSlice(pertVar, timeIndex);
    Array baseArray = getTimeSlice(baseVar, timeIndex);

    //ADD: use MAMath?
    //ADD: use IndexIterator from getIndexIteratorFast?
    int[] shape = pertArray.getShape();
    //ADD: assert that rank = 3
    //ADD: assert that both arrays are same shape
    int ni = shape[0];
    int nj = shape[1];
    int nk = shape[2];

    array = new ArrayDouble.D3(ni, nj, nk);
    Index index = array.getIndex();

    for (int i = 0; i < ni; i++) {
      for (int j = 0; j < nj; j++) {
        for (int k = 0; k < nk; k++) {
          index.set(i, j, k);
          double d = pertArray.getDouble(index)
              + baseArray.getDouble(index);
          if (isZStag) {
            d = d / 9.81//convert geopotential to height
          }
          array.setDouble(index, d);
        }
View Full Code Here

      float val = att.getNumericValue().floatValue();
      if (!Float.isNaN(scale_factor)) val *= scale_factor;
      var.addAttribute(new Attribute("missing_value", (short) val));
    }
    // hack
    Array missingData = Array.factory(DataType.SHORT.getPrimitiveClassType(), new int[] {2}, new short[] {-990, -9990});
    var.addAttribute(new Attribute("missing_value", missingData));   
    var.addAttribute(new Attribute(_Coordinate.Axes, "Height Lat Lon"));
  }
View Full Code Here

    for (int i = 0; i < getNEnsembles(); i++) {
      EnsCoord ec = ensCoords.get(i);
      data[i] = Grib2Tables.codeTable4_6( ec.type) +" "+ ec.number;
    }
    Array dataArray = Array.factory(DataType.STRING, new int[]{getNEnsembles()}, data);
    v.setCachedData(dataArray, false);

    ncfile.addVariable(g, v);
  }
View Full Code Here

    // create the data
    double[] data = new double[n];
    for (int i = 0; i < n; i++) {
      data[i] = start + incr * i;
    }
    Array dataArray = Array.factory(DataType.DOUBLE, new int[]{n}, data);
    v.setCachedData(dataArray, false);

    v.addAttribute(new Attribute("units", units));
    v.addAttribute(new Attribute("long_name", desc));
    v.addAttribute(new Attribute("standard_name", standard_name));
View Full Code Here

TOP

Related Classes of com.google.test.metric.MetricComputerTest$Array

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.