Changeset 9051


Ignore:
Timestamp:
Feb 11, 2014, 9:09:53 PM (11 years ago)
Author:
davies
Message:

Fix makeGeoTif + minor tweaks

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/shallow_water/swDE1_domain_ext.c

    r9039 r9051  
    558558
    559559
    560             // If neighbour is a boundary condition, add the flux to the boundary_flux_integral
    561             if(n<0){
     560            // If this cell is not a ghost, and the neighbour is a boundary
     561            // condition OR a ghost cell, then add the flux to the
     562            // boundary_flux_integral
     563            if( (n<0 & tri_full_flag[k]==1) | ( n>=0 && (tri_full_flag[k]==1 & tri_full_flag[n]==0)) ){
    562564                boundary_flux_sum[0] += edgeflux_store[ki3];
    563565            }
  • trunk/anuga_core/source/anuga/utilities/plot_utils.py

    r9044 r9051  
    550550    xsize = len(lons)
    551551
    552     # Assume data/lats/longs refer to cell centres, and compute lower left coordinate
    553     llx = lons[0] - (xres / 2.)
    554     lly = lats[0] - (yres / 2.)
     552    # Assume data/lats/longs refer to cell centres, and compute upper left coordinate
     553    ulx = lons[0] - (xres / 2.)
     554    uly = lats[lats.shape[0]-1] + (yres / 2.)
    555555
    556556    # GDAL magic to make the tif
     
    568568    ds.SetProjection(srs.ExportToWkt())
    569569
    570     gt = [llx, xres, 0, lly, 0, yres ]
     570    gt = [ulx, xres, 0, uly, 0, -yres ]
     571    #gt = [llx, xres, 0, lly, yres,0 ]
    571572    ds.SetGeoTransform(gt)
     573
     574    #import pdb
     575    #pdb.set_trace()
    572576
    573577    outband = ds.GetRasterBand(1)
     
    595599        INPUTS: swwFile -- name of sww file
    596600                output_quantities -- list of quantitiies to plot, e.g. ['depth', 'velocity', 'stage','elevation','depthIntegratedVelocity']
    597                 myTimeStep -- time-index of swwFile to plot, or 'last', or 'max'
     601                myTimeStep -- list containing time-index of swwFile to plot, or 'last', or 'max'
    598602                CellSize -- approximate pixel size for output raster [adapted to fit lower_left / upper_right]
    599603                lower_left -- [x0,y0] of lower left corner. If None, use extent of swwFile.
     
    624628        raise Exception, 'Must specify EITHER an integer EPSG_CODE describing the file projection, OR a proj4string'
    625629
     630    # Ensure myTimeStep is a list
     631    if type(myTimeStep)!=list:
     632        myTimeStep=[myTimeStep]
     633
    626634    # Make output_dir
    627635    try:
     
    640648    yllcorner=swwIn.yllcorner
    641649
    642     if(myTimeStep=='last'):
    643         myTimeStep=len(p.time)-1
    644    
    645650
    646651    if(verbose):
     
    650655    swwY=p2.y+yllcorner
    651656
     657    # Grid for meshing
     658    if(verbose):
     659        print 'Computing grid of output locations...'
     660    # Get points where we want raster cells
     661    if(lower_left is None):
     662        lower_left=[swwX.min(),swwY.min()]
     663    if(upper_right is None):
     664        upper_right=[swwX.max(),swwY.max()]
     665    nx=round((upper_right[0]-lower_left[0])*1.0/(1.0*CellSize)) + 1
     666    xres=(upper_right[0]-lower_left[0])*1.0/(1.0*(nx-1))
     667    desiredX=scipy.arange(lower_left[0], upper_right[0],xres )
     668    ny=round((upper_right[1]-lower_left[1])*1.0/(1.0*CellSize)) + 1
     669    yres=(upper_right[1]-lower_left[1])*1.0/(1.0*(ny-1))
     670    desiredY=scipy.arange(lower_left[1], upper_right[1], yres)
     671
     672    gridX, gridY=scipy.meshgrid(desiredX,desiredY)
     673
     674    if(verbose):
     675        print 'Making interpolation functions...'
     676    swwXY=scipy.array([swwX[:],swwY[:]]).transpose()
     677    # Get index of nearest point
     678    index_qFun=scipy.interpolate.NearestNDInterpolator(swwXY,scipy.arange(len(swwX),dtype='int32').transpose())
     679    gridqInd=index_qFun(scipy.array([scipy.concatenate(gridX),scipy.concatenate(gridY)]).transpose())
     680
    652681    # Loop over all output quantities and produce the output
    653     for output_quantity in output_quantities:
    654 
    655         if(myTimeStep!='max'):
    656             if(output_quantity=='stage'):
    657                 swwStage=p2.stage[myTimeStep,:]
    658             if(output_quantity=='depth'):
    659                 swwHeight=p2.height[myTimeStep,:]
    660             if(output_quantity=='velocity'):
    661                 swwVel=p2.vel[myTimeStep,:]
    662             if(output_quantity=='depthIntegratedVelocity'):
    663                 swwDIVel=(p2.xmom[myTimeStep,:]**2+p2.ymom[myTimeStep,:]**2)**0.5
    664             timestepString=str(round(p2.time[myTimeStep]))
    665         else:
    666             if(output_quantity=='stage'):
    667                 swwStage=p2.stage.max(axis=0)
    668             if(output_quantity=='depth'):
    669                 swwHeight=p2.height.max(axis=0)
    670             if(output_quantity=='velocity'):
    671                 swwVel=p2.vel.max(axis=0)
    672             if(output_quantity=='depthIntegratedVelocity'):
    673                 swwDIVel=((p2.xmom**2+p2.ymom**2).max(axis=0))**0.5
    674             timestepString='max'
    675            
    676         # Make name for output file
    677         output_name=output_dir+'/'+os.path.splitext(os.path.basename(swwFile))[0] + '_'+\
    678                     output_quantity+'_'+timestepString+\
    679                     '_'+str(myTimeStep)+'.tif'
    680 
     682    for myTS in myTimeStep:
    681683        if(verbose):
    682             print 'Computing grid of output locations...'
    683         # Get points where we want raster cells
    684         if(lower_left is None):
    685             lower_left=[swwX.min(),swwY.min()]
    686         if(upper_right is None):
    687             upper_right=[swwX.max(),swwY.max()]
    688 
    689         nx=round((upper_right[0]-lower_left[0])*1.0/(1.0*CellSize)) + 1
    690         xres=(upper_right[0]-lower_left[0])*1.0/(1.0*(nx-1))
    691         desiredX=scipy.arange(lower_left[0], upper_right[0],xres )
    692         ny=round((upper_right[1]-lower_left[1])*1.0/(1.0*CellSize)) + 1
    693         yres=(upper_right[1]-lower_left[1])*1.0/(1.0*(ny-1))
    694         desiredY=scipy.arange(lower_left[1], upper_right[1], yres)
    695 
    696         gridX, gridY=scipy.meshgrid(desiredX,desiredY)
    697 
    698         # Make functions to interpolate quantities at points
    699         if(verbose):
    700             print 'Making interpolation functions...'
    701         swwXY=scipy.array([swwX[:],swwY[:]]).transpose()
    702         if(output_quantity=='stage'):
    703             qFun=scipy.interpolate.NearestNDInterpolator(swwXY,swwStage.transpose())
    704         elif(output_quantity=='velocity'):
    705             qFun=scipy.interpolate.NearestNDInterpolator(swwXY,swwVel.transpose())
    706         elif(output_quantity=='elevation'):
    707             qFun=scipy.interpolate.NearestNDInterpolator(swwXY,p2.elev.transpose())
    708         elif(output_quantity=='depth'):
    709             qFun=scipy.interpolate.NearestNDInterpolator(swwXY,swwHeight.transpose())
    710         elif(output_quantity=='depthIntegratedVelocity'):
    711             qFun=scipy.interpolate.NearestNDInterpolator(swwXY,swwDIVel.transpose())
    712         else:
    713             raise Exception, 'output_quantity not available -- check if it is spelled correctly'
    714 
    715         if(verbose):
    716             print 'Interpolating'
    717         gridq=qFun(scipy.array([scipy.concatenate(gridX),scipy.concatenate(gridY)]).transpose()).transpose()
    718         gridq.shape=(len(desiredY),len(desiredX))
    719 
    720         if(verbose):
    721             print 'Making raster ...'
    722         make_grid(gridq,desiredY,desiredX, output_name,EPSG_CODE=EPSG_CODE, proj4string=proj4string)
     684            print myTS
     685        for output_quantity in output_quantities:
     686
     687            if(myTS=='last'):
     688                myTS=len(p.time)-1
     689       
     690
     691            if(myTS!='max'):
     692                if(output_quantity=='stage'):
     693                    gridq=p2.stage[myTS,:][gridqInd]
     694                if(output_quantity=='depth'):
     695                    gridq=p2.height[myTS,:][gridqInd]
     696                if(output_quantity=='velocity'):
     697                    gridq=p2.vel[myTS,:][gridqInd]
     698                if(output_quantity=='depthIntegratedVelocity'):
     699                    swwDIVel=(p2.xmom[myTS,:]**2+p2.ymom[myTS,:]**2)**0.5
     700                    gridq=swwDIVel[gridqInd]
     701                timestepString=str(round(p2.time[myTS]))
     702            else:
     703                if(output_quantity=='stage'):
     704                    gridq=p2.stage.max(axis=0)[gridqInd]
     705                if(output_quantity=='depth'):
     706                    gridq=p2.height.max(axis=0)[gridqInd]
     707                if(output_quantity=='velocity'):
     708                    gridq=p2.vel.max(axis=0)[gridqInd]
     709                if(output_quantity=='depthIntegratedVelocity'):
     710                    swwDIVel=((p2.xmom**2+p2.ymom**2).max(axis=0))**0.5
     711                    gridq=swwDIVel[gridqInd]
     712                timestepString='max'
     713               
     714            # Make name for output file
     715            output_name=output_dir+'/'+os.path.splitext(os.path.basename(swwFile))[0] + '_'+\
     716                        output_quantity+'_'+timestepString+\
     717                        '_'+str(myTS)+'.tif'
     718
     719            if(verbose):
     720                print 'Making raster ...'
     721            gridq.shape=(len(desiredY),len(desiredX))
     722            make_grid(scipy.flipud(gridq),desiredY,desiredX, output_name,EPSG_CODE=EPSG_CODE, proj4string=proj4string)
    723723
    724724    return
  • trunk/anuga_core/source/anuga_validation_tests/case_studies/towradgi/Compare_results_with_fieldObs.py

    r9044 r9051  
    88from anuga.utilities import plot_utils as util
    99
    10 p=util.get_output('MODEL_OUTPUTS/Towradgi_historic_flood.sww')
     10swwdir='MODEL_OUTPUTS/'
     11#swwdir='MODEL_bridges_n0p04/'
     12
     13p=util.get_output(swwdir+'Towradgi_historic_flood.sww')
    1114p2=util.get_centroids(p,velocity_extrapolation=True)
    1215floodLevels=scipy.genfromtxt('Validation/historic_1998_flood_levels_towradgi_ck.csv', delimiter=',',skip_header=1)
     
    5053    tif_outdir='OUTPUT_TIFS'
    5154    CellSize=5.0
    52     util.Make_Geotif('MODEL_OUTPUTS/Towradgi_historic_flood.sww',
     55    util.Make_Geotif(swwdir+'Towradgi_historic_flood.sww',
    5356                      ['depth','velocity','depthIntegratedVelocity','elevation'],'max',
    5457                      CellSize=CellSize,EPSG_CODE=32756,output_dir=tif_outdir)
  • trunk/anuga_core/source/anuga_validation_tests/case_studies/towradgi/Towradgi_historic_flood.py

    r9044 r9051  
    983983        domain.write_time()
    984984
     985barrier()
    985986if myid == 0:
    986987    print 'Number of processors %g ' %numprocs
  • trunk/anuga_work/development/gareth/tests/Petar/Towradgi/Aug98_hort_discontinous.py

    r9040 r9051  
    249249 
    250250if myid == 0 and verbose: print 'CREATING INLETS'
    251 """
     251
    252252#------------------------------------------------------------------------------
    253253# ENTER CULVERT DATA
     
    670670                                    label=join('Runs', '7H'), # this puts the culvert hydraulics output into the same dir as the sww's
    671671                                    verbose=False)
    672 """
     672
    673673
    674674#------------------------------------------------------------------------------
  • trunk/anuga_work/development/gareth/tests/shallow_steep_slope/channel_SU_sparse.py

    r9039 r9051  
    2121from anuga.structures.inlet_operator import Inlet_operator
    2222from anuga.shallow_water.shallow_water_domain import Domain as Domain
    23 from bal_and import *
     23#from bal_and import *
    2424#from balanced_dev import Domain as Domain
    2525#from anuga_tsunami import *
     
    3232domain = Domain(points, vertices, boundary) # Create domain
    3333domain.set_name('channel_SU_2_v2') # Output name
    34 #domain.set_flow_algorithm('DE1')
     34domain.set_flow_algorithm('DE1')
    3535#------------------------------------------------------------------------------
    3636# Setup initial conditions
    3737#------------------------------------------------------------------------------
    3838def topography(x, y):
    39         return -x/10.  #+ 1.*(numpy.sin(x/10.) +abs(y-50.)/10.) -0.*(x>80.) # linear bed slope
     39        return -x/10.  + 1.*(numpy.sin(x/10.) +abs(y-50.)/10.) -0.*(x>80.) # linear bed slope
    4040
    4141def stagetopo(x,y):
  • trunk/anuga_work/development/gareth/tests/taguig_parallel/runThis.sh

    r9040 r9051  
    22rm -r MODEL_OUTPUTS*
    33# Run in parallel
    4 mpirun -np 12 python runtaguig.py
     4mpirun -np 40 python runtaguig.py
    55# Run in serial
    6 mpirun -np 5 python runtaguig.py
     6mpirun -np 80 python runtaguig.py
    77# Compare serial and parallel
    88ipython compare_parallel_serial.py
  • trunk/anuga_work/development/gareth/tests/taguig_parallel/runtaguig.py

    r9042 r9051  
    5959    #domain.ghost_layer_width=4
    6060    domain.set_store_centroids(True)
    61     #domain.set_flow_algorithm('DE1')
     61    domain.set_flow_algorithm('DE1')
    6262
    6363    # Define function to compute elevation
     
    6969                            alpha=0.0001)
    7070
     71
    7172else:
    7273    domain=None
     
    7778barrier()
    7879
     80domain.set_quantity('stage', 1.0)
     81domain.set_quantity('friction', 0.03)
    7982## Force first order
    8083#domain.beta_w=0.0
     
    8588#domain.beta_vh_dry=0.0
    8689###
     90#print domain.quantities['stage'].centroid_values.max()
     91#print domain.quantities['stage'].vertex_values.max()
    8792
    88 domain.set_quantity('stage', 1.0)
    89 domain.set_quantity('friction', 0.03)
    90 
     93#barrier()
     94#raise Exception, 'Finish here'
    9195# Rain
    92 #rain_mps=90.0/(1000*3600) # 90mm/hr is meters-per-second
    93 #def myrain(t):
    94 #    return(rain_mps)
    95 #rainin_term=anuga.operators.rate_operators.Rate_operator(domain,rate=myrain)
     96rain_mps=90.0/(1000.*3600.) # 90mm/hr is meters-per-second
     97def myrain(t):
     98    return(rain_mps)
     99#myindices=range(len(domain.centroid_coordinates[:,0]))
     100#rainin_term=anuga.operators.rate_operators.Rate_operator(domain,rate=myrain,indices=myindices)
     101rainin_term=anuga.operators.rate_operators.Rate_operator(domain,rate=myrain,polygon=project.bounding_polygon)
    96102
    97103## Boundary conditions
     
    119125
    120126barrier()
     127finalize()
Note: See TracChangeset for help on using the changeset viewer.