Changeset 1121


Ignore:
Timestamp:
Mar 22, 2005, 3:57:26 PM (20 years ago)
Author:
prow
Message:
 
File:
1 edited

Legend:

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

    r1044 r1121  
    707707        os.remove('small.sww')
    708708
     709    def test_ferret2sww3(self):
     710        """
     711        """
     712        from Scientific.IO.NetCDF import NetCDFFile
     713
     714        #The test file has
     715        # LON = 150.66667, 150.83334, 151, 151.16667
     716        # LAT = -34.5, -34.33333, -34.16667, -34 ;
     717        # ELEVATION = [-1 -2 -3 -4
     718        #             -5 -6 -7 -8
     719        #              ...
     720        #              ...      -16]
     721        # where the top left corner is -1m,
     722        # and the ll corner is -13.0m
     723        #
     724        # First value (index=0) in small_ha.nc is 0.3400644 cm,
     725        # Fourth value (index==3) is -6.50198 cm
     726
     727
     728        from coordinate_transforms.redfearn import redfearn
     729
     730        fid1 = NetCDFFile('small_ha.nc')
     731        fid2 = NetCDFFile('small_e.nc')
     732        fid3 = NetCDFFile('small_va.nc')
     733
     734        first_amp = fid1.variables['HA'][:][0,0,0]
     735        fourth_amp = fid1.variables['HA'][:][0,0,3]
     736        first_elevation = fid2.variables['ELEVATION'][0,0]
     737        fourth_elevation= fid2.variables['ELEVATION'][:][0,3]
     738        first_speed = fid3.variables['VA'][0,0]
     739        fourth_speed = fid3.variables['VA'][:][0,3]
     740
     741        fid1.close()
     742        fid2.close()
     743        fid3.close()
     744
     745        #Call conversion (with zero origin)
     746        ferret2sww('small', verbose=False,
     747                   origin = (56, 0, 0))
     748
     749
     750        #Work out the UTM coordinates for first point
     751        zone, e, n = redfearn(-34.5, 150.66667)
     752        #print zone, e, n
     753
     754        #Read output file 'small.sww'
     755        fid = NetCDFFile('small.sww')
     756
     757        x = fid.variables['x'][:]
     758        y = fid.variables['y'][:]
     759       
     760
     761        #Check that first coordinate is correctly represented
     762        assert allclose(x[0], e)
     763        assert allclose(y[0], n)
     764
     765        #Check first value
     766        stage = fid.variables['stage'][:]
     767        xmomentum = fid.variables['xmomentum'][:]
     768        ymomentum = fid.variables['ymomentum'][:]       
     769
     770        #print ymomentum
     771        first_height = first_amp/100 - first_elevation
     772        fourth_height = fourth_amp/100 - fourth_elevation
     773
     774        first_momentum=first_speed*first_height/100
     775        fourth_momentum=fourth_speed*fourth_height/100
     776
     777        assert allclose(ymomentum[0][0],first_momentum)  #Meters
     778        assert allclose(ymomentum[0][1],fourth_momentum)  #Meters
     779
     780        fid.close()
     781
     782        #Cleanup
     783        import os
     784        os.remove('small.sww')
     785
    709786
    710787
Note: See TracChangeset for help on using the changeset viewer.