Changeset 2060


Ignore:
Timestamp:
Nov 24, 2005, 10:46:22 AM (19 years ago)
Author:
ole
Message:

Made asc and ers formats use the same method for assigning missing values

Location:
inundation/pyvolution
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inundation/pyvolution/data_manager.py

    r2057 r2060  
    14241424            reduction = None,
    14251425            cellsize = 10,
     1426            NODATA_value = -9999,
    14261427            easting_min = None,
    14271428            easting_max = None,
     
    14811482    msg = 'Format must be either asc or ers'
    14821483    assert format.lower() in ['asc', 'ers'], msg
    1483    
     1484
     1485       
    14841486    false_easting = 500000
    14851487    false_northing = 10000000
     
    16701672    grid_values = interp.interpolate(q).flat
    16711673
     1674
     1675    #Assign NODATA_value to all points outside bounding polygon (from interpolation mesh)
     1676    P = interp.mesh.get_boundary_polygon()
     1677    inside_indices = inside_polygon(grid_points, P)
     1678
     1679    #FIXME: Remove when new interpolation takes care of this
     1680    for i in range(nrows):
     1681        if verbose and i%((nrows+10)/10)==0:
     1682            print 'Doing row %d of %d' %(i, nrows)
     1683
     1684        base_index = (nrows-i-1)*ncols     
     1685        for j in range(ncols):
     1686            index = base_index+j
     1687
     1688            if not sometrue(inside_indices == index):
     1689                grid_values[index] = NODATA_value
     1690
     1691    #############           
     1692
     1693   
     1694
    16721695    if verbose:
    16731696        print 'Interpolated values are in [%f, %f]' %(min(grid_values),
     
    16771700        # setup ERS header information
    16781701        grid_values = reshape(grid_values,(nrows, ncols))   
    1679         NODATA_value = 0
    16801702        header = {}
    16811703        header['datum'] = '"' + datum + '"'
     
    17251747   
    17261748        if verbose: print 'Writing %s' %demfile
    1727         NODATA_value = -9999
    17281749 
    17291750        ascid = open(demfile, 'w')
     
    17381759
    17391760        #Get bounding polygon from mesh
    1740         P = interp.mesh.get_boundary_polygon()
    1741         inside_indices = inside_polygon(grid_points, P)
     1761        #P = interp.mesh.get_boundary_polygon()
     1762        #inside_indices = inside_polygon(grid_points, P)
    17421763
    17431764        for i in range(nrows):
     
    17451766                print 'Doing row %d of %d' %(i, nrows)
    17461767
     1768            base_index = (nrows-i-1)*ncols     
    17471769            for j in range(ncols):
    1748                 index = (nrows-i-1)*ncols+j
    1749 
    1750                 if sometrue(inside_indices == index):
    1751                     ascid.write('%f ' %grid_values[index])
    1752                 else:
    1753                     ascid.write('%d ' %NODATA_value)
     1770                index = base_index+j
     1771
     1772                ascid.write('%f ' %grid_values[index])
    17541773
    17551774            ascid.write('\n')
  • inundation/pyvolution/test_data_manager.py

    r2054 r2060  
    16941694        from Scientific.IO.NetCDF import NetCDFFile
    16951695
     1696
     1697        NODATA_value = 1758323
     1698
    16961699        #Setup
    16971700        self.domain.filename = 'datatest'
     
    17371740                quantity = 'elevation',
    17381741                cellsize = cellsize,
     1742                NODATA_value = NODATA_value,
    17391743                verbose = False,
    17401744                format = 'ers')
     
    17551759        assert int(header['nroflines']) == 5
    17561760        assert int(header['nrofcellsperline']) == 5     
    1757         assert int(header['nullcellvalue']) == 0   #?           
     1761        assert int(header['nullcellvalue']) == NODATA_value
    17581762        #FIXME - there is more in the header                   
    17591763
     
    17631767       
    17641768        #FIXME (Ole): Why is this the desired reference grid for -x-y?
    1765         ref_grid = [0,      0,     0,     0,     0,
     1769        ref_grid = [NODATA_value, NODATA_value, NODATA_value, NODATA_value, NODATA_value,
    17661770                    -1,    -1.25, -1.5,  -1.75, -2.0,
    17671771                    -0.75, -1.0,  -1.25, -1.5,  -1.75,             
     
    17701774                                         
    17711775
     1776        #print grid
    17721777        assert allclose(grid, ref_grid)
    17731778
     
    35813586if __name__ == "__main__":
    35823587    #suite = unittest.makeSuite(Test_Data_Manager,'test_asc_csiro2sww4')
    3583     suite = unittest.makeSuite(Test_Data_Manager,'test')
    3584     #suite = unittest.makeSuite(Test_Data_Manager,'xxxtest')
     3588    #suite = unittest.makeSuite(Test_Data_Manager,'test')
     3589    suite = unittest.makeSuite(Test_Data_Manager,'test_sww2dem_asc_missing_points')
    35853590    #suite = unittest.makeSuite(Test_Data_Manager,'test_sww2dem_boundingbox')   
    35863591    #suite = unittest.makeSuite(Test_Data_Manager,'test_dem2pts_bounding_box')
Note: See TracChangeset for help on using the changeset viewer.