Ignore:
Timestamp:
Nov 28, 2006, 11:54:54 AM (18 years ago)
Author:
duncan
Message:

removed bug that broke maxlat and minlat in sww2ferret

File:
1 edited

Legend:

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

    r4031 r4037  
    6464
    6565from Numeric import concatenate, array, Float, Int, Int32, resize, sometrue, \
    66      searchsorted, zeros, allclose, around, reshape, transpose
     66     searchsorted, zeros, allclose, around, reshape, transpose, sort
    6767from Scientific.IO.NetCDF import NetCDFFile
    6868
     
    26862686        jmax = searchsorted(times, maxt)
    26872687
     2688    #print "latitudes[:]",latitudes[:]
     2689    #print "longitudes[:]",longitudes [:]
    26882690    kmin, kmax, lmin, lmax = _get_min_max_indexes(latitudes[:],
    26892691                                                  longitudes[:],
     
    26972699    longitudes = longitudes[lmin:lmax]
    26982700
     2701    #print "latitudes[:]",latitudes[:]
     2702    #print "longitudes[:]",longitudes [:]
    26992703
    27002704    if verbose: print 'cropping'
     
    38893893    outfile.close()
    38903894
    3891 def _get_min_max_indexes(latitudes,longitudes,
     3895def _get_min_max_indexes(latitudes_ref,longitudes_ref,
    38923896                        minlat=None, maxlat=None,
    38933897                        minlon=None, maxlon=None):
     
    39013905    has a section outside of the latitudes/longitudes area.)
    39023906
    3903     assume latitudess & longitudes are sorted,
     3907    asset longitudes are sorted,
    39043908    long - from low to high (west to east, eg 148 - 151)
    3905     lat - from high to low (north to south, eg -35 - -38)
    3906     """
    3907 
    3908     # reverse order of lat, so it's in ascending order
    3909     try:
    3910         latitudes = latitudes.tolist()
    3911     except:
    3912         pass
     3909    assert latitudes are sorted, ascending or decending
     3910    """
     3911    latitudes = latitudes_ref[:]
     3912    longitudes = longitudes_ref[:]
     3913
     3914    latitudes = ensure_numeric(latitudes)
     3915    longitudes = ensure_numeric(longitudes)
    39133916   
    3914     latitudes.reverse()
     3917    assert allclose(sort(longitudes), longitudes)
     3918   
     3919    lat_ascending = True
     3920    if not allclose(sort(latitudes), latitudes):
     3921        lat_ascending = False
     3922        # reverse order of lat, so it's in ascending order         
     3923        latitudes = latitudes[::-1]
     3924        assert allclose(sort(latitudes), latitudes)
     3925    #print "latitudes  in funct", latitudes
    39153926   
    39163927    largest_lat_index = len(latitudes)-1
     
    39433954        lon_max_index = searchsorted(longitudes, maxlon)
    39443955
    3945     #Take into account that the latitude list was reversed
    3946     latitudes.reverse() # Python passes by reference, need to swap back
    3947     lat_min_index, lat_max_index = largest_lat_index - lat_max_index , \
    3948                                    largest_lat_index - lat_min_index
     3956    # Reversing the indexes, if the lat array is decending
     3957    if lat_ascending is False:
     3958        lat_min_index, lat_max_index = largest_lat_index - lat_max_index , \
     3959                                       largest_lat_index - lat_min_index
    39493960    lat_max_index = lat_max_index + 1 # taking into account how slicing works
    39503961    lon_max_index = lon_max_index + 1 # taking into account how slicing works
Note: See TracChangeset for help on using the changeset viewer.