Esempio n. 1
0
  action="store_true", default=False)
args = parser.parse_args()
writeLog(parser, args, args.printOnly)
#==========================================================#

fileout = args.fileout
Rdims = args.Dims
ROrig = args.Orig
dP = args.dP
rotation = args.rotation
printOn = args.printOn
printOnly = args.printOnly

Rdict = dict()
R = np.zeros(Rdims)
Rdict['R'] = R
Rdict['GlobOrig'] = np.array(ROrig)
Rdict['dPx'] = np.array(dP)
Rdict['gridRot'] = rotation

if (not args.printOnly):
    saveTileAsNumpyZ(fileout, Rdict)

if (args.printOn or args.printOnly):
    Rdims = np.array(np.shape(R))
    figDims = 13. * (Rdims[::-1].astype(float) / np.max(Rdims))
    fig = plt.figure(num=1, figsize=figDims)
    fig = addImagePlot(fig, R, fileout)

    plt.show()
Esempio n. 2
0
# Retain unused keys from original raster
PRdict = Rdict.copy()
Rdict = None
PRdict['R'] = PR
PRdict['GlobOrig'] = PROrig
PRdict['gridRot'] = rotation
PRdict['dPx'] = np.array([dxG[0], dxG[1]])

if (not args.printOnly):
    saveTileAsNumpyZ(fileout, PRdict)

# Print the raster map, first, in a coordinate system where x-axis is aligned with the windDir
# and, second, in its original orientation.
if (printOn or printOnly):
    figDims = 13. * (Xdims[::-1].astype(float) / np.max(Xdims))
    fig = plt.figure(num=1, figsize=figDims)
    fig = addImagePlot(fig, PR, args.fileout)

    CfD = dict()
    CfD['title'] = ' Z(x,y) '
    CfD['label'] = "PALM DOMAIN ON MAP"
    CfD['N'] = 16
    CO = addContourf(XTRM, YTRM, PR[::-1, :], CfD)
    plt.show()

XTRM = None
YTRM = None
PR = None
PRDict = None
Esempio n. 3
0
  action="store_true", default=False)
parser.add_argument("-s", "--scale",type=float, default=1.,\
   help="Scale factor for the output. Default=1.")
args = parser.parse_args()
writeLog( parser, args, args.printOnly )
#==========================================================#

# Renaming, nothing more.
filename  = args.filename
fileout   = args.fileout
reso      = args.reso
ROrig     = args.xorig
printOn   = args.printOn
printOnly = args.printOnly
sc        = args.scale


R = openTifAsNumpy(filename)
dPx      = np.array([sc*reso, sc*reso])
Rdict = {'R' : R, 'GlobOrig' : ROrig, 'gridRot' : 0., 'dPx' : dPx}

if( not printOnly ):
  print(' Writing file {} ... '.format(fileout) )
  saveTileAsNumpyZ( fileout, Rdict)
  print(' ... done! ')

if( printOn or printOnly ):
  pfig = plt.figure(num=1, figsize=(10.,10.))
  pfig = addImagePlot( pfig, R, fileout, gridOn=True )
  plt.show()
Esempio n. 4
0
nBands = numberOfRasterBands(dataset, True)  # PrintOn = True/False
ROrig, dPx = getGeoTransform(dataset)  # Both 2d arrays. XOrig is Top Left!

# Ask for the band ID if the user so wants (given that it makes sense)
ib = selectBand(nBands, bandSelect, 1)  # last argument is for default
rb = getRasterBand(dataset, ib)
printRasterBandStatistics(rb)

# Read the raster
R = readAsNumpyArray(rb)

print(' Number of non-zero values = {}'.format(np.count_nonzero(R)))

# Construct the Raster dict
Rdict = dict()
Rdict['dPx'] = dPx
Rdict['rotation'] = 0.
Rdict['R'] = np.round(R, decimals=ndecimals)
Rdict['GlobOrig'] = ROrig

if (not printOnly):
    saveTileAsNumpyZ(filename.replace('.tif', '.npz'), Rdict)
    Rdict = None

if (printOnly or printOn):
    Rdims = np.array(R.shape)
    figDims = 13. * (Rdims[::-1].astype(float) / np.max(Rdims))
    fig = plt.figure(num=1, figsize=figDims)
    fig = addImagePlot(fig, R, filename)
    plt.show()
Esempio n. 5
0
    # Write the data into a VTK file
    # N axis of (N,E) coordinates has to be reversed
    fname = fileout.split('.')[0] + '.vtk'
    t_vtk = vtkWriteHeaderAndGridStructured2d(X, Y, topo[::-1, :], fname,
                                              'VTK map')
    t_vtk = vtkWritePointDataHeader(t_vtk, Rx[::-1, :], 1)
    t_vtk = vtkWritePointDataStructured2D(t_vtk, Rx[::-1, :], X, varname)

    t_vtk.close()

