Changeset 1046


Ignore:
Timestamp:
Mar 9, 2005, 4:37:00 PM (20 years ago)
Author:
duncan
Message:

added reading and writing to ASCII files

Location:
inundation/ga/storm_surge/pyvolution/coordinate_transforms
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/pyvolution/coordinate_transforms/geo_reference.py

    r1031 r1046  
    1414                 xllcorner=None,
    1515                 yllcorner=None,
    16                  NetCDFObject = None):
     16                 NetCDFObject = None,
     17                 ASCIIFile = None):
    1718        if not xllcorner == None:
    1819            self.xllcorner = xllcorner #Easting of lower left corner
     
    2425        if not NetCDFObject == None:
    2526            self.read_NetCDF(NetCDFObject)
     27
     28        #FIXME think if this should be here   
     29        if not ASCIIFile == None:
     30            self.read_ASCII(ASCIIFile)
    2631       
    2732    def write_NetCDF(self, outfile):
     
    4651        assert (type(self.yllcorner) == types.FloatType)
    4752        assert (type(self.zone) == types.IntType)
     53
     54       
     55    def write_ASCII(self, fd):
     56        fd.write('# Geo reference' + "\n")
     57        fd.write(str(self.zone) + "\n")
     58        fd.write(str(self.xllcorner) + "\n")
     59        fd.write(str(self.yllcorner) + "\n")
     60
     61    def read_ASCII(self, fd):
     62        fd.readline() # remove the title line
     63        self.zone = int(fd.readline())
     64        self.xllcorner = float(fd.readline())
     65        self.yllcorner = float(fd.readline())
     66           
     67       
     68        assert (type(self.xllcorner) == types.FloatType)
     69        assert (type(self.yllcorner) == types.FloatType)
     70        assert (type(self.zone) == types.IntType)
    4871       
    4972        #false_easting = infile.false_easting[0]
    5073        #false_northing = infile.false_northing[0]
     74
     75    def change_geo_ref(self, primary_geo_ref,
     76                       secondary_geo_ref, secondary_points):
     77        #convert into array
     78        #add secondary geo ref to points
     79        #subtract secondary geo ref from points
     80        # return points
     81        pass
    5182
    5283    def __repr__(self):
  • inundation/ga/storm_surge/pyvolution/coordinate_transforms/test_geo_reference.py

    r1030 r1046  
    3232        self.failUnless(g == new_g, 'test_read_write_NetCDF failed') 
    3333       
     34    def test_read_write_ASCII(self):
     35        from Scientific.IO.NetCDF import NetCDFFile
     36        g = Geo_reference(56,1.9,1.9)
     37        file_name = tempfile.mktemp(".geo_referenceTest")
     38        print "file_name",file_name
     39        fd = open(file_name,'w')
     40        g.write_ASCII(fd)
     41        fd.close()
     42       
     43        fd = open(file_name,'r')
     44        new_g = Geo_reference(ASCIIFile=fd)
     45        fd.close()
     46        os.remove(file_name)
     47
     48        self.failUnless(g == new_g, 'test_read_write_ASCII failed') 
     49       
    3450    def test___cmp__(self):
    3551        g = Geo_reference(56,1.9,1.9,)
Note: See TracChangeset for help on using the changeset viewer.