Changeset 3820


Ignore:
Timestamp:
Oct 18, 2006, 11:04:59 AM (17 years ago)
Author:
duncan
Message:

bug fix. takes into account mux has lat varying fastest, nc has long varying fastest

Location:
anuga_core/source/anuga/shallow_water
Files:
2 edited

Legend:

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

    r3750 r3820  
    6464
    6565from Numeric import concatenate, array, Float, Int, Int32, resize, sometrue, \
    66      searchsorted, zeros, allclose, around, reshape
     66     searchsorted, zeros, allclose, around, reshape, transpose
    6767from Scientific.IO.NetCDF import NetCDFFile
    6868
     
    42004200                                           files_out,
    42014201                                           quantities):
    4202         lonlatdep, lon, lat = _binary_c2nc(file_in,
     4202        lonlatdep, lon, lat, depth = _binary_c2nc(file_in,
    42034203                                         file_out,
    42044204                                         quantity)
     
    42104210                                lon,
    42114211                                lat,
    4212                                 lonlatdep[:,2])
     4212                                depth)
    42134213            hashed_elevation = myhash(lonlatdep)
    42144214        else:
     
    42514251    lonlatdep = reshape(lonlatdep, ( points_num, columns))
    42524252   
    4253     lon, lat = lon_lat2grid(lonlatdep)
     4253    #print "lonlatdep", lonlatdep
     4254   
     4255    lon, lat, depth = lon_lat2grid(lonlatdep)
    42544256    lon_sorted = lon[:]
    42554257    lon_sorted.sort()
     
    42754277        hz_p_array.read(f, points_num)
    42764278        hz_p = array(hz_p_array, typecode=Float)
    4277         hz_p = reshape(hz_p, ( len(lat), len(lon)))
     4279        hz_p = reshape(hz_p, (len(lon), len(lat)))
     4280        hz_p = transpose(hz_p) #mux has lat varying fastest, nc has long v.f.
    42784281       
    42794282        nc_file.store_timestep(hz_p)
     
    42814284    nc_file.close()
    42824285
    4283     return lonlatdep, lon, lat
     4286    return lonlatdep, lon, lat, depth
    42844287   
    42854288
     
    43364339    The first column is longitudes.
    43374340    The second column is latitudes.
     4341
     4342    The latitude is the fastest varying dimension - in mux files
    43384343    """
    43394344    LONG = 0
    43404345    LAT = 1
     4346    QUANTITY = 2
    43414347    points_num = len(long_lat_dep)
    43424348    lat = [long_lat_dep[0][LAT]]
    43434349    this_rows_long = long_lat_dep[0][LONG]
    4344     i = 1 # Index of long_lat_dep 
    4345 
     4350    i = 1 # Index of long_lat_dep
     4351   
    43464352    #Working out the lat's
    43474353    while long_lat_dep[i][LONG] == this_rows_long and i < points_num:
     
    43624368    for l in lat:assert -90 < l < 90 , msg
    43634369    for l in long:assert -180 < l < 180 , msg
    4364        
    4365     return long, lat
     4370
     4371    #changing quantity from lat being the fastest varying dimension to
     4372    # long being the fastest varying dimension
     4373    # FIXME - make this faster/do this a better way
     4374    # use numeric transpose, after reshaping the quantity vector
     4375    quantity = zeros(len(long_lat_dep), Float)
     4376    lenlong = len(long)
     4377    lenlat = len(lat)
     4378    for lat_i, _ in enumerate(lat):
     4379        for long_i, _ in enumerate(long):
     4380            q_index = lat_i*lenlong+long_i
     4381            lld_index = long_i*lenlat+lat_i
     4382            quantity[q_index] = long_lat_dep[lld_index][QUANTITY]
     4383           
     4384    return long, lat, quantity
    43664385
    43674386    ####  END URS 2 SWW  ###     
  • anuga_core/source/anuga/shallow_water/test_data_manager.py

    r3761 r3820  
    47034703        base_name = 'o-e-mux'
    47044704        file_name = base_name + '.nc'
    4705         lonlatdep_numeric, lon, lat = _binary_c2nc(base_name, file_name, 'HA')
     4705        lonlatdep_numeric, lon, lat, depth = \
     4706                           _binary_c2nc(base_name, file_name, 'HA')
    47064707       
    47074708        #os.remove(file_name)
     
    47094710    def test_lon_lat2grid(self):
    47104711        lonlatdep = [
    4711             [ 113.06700134  ,  -26.06669998 ,   0.        ] ,
    4712             [ 113.06700134  ,  -26.33329964 ,   0.        ] ,
    4713             [ 113.19999695  ,  -26.06669998 ,   0.        ] ,
    4714             [ 113.19999695  ,  -26.33329964 ,   0.        ] ]
     4712            [ 113.06700134  ,  -26.06669998 ,   1.        ] ,
     4713            [ 113.06700134  ,  -26.33329964 ,   3.        ] ,
     4714            [ 113.19999695  ,  -26.06669998 ,   2.        ] ,
     4715            [ 113.19999695  ,  -26.33329964 ,   4.        ] ]
    47154716           
    4716         long, lat = lon_lat2grid(lonlatdep)
     4717        long, lat, quantity = lon_lat2grid(lonlatdep)
    47174718
    47184719        for i, result in enumerate(lat):
     
    47244725        assert len(long) == 2
    47254726
     4727        for i,q in enumerate(quantity):
     4728            assert q == i+1
     4729           
    47264730    def test_lon_lat2grid_bad(self):
    47274731        lonlatdep  = [
     
    47434747            [ -26.43330002 , 113.43299866,    16.        ]]
    47444748        try:
    4745             long, lat = lon_lat2grid(lonlatdep)
     4749            long, lat, quantity = lon_lat2grid(lonlatdep)
    47464750        except AssertionError:
    47474751            pass
     
    47524756    def test_lon_lat2gridII(self):
    47534757        lonlatdep = [
    4754             [ 113.06700134  ,  -26.06669998 ,   0.        ] ,
    4755             [ 113.06700134  ,  -26.33329964 ,   0.        ] ,
    4756             [ 113.19999695  ,  -26.06669998 ,   0.        ] ,
    4757             [ 113.19999695  ,  -26.344329964 ,   0.        ] ]
     4758            [ 113.06700134  ,  -26.06669998 ,   1.        ] ,
     4759            [ 113.06700134  ,  -26.33329964 ,   2.        ] ,
     4760            [ 113.19999695  ,  -26.06669998 ,   3.        ] ,
     4761            [ 113.19999695  ,  -26.344329964 ,   4.        ] ]
    47584762        try:
    4759             long, lat = lon_lat2grid(lonlatdep)
     4763            long, lat, quantity = lon_lat2grid(lonlatdep)
    47604764        except AssertionError:
    47614765            pass
     
    47674771        basename_in = 'karratha'
    47684772        basename_out = basename_in
    4769         urs2sww(basename_in, basename_out)
     4773        urs2sww(basename_in, basename_out, remove_nc_files=True,
     4774                zscale=10000000)
    47704775    #### END TESTS FOR URS 2 SWW  ###
    47714776
     
    47734778#-------------------------------------------------------------
    47744779if __name__ == "__main__":
    4775     #suite = unittest.makeSuite(Test_Data_Manager,'test_urs2sww_test_fail')
    4776     #suite = unittest.makeSuite(Test_Data_Manager,'test_urs2sww')
     4780    #suite = unittest.makeSuite(Test_Data_Manager,'test_lon')
     4781    #suite = unittest.makeSuite(Test_Data_Manager,'trial')
    47774782    suite = unittest.makeSuite(Test_Data_Manager,'test')
    47784783    runner = unittest.TextTestRunner()
Note: See TracChangeset for help on using the changeset viewer.