Ignore:
Timestamp:
Nov 15, 2007, 10:24:02 AM (16 years ago)
Author:
nick
Message:

changed find_optimal_smoothing_parameter to use a passed mesh_file and added some checks.
plus updated split to be more robust
plus added two more test

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/geospatial_data/geospatial_data.py

    r4776 r4816  
    1111                        size, shape
    1212#from Array import tolist
    13 from RandomArray import randint, seed
     13from RandomArray import randint, seed, get_seed
    1414from copy import deepcopy
    1515
     
    670670       
    671671        # Set seed if provided, mainly important for unit test!
     672        # plus recalcule seed when no seed provided.
    672673        if seed_num != None:
    673674            seed(seed_num,seed_num)
     675        else:
     676            seed()
     677        if verbose: print "seed:", get_seed()
    674678       
    675679        random_num = randint(0,self_size-1,(int(new_size),))
     
    13931397    alpha_list: the alpha values to test in a single list
    13941398   
    1395     mesh_file: name of the created mesh file
     1399    mesh_file: name of the created mesh file or if passed in will read it.
     1400            NOTE, if there is a mesh file mesh_resolution,
     1401            north_boundary, south... etc will be ignored.
    13961402   
    13971403    mesh_resolution: the maximum area size for a triangle
     
    14041410   
    14051411    USAGE:
    1406         find_optimal_smoothing_parameter(data_file=fileName,
     1412        value, alpha = find_optimal_smoothing_parameter(data_file=fileName,
    14071413                                             alpha_list=[0.0001, 0.01, 1],
    14081414                                             mesh_file=None,
     
    14301436    attribute_smoothed='elevation'
    14311437
    1432     if north_boundary is None or south_boundary is None or \
    1433        east_boundary is None or west_boundary is None:
    1434         no_boundary=True
    1435     else:
    1436         no_boundary=False
    1437    
    1438     if no_boundary is True:
    1439         msg= 'All boundaries must be defined'
    1440         raise msg
    1441 
    14421438    if mesh_file is None:
    14431439        mesh_file='temp.msh'
    14441440
    1445        
    1446        
    1447     poly_topo = [[east_boundary,south_boundary],
    1448                  [east_boundary,north_boundary],
    1449                  [west_boundary,north_boundary],
    1450                  [west_boundary,south_boundary]]
    1451                  
    1452     create_mesh_from_regions(poly_topo,
    1453                              boundary_tags={'back': [2],
    1454                                             'side': [1,3],
    1455                                             'ocean': [0]},
    1456                          maximum_triangle_area=mesh_resolution,
    1457                          filename=mesh_file,
    1458                          use_cache=cache,
    1459                          verbose=verbose)
     1441        if north_boundary is None or south_boundary is None or \
     1442           east_boundary is None or west_boundary is None:
     1443            no_boundary=True
     1444        else:
     1445            no_boundary=False
     1446       
     1447        if no_boundary is True:
     1448            msg= 'All boundaries must be defined'
     1449            raise msg
     1450
     1451        poly_topo = [[east_boundary,south_boundary],
     1452                     [east_boundary,north_boundary],
     1453                     [west_boundary,north_boundary],
     1454                     [west_boundary,south_boundary]]
     1455                     
     1456        create_mesh_from_regions(poly_topo,
     1457                                 boundary_tags={'back': [2],
     1458                                                'side': [1,3],
     1459                                                'ocean': [0]},
     1460                             maximum_triangle_area=mesh_resolution,
     1461                             filename=mesh_file,
     1462                             use_cache=cache,
     1463                             verbose=verbose)
     1464
     1465    else: # if mesh file provided
     1466        #test mesh file exists?
     1467        if access(mesh_file,F_OK) == 0:
     1468            msg="file %s doesn't exist!" %mesh_file
     1469            raise IOError, msg
    14601470
    14611471    #split topo data
     
    15301540        loglog(normal_cov_new[:,0],normal_cov_new[:,1])
    15311541        savefig(plot_name,dpi=300)
    1532    
    1533     remove(mesh_file)
     1542    if mesh_file == 'temp.msh':
     1543        remove(mesh_file)
    15341544   
    15351545    return min(normal_cov_new[:,1]) , normal_cov_new[(argmin(normal_cov_new,axis=0))[1],0]
Note: See TracChangeset for help on using the changeset viewer.