# - - - - - - - - - - - - - - - - - - - - - - - - - - #

# Save as npz
if (not printOnly):
    Rdict['R'] = Rx
    Rdict['dPx'] = dPx
    Rdict['GlobOrig'] = ROrig
    Rdict['Nshapes'] = Nshapes
    saveTileAsNumpyZ(fileout, Rdict)
    Rdict = None

# - - - - - - - - - - - - - - - - - - - - - - - - - - #

# Plot the resulting raster
if (printOn or printOnly):
    Rx[Rx == 0] = np.nan  # Replacing zeros with NaN helps plotting
    figDims = 13. * (Rxdims[::-1].astype(float) / np.max(Rxdims))
    fig = plt.figure(num=1, figsize=figDims)
    fig = addImagePlot(fig, Rx, fileout, False, False)
    plt.show()
Esempio n. 6
0
  if( mode == 'R'):
    dv = (v1x-vm1)*(v2x-vm2)
    RES = (np.sum(dv)/N)/(np.std(v1x)*np.std(v2x))
    print('{} (d{}) = {}'.format(Sdict[mode], vn , RES))
  
  if( writeFile ):
    fout.write('{:.2f}\t{:.2e}\n'.format( z1[k1], RES ))


  if( printOn ):
    dimsf  = np.array( np.shape( dv ) )
    xydims = dimsf
    figDims = 13.*(xydims[::-1].astype(float)/np.max(xydims))
    fig = plt.figure(num=1, figsize=figDims)
    labelStr = '({0}_2 - {0}_1)(z={1} m)'.format(vn, z1[k1])
    fig = addImagePlot( fig, dv[::-1,:], labelStr, gridOn, limsOn )
    
    
    fig2 = plt.figure(num=2, figsize=figDims)
    lbl = '(Ref {0})(z={1} m)'.format(vn, z1[k1])
    fig2 = addImagePlot( fig2, v1x[::-1,:], lbl, gridOn, limsOn )
    
    fig3 = plt.figure(num=3, figsize=figDims)
    lbl = '(f2 {0})(z={1} m)'.format(vn, z1[k1])
    fig3 = addImagePlot( fig3, v2x[::-1,:], lbl, gridOn, limsOn )
    
    #fig3 = plt.figure(num=3)
    #plt.hist( np.ravel(dv[idnn]), bins=25, \
    #  normed=True, log=True, histtype=u'bar', label=labelStr )
    
    if( saveOn ):
Esempio n. 7
0
    ROrig = np.zeros(2)
    dPx = np.array([(X[0, 1] - X[0, 0]), (Y[1, 0] - Y[0, 0])])
    X = None
    Y = None
    Z = None
    C = None  # Clear memory

info = ''' Info:
 Dimensions [rows, cols] = {}
 Origin (top-left) [N,E] = {}
 Resolution        [dX,dY] = {}
'''.format(Rdims, ROrig, dPx)

print(info)

figDims = size * (Rdims[::-1].astype(float) / np.max(Rdims))
fig = plt.figure(num=1, figsize=figDims)
fig = addImagePlot(fig, R, rasterfile, gridOn, limsOn)
R = None

if (labels):
    fig = userLabels(fig)

if (not (save == '')):
    filename = rasterfile.split('/')[-1]  # Remove the path in Linux system
    filename = filename.split('\\')[-1]  # Remove the path in Windows system
    filename = filename.strip('.npz') + '.' + save
    fig.savefig(filename, format=save, dpi=args.dpi)

plt.show()
Esempio n. 8
0
    dictList.append(dataDict)
    dataDict = None
    fstr = filename.split('.')[0]
    fileout += fstr[-1]  # Gather the last character/number from the name.

fstr = filename.split('.')[0]
fileout = fstr[:-1] + '_' + fileout  # Complete the filename.
dPx = resolutionFromDicts(dictList)

#print ' dictList = {} '.format(dictList)

gIJ, XOrig, Mrows, Mcols = arrangeTileGrid(dictList, [ascii, npz])
print 'gIJ : {} '.format(gIJ)

Rdict = compileTileGrid(dictList, gIJ, Mrows, Mcols, [ascii, npz])
Rdims = np.array(np.shape(Rdict['R']))
Rdict['GlobOrig'] = XOrig
Rdict['dPx'] = dPx

if (not args.printOnly):
    saveTileAsNumpyZ(fileout, Rdict)

if (args.printOn or args.printOnly):
    R = Rdict['R']
    figDims = 13. * (Rdims[::-1].astype(float) / np.max(Rdims))
    fig = plt.figure(num=1, figsize=figDims)
    fig = addImagePlot(fig, R, 'Combined Tiles: ' + fileout)
    plt.show()
    R = None
