Ignore:
Timestamp:
Feb 8, 2010, 1:59:54 PM (14 years ago)
Author:
habili
Message:

New test for sww2dem since timestep and reduction have now been combined.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/shallow_water/test_data_manager.py

    r7602 r7618  
    25802580        os.remove(swwfile)
    25812581
     2582    def test_sww2dem_asc_stage_time(self):
     2583        """Test that sww information can be converted correctly to asc/prj
     2584        format readable by e.g. ArcView
     2585
     2586        This tests the reduction of quantity stage using min
     2587        """
     2588
     2589        import time, os
     2590        from Scientific.IO.NetCDF import NetCDFFile
     2591
     2592        #Setup
     2593        self.domain.set_name('datatest')
     2594
     2595        prjfile = self.domain.get_name() + '_stage.prj'
     2596        ascfile = self.domain.get_name() + '_stage.asc'
     2597        swwfile = self.domain.get_name() + '.sww'
     2598
     2599        self.domain.set_datadir('.')
     2600        self.domain.format = 'sww'
     2601        self.domain.smooth = True
     2602        self.domain.set_quantity('elevation', lambda x,y: -x-y)
     2603
     2604        self.domain.geo_reference = Geo_reference(56,308500,6189000)
     2605
     2606        sww = SWW_file(self.domain)
     2607        sww.store_connectivity()
     2608        sww.store_timestep()
     2609
     2610        #self.domain.tight_slope_limiters = 1
     2611        self.domain.evolve_to_end(finaltime = 0.01)
     2612        sww.store_timestep()
     2613
     2614        cellsize = 0.25
     2615        #Check contents
     2616        #Get NetCDF
     2617
     2618        fid = NetCDFFile(sww.filename, netcdf_mode_r)
     2619
     2620        # Get the variables
     2621        x = fid.variables['x'][:]
     2622        y = fid.variables['y'][:]
     2623        z = fid.variables['elevation'][:]
     2624        time = fid.variables['time'][:]
     2625        stage = fid.variables['stage'][:]
     2626
     2627        #Export to ascii/prj files
     2628        sww2dem(self.domain.get_name(),
     2629                quantity = 'stage',
     2630                cellsize = cellsize,
     2631                number_of_decimal_places = 9,
     2632                reduction = 1,
     2633                format = 'asc',
     2634                verbose=self.verbose)
     2635
     2636
     2637        #Check asc file
     2638        ascid = open(ascfile)
     2639        lines = ascid.readlines()
     2640        ascid.close()
     2641
     2642        L = lines[0].strip().split()
     2643        assert L[0].strip().lower() == 'ncols'
     2644        assert L[1].strip().lower() == '5'
     2645
     2646        L = lines[1].strip().split()
     2647        assert L[0].strip().lower() == 'nrows'
     2648        assert L[1].strip().lower() == '5'
     2649
     2650        L = lines[2].strip().split()
     2651        assert L[0].strip().lower() == 'xllcorner'
     2652        assert num.allclose(float(L[1].strip().lower()), 308500)
     2653
     2654        L = lines[3].strip().split()
     2655        assert L[0].strip().lower() == 'yllcorner'
     2656        assert num.allclose(float(L[1].strip().lower()), 6189000)
     2657
     2658        L = lines[4].strip().split()
     2659        assert L[0].strip().lower() == 'cellsize'
     2660        assert num.allclose(float(L[1].strip().lower()), cellsize)
     2661
     2662        L = lines[5].strip().split()
     2663        assert L[0].strip() == 'NODATA_value'
     2664        assert L[1].strip().lower() == '-9999'
     2665
     2666        #Check grid values (where applicable)
     2667        for j in range(5):
     2668            if j%2 == 0:
     2669                L = lines[6+j].strip().split()
     2670                jj = 4-j
     2671                for i in range(5):
     2672                    if i%2 == 0:
     2673                        index = jj/2 + i/2*3
     2674                       
     2675                        val = stage[1,index]
     2676                   
     2677                        assert num.allclose(float(L[i]), val)
     2678
     2679        fid.close()
     2680
     2681        #Cleanup
     2682        os.remove(prjfile)
     2683        os.remove(ascfile)
     2684        os.remove(swwfile)
    25822685
    25832686
Note: See TracChangeset for help on using the changeset viewer.