Changeset 4562


Ignore:
Timestamp:
Jun 25, 2007, 5:33:22 PM (17 years ago)
Author:
ole
Message:

Added test for zscale in ferret2sww as requested in ticket:177

File:
1 edited

Legend:

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

    r4558 r4562  
    27792779        import os
    27802780        os.remove(self.test_MOST_file + '.sww')
     2781
     2782
     2783
     2784    def test_ferret2sww_zscale(self):
     2785        """Test that zscale workse
     2786        """
     2787        from Scientific.IO.NetCDF import NetCDFFile
     2788        import os, sys
     2789
     2790        #The test file has
     2791        # LON = 150.66667, 150.83334, 151, 151.16667
     2792        # LAT = -34.5, -34.33333, -34.16667, -34 ;
     2793        # TIME = 0, 0.1, 0.6, 1.1, 1.6, 2.1 ;
     2794        #
     2795        # First value (index=0) in small_ha.nc is 0.3400644 cm,
     2796        # Fourth value (index==3) is -6.50198 cm
     2797
     2798
     2799        #Read
     2800        from anuga.coordinate_transforms.redfearn import redfearn
     2801        fid = NetCDFFile(self.test_MOST_file + '_ha.nc')
     2802        first_value = fid.variables['HA'][:][0,0,0]
     2803        fourth_value = fid.variables['HA'][:][0,0,3]
     2804        fid.close()
     2805
     2806        #Call conversion (with no scaling)
     2807        ferret2sww(self.test_MOST_file, verbose=self.verbose,
     2808                   origin = (56, 0, 0))
     2809
     2810        #Work out the UTM coordinates for first point
     2811        fid = NetCDFFile(self.test_MOST_file + '.sww')
     2812
     2813        #Check values
     2814        stage_1 = fid.variables['stage'][:]
     2815        xmomentum_1 = fid.variables['xmomentum'][:]
     2816        ymomentum_1 = fid.variables['ymomentum'][:]
     2817
     2818        assert allclose(stage_1[0,0], first_value/100)  #Meters
     2819        assert allclose(stage_1[0,3], fourth_value/100)  #Meters
     2820
     2821        fid.close()
     2822
     2823        #Call conversion (with scaling)
     2824        ferret2sww(self.test_MOST_file,
     2825                   zscale = 5,
     2826                   verbose=self.verbose,
     2827                   origin = (56, 0, 0))
     2828
     2829        #Work out the UTM coordinates for first point
     2830        fid = NetCDFFile(self.test_MOST_file + '.sww')
     2831
     2832        #Check values
     2833        stage_5 = fid.variables['stage'][:]
     2834        xmomentum_5 = fid.variables['xmomentum'][:]
     2835        ymomentum_5 = fid.variables['ymomentum'][:]
     2836        elevation = fid.variables['elevation'][:]
     2837
     2838        assert allclose(stage_5[0,0], 5*first_value/100)  #Meters
     2839        assert allclose(stage_5[0,3], 5*fourth_value/100)  #Meters
     2840
     2841        assert allclose(5*stage_1, stage_5)
     2842
     2843        # Momentum will also be changed due to new depth
     2844
     2845        depth_1 = stage_1-elevation
     2846        depth_5 = stage_5-elevation
     2847
     2848
     2849        for i in range(stage_1.shape[0]):
     2850            for j in range(stage_1.shape[1]):           
     2851                if depth_1[i,j] > epsilon:
     2852
     2853                    scale = depth_5[i,j]/depth_1[i,j]
     2854                    ref_xmomentum = xmomentum_1[i,j] * scale
     2855                    ref_ymomentum = ymomentum_1[i,j] * scale
     2856                   
     2857                    #print i, scale, xmomentum_1[i,j], xmomentum_5[i,j]
     2858                   
     2859                    assert allclose(xmomentum_5[i,j], ref_xmomentum)
     2860                    assert allclose(ymomentum_5[i,j], ref_ymomentum)
     2861                   
     2862       
     2863
     2864        fid.close()
     2865
     2866
     2867        #Cleanup
     2868        import os
     2869        os.remove(self.test_MOST_file + '.sww')
     2870
    27812871
    27822872
Note: See TracChangeset for help on using the changeset viewer.