Exemplo n.º 1
0
def gridmatch(lmod, ctxt, rtxt):
    """ Matches the rows and columns of the second grid to the first
    grid """
    rgrv = lmod.griddata[rtxt]
    cgrv = lmod.griddata[ctxt]

    data = rgrv
    data2 = cgrv
    orig_wkt = data.wkt
    orig_wkt2 = data2.wkt

    doffset = 0.0
    if data.data.min() <= 0:
        doffset = data.data.min() - 1.
        data.data = data.data - doffset

    rows, cols = data.data.shape
    rows2, cols2 = data2.data.shape

    gtr0 = data.get_gtr()
    gtr = data2.get_gtr()
    src = data_to_gdal_mem(data, gtr0, orig_wkt, cols, rows)
    dest = data_to_gdal_mem(data, gtr, orig_wkt2, cols2, rows2, True)

    gdal.ReprojectImage(src, dest, orig_wkt, orig_wkt2, gdal.GRA_Bilinear)

    dat = gdal_to_dat(dest, data.dataid)

    if doffset != 0.0:
        dat.data = dat.data + doffset
        data.data = data.data + doffset

    return dat.data
Exemplo n.º 2
0
def gridmatch(lmod, ctxt, rtxt):
    """ Matches the rows and columns of the second grid to the first
    grid """
    rgrv = lmod.griddata[rtxt]
    cgrv = lmod.griddata[ctxt]

    data = rgrv
    data2 = cgrv
    orig_wkt = data.wkt
    orig_wkt2 = data2.wkt

    doffset = 0.0
    if data.data.min() <= 0:
        doffset = data.data.min()-1.
        data.data = data.data - doffset

    gtr0 = (data.tlx, data.xdim, 0.0, data.tly, 0.0, -data.ydim)
    gtr = (data2.tlx, data2.xdim, 0.0, data2.tly, 0.0, -data2.ydim)
    src = data_to_gdal_mem(data, gtr0, orig_wkt, data.cols, data.rows)
    dest = data_to_gdal_mem(data, gtr, orig_wkt2, data2.cols, data2.rows, True)

    gdal.ReprojectImage(src, dest, orig_wkt, orig_wkt2, gdal.GRA_Bilinear)

    dat = gdal_to_dat(dest, data.dataid)

    if doffset != 0.0:
        dat.data = dat.data + doffset
        data.data = data.data + doffset

    return dat.data
Exemplo n.º 3
0
def gridmatch(lmod, ctxt, rtxt):
    """ Matches the rows and columns of the second grid to the first
    grid """
    rgrv = lmod.griddata[rtxt]
    cgrv = lmod.griddata[ctxt]

    data = rgrv
    data2 = cgrv
    orig_wkt = data.wkt
    orig_wkt2 = data2.wkt

    doffset = 0.0
    if data.data.min() <= 0:
        doffset = data.data.min()-1.
        data.data = data.data - doffset

    gtr0 = (data.tlx, data.xdim, 0.0, data.tly, 0.0, -data.ydim)
    gtr = (data2.tlx, data2.xdim, 0.0, data2.tly, 0.0, -data2.ydim)
    src = data_to_gdal_mem(data, gtr0, orig_wkt, data.cols, data.rows)
    dest = data_to_gdal_mem(data, gtr, orig_wkt2, data2.cols, data2.rows, True)

    gdal.ReprojectImage(src, dest, orig_wkt, orig_wkt2, gdal.GRA_Bilinear)

    dat = gdal_to_dat(dest, data.dataid)

    if doffset != 0.0:
        dat.data = dat.data + doffset
        data.data = data.data + doffset

    return dat.data
