Ignore:
Timestamp:
Mar 10, 2008, 3:41:36 PM (17 years ago)
Author:
nick
Message:

update geospatial_data.py

File:
1 edited

Legend:

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

    r5010 r5146  
    282282            # Polygon is an object - extract points
    283283            polygon = polygon.get_data_points()
    284             #print 'polygon',polygon
    285284
    286285        points = self.get_data_points()   
    287         #print '%s points:%s' %(verbose,points)
     286#        if verbose: print '%s points:%s' %(verbose,points)
    288287        inside_indices = inside_polygon(points, polygon, closed, verbose)
    289288
    290289        clipped_G = self.get_sample(inside_indices)
     290
    291291#        clipped_points = take(points, inside_indices)
    292292
     
    375375                lats_longs.append((lat_calced, long_calced)) # to hash
    376376            return lats_longs
    377            
    378377        if absolute is True and geo_reference is None:
    379378            return self.geo_reference.get_absolute(self.data_points)
     
    384383        else:
    385384            return self.data_points
    386        
     385
    387386   
    388387    def get_attributes(self, attribute_name=None):
     
    617616            """
    618617        #FIXME: add the geo_reference to this
    619        
     618#        print 'hello from get_sample'
    620619        points = self.get_data_points()
    621620        sampled_points = take(points, indices)
     
    627626            for key, att in attributes.items():
    628627                sampled_attributes[key] = take(att, indices)
     628
     629#        print 'goodbye from get_sample'
    629630
    630631        return Geospatial_data(sampled_points, sampled_attributes)
     
    13981399   
    13991400    """
     1401    Removes a small random sample of points from 'data_file'. Then creates
     1402    models with different alpha values from 'alpha_list' and cross validates
     1403    the predicted value to the previously removed point data. Returns the
     1404    alpha value which has the smallest covariance.
     1405   
    14001406    data_file: must not contain points outside the boundaries defined
    14011407           and it either a pts, txt or csv file.
     
    14311437           alpha that created it. PLUS writes a plot of the results
    14321438           
    1433     NOTE: code will not work if the data_file extend is greater than the
    1434     boundary_polygon or the north_boundary...west_boundary
     1439    NOTE: code will not work if the data_file extent is greater than the
     1440    boundary_polygon or any of the boundaries, eg north_boundary...west_boundary
    14351441       
    14361442    """
     
    14911497    points=G_small.get_data_points()
    14921498
    1493 
    1494 
    1495 
    1496     #FIXME: Remove points outside boundary polygon
    1497 #    print 'new point',len(points)
    1498 #   
    1499 #    new_points=[]
    1500 #    new_points=array([],typecode=Float)
    1501 #    new_points=resize(new_points,(len(points),2))
    1502 #    print "BOUNDARY", boundary_poly
    1503 #    for i,point in enumerate(points):
    1504 #        if is_inside_polygon(point,boundary_poly, verbose=True):
    1505 #            new_points[i] = point
    1506 #            print"WOW",i,new_points[i]
    1507 #    points = new_points
    1508 
    1509    
    15101499    if verbose: print "Number of points in sample to compare: ", len(points)
    15111500   
     
    15171506    else:
    15181507        alphas=alpha_list
    1519 #    domains = {}
    15201508
    15211509    #creates array with columns 1 and 2 are x, y. column 3 is elevation
     
    15331521
    15341522    normal_cov=array(zeros([len(alphas),2]),typecode=Float)
    1535 
    1536 
    1537 
    1538 
    15391523
    15401524    if verbose: print 'Setup computational domains with different alphas'
     
    15521536                    verbose = verbose,
    15531537                    alpha = alpha)
    1554 #        domains[alpha]=domain
    15551538
    15561539        points_geo=domain.geo_reference.change_points_geo_ref(points)
     
    15721555        if verbose: print'Covariance for alpha ',normal_cov[i][0],'= ',normal_cov[i][1]
    15731556        if verbose: print'-------------------------------------------- \n'
    1574 #    if verbose: print 'Determine difference between predicted results and actual data'
    1575 #    for i,alpha in enumerate(domains):
    1576 #        if verbose: print'Alpha =',alpha
    1577 #       
    1578 #        points_geo=domains[alpha].geo_reference.change_points_geo_ref(points)
    1579 #        #returns the predicted elevation of the points that were "split" out
    1580 #        #of the original data set for one particular alpha
    1581 #        elevation_predicted=domains[alpha].quantities[attribute_smoothed].\
    1582 #                            get_values(interpolation_points=points_geo)
    1583 #
    1584 #        #add predicted elevation to array that starts with x, y, z...
    1585 #        data[:,i+3]=elevation_predicted
    1586 #
    1587 #        sample_cov= cov(elevation_sample)
    1588 #        #print elevation_predicted
    1589 #        ele_cov= cov(elevation_sample-elevation_predicted)
    1590 #        normal_cov[i,:]= [alpha,ele_cov/sample_cov]
    1591 #        print 'memory usage during compare',mem_usage()
    1592 #       
    1593 #
    1594 #        if verbose: print'cov',normal_cov[i][0],'= ',normal_cov[i][1]
    15951557
    15961558    normal_cov0=normal_cov[:,0]
     
    16111573        print '\n Optimal alpha is: %s ' % normal_cov_new[(argmin(normal_cov_new,axis=0))[1],0]
    16121574
     1575    # covariance and optimal alpha
    16131576    return min(normal_cov_new[:,1]) , normal_cov_new[(argmin(normal_cov_new,axis=0))[1],0]
    16141577
Note: See TracChangeset for help on using the changeset viewer.