Changeset 836


Ignore:
Timestamp:
Feb 7, 2005, 2:56:07 PM (20 years ago)
Author:
ole
Message:

Moved NetCDF xya formt to pts format

Location:
inundation/ga/storm_surge/pyvolution
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/pyvolution/data_manager.py

    r834 r836  
    88
    99
    10 Formats used within GANUGA:
     10Formats used within ANUGA:
    1111
    1212.sww: Netcdf format for storing model output
    13 .xya: Either ASCII or NetCDF format for storing arbitrary points and associated attributed
     13
     14.xya: ASCII format for storing arbitrary points and associated attributes
     15.pts: NetCDF format for storing arbitrary points and associated attributes
     16
     17.asc: ASCII foramt of regular DEMs as output from ArcView
    1418.dem: NetCDF representation of regular DEM data
     19
    1520.tsh: ASCII format for storing meshes and associated boundary and region info
     21
     22
     23#Not yet implemented
     24.nc: Native ferret NetCDF format
     25
     26
    1627FIXME: What else
    1728
     
    799810    return cls(domain, mode)
    800811
    801 def dem2xya(filename, verbose=False):
     812def dem2pts(filename, verbose=False):
    802813    """Read Digitial Elevation model from the following NetCDF format (.dem)
    803814
     
    812823    138.3698 137.4194 136.5062 135.5558 ..........
    813824
    814     Convert to NetCDF xyz format (.xya)
     825    Convert to NetCDF pts format
    815826    """
    816827
     
    835846
    836847    #Get output file                               
    837     xyaname = root + '.xya'
     848    xyaname = root + '.pts'
    838849    if verbose: print 'Store to NetCDF file %s' %xyaname
    839850    # NetCDF file definition
     
    842853    #Create new file
    843854    outfile.institution = 'Geoscience Australia'
    844     outfile.description = 'NetCDF xya format for compact and portable storage ' +\
     855    outfile.description = 'NetCDF pts format for compact and portable storage ' +\
    845856                      'of spatial point data'
    846857
     
    866877
    867878    #Store data
    868     #FIXME: Could be faster using array operations
     879    #FIXME: Could perhaps be faster using array operations
    869880    for i in range(nrows):
    870881        if verbose: print 'Processing row %d of %d' %(i, nrows)
     
    880891    infile.close()           
    881892    outfile.close()
    882 
    883 
    884 # def dem2xya(filename, verbose=False):
    885 #     """Read Digitial Elevation model from the following ASCII format (.asc)
    886 
    887 #     Example:
    888 
    889 #     ncols         3121
    890 #     nrows         1800
    891 #     xllcorner     722000
    892 #     yllcorner     5893000
    893 #     cellsize      25
    894 #     NODATA_value  -9999
    895 #     138.3698 137.4194 136.5062 135.5558 ..........
    896 
    897 #     Convert to NetCDF xyz format (.xya)
    898 #     """
    899 
    900 #     import os
    901 #     from Scientific.IO.NetCDF import NetCDFFile
    902 #     from Numeric import Float, arrayrange, concatenate   
    903 
    904 #     root, ext = os.path.splitext(filename)
    905 #     fid = open(filename)
    906 
    907 #     if verbose: print 'Reading DEM from %s' %filename
    908 #     lines = fid.readlines()
    909 #     fid.close()
    910 
    911 #     if verbose: print 'Got', len(lines), ' lines'
    912    
    913 #     ncols = int(lines[0].split()[1].strip())
    914 #     nrows = int(lines[1].split()[1].strip())
    915 #     xllcorner = float(lines[2].split()[1].strip())
    916 #     yllcorner = float(lines[3].split()[1].strip())
    917 #     cellsize = float(lines[4].split()[1].strip())
    918 #     NODATA_value = int(lines[5].split()[1].strip())
    919 
    920 #     assert len(lines) == nrows + 6
    921 
    922 #     netcdfname = root + '.xya'
    923 #     if verbose: print 'Store to NetCDF file %s' %netcdfname
    924 #     # NetCDF file definition
    925 #     fid = NetCDFFile(netcdfname, 'w')
    926        
    927 #     #Create new file
    928 #     fid.institution = 'Geoscience Australia'
    929 #     fid.description = 'NetCDF xya format for compact and portable storage ' +\
    930 #                       'of spatial point data'
    931 
    932 #     fid.ncols = ncols
    933 #     fid.nrows = nrows   
    934 
    935 
    936 #     # dimension definitions
    937 #     fid.createDimension('number_of_points', nrows*ncols)   
    938 #     fid.createDimension('number_of_attributes', 1) #Always 1 with the dem fmt
    939 #     fid.createDimension('number_of_dimensions', 2) #This is 2d data
    940    
    941 
    942 #     # variable definitions
    943 #     fid.createVariable('points', Float, ('number_of_points',
    944 #                                          'number_of_dimensions'))
    945 #     fid.createVariable('attributes', Float, ('number_of_points',
    946 #                                              'number_of_attributes'))
    947 
    948 #     # Get handles to the variables
    949 #     points = fid.variables['points']
    950 #     attributes = fid.variables['attributes']
    951 
    952 #     #Store data
    953 #     #FIXME: Could be faster using array operations
    954 #     #FIXME: Perhaps the y dimension needs to be reversed
    955 #     #FIXME: x and y definitely needs to be swapped
    956 #     for i, line in enumerate(lines[6:]):
    957 #         fields = line.split()
    958 #         if verbose: print 'Processing row %d of %d' %(i, nrows)
    959        
    960 #         x = i*cellsize           
    961 #         for j, field in enumerate(fields):
    962 #             index = i*ncols + j
    963            
    964 #             y = j*cellsize
    965 #             points[index, :] = [x,y]
    966 
    967 #             z = float(field)                       
    968 #             attributes[index, 0] = z
    969 
    970 #     fid.close()
    971893
    972894                                     
  • inundation/ga/storm_surge/pyvolution/least_squares.py

    r834 r836  
    147147   
    148148   
    149 def xya2rectangular(xya_name, M, N, alpha = DEFAULT_ALPHA,
     149def pts2rectangular(pts_name, M, N, alpha = DEFAULT_ALPHA,
    150150                    verbose = False, reduction = 1, format = 'netcdf'):
    151     """Fits attributes from xya file to MxN rectangular mesh
    152    
    153     Read xya file and create rectangular mesh of resolution MxN such that
    154     it covers all points specified in xya file.
     151    """Fits attributes from pts file to MxN rectangular mesh
     152   
     153    Read pts file and create rectangular mesh of resolution MxN such that
     154    it covers all points specified in pts file.
    155155   
    156156    FIXME: This may be a temporary function until we decide on
     
    160160    import util, mesh_factory
    161161
    162     if verbose: print 'Read xya'
    163     points, attributes, _ = util.read_xya(xya_name, format)
     162    if verbose: print 'Read pts'
     163    points, attributes, _ = util.read_xya(pts_name, format)
    164164
    165165    #Reduce number of points a bit
  • inundation/ga/storm_surge/pyvolution/test_data_manager.py

    r835 r836  
    498498
    499499
    500     def test_dem2xya(self):
     500    def test_dem2pts(self):
    501501        """Test conversion from dem in ascii format to native NetCDF xya format
    502502        """
     
    537537        #Convert to NetCDF xya
    538538        convert_dem_from_ascii2netcdf(filename)
    539         dem2xya(root + '.dem')
    540 
    541         #Check contents
    542         #Get NetCDF
    543         fid = NetCDFFile(root+'.xya', 'r')
     539        dem2pts(root + '.dem')
     540
     541        #Check contents
     542        #Get NetCDF
     543        fid = NetCDFFile(root+'.pts', 'r')
    544544     
    545545        # Get the variables
     
    561561       
    562562
    563         os.remove(root + '.xya')
     563        os.remove(root + '.pts')
    564564        os.remove(root + '.dem')               
    565565        os.remove(root + '.asc')       
  • inundation/ga/storm_surge/pyvolution/test_least_squares.py

    r835 r836  
    489489
    490490       
    491     def test_xya2rectangular(self):
     491    def test_pts2rectangular(self):
    492492
    493493        import time, os
     
    500500       
    501501        points, triangles, boundary, attributes =\
    502                 xya2rectangular(FN, 4, 4, format = 'asc')
     502                pts2rectangular(FN, 4, 4, format = 'asc')
    503503       
    504504        z1 = [2, 4]
  • inundation/ga/storm_surge/pyvolution/util.py

    r835 r836  
    303303    attribute names if present otherwise None
    304304    """
     305    #FIXME: Probably obsoleted by similar function in load_ASCII
    305306   
    306307    from Scientific.IO.NetCDF import NetCDFFile
Note: See TracChangeset for help on using the changeset viewer.