Ignore:
Timestamp:
Jun 3, 2010, 6:03:07 PM (15 years ago)
Author:
James Hudson
Message:

Removed redundant data_manager class. Unit tests are running, but may fail.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/file_conversion/urs2nc.py

    r7765 r7776  
    133133
    134134
     135
     136##
     137# @brief
     138# @param long_lat_dep
     139# @return A tuple (long, lat, quantity).
     140# @note The latitude is the fastest varying dimension - in mux files.
     141def lon_lat2grid(long_lat_dep):
     142    """
     143    given a list of points that are assumed to be an a grid,
     144    return the long's and lat's of the grid.
     145    long_lat_dep is an array where each row is a position.
     146    The first column is longitudes.
     147    The second column is latitudes.
     148
     149    The latitude is the fastest varying dimension - in mux files
     150    """
     151
     152    LONG = 0
     153    LAT = 1
     154    QUANTITY = 2
     155
     156    long_lat_dep = ensure_numeric(long_lat_dep, num.float)
     157
     158    num_points = long_lat_dep.shape[0]
     159    this_rows_long = long_lat_dep[0,LONG]
     160
     161    # Count the length of unique latitudes
     162    i = 0
     163    while long_lat_dep[i,LONG] == this_rows_long and i < num_points:
     164        i += 1
     165
     166    # determine the lats and longsfrom the grid
     167    lat = long_lat_dep[:i, LAT]
     168    long = long_lat_dep[::i, LONG]
     169
     170    lenlong = len(long)
     171    lenlat = len(lat)
     172
     173    msg = 'Input data is not gridded'
     174    assert num_points % lenlat == 0, msg
     175    assert num_points % lenlong == 0, msg
     176
     177    # Test that data is gridded
     178    for i in range(lenlong):
     179        msg = 'Data is not gridded.  It must be for this operation'
     180        first = i * lenlat
     181        last = first + lenlat
     182
     183        assert num.allclose(long_lat_dep[first:last,LAT], lat), msg
     184        assert num.allclose(long_lat_dep[first:last,LONG], long[i]), msg
     185
     186    msg = 'Out of range latitudes/longitudes'
     187    for l in lat:assert -90 < l < 90 , msg
     188    for l in long:assert -180 < l < 180 , msg
     189
     190    # Changing quantity from lat being the fastest varying dimension to
     191    # long being the fastest varying dimension
     192    # FIXME - make this faster/do this a better way
     193    # use numeric transpose, after reshaping the quantity vector
     194    quantity = num.zeros(num_points, num.float)
     195
     196    for lat_i, _ in enumerate(lat):
     197        for long_i, _ in enumerate(long):
     198            q_index = lat_i*lenlong + long_i
     199            lld_index = long_i*lenlat + lat_i
     200            temp = long_lat_dep[lld_index, QUANTITY]
     201            quantity[q_index] = temp
     202
     203    return long, lat, quantity
     204
     205
     206
Note: See TracChangeset for help on using the changeset viewer.