Examples of GridCoordSystem


Examples of ucar.nc2.dt.GridCoordSystem

    }

    GridDatatype grid = gridDs.findGridDatatype(gridName);
    assert (grid != null) : "Cant find grid "+gridName;

    GridCoordSystem gcs = grid.getCoordinateSystem();
    CoordinateAxis1DTime runtime = gcs.getRunTimeAxis();
    assert (runtime != null) : "Cant find runtime for "+gridName;
    CoordinateAxis time = gcs.getTimeAxis();
    assert (time != null) : "Cant find time for "+gridName;
    assert (time.getRank() == 2) : "Time should be 2D "+gridName;

    if (showCount) {
      System.out.println(" runtimes=" + runtime.getSize());
View Full Code Here

Examples of ucar.nc2.dt.GridCoordSystem

    }

    GridDatatype grid = gridDs.findGridDatatype(gridName);
    assert (grid != null) : "Cant find grid "+gridName;

    GridCoordSystem gcs = grid.getCoordinateSystem();
    CoordinateAxis1DTime runtime = gcs.getRunTimeAxis();
    //System.out.println(" has runtime axis=" +  (runtime != null));

    assert (runtime != null) : "Cant find runtime for "+gridName;
    //assert (runtime == null) : "Should not have runtime coord= "+runtime;

    CoordinateAxis time = gcs.getTimeAxis();
    assert (time != null) : "Cant find time for "+gridName;

    if (showCount) {
      System.out.println(" ntimes=" +  time.getDimension(0).getLength());
    }
View Full Code Here