Esempio n. 9
0
    R -= R0
    R[R < 0.] = 0.

R = applyMargins(R, mw, mr, mh)

# Apply desired filters.
Rf = np.zeros(np.shape(R), float)
Rf = filterAndScale(Rf, R, flt)
if (rmax is not None):
    idv = (Rf > rmax)
    Rf[idv] = np.maximum(Rf[idv], R[idv])

if (hmax):
    Rf = np.minimum(hmax, Rf)

Rdict['R'] = Rf
Rdict['GlobOrig'] = ROrig

if (not args.printOnly):
    saveTileAsNumpyZ(fileout, Rdict)

if (args.printOn or args.printOnly):
    figDims = 13. * (Rdims[::-1].astype(float) / np.max(Rdims))
    #print('Sum = {}'.format(np.sum(Rf)))
    fig = plt.figure(num=1, figsize=figDims)
    fig = addImagePlot(fig, Rf, fltStr + fileout)

    plt.show()

R = Rf = None
Esempio n. 10
0
In case two rasters need to be merged, but not superimposed.
Rt = Rt1.copy()
idx = (Rt == 0.)
Rt[idx] = Rt2[idx]
'''

Rdict1['R'] = Rt
Rdict1['GlobOrig'] = R1Orig
Rdict1['dPx'] = np.array([dPf, dPf])

# Print the filtered raster maps.
if (printOn or printOnly):
    if (flt1.count(None) == 0):
        fg1 = plt.figure(num=figN, figsize=(9., 9.))
        figN += 1
        fg1 = addImagePlot(fg1, Rt1, args.file1, gridOn=True)

    if (flt2.count(None) == 0):
        fg2 = plt.figure(num=figN, figsize=(9., 9.))
        figN += 1
        fg2 = addImagePlot(fg2, Rt2, args.file2, gridOn=True)

Rt1 = Rt2 = None

if (not printOnly):
    saveTileAsNumpyZ(args.fileout, Rdict1)

if (printOn or printOnly):
    fig = plt.figure(num=figN, figsize=(9., 9.))
    figN += 1
    fig = addImagePlot(fig, Rt, args.file1 + ' + ' + args.file2, gridOn=True)
Esempio n. 11
0
# Determine the resolution of the raster data [dn,de].
#resolution_check = UtmTileDims() / Rdims
#print ' Pixel resolution (m): {} vs. {}'.format(resolution, resolution_check)
Rdict = extractSubTile( rb, utmTile, XOrig, resolution)

Rdict['dPx'] = resolution
Rdict['rotation'] = 0.

Rdict['R'][Rdict['R']>32765] = 0.

if( args.scale != 1.):
  Rdict['R']=Rdict['R']*args.scale

if( utmTile is not None):
  fileout = utmTile
else:
  fileout = filename.split('.')[0]


if( not args.printOnly ):
  saveTileAsNumpyZ( fileout , Rdict )


if( args.printOnly or args.printOn ):
  Rdims = np.array( Rdict['R'].shape )
  figDims = 13.*(Rdims[::-1].astype(float)/np.max(Rdims))
  fig = plt.figure(num=1, figsize=figDims)
  fig = addImagePlot( fig, Rdict['R'], fileout )
  plt.show()
Esempio n. 12
0
  mskList = maskFromData( Rm, mskList, maxMaskNo )
  Rxm = Rm.copy()
else:
  sys.exit(' Nothing to do. Exiting ...')

if( filedata ):
  zbins = histogram( Rxm, Rt, mskList )
  np.savetxt('mask_height_histogram.dat', \
    np.c_[np.arange(1,len(zbins[0,:])+1), 100.*np.transpose(zbins) ])
  #print(' sum = {} '.format( np.sum(zbins[0,:])))


# Create an empty mask id list
if( Rxm is not None ):
  ratios = planAreaFractions( Rxm , mskList )
  if( Rt is not None ):
    vmeam, vvar, vstd = maskMeanValues( Rxm, Rt, mskList )

  if( printOn ):
    Rdims = np.array(Rxm.shape)
    figDims = 13.*(Rdims[::-1].astype(float)/np.max(Rdims))
    pfig = plt.figure(num=1, figsize=figDims)
    gridOn = True
    pfig = addImagePlot( pfig, Rxm, ' Mask ', gridOn, limsOn )
    if( saveFig ):
      if( filemask ): figname = filemask.split('.')[0]+'.jpg'
      else:           figname = filedata.split('.')[0]+'.jpg'
      pfig.savefig( figname , format='jpg', dpi=300)
      
    plt.show()