Пример #1
0
def model_to_grid_thickness():
    """ loads in a model """

    tmp = pio3d.ImportMod3D(None)
    tmp.ifile = r'C:\Work\Programming\pygmi\data\7-BC_57km_StagChamOnly_NEW.npz'
    ofile = r'C:\Work\Programming\pygmi\data\7-BC_57km_StagChamOnly_NEW.tif'

    # Reset Variables
    tmp.lmod.griddata.clear()
    tmp.lmod.lith_list.clear()

    # load model
    indict = np.load(tmp.ifile)
    tmp.dict2lmod(indict)

    lith_index = tmp.lmod.lith_index

    lith_index[lith_index == -1] = 0
    lith_index[lith_index > 0] = 1

    dz = tmp.lmod.d_z
    out = lith_index.sum(2) * dz

    gout = tmp.lmod.griddata['Calculated Gravity']
    gout.data = out.T
    gout.data = gout.data[::-1]
    gout.nullvalue = 0.
    gout.data = np.ma.masked_equal(gout.data, 0.)

    tmp = pio.ExportData(None)
    tmp.ifile = ofile
    tmp.export_gdal([gout], 'GTiff')

    pdb.set_trace()
Пример #2
0
def test_io_xyz(smalldata):
    """Tests IO for xyz files."""
    ofile = tempfile.gettempdir() + '\\iotest.xyz'

    tmp = iodefs.ExportData(None)
    tmp.ifile = ofile
    tmp.export_ascii_xyz([smalldata])

    dat2 = iodefs.get_raster(ofile)

    # Cleanup files
    for i in glob.glob(tempfile.gettempdir() + '\\iotest*'):
        os.unlink(i)

    np.testing.assert_array_equal(smalldata.data, dat2[0].data)
Пример #3
0
def test_io_gdal(smalldata, ext, drv):
    """Tests IO for gdal files."""
    ofile = tempfile.gettempdir() + '\\iotest' + ext

    tmp = iodefs.ExportData(None)
    tmp.ifile = ofile
    tmp.export_gdal([smalldata], drv)

    dat2 = iodefs.get_raster(ofile)

    # Cleanup files
    for i in glob.glob(tempfile.gettempdir() + '\\iotest*'):
        os.unlink(i)

    np.testing.assert_array_equal(smalldata.data, dat2[0].data)
Пример #4
0
def model_to_lith_depth():
    """ loads in a model """

    tmp = pio3d.ImportMod3D(None)
    tmp.ifile = r'C:\Work\Programming\pygmi\data\StagCham_Youssof_ALTComplexMantleLC_ds_extended.npz'
    ofile = r'C:\Work\Programming\pygmi\data\hope.tif'

    # Reset Variables
    tmp.lmod.griddata.clear()
    tmp.lmod.lith_list.clear()

    # load model
    indict = np.load(tmp.ifile)
    tmp.dict2lmod(indict)

    tmp.lmod.update_lith_list_reverse()

    print('These are the lithologies and their codes:')
    pprint.pprint(tmp.lmod.lith_list_reverse)
    print('')
    lithcode = int(input("what lithology code do you wish? "))

    lith_index = tmp.lmod.lith_index

    dz = tmp.lmod.d_z
    dtm = (lith_index == -1).sum(2)*dz

    lith = (lith_index == lithcode)

    xxx, yyy, zzz = lith.shape

    out = np.zeros((xxx, yyy))-1.

    for i in range(xxx):
        for j in range(yyy):
            if True in lith[i, j]:
                out[i, j] = np.nonzero(lith[i, j])[0][0]*dz - dtm[i, j]

    gout = tmp.lmod.griddata['Calculated Gravity']
    gout.data = out.T
    gout.data = gout.data[::-1]
    gout.nullvalue = -1.
    gout.data = np.ma.masked_equal(gout.data, -1.)

    tmp = pio.ExportData(None)
    tmp.ifile = ofile
    tmp.export_gdal([gout], 'GTiff')
Пример #5
0
def grid():
    """ First 2 columns must be x and y """

    filename = r'C:\Work\Programming\pygmi\data\sue\filt_magdata.csv'
    ofile = r'C:\Work\Programming\pygmi\data\magdata.tif'
    srows = 0
    dlim = None
    xcol = 0
    ycol = 1
    zcol = 2
    dxy = 15

    # This bit reads in the first line to see if it is a header
    pntfile = open(filename)
    ltmp = pntfile.readline()
    pntfile.close()
    ltmp = ltmp.lower()
    isheader = any(c.isalpha() for c in ltmp)

    # Check for comma delimiting
    if ',' in ltmp:
        dlim = ','

    # Set skip rows
    if isheader:
        srows = 1

    # Now read in data

    datatmp = np.genfromtxt(filename, unpack=True, delimiter=dlim,
                            skip_header=srows, usemask=False)

    # Now we interpolate
    xdata = datatmp[xcol]
    ydata = datatmp[ycol]
    zdata = datatmp[zcol]

    points = datatmp[:2].T

    newxdata = np.arange(xdata.min(), xdata.max(), dxy)
    newydata = np.arange(ydata.min(), ydata.max(), dxy)

    newpoints = np.meshgrid(newxdata, newydata)
    newpoints = (newpoints[0].flatten(), newpoints[1].flatten())

    grid = si.griddata(points, zdata, newpoints, method='cubic')

    grid.shape = (newydata.shape[0], newxdata.shape[0])

    grid = grid[::-1]

    # export data
    odat = Data()
    odat.dataid = ''
    odat.tlx = newxdata.min()
    odat.tly = newydata.max()
    odat.xdim = dxy
    odat.ydim = dxy
    odat.nrofbands = 1
    odat.nullvalue = 1e+20
    odat.rows, odat.cols = grid.shape
    odat.data = np.ma.masked_invalid(grid)

    tmp = pio.ExportData(None)
    tmp.ifile = ofile
#    tmp.export_ascii_xyz([odat])
#    tmp.export_gdal([odat], 'ENVI')
    tmp.export_gdal([odat], 'GTiff')

    # Plotting section

#    dataex = (newxdata.min(), newxdata.max(), newydata.min(), newydata.max())
#    plt.imshow(grid, cmap = plt.cm.jet, extent=dataex, origin='upper')

    plt.tricontourf(xdata, ydata, zdata, 40, cmap=plt.cm.jet)

#    plt.plot(xdata, ydata, '.')
    plt.colorbar()
    plt.show()

    pdb.set_trace()