Changeset 6546


Ignore:
Timestamp:
Mar 18, 2009, 4:28:11 PM (15 years ago)
Author:
ole
Message:

Made is_absolute use a flag instead of re-evaluating.
This saved up to 50% of time spent in fitting.

Also, changed the way points are copied to be more intelligent.

Location:
anuga_core/source/anuga
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/coordinate_transforms/geo_reference.py

    r6438 r6546  
    7272        if ASCIIFile is not None:
    7373            self.read_ASCII(ASCIIFile, read_title=read_title)
     74           
     75        # Set flag for absolute points (used by get_absolute)   
     76        self.absolute = num.allclose([self.xllcorner, self.yllcorner], 0)
     77           
    7478
    7579    def get_xllcorner(self):
     
    200204            is_list = True
    201205
    202         points = ensure_numeric(copy.copy(points), num.Float)
     206        points = ensure_numeric(points, num.Float)
    203207       
    204208        if len(points.shape) == 1:
     
    222226            # If georeferences are different
    223227       
     228            points = copy.copy(points) # Don't destroy input                   
    224229            if not points_geo_ref is None:
    225230                # Convert points to absolute coordinates
     
    242247        in question are absolute.
    243248        """
    244 
    245         return num.allclose([self.xllcorner, self.yllcorner], 0)
    246 
     249       
     250        # FIXME(Ole): It is unfortunate that decision about whether points
     251        # are absolute or not lies with the georeference object. Ross pointed this out.
     252        # Moreover, this little function is responsible for a large fraction of the time
     253        # using in data fitting (something in like 40 - 50%.
     254        # This was due to the repeated calls to allclose.
     255        # With the flag method fitting is much faster (18 Mar 2009).
     256
     257       
     258        # FIXME(Ole): HACK to be able to reuse data already cached (18 Mar 2009).
     259        # Remove at some point
     260        if not hasattr(self, 'absolute'):
     261            self.absolute = num.allclose([self.xllcorner, self.yllcorner], 0)
     262
     263           
     264        # Return absolute flag   
     265        return self.absolute
    247266       
    248267   
     
    253272        """
    254273
    255         #if self.is_absolute():
    256         #    return points
    257274        is_list = False
    258275        if type(points) == types.ListType:
    259276            is_list = True
    260277
    261         points = ensure_numeric(copy.copy(points), num.Float)
     278        points = ensure_numeric(points, num.Float)
    262279        if len(points.shape) == 1:
    263             #One point has been passed
     280            # One point has been passed
    264281            msg = 'Single point must have two elements'
    265282            if not len(points) == 2:
    266283                raise ShapeError, msg   
    267                 #points = reshape(points, (1,2))
    268284
    269285
     
    276292        # Add geo ref to points
    277293        if not self.is_absolute():
     294            points = copy.copy(points) # Don't destroy input                   
    278295            points[:,0] += self.xllcorner
    279296            points[:,1] += self.yllcorner
     
    316333        # Subtract geo ref from points
    317334        if not self.is_absolute():
     335            points = copy.copy(points) # Don't destroy input                           
    318336            points[:,0] -= self.xllcorner
    319337            points[:,1] -= self.yllcorner
  • anuga_core/source/anuga/geospatial_data/test_geospatial_data.py

    r6488 r6546  
    19881988
    19891989    #suite = unittest.makeSuite(Test_Geospatial_data, 'test_write_csv_attributes_lat_long')
    1990     #suite = unittest.makeSuite(Test_Geospatial_data, 'test_find_optimal_smoothing_parameter')
     1990    suite = unittest.makeSuite(Test_Geospatial_data, 'test_find_optimal_smoothing_parameter')
    19911991    #suite = unittest.makeSuite(Test_Geospatial_data, 'test_split1')
    1992     suite = unittest.makeSuite(Test_Geospatial_data, 'test')
     1992    #suite = unittest.makeSuite(Test_Geospatial_data, 'test')
    19931993    runner = unittest.TextTestRunner() #verbosity=2)
    19941994    runner.run(suite)
Note: See TracChangeset for help on using the changeset viewer.