Changeset 1875


Ignore:
Timestamp:
Oct 6, 2005, 2:38:17 PM (19 years ago)
Author:
ole
Message:

Bounding box for sww2dem

Location:
inundation/pyvolution
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inundation/pyvolution/data_manager.py

    r1874 r1875  
    12111211            reduction = None,
    12121212            cellsize = 10,
     1213            easting_min = None,
     1214            easting_max = None,
     1215            northing_min = None,
     1216            northing_max = None,         
    12131217            verbose = False,
    12141218            origin = None,
     
    12771281    # Note the use of a .ers extension is optional (write_ermapper_grid will
    12781282    # deal with either option
    1279     # ersfile = basename_out
    1280 
     1283
     1284    #Read sww file
    12811285    if verbose: print 'Reading from %s' %swwfile
    1282     #Read sww file
    12831286    from Scientific.IO.NetCDF import NetCDFFile
    12841287    fid = NetCDFFile(swwfile)
     
    12881291    y = fid.variables['y'][:]
    12891292    volumes = fid.variables['volumes'][:]
    1290 
    1291     ymin = min(y); ymax = max(y)
    1292     xmin = min(x); xmax = max(x)
    12931293
    12941294    number_of_timesteps = fid.dimensions['number_of_timesteps']
     
    13121312
    13131313
     1314
    13141315    #Get quantity and reduce if applicable
    13151316    if verbose: print 'Reading quantity %s' %quantity
     
    13221323
    13231324    if len(q.shape) == 2:
     1325        #q has a time component and needs to be reduced along
     1326        #the temporal dimension
    13241327        if verbose: print 'Reducing quantity %s' %quantity
    13251328        q_reduced = zeros( number_of_points, Float )
     
    13301333        q = q_reduced
    13311334
    1332     #Now q has dimension: number_of_points
     1335    #Post condition: Now q has dimension: number_of_points
     1336    assert len(q.shape) == 1
     1337    assert q.shape[0] == number_of_points   
     1338   
    13331339
    13341340    #Create grid and update xll/yll corner and x,y
     1341
     1342    #Relative extent
     1343    if easting_min is None:
     1344        xmin = min(x)
     1345    else:
     1346        xmin = easting_min - xllcorner
     1347
     1348    if easting_max is None:
     1349        xmax = max(x)
     1350    else:
     1351        xmax = easting_max - xllcorner
     1352       
     1353    if northing_min is None:       
     1354        ymin = min(y)
     1355    else:
     1356        ymin = northing_min - yllcorner
     1357       
     1358    if northing_max is None:       
     1359        ymax = max(y)
     1360    else:
     1361        ymax = northing_max - yllcorner
     1362       
     1363       
     1364   
    13351365    if verbose: print 'Creating grid'
    13361366    ncols = int((xmax-xmin)/cellsize)+1
    13371367    nrows = int((ymax-ymin)/cellsize)+1
    13381368
     1369
     1370    #New absolute reference and coordinates
    13391371    newxllcorner = xmin+xllcorner
    13401372    newyllcorner = ymin+yllcorner
     
    13711403    #FIXME: This should be done with precrop = True (?), otherwise it'll
    13721404    #take forever. With expand_search  set to False, some grid points might
    1373     #miss out....
     1405    #miss out.... This will be addressed though Duncan's refactoring of least_squares
    13741406
    13751407    interp = Interpolation(vertex_points, volumes, grid_points, alpha=0.0,
     
    14741506            origin = None):
    14751507    print 'sww2asc will soon be obsoleted - please use sww2dem'
    1476     sww2dem(basename_in, 
    1477             basename_out,
    1478             quantity,
    1479             timestep,
    1480             reduction,
    1481             cellsize,
    1482             verbose,
    1483             origin,
     1508    sww2dem(basename_in,
     1509            basename_out = basename_out,
     1510            quantity = quantity,
     1511            timestep = timestep,
     1512            reduction = reduction,
     1513            cellsize = cellsize,
     1514            verbose = verbose,
     1515            origin = origin,
    14841516            datum = 'WGS84',
    14851517            format = 'asc')
     
    14951527    print 'sww2ers will soon be obsoleted - please use sww2dem'
    14961528    sww2dem(basename_in,
    1497             basename_out,
    1498             quantity,
    1499             timestep,
    1500             reduction,
    1501             cellsize,
    1502             verbose,
    1503             origin,
    1504             datum,
     1529            basename_out = basename_out,
     1530            quantity = quantity,
     1531            timestep = timestep,
     1532            reduction = reduction,
     1533            cellsize = cellsize,
     1534            verbose = verbose,
     1535            origin = origin,
     1536            datum = datum,
    15051537            format = 'ers')         
    15061538################################# END COMPATIBILITY ##############         
  • inundation/pyvolution/test_data_manager.py

    r1867 r1875  
    965965                verbose = False,
    966966                format = 'asc')
    967         #dem2pts(root, easting_min=2010.0, easting_max=2110.0,
    968         #        northing_min=3035.0, northing_max=3125.5)
    969        
    970967       
    971968               
     
    10561053
    10571054
    1058     #FIXME: TODO
    1059     def xtest_sww2dem_boundingbox(self):
     1055    def test_sww2dem_boundingbox(self):
    10601056        """Test that sww information can be converted correctly to asc/prj
    10611057        format readable by e.g. ArcView.
     
    11581154                format = 'asc')
    11591155       
    1160                
     1156        fid.close()
     1157
     1158       
    11611159        #Check prj (meta data)
    11621160        prjid = open(prjfile)
     
    12361234       
    12371235
    1238         fid.close()
    12391236
    12401237        #Cleanup
     
    15931590        os.remove(sww.filename)
    15941591
    1595 
    1596     def xxxtestz_sww2ers_real(self):
    1597         """Test that sww information can be converted correctly to asc/prj
    1598         format readable by e.g. ArcView
    1599         """
    1600 
    1601         import time, os
    1602         from Numeric import array, zeros, allclose, Float, concatenate
    1603         from Scientific.IO.NetCDF import NetCDFFile
    1604 
    1605 
    1606 
    1607 
    1608         #Export to ascii/prj files
    1609         sww2ers('karratha_100m.sww',
    1610                 quantity = 'depth',
    1611                 cellsize = 5,
    1612                 verbose = False)
    16131592
    16141593
     
    25412520if __name__ == "__main__":
    25422521    suite = unittest.makeSuite(Test_Data_Manager,'test')
     2522    #suite = unittest.makeSuite(Test_Data_Manager,'test_sww2dem_boundingbox')   
    25432523    #suite = unittest.makeSuite(Test_Data_Manager,'test_dem2pts_bounding_box')
    25442524    #suite = unittest.makeSuite(Test_Data_Manager,'test_decimate_dem')
Note: See TracChangeset for help on using the changeset viewer.