Ignore:
Timestamp:
Mar 31, 2010, 10:57:09 PM (14 years ago)
Author:
hudson
Message:

Ticket 113 - added an output_centroids parameter to allow centroid data to be written to gauges, rather than the data at the sampled point.

Added 2 new unit tests for this functionality.

Location:
anuga_core/source/anuga/abstract_2d_finite_volumes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/abstract_2d_finite_volumes/gauge.py

    r7672 r7673  
    180180                                     verbose=verbose,
    181181                                     use_cache=use_cache,
    182                                                                         output_centroids = output_centroids)
     182                                    output_centroids = output_centroids)
    183183
    184184        if quake_offset_time is None:
     
    190190                quake_time = time + quake_offset_time
    191191                points_list = [quake_time, quake_time/3600.]# fudge around SWW time bug
    192                 point_quantities = callable_sww(time,point_i)
    193                
     192                point_quantities = callable_sww(time,point_i) # __call__ is overridden
     193                               
    194194                for quantity in quantities:
    195195                    if quantity == NAN:
     
    271271                   title_on=None,
    272272                   use_cache=False,
    273                    verbose=False):
     273                   verbose=False,
     274                                   output_centroids=False):
    274275    """ Read sww file and plot the time series for the
    275276    prescribed quantities at defined gauge locations and
     
    388389                        title_on,
    389390                        use_cache,
    390                         verbose)
     391                        verbose,
     392                                                output_centroids = output_centroids)
    391393    return k
    392394
     
    423425                    title_on = None,
    424426                    use_cache = False,
    425                     verbose = False):   
     427                    verbose = False,
     428                                        output_centroids = False):   
    426429       
    427430    # FIXME(Ole): Shouldn't print statements here be governed by verbose?
     
    486489                          time_thinning = time_thinning,
    487490                          verbose = verbose,
    488                           use_cache = use_cache)
     491                          use_cache = use_cache,
     492                                                  output_centroids = output_centroids)
    489493
    490494        # determine which gauges are contained in sww file
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_gauge.py

    r7672 r7673  
    451451
    452452        # create a csv file containing our gauge points
    453         points = [[2.0,1.0],[5.0,5.0]]
     453        points = [[2.0,1.0],[4.5,4.0]]
    454454
    455455        points_file = tempfile.mktemp(".csv")
    456456        file_id = open(points_file,"w")
    457 # These values are where the centroids should be
     457# These values are where the centroids should be               
    458458#        file_id.write("name, easting, northing, elevation \n\
    459 #point1, 1.5, 1.5, 3.0\n\
    460 #point2, 4.5, 4.5, 9.0\n")
     459#point1, 2.0, 2.0, 3.0\n\
     460#point2, 4.0, 4.0, 9.0\n")
    461461 
    462  # These values are slightly off the centroids - will it find them?
     462# These values are slightly off the centroids - will it find the centroids?
    463463        file_id.write("name, easting, northing, elevation \n\
    464464point1, 2.0, 1.0, 3.0\n\
    465 point2, 5.5, 4.0, 9.0\n")
     465point2, 4.5, 4.0, 9.0\n")
    466466
    467467 
     
    474474                       output_centroids=True)
    475475
    476         point1_answers_array = [[0.0,0.0,1.0,2.5,-1.5,3.0,4.0], [2.0,2.0/3600.,10.0,11.5,-1.5,3.0,4.0]]
     476        point1_answers_array = [[0.0,0.0,1.0,3.0,-2.0,3.0,4.0], [2.0,2.0/3600.,10.0,12.0,-2.0,3.0,4.0]]
    477477        point1_filename = 'gauge_point1.csv'
    478478        point1_handle = file(point1_filename)
     
    482482        line=[]
    483483        for i,row in enumerate(point1_reader):
    484 #           print 'i',i,'row',row
    485484            line.append([float(row[0]),float(row[1]),float(row[2]),float(row[3]),
    486485                         float(row[4]),float(row[5]),float(row[6])])
     
    488487            assert num.allclose(line[i], point1_answers_array[i])
    489488
    490         point2_answers_array = [[0.0,0.0,1.0,5.5,-4.5,3.0,4.0], [2.0,2.0/3600.,10.0,14.5,-4.5,3.0,4.0]]
     489        point2_answers_array = [[0.0,0.0,1.0,5.0,-4.0,3.0,4.0], [2.0,2.0/3600.,10.0,14.0,-4.0,3.0,4.0]]
    491490        point2_filename = 'gauge_point2.csv'
    492491        point2_handle = file(point2_filename)
     
    496495        line=[]
    497496        for i,row in enumerate(point2_reader):
    498 #           print 'i',i,'row',row
    499497            line.append([float(row[0]),float(row[1]),float(row[2]),float(row[3]),
    500498                         float(row[4]),float(row[5]),float(row[6])])
    501 #           print 'assert line',line[i],'point1',point1_answers_array[i]
     499#           print i, 'assert line',line[i],'point2',point2_answers_array[i]
    502500            assert num.allclose(line[i], point2_answers_array[i])
    503501                         
  • anuga_core/source/anuga/abstract_2d_finite_volumes/util.py

    r7672 r7673  
    5454                  use_cache=False,
    5555                  boundary_polygon=None,
    56                                   output_centroids=False):
     56                  output_centroids=False):
    5757    """Read time history of spatial data from NetCDF file and return
    5858    a callable object.
     
    140140              'verbose': verbose,
    141141              'boundary_polygon': boundary_polygon,
    142                           'output_centroids': output_centroids}
     142              'output_centroids': output_centroids}
    143143
    144144    # Call underlying engine with or without caching
     
    232232                                        verbose=verbose,
    233233                                        boundary_polygon=boundary_polygon,
    234                                                                                 output_centroids=output_centroids)
     234                                        output_centroids=output_centroids)
    235235    else:
    236236        # FIXME (Ole): Could add csv file here to address Ted Rigby's
     
    260260                             verbose=False,
    261261                             boundary_polygon=None,
    262                                                         output_centroids=False):
     262                            output_centroids=False):
    263263    """Read time history of spatial data from NetCDF sww file and
    264264    return a callable object f(t,x,y)
     
    501501                                   time_thinning=time_thinning,
    502502                                   verbose=verbose,
    503                                    gauge_neighbour_id=gauge_neighbour_id),
     503                                   gauge_neighbour_id=gauge_neighbour_id,
     504                                                                   output_centroids=output_centroids),
    504505            starttime)
    505506
Note: See TracChangeset for help on using the changeset viewer.