Changeset 4129 for anuga_core/source


Ignore:
Timestamp:
Jan 5, 2007, 11:05:11 AM (18 years ago)
Author:
duncan
Message:

fit.py now blocks, on .txt/.csv files

Location:
anuga_core/source/anuga
Files:
6 edited

Legend:

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

    r4127 r4129  
    692692        #print kwargs
    693693
     694        #FIXME(dsg):Why is this catched? fit_to_mesh handles caching.
    694695        if use_cache is True:
    695696            try:
     
    734735        assert type(filename) == StringType, msg
    735736
    736 
    737         # Read from (NetCDF) file
    738         # FIXME (Ole): This function should really return a
    739         # Geospatial_data object.
    740737        geospatial_data = Geospatial_data(filename)
    741738       
    742         #points_dict = import_points_file(filename)
    743         #points_dict['pointlist'] = None
    744         #points_dict['attributelist'] = None
    745         #points = points_dict['pointlist']
    746         #attributes = points_dict['attributelist']
    747 
    748 
    749         #Take care of georeferencing
    750         # this doesn't do anything....
    751         #if points_dict.has_key('geo_reference') and \
    752         #       points_dict['geo_reference'] is not None:
    753         #    data_georef = points_dict['geo_reference']
    754         #else:
    755         #    data_georef = None
    756            
    757         # if there is no attribute name, use the 1st key?
    758         # This isn't so good..., if there is more than 1 key
    759         # since it will not always be the 1 column
    760         # or anything predictable...       
    761 
    762         #if attribute_name is None:
    763         #    names = attributes.keys()
    764         #    attribute_name = names[0]
    765 
    766         #msg = 'Attribute_name must be a text string'
    767         #assert type(attribute_name) == StringType, msg
    768 
    769 
    770         #if verbose:
    771         #    print 'Using attribute %s from file %s' %(attribute_name, filename)
    772         #    print 'Available attributes: %s' %(names)
    773 
    774         #try:
    775         #    z = attributes[attribute_name]
    776         #except:
    777         #    msg = 'Could not extract attribute %s from file %s'\
    778         #          %(attribute_name, filename)
    779         #    raise msg
    780        
    781         #Call underlying method for geospatial data
    782         #geospatial_data = points_dictionary2geospatial_data(points_dict)
    783         # geospatial_data.set_default_attribute_name(attribute_name)
    784 
    785739        self.set_values_from_geospatial_data(geospatial_data,
    786740                                             alpha,
  • anuga_core/source/anuga/fit_interpolate/benchmark_least_squares.py

    r4108 r4129  
    4949
    5050class BenchmarkLeastSquares:
    51 
     51"""
     52"""
     53
     54"""
     55
     56Note(DSG-DSG): If you are interested in benchmarking fitting, before
     57and after blocking O:\1\dgray\before_blocking_subsandpit is before blocking
     58
     59"""
    5260
    5361    def __init__(self):
  • anuga_core/source/anuga/fit_interpolate/fit.py

    r4108 r4129  
    2323   * (DSG-) Change the interface of fit, so a domain object can
    2424      be passed in. (I don't know if this is feasible). If could
    25       save time.
     25      save time/memory.
    2626"""
     27import types
    2728
    2829from Numeric import zeros, Float, ArrayType,take
     
    300301   
    301302       
    302     def fit(self, point_coordinates=None, z=None,
    303                               verbose = False,
    304                               point_origin = None):
     303    def fit(self, point_coordinates_or_filename=None, z=None,
     304            verbose=False,
     305            point_origin=None,
     306            max_read_lines=500):
    305307        """Fit a smooth surface to given 1d array of data points z.
    306308
     
    315317         
    316318        """
     319
     320        # use blocking to load in the point info
     321        if type(point_coordinates_or_filename) == types.StringType:
     322            filename = point_coordinates_or_filename
     323            for geo_block in  Geospatial_data(filename,
     324                                              max_read_lines=max_read_lines,
     325                                              load_file_now=False):
     326                # build the array
     327                points = geo_block.get_data_points(absolute=True)
     328                z = geo_block.get_attributes()
     329                self.build_fit_subset(points, z)
     330            point_coordinates = None
     331        else:
     332            point_coordinates =  point_coordinates_or_filename
     333           
    317334        if point_coordinates is None:
    318335            assert self.AtA <> None
     
    320337            #FIXME (DSG) - do  a message
    321338        else:
    322             # This is where build fit subset can be looped over,
    323             # if a file name is passed in.
    324339            point_coordinates = ensure_absolute(point_coordinates,
    325340                                                geo_reference=point_origin)
     
    400415def fit_to_mesh(vertex_coordinates,
    401416                triangles,
    402                 point_coordinates,
    403                 point_attributes,
     417                point_coordinates=None,
     418                point_attributes=None,
    404419                alpha = DEFAULT_ALPHA,
    405420                verbose = False,
  • anuga_core/source/anuga/fit_interpolate/test_fit.py

    r3560 r4129  
    55import unittest
    66from math import sqrt
     7import tempfile
    78
    89from Numeric import zeros, take, compress, Float, Int, dot, concatenate, \
     
    199200        assert allclose(f, answer)
    200201
     202        # test fit 2 mesh as well.
     203    def test_fit_file_blocking(self):
     204
     205        a = [-1.0, 0.0]
     206        b = [3.0, 4.0]
     207        c = [4.0,1.0]
     208        d = [-3.0, 2.0] #3
     209        e = [-1.0,-2.0]
     210        f = [1.0, -2.0] #5
     211
     212        vertices = [a, b, c, d,e,f]
     213        triangles = [[0,1,3], [1,0,2], [0,4,5], [0,5,2]] #abd bac aef afc
     214
     215        interp = Fit(vertices, triangles,
     216                                alpha=0.0)
     217
     218
     219        fileName = tempfile.mktemp(".ddd")
     220        file = open(fileName,"w")
     221        file.write(" x,y, elevation \n\
     222-2.0, 2.0, 0.\n\
     223-1.0, 1.0, 0.\n\
     2240.0, 2.0 , 2.\n\
     2251.0, 1.0 , 2.\n\
     226 2.0,  1.0 ,3. \n\
     227 0.0,  0.0 , 0.\n\
     228 1.0,  0.0 , 1.\n\
     229 0.0,  -1.0, -1.\n\
     230 -0.2, -0.5, -0.7\n\
     231 -0.9, -1.5, -2.4\n\
     232 0.5,  -1.9, -1.4\n\
     233 3.0,  1.0 , 4.\n")
     234        file.close()
     235       
     236        f = interp.fit(fileName, max_read_lines=2)
     237        answer = linear_function(vertices)
     238        #print "f\n",f
     239        #print "answer\n",answer
     240        assert allclose(f, answer)
     241       
    201242    def test_fit_and_interpolation(self):
    202243
  • anuga_core/source/anuga/geospatial_data/geospatial_data.py

    r4126 r4129  
    2929                 longitudes=None,
    3030                 points_are_lats_longs=False,
    31                  max_read_lines=None,                 
     31                 max_read_lines=None,
     32                 load_file_now=True,
    3233                 verbose=False):
    3334
     
    105106           
    106107        verbose:
     108
     109        load_file_now: if load file now is true, the file is
     110        loaded during instanciation.
    107111         
    108112        """
     
    134138            self.set_default_attribute_name(default_attribute_name)
    135139
    136         else:
     140        elif load_file_now is True:
    137141            # watch for case where file name and points,
    138142            # attributes etc are provided!!
     
    145149            self.set_default_attribute_name(default_attribute_name)
    146150
    147 
    148         assert self.attributes is None or isinstance(self.attributes, DictType)
     151        #Why?   
     152        #assert self.attributes is None or isinstance(self.attributes, DictType)
     153        #This is a hassle when blocking, so I've removed it.
    149154       
    150155
     
    539544                raise IOError, msg 
    540545       
    541         elif file_name[-4:]== ".xxx":
     546        elif file_name[-4:]== ".txt" or file_name[-4:]== ".csv":
    542547            #let's do ticket#116 stuff
    543548            #
     
    677682
    678683        #FIXME - what to do if the file isn't there
     684
     685        #FIXME - give warning if the file format is .xya
    679686        file_pointer = open(self.file_name)
    680687        self.header, self.file_pointer = _read_csv_file_header(file_pointer)
     
    771778                file_pointer,
    772779                header,
    773                 max_read_lines=5000) #FIXME: how hacky is that!
     780                max_read_lines=MAX_READ_LINES) #FIXME: how hacky is that!
    774781        except StopIteration:
    775782            break
     
    792799def _read_csv_file_blocking(file_pointer, header,
    793800                            delimiter=CSV_DELIMITER,
    794                             max_read_lines=500,
     801                            max_read_lines=MAX_READ_LINES,
    795802                            verbose=False):
    796803   
     
    805812
    806813    #This is to remove the x and y headers.
     814    header = header[:]
    807815    header.pop(0)
    808816    header.pop(0)
     
    11361144         
    11371145if __name__ == "__main__":
    1138     g = Geospatial_data("t.xxx")
     1146    g = Geospatial_data("t.txt")
    11391147    print "g.get_data_points()", g.get_data_points()
    11401148    for i,a in enumerate(g):
  • anuga_core/source/anuga/geospatial_data/test_geospatial_data.py

    r4103 r4129  
    912912        import os
    913913       
    914         fileName = tempfile.mktemp(".xxx")
     914        fileName = tempfile.mktemp(".txt")
    915915        file = open(fileName,"w")
    916916        file.write(" x,y, elevation ,  speed \n\
Note: See TracChangeset for help on using the changeset viewer.