Examples of ucar.nc2.dt.GridCoordSystem

    DateFormatter df = new DateFormatter();
    this.runTime = df.toDateTimeStringISO(this.runDate);

    // add each variable, collect unique time and vertical axes
    for (GridDatatype gg : gds.getGrids()) {
      GridCoordSystem gcs = gg.getCoordinateSystem();
      Grid grid = new Grid(gg.getFullName());

      // LOOK: Note this assumes a dense coordinate system
      CoordinateAxis1DTime axis = gcs.getTimeAxis1D();
      if (axis != null) {
        TimeCoord tc = getTimeCoordinate(axis);
        tc.addGridInventory(grid);
        grid.tc = tc;
      }

     CoordinateAxis1D vaxis = gcs.getVerticalAxis();
      if (vaxis != null) {
        grid.vc = getVertCoordinate(vaxis);
      }

     /* not yet
View Full Code Here

Examples of ucar.nc2.dt.GridCoordSystem

     * @param greyScale if true, write greyScale image, else dataSample.
     * @throws IOException on i/o error
     */
    public void writeGrid(GridDataset dataset, GridDatatype grid, Array data,
                          boolean greyScale) throws IOException {
        GridCoordSystem gcs = grid.getCoordinateSystem();

        if ( !gcs.isRegularSpatial()) {
            throw new IllegalArgumentException(
                "Must have 1D x and y axes for " + grid.getFullName());
        }

        CoordinateAxis1D xaxis = (CoordinateAxis1D) gcs.getXHorizAxis();
        CoordinateAxis1D yaxis = (CoordinateAxis1D) gcs.getYHorizAxis();

        //latlon coord does not need to be scaled
        double scaler = (gcs.isLatLon())
                        ? 1.0
                        : 1000.0;

        // data must go from top to bottom LOOK IS THIS REALLY NEEDED ?
        double xStart = xaxis.getCoordValue(0) * scaler;
        double yStart = yaxis.getCoordValue(0) * scaler;
        double xInc   = xaxis.getIncrement() * scaler;
        double yInc   = Math.abs(yaxis.getIncrement()) * scaler;

        if (yaxis.getCoordValue(0) < yaxis.getCoordValue(1)) {
            data   = data.flip(0);
            yStart = yaxis.getCoordValue((int) yaxis.getSize() - 1) * scaler;
        }

        if (gcs.isLatLon()) {
            Array lon = xaxis.read();
            data   = geoShiftDataAtLon(data, lon);
            xStart = geoShiftGetXstart(lon, xInc);
            //xStart = -180.0;
        }
View Full Code Here

Examples of ucar.nc2.dt.GridCoordSystem

                          int level, boolean greyScale,
                          LatLonRect pt) throws IOException {
        double          scaler;
        GridDataset     dataset = ucar.nc2.dt.grid.GridDataset.open(fileName);
        GridDatatype    grid    = dataset.findGridDatatype(gridName);
        GridCoordSystem gcs     = grid.getCoordinateSystem();
        ProjectionImpl  proj    = grid.getProjection();

        if (grid == null) {
            throw new IllegalArgumentException("No grid named " + gridName
                    + " in fileName");
        }
        if ( !gcs.isRegularSpatial()) {
            Attribute att = dataset.findGlobalAttributeIgnoreCase("datasetId");
            if(att != null && att.getStringValue().contains("DMSP")){
                writeSwathGrid(fileName, gridName,time,level, greyScale, pt);
                return;
            } else {
                throw new IllegalArgumentException(
                    "Must have 1D x and y axes for " + grid.getFullName());
            }

        }

        CoordinateAxis1D xaxis = (CoordinateAxis1D) gcs.getXHorizAxis();
        CoordinateAxis1D yaxis = (CoordinateAxis1D) gcs.getYHorizAxis();
        if ( !xaxis.isRegular() || !yaxis.isRegular()) {
            throw new IllegalArgumentException(
                "Must be evenly spaced grid = " + grid.getFullName());
        }

        // read in data
        Array data = grid.readDataSlice(time, level, -1, -1);
        Array lon  = xaxis.read();
        Array lat  = yaxis.read();

        //latlon coord does not need to time 1000.0
        if (gcs.isLatLon()) {
            scaler = 1.0;
        } else {
            scaler = 1000.0;
        }

        if (yaxis.getCoordValue(0) < yaxis.getCoordValue(1)) {
            data = data.flip(0);
            lat  = lat.flip(0);
        }

        if (gcs.isLatLon()) {
            data = geoShiftDataAtLon(data, lon);
            lon  = geoShiftLon(lon);
        }
        // now it is time to subset the data out of latlonrect
        // it is assumed that latlonrect pt is in +-180
        LatLonPointImpl llp0   = pt.getLowerLeftPoint();
        LatLonPointImpl llpn   = pt.getUpperRightPoint();
        double          minLon = llp0.getLongitude();
        double          minLat = llp0.getLatitude();
        double          maxLon = llpn.getLongitude();
        double          maxLat = llpn.getLatitude();

        // (x1, y1) is upper left point and (x2, y2) is lower right point
        int    x1;
        int    x2;
        int    y1;
        int    y2;
        double xStart;
        double yStart;
        if ( !gcs.isLatLon()) {

            ProjectionPoint pjp0     = proj.latLonToProj(maxLat, minLon);
            double[]        lonArray = (double[]) lon.copyTo1DJavaArray();
            double[]        latArray = (double[]) lat.copyTo1DJavaArray();
            x1     = getXIndex(lon, pjp0.getX(), 0);
View Full Code Here

Examples of ucar.nc2.dt.GridCoordSystem

        double           scaler;
        GridDataset      dataset =
            ucar.nc2.dt.grid.GridDataset.open(fileName);
        GridDatatype     grid    = dataset.findGridDatatype(gridName);
        GridCoordSystem  gcs     = grid.getCoordinateSystem();
        ProjectionImpl   proj    = grid.getProjection();

        CoordinateAxis2D xaxis   = (CoordinateAxis2D) gcs.getXHorizAxis();
        CoordinateAxis2D yaxis   = (CoordinateAxis2D) gcs.getYHorizAxis();

        // read in data
        Array    data      = grid.readDataSlice(time, level, -1, -1);
        Array    lon       = xaxis.read();
        Array    lat       = yaxis.read();

        double[] swathInfo = getSwathLatLonInformation(lat, lon);

        //latlon coord does not need to time 1000.0
        if (gcs.isLatLon()) {
            scaler = 1.0;
        } else {
            scaler = 1000.0;
        }

        //if (yaxis.getCoordValue(0, 0) < yaxis.getCoordValue(0, 1)) {//???
        data = data.flip(0);
        //lat = lat.flip(0);
        //}

        if (gcs.isLatLon()) {
            data = geoShiftDataAtLon(data, lon);
            lon  = geoShiftLon(lon);
        }

        double minLon;
        double minLat;
        double maxLon;
        double maxLat;
        double xStart;
        double yStart;  //upper right point

        double xInc = swathInfo[0] * scaler;
        double yInc = swathInfo[1] * scaler;

        // (x1, y1) is upper left point and (x2, y2) is lower right point
        int x1;
        int x2;
        int y1;
        int y2;

        if (llr == null//get the whole area
        {
            minLon = swathInfo[4];
            minLat = swathInfo[2];
            maxLon = swathInfo[5];
            maxLat = swathInfo[3];
            xStart = minLon;
            yStart = maxLat;
            x1     = 0;
            y1     = 0;
            x2     = (int) ((maxLon - minLon) / xInc + 0.5);
            y2     = (int) ((maxLat - minLat) / yInc + 0.5);
        } else            //assign the special area  surrounded by the llr
        {
            LatLonPointImpl llp0 = llr.getLowerLeftPoint();
            LatLonPointImpl llpn = llr.getUpperRightPoint();
            minLon = (llp0.getLongitude() < swathInfo[4])
                     ? swathInfo[4]
                     : llp0.getLongitude();
            minLat = (llp0.getLatitude() < swathInfo[2])
                     ? swathInfo[2]
                     : llp0.getLatitude();
            maxLon = (llpn.getLongitude() > swathInfo[5])
                     ? swathInfo[5]
                     : llpn.getLongitude();
            maxLat = (llpn.getLatitude() > swathInfo[3])
                     ? swathInfo[3]
                     : llpn.getLatitude();

            //construct the swath  LatLonRect
            LatLonPointImpl pUpLeft = new LatLonPointImpl(swathInfo[3],
                                          swathInfo[4]);
            LatLonPointImpl pDownRight = new LatLonPointImpl(swathInfo[2],
                                             swathInfo[5]);
            LatLonRect swathLLR   = new LatLonRect(pUpLeft, pDownRight);
            LatLonRect bIntersect = swathLLR.intersect(llr);
            if (bIntersect == null) {
                throw new IllegalArgumentException(
                    "The assigned extent of latitude and longitude is unvalid. "
                    + "No intersection with the swath extent");
            }

            xStart = minLon;
            yStart = maxLat;
            x1     = (int) ((minLon - swathInfo[4]) / xInc + 0.5);
            y1     = (int) Math.abs((maxLat - swathInfo[3]) / yInc + 0.5);
            x2     = (int) ((maxLon - swathInfo[4]) / xInc + 0.5);
            y2     = (int) Math.abs((minLat - swathInfo[3]) / yInc + 0.5);
        }

        if ( !gcs.isLatLon()) {
            ProjectionPoint pjp0 = proj.latLonToProj(maxLat, minLon);
            x1     = getXIndex(lon, pjp0.getX(), 0);
            y1     = getYIndex(lat, pjp0.getY(), 0);
            yStart = pjp0.getY() * 1000.0//latArray[y1];
            xStart = pjp0.getX() * 1000.0//lonArray[x1];
View Full Code Here

Examples of ucar.nc2.dt.GridCoordSystem

    public void writeGrid(GridDatatype grid, Array data, boolean greyScale,
                          double xStart, double yStart, double xInc,
                          double yInc, int imageNumber) throws IOException {

        int             nextStart = 0;
        GridCoordSystem gcs       = grid.getCoordinateSystem();

        // get rid of this when all projections are implemented
        if ( !gcs.isLatLon()
                && !(gcs.getProjection() instanceof LambertConformal)
                && !(gcs.getProjection() instanceof Stereographic)
                && !(gcs.getProjection() instanceof Mercator)
        //  && !(gcs.getProjection() instanceof TransverseMercator)
                && !(gcs.getProjection() instanceof AlbersEqualAreaEllipse)
        && !(gcs.getProjection() instanceof AlbersEqualArea)) {
            throw new IllegalArgumentException(
                "Must be lat/lon or LambertConformal or Mercator and grid = "
                + gcs.getProjection().getClass().getName());
        }

        // write the data first
        if (greyScale) {
            ArrayByte result = replaceMissingValuesAndScale(grid, data);
            nextStart = geotiff.writeData((byte[]) result.getStorage(),
                                          imageNumber);
        } else {
            ArrayFloat result = replaceMissingValues(grid, data);
            nextStart = geotiff.writeData((float[]) result.getStorage(),
                                          imageNumber);
        }

        // set the width and the height
        int elemSize = greyScale
                       ? 1
                       : 4;
        int height   = data.getShape()[0];         // Y
        int width    = data.getShape()[1];         // X
        int size     = elemSize * height * width;  // size in bytes
        geotiff.addTag(new IFDEntry(Tag.ImageWidth,
                                    FieldType.SHORT).setValue(width));
        geotiff.addTag(new IFDEntry(Tag.ImageLength,
                                    FieldType.SHORT).setValue(height));

        // set the multiple images tag
        int ff   = 1 << 1;
        int page = imageNumber - 1;
        geotiff.addTag(new IFDEntry(Tag.NewSubfileType,
                                    FieldType.SHORT).setValue(ff));
        geotiff.addTag(new IFDEntry(Tag.PageNumber,
                                    FieldType.SHORT).setValue(page, 2));

        // just make it all one big "row"
        geotiff.addTag(new IFDEntry(Tag.RowsPerStrip,
                                    FieldType.SHORT).setValue(1))//height));
        // the following changes to make it viewable in ARCMAP
        /*
        geotiff.addTag( new IFDEntry(Tag.StripByteCounts, FieldType.LONG).setValue( size));
        // data starts here, header is written at the end
        if( imageNumber == 1 )
          geotiff.addTag( new IFDEntry(Tag.StripOffsets, FieldType.LONG).setValue( 8));
        else
          geotiff.addTag( new IFDEntry(Tag.StripOffsets, FieldType.LONG).setValue(nextStart));
        */
        int[] soffset    = new int[height];
        int[] sbytecount = new int[height];
        if (imageNumber == 1) {
            soffset[0] = 8;
        } else {
            soffset[0] = nextStart;
        }
        sbytecount[0] = width * elemSize;
        for (int i = 1; i < height; i++) {
            soffset[i]    = soffset[i - 1] + width * elemSize;
            sbytecount[i] = width * elemSize;
        }
        geotiff.addTag(new IFDEntry(Tag.StripByteCounts, FieldType.LONG,
                                    width).setValue(sbytecount));
        geotiff.addTag(new IFDEntry(Tag.StripOffsets, FieldType.LONG,
                                    width).setValue(soffset));
        // standard tags
        geotiff.addTag(new IFDEntry(Tag.Orientation,
                                    FieldType.SHORT).setValue(1));
        geotiff.addTag(new IFDEntry(Tag.Compression,
                                    FieldType.SHORT).setValue(1))// no compression
        geotiff.addTag(new IFDEntry(Tag.Software,
                                    FieldType.ASCII).setValue("nc2geotiff"));
        geotiff.addTag(new IFDEntry(Tag.PhotometricInterpretation,
                                    FieldType.SHORT).setValue(1))// black is zero : not used?
        geotiff.addTag(new IFDEntry(Tag.PlanarConfiguration,
                                    FieldType.SHORT).setValue(1));

        if (greyScale) {
            // standard tags for Greyscale images ( see TIFF spec, section 4)
            geotiff.addTag(new IFDEntry(Tag.BitsPerSample,
                                        FieldType.SHORT).setValue(8))// 8 bits per sample
            geotiff.addTag(new IFDEntry(Tag.SamplesPerPixel,
                                        FieldType.SHORT).setValue(1));

            geotiff.addTag(new IFDEntry(Tag.XResolution,
                                        FieldType.RATIONAL).setValue(1, 1));
            geotiff.addTag(new IFDEntry(Tag.YResolution,
                                        FieldType.RATIONAL).setValue(1, 1));
            geotiff.addTag(new IFDEntry(Tag.ResolutionUnit,
                                        FieldType.SHORT).setValue(1));

        } else {
            // standard tags for SampleFormat ( see TIFF spec, section 19)
            geotiff.addTag(new IFDEntry(Tag.BitsPerSample,
                                        FieldType.SHORT).setValue(32))// 32 bits per sample
            geotiff.addTag(new IFDEntry(Tag.SampleFormat,
                                        FieldType.SHORT).setValue(3))// Sample Format
            geotiff.addTag(new IFDEntry(Tag.SamplesPerPixel,
                                        FieldType.SHORT).setValue(1));
            MAMath.MinMax dataMinMax = grid.getMinMaxSkipMissingData(data);
            float         min        = (float) (dataMinMax.min);
            float         max        = (float) (dataMinMax.max);
            geotiff.addTag(new IFDEntry(Tag.SMinSampleValue,
                                        FieldType.FLOAT).setValue(min));
            geotiff.addTag(new IFDEntry(Tag.SMaxSampleValue,
                                        FieldType.FLOAT).setValue(max));
            geotiff.addTag(new IFDEntry(Tag.GDALNoData,
                                        FieldType.FLOAT).setValue(min - 1.f));
        }

        /*
              geotiff.addTag( new IFDEntry(Tag.Geo_ModelPixelScale, FieldType.DOUBLE).setValue(
                new double[] {5.0, 2.5, 0.0} ));
              geotiff.addTag( new IFDEntry(Tag.Geo_ModelTiepoint, FieldType.DOUBLE).setValue(
                new double[] {0.0, 0.0, 0.0, -180.0, 90.0, 0.0 } ));
              //  new double[] {0.0, 0.0, 0.0, 183.0, 90.0, 0.0} ));
              IFDEntry ifd = new IFDEntry(Tag.Geo_KeyDirectory, FieldType.SHORT).setValue(
                new int[] {1, 1, 0, 4, 1024, 0, 1, 2, 1025, 0, 1, 1, 2048, 0, 1, 4326, 2054, 0, 1, 9102} );
              geotiff.addTag( ifd);
        */

        // set the transformation from projection to pixel, add tie point tag
        geotiff.setTransform(xStart, yStart, xInc, yInc);

        if (gcs.isLatLon()) {
            addLatLonTags();
        } else if (gcs.getProjection() instanceof LambertConformal) {
            addLambertConformalTags((LambertConformal) gcs.getProjection(),
                                    xStart, yStart);
        } else if (gcs.getProjection() instanceof Stereographic) {
            addPolarStereographicTags((Stereographic) gcs.getProjection(),
                                      xStart, yStart);
        } else if (gcs.getProjection() instanceof Mercator) {
            addMercatorTags((Mercator) gcs.getProjection());
        } else if (gcs.getProjection() instanceof TransverseMercator) {
            addTransverseMercatorTags(
                (TransverseMercator) gcs.getProjection());
        } else if (gcs.getProjection() instanceof AlbersEqualArea) {
            addAlbersEqualAreaTags((AlbersEqualArea) gcs.getProjection());
        } else if (gcs.getProjection() instanceof AlbersEqualAreaEllipse) {
            addAlbersEqualAreaEllipseTags((AlbersEqualAreaEllipse) gcs.getProjection());
        }

        geotiff.writeMetadata(imageNumber);
        //geotiff.close();

View Full Code Here

Examples of ucar.nc2.dt.GridCoordSystem

    String defaultFilename = "C:/data/rap/fmrc.xml";
    String filename = (arg.length > 0) ? arg[0] : defaultFilename;

    GridDataset gds = ucar.nc2.dt.grid.GridDataset.open(filename);
    GridDatatype gg = gds.findGridDatatype("T");
    GridCoordSystem gsys = gg.getCoordinateSystem();

    // gsys.getTimeAxisForRun(1);  // generate error

    CoordinateAxis1DTime rtaxis = gsys.getRunTimeAxis();
    CoordinateAxis taxis2D = gsys.getTimeAxis();
    Array data = taxis2D.read();
    NCdump.printArray(data, "2D time array", System.out, null);

    System.out.println("Run Time, Valid Times");
    Date[] runtimes = rtaxis.getTimeDates();
    for (int i = 0; i < runtimes.length; i++) {
      System.out.println("\n" + runtimes[i]);

      CoordinateAxis1DTime taxis = gsys.getTimeAxisForRun(i);
      Date[] times = taxis.getTimeDates();
      for (int j = 0; j < times.length; j++) {
        System.out.println("   " + times[j]);
      }
    }
View Full Code Here

Examples of ucar.nc2.dt.GridCoordSystem

    System.out.printf(format, " ", "level", "stat", "ens", "prob" );

    List<GridDatatype> grids =  ncd.getGrids();
    Collections.sort(grids);
    for (GridDatatype g : grids) {
      GridCoordSystem gsys = g.getCoordinateSystem();
      CoordinateAxis t = gsys.getTimeAxis();
      Variable v = g.getVariable();
      String level = v.findAttribute("GRIB_level_type_name").getStringValue();
      Attribute att = v.findAttribute("GRIB_interval_stat_type");
      String stat = (att == null) ? "" : att.getStringValue();
      att = v.findAttribute("GRIB_ensemble");
View Full Code Here

Examples of ucar.nc2.dt.GridCoordSystem

    nfiles++;

    Map<String, HoldEm> map = new HashMap<String, HoldEm>();

    for (ucar.nc2.dt.GridDataset.Gridset g : gds.getGridsets()) {
      GridCoordSystem gsys = g.getGeoCoordSystem();
      for (CoordinateTransform t : gsys.getCoordinateTransforms()) {
        if (t instanceof ProjectionCT) {
          ncd.findVariable(t.getName());
          ProjectionImpl p = ((ProjectionCT)t).getProjection();
          map.put(t.getName()+" "+p.paramsToString(), new HoldEm(gsys, p, ncd.findVariable(t.getName())));
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.