Exemplo n.º 4
0
def gmerge(master, slave, xrange=None, yrange=None):
    """
    This routine is used to merge two grids.
    """

    if xrange is None or yrange is None:
        return master

    xdim = master.xdim
    ydim = master.ydim
    orig_wkt = master.wkt

    xmin = xrange[0]
    xmax = xrange[-1]
    ymin = yrange[0]
    ymax = yrange[-1]

    cols = int((xmax - xmin) // xdim) + 1
    rows = int((ymax - ymin) // ydim) + 1
    gtr = (xmin, xdim, 0.0, ymax, 0.0, -ydim)

    dat = []

    for data in [master, slave]:
        doffset = 0.0
        if data.data.min() <= 0:
            doffset = data.data.min() - 1.
            data.data -= doffset
        data.data.set_fill_value(0)
        tmp = data.data.filled()
        data.data = np.ma.masked_equal(tmp, 0)
        data.nullvalue = 0

        drows, dcols = data.data.shape

        gtr0 = data.get_gtr()
        src = data_to_gdal_mem(data, gtr0, orig_wkt, dcols, drows)
        dest = data_to_gdal_mem(data, gtr, orig_wkt, cols, rows, True)

        gdal.ReprojectImage(src, dest, orig_wkt, orig_wkt, gdal.GRA_Bilinear)

        dat.append(gdal_to_dat(dest, data.dataid))
        dat[-1].data = np.ma.masked_outside(dat[-1].data, 0.1,
                                            data.data.max() + 1000)
        dat[-1].data += doffset
        dat[-1].data.set_fill_value(1e+20)
        tmp = dat[-1].data.filled()
        dat[-1].data = np.ma.masked_equal(tmp, 1e+20)
        dat[-1].nullvalue = 1e+20

    imask = np.logical_and(dat[0].data.mask, np.logical_not(dat[1].data.mask))
    if imask.size > 1:
        dat[0].data.data[imask] = dat[1].data.data[imask]
        dat[0].data.mask[imask] = False

    return dat[0]
Exemplo n.º 5
0
def gmerge(master, slave, xrange=None, yrange=None):
    """
    This routine is used to merge two grids.
    """

    if xrange is None or yrange is None:
        return master

    xdim = master.xdim
    ydim = master.ydim
    orig_wkt = master.wkt

    xmin = xrange[0]
    xmax = xrange[-1]
    ymin = yrange[0]
    ymax = yrange[-1]

    cols = int((xmax - xmin)//xdim)+1
    rows = int((ymax - ymin)//ydim)+1
    gtr = (xmin, xdim, 0.0, ymax, 0.0, -ydim)

    dat = []

    for data in [master, slave]:
        doffset = 0.0
        if data.data.min() <= 0:
            doffset = data.data.min()-1.
            data.data -= doffset
        data.data.set_fill_value(0)
        tmp = data.data.filled()
        data.data = np.ma.masked_equal(tmp, 0)
        data.nullvalue = 0

        gtr0 = (data.tlx, data.xdim, 0.0, data.tly, 0.0, -data.ydim)
        src = data_to_gdal_mem(data, gtr0, orig_wkt, data.cols, data.rows)
        dest = data_to_gdal_mem(data, gtr, orig_wkt, cols, rows, True)

        gdal.ReprojectImage(src, dest, orig_wkt, orig_wkt, gdal.GRA_Bilinear)

        dat.append(gdal_to_dat(dest, data.dataid))
        dat[-1].data = np.ma.masked_outside(dat[-1].data, 0.1,
                                            data.data.max() + 1000)
        dat[-1].data += doffset
        dat[-1].data.set_fill_value(1e+20)
        tmp = dat[-1].data.filled()
        dat[-1].data = np.ma.masked_equal(tmp, 1e+20)
        dat[-1].nullvalue = 1e+20

    imask = np.logical_and(dat[0].data.mask == True, dat[1].data.mask == False)
    if imask.size > 1:
        dat[0].data.data[imask] = dat[1].data.data[imask]
        dat[0].data.mask[imask] = False

    return dat[0]
Exemplo n.º 6
0
def gridmatch(lmod, ctxt, rtxt):
    """
    Matches the rows and columns of the second grid to the first
    grid.

    Parameters
    ----------
    lmod : LithModel
        Lithology Model.
    ctxt : str
        First grid text label.
    rtxt : str
        Second grid text label.

    Returns
    -------
    dat : numpy array
        Numpy array of data.

    """
    rgrv = lmod.griddata[rtxt]
    cgrv = lmod.griddata[ctxt]

    data = rgrv
    data2 = cgrv
    orig_wkt = data.wkt
    orig_wkt2 = data2.wkt

    doffset = 0.0
    if data.data.min() <= 0:
        doffset = data.data.min() - 1.
        data.data = data.data - doffset

    rows, cols = data.data.shape
    rows2, cols2 = data2.data.shape

    gtr0 = data.get_gtr()
    gtr = data2.get_gtr()
    src = data_to_gdal_mem(data, gtr0, orig_wkt, cols, rows)
    dest = data_to_gdal_mem(data, gtr, orig_wkt2, cols2, rows2, True)

    gdal.ReprojectImage(src, dest, orig_wkt, orig_wkt2, gdal.GRA_Bilinear)

    dat = gdal_to_dat(dest, data.dataid)

    if doffset != 0.0:
        dat.data = dat.data + doffset
        data.data = data.data + doffset

    return dat.data
Exemplo n.º 7
0
def gmerge(master, slave, xrange=None, yrange=None):
    """
    This routine is used to merge two grids.

    Parameters
    ----------
    master : PyGMI Data
        PyGMI raster dataset.
    slave : PyGMI Data
        PyGMI raster dataset.
    xrange : list, optional
        List containg range of minimum and maximum X. The default is None.
    yrange : list, optional
        List containg range of minimum and maximum Y. The default is None.

    Returns
    -------
    PyGMI Data
        PyGMI raster dataset.

    """
    if xrange is None or yrange is None:
        return master

    xdim = master.xdim
    ydim = master.ydim
    orig_wkt = master.wkt

    xmin = xrange[0]
    xmax = xrange[-1]
    ymin = yrange[0]
    ymax = yrange[-1]

    cols = int((xmax - xmin) // xdim) + 1
    rows = int((ymax - ymin) // ydim) + 1
    gtr = (xmin, xdim, 0.0, ymax, 0.0, -ydim)

    dat = []

    for data in [master, slave]:
        doffset = 0.
        data.data = data.data.astype(float)
        if data.data.min() <= 0.:
            doffset = data.data.min() - 1.
            data.data = data.data - doffset
        data.data.set_fill_value(0.)
        tmp = data.data.filled()
        data.data = np.ma.masked_equal(tmp, 0.)
        data.nullvalue = 0

        drows, dcols = data.data.shape

        gtr0 = data.get_gtr()
        src = data_to_gdal_mem(data, gtr0, orig_wkt, dcols, drows)
        dest = data_to_gdal_mem(data, gtr, orig_wkt, cols, rows, True)

        gdal.ReprojectImage(src, dest, orig_wkt, orig_wkt, gdal.GRA_Bilinear)

        dat.append(gdal_to_dat(dest, data.dataid))
        dat[-1].data = np.ma.masked_outside(dat[-1].data, 0.1,
                                            data.data.max() + 1000)
        dat[-1].data = dat[-1].data + doffset
        dat[-1].data.set_fill_value(1e+20)
        tmp = dat[-1].data.filled()
        dat[-1].data = np.ma.masked_equal(tmp, 1e+20)
        dat[-1].nullvalue = 1e+20

    imask = np.logical_and(dat[0].data.mask, np.logical_not(dat[1].data.mask))
    if imask.size > 1:
        dat[0].data.data[imask] = dat[1].data.data[imask]
        dat[0].data.mask[imask] = False

    return dat[0]