Changeset 5730


Ignore:
Timestamp:
Sep 4, 2008, 5:22:08 PM (14 years ago)
Author:
ole
Message:

Run time - flow through cross section and some refactoring + clean up

Location:
anuga_core
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/documentation/user_manual/anuga_user_manual.tex

    r5719 r5730  
    1818%   makeindex modanuga_user_manual.idx
    1919% To produce the modanuga_user_manual.ind file.
     20
     21
     22%%%%%%%%%%%%%% TODO %%%%%%%%%%%%%%%%
     23%
     24% ensure_geospatial
     25% ensure_absolute
     26% set_geo_reference
     27
     28
    2029
    2130
  • anuga_core/source/anuga/coordinate_transforms/geo_reference.py

    r5665 r5730  
    385385        geo_ref = None
    386386    else:
    387         geo_ref = apply(Geo_reference,origin)       
     387        geo_ref = apply(Geo_reference, origin)       
    388388    return geo_ref
    389389
  • anuga_core/source/anuga/geospatial_data/geospatial_data.py

    r5729 r5730  
    228228        self.attributes = attributes   
    229229
     230    #def set_geo_reference(self, geo_reference):
     231    #    # FIXME (Ole): Backwards compatibility - deprecate
     232    #    self.setgeo_reference(geo_reference)
    230233
    231234    def set_geo_reference(self, geo_reference):
    232         """
    233         Set's the georeference of geospatial.
    234         It can also be used to change the georeference
     235        """Set the georeference of geospatial data.
     236       
     237        It can also be used to change the georeference and will ensure that
     238        the absolute coordinate values are unchanged.
    235239        """
    236240        from anuga.coordinate_transforms.geo_reference import Geo_reference
    237241
    238242        if geo_reference is None:
    239             geo_reference = Geo_reference() # Use default
     243            # Use default - points are in absolute coordinates
     244            geo_reference = Geo_reference()
     245           
     246        # Allow for tuple (zone, xllcorner, yllcorner)   
    240247        geo_reference = ensure_geo_reference(geo_reference)
     248       
    241249        if not isinstance(geo_reference, Geo_reference):
     250            # FIXME (Ole): This exception will be raised if geo_reference is None
    242251            msg = 'Argument geo_reference must be a valid Geo_reference \n'
    243252            msg += 'object or None.'
    244253            raise msg
    245254
    246         # if a geo ref already exists, change the point data to
    247         # represent the new geo-ref
     255        # If a geo_reference already exists, change the point data according to
     256        # the new geo reference
    248257        if  self.geo_reference is not None:
    249             #FIXME: Maybe put out a warning here...
    250             self.data_points = self.get_data_points \
    251                                (geo_reference=geo_reference)
     258            self.data_points = self.get_data_points(geo_reference=geo_reference)
    252259           
    253260        self.geo_reference = geo_reference
     
    376383            lats_longs = []
    377384            for point in self.get_data_points(True):
    378                 ### UTMtoLL(northing, easting, zone,
     385           
     386                # UTMtoLL(northing, easting, zone,
    379387                lat_calced, long_calced = UTMtoLL(point[1],point[0],
    380388                                                  zone, isSouthHemisphere)
    381389                lats_longs.append((lat_calced, long_calced)) # to hash
    382390            return lats_longs
     391           
    383392        if absolute is True and geo_reference is None:
    384393            return self.geo_reference.get_absolute(self.data_points)
     
    388397                                self.geo_reference)
    389398        else:
     399            # If absolute is False
    390400            return self.data_points
    391401
     
    13151325           
    13161326def ensure_absolute(points, geo_reference=None):
    1317     """
     1327    """Ensure that points are in absolute coordinates.
     1328   
    13181329    This function inputs several formats and
    13191330    outputs one format. - a numeric array of absolute points.
    13201331
    1321     Inputed formats are;
    1322     points: List or numeric array of coordinate pairs [xi, eta] of
     1332    Input formats are;
     1333      points: List or numeric array of coordinate pairs [xi, eta] of
    13231334              points or geospatial object or points file name
    13241335
     
    13281339                 relative to their respective origins.
    13291340    """
    1330     if isinstance(points,type('')):
    1331         #It's a string
    1332         #assume it is a point file
    1333         points = Geospatial_data(file_name = points)
    1334        
    1335     if isinstance(points,Geospatial_data):
    1336         points = points.get_data_points( \
    1337                 absolute = True)
    1338         msg = "Use a Geospatial_data object or a mesh origin. Not both."
     1341
     1342    # Input check
     1343    if isinstance(points, basestring):
     1344        #It's a string - assume it is a point file
     1345        points = Geospatial_data(file_name=points)
     1346       
     1347    if isinstance(points, Geospatial_data):
     1348        points = points.get_data_points(absolute=True)
     1349        msg = 'Use a Geospatial_data object or a mesh origin. Not both.'
    13391350        assert geo_reference == None, msg
    1340            
    13411351    else:
    13421352        points = ensure_numeric(points, Float)
     1353       
     1354    # Sort of geo_reference and convert points
    13431355    if geo_reference is None:
    13441356        geo = None #Geo_reference()
     
    13511363                                geo_reference[2])
    13521364        points = geo.get_absolute(points)
     1365       
     1366    # Return   
    13531367    return points
    13541368     
     
    13681382                 relative to their respective origins.
    13691383    """
    1370     if isinstance(points,Geospatial_data):
     1384   
     1385    # Input check
     1386    if isinstance(points, Geospatial_data):
    13711387        msg = "Use a Geospatial_data object or a mesh origin. Not both."
    1372         assert geo_reference == None, msg
     1388        assert geo_reference is None, msg
    13731389        return points   
    13741390    else:
     1391        # List or numeric array of absolute points
    13751392        points = ensure_numeric(points, Float)
     1393
     1394    # Sort out geo reference   
    13761395    if geo_reference is None:
    13771396        geo = None
     
    13831402                                geo_reference[1],
    13841403                                geo_reference[2])
     1404                               
     1405    # Create Geospatial_data object with appropriate geo reference and return                           
    13851406    points = Geospatial_data(data_points=points, geo_reference=geo)       
    13861407    return points
  • anuga_core/source/anuga/geospatial_data/test_geospatial_data.py

    r5729 r5730  
    205205             
    206206    def test_set_geo_reference(self):
     207        """test_set_georeference
     208       
     209        Test that georeference can be changed without changing the
     210        absolute values.
     211        """
     212           
    207213        points_ab = [[12.5,34.7],[-4.5,-60.0]]
    208214        x_p = -10
     
    210216        geo_ref = Geo_reference(56, x_p, y_p)
    211217        points_rel = geo_ref.change_points_geo_ref(points_ab)
    212         spatial = Geospatial_data(points_rel)
    213         # since the geo_ref wasn't set
    214         assert not allclose( points_ab, spatial.get_data_points(absolute=True))
    215        
    216         spatial = Geospatial_data(points_rel, geo_reference=geo_ref)
    217         assert allclose( points_ab, spatial.get_data_points(absolute=True))
    218        
     218       
     219        # Create without geo_ref properly set
     220        G = Geospatial_data(points_rel)       
     221        assert not allclose(points_ab, G.get_data_points(absolute=True))
     222       
     223        # Create the way it should be
     224        G = Geospatial_data(points_rel, geo_reference=geo_ref)
     225        assert allclose(points_ab, G.get_data_points(absolute=True))
     226       
     227        # Change georeference and check that absolute values are unchanged.
    219228        x_p = 10
    220229        y_p = 400
    221230        new_geo_ref = Geo_reference(56, x_p, y_p)
    222         spatial.set_geo_reference(new_geo_ref)
    223         assert allclose( points_ab, spatial.get_data_points(absolute=True))
    224        
    225        
     231        G.set_geo_reference(new_geo_ref)
     232        assert allclose(points_ab, G.get_data_points(absolute=True))
     233       
     234
     235               
    226236       
    227237    def test_conversions_to_points_dict(self):
  • anuga_core/source/anuga/shallow_water/shallow_water_domain.py

    r5729 r5730  
    9797
    9898from anuga.utilities.numerical_tools import gradient, mean, ensure_numeric
     99from anuga.geospatial_data.geospatial_data import ensure_geospatial
     100
    99101from anuga.config import minimum_storable_height
    100102from anuga.config import minimum_allowed_height, maximum_allowed_speed
     
    409411       
    410412        # FIXME (Ole): HACK - need to make midpoints Geospatial instances
    411         midpoints = self.geo_reference.get_absolute(midpoints)       
     413        #midpoints = self.geo_reference.get_absolute(midpoints)       
     414       
     415        # Make midpoints Geospatial instances
     416        midpoints = ensure_geospatial(midpoints, self.geo_reference)       
    412417       
    413418        # Compute flow       
  • anuga_core/source/anuga/shallow_water/test_shallow_water_domain.py

    r5729 r5730  
    59055905if __name__ == "__main__":
    59065906
    5907     #suite = unittest.makeSuite(Test_Shallow_Water,'test')
    5908 
    5909     suite = unittest.makeSuite(Test_Shallow_Water,'test_get_flow_through_cross_section_with_geo')   
     5907    suite = unittest.makeSuite(Test_Shallow_Water,'test')
     5908
     5909    #suite = unittest.makeSuite(Test_Shallow_Water,'test_get_flow_through_cross_section_with_geo')   
    59105910    #suite = unittest.makeSuite(Test_Shallow_Water,'test_fitting_using_shallow_water_domain')   
    59115911    #suite = unittest.makeSuite(Test_Shallow_Water,'test_tight_slope_limiters')
Note: See TracChangeset for help on using the changeset viewer.