Changeset 2038 for inundation/pyvolution/data_manager.py
- Timestamp:
- Nov 18, 2005, 2:39:35 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/pyvolution/data_manager.py
r2035 r2038 3355 3355 latitudes = [bath_metadata['yllcorner']+y*bath_metadata['cellsize'] \ 3356 3356 for y in range(number_of_latitudes)] 3357 3357 3358 # reverse order of lat, so the fist lat represents the first grid row 3359 latitudes.reverse() 3360 3361 #print "latitudes - before get_min_max_indexes",latitudes 3358 3362 kmin, kmax, lmin, lmax = get_min_max_indexes(latitudes,longitudes, 3359 3363 minlat=minlat, maxlat=maxlat, 3360 3364 minlon=minlon, maxlon=maxlon) 3361 #print "latitudes", latitudes 3362 #print "********************" 3363 #print "kmin",kmin 3364 #print "kmax",kmax 3365 #print "lmin",lmin 3366 #print "lmax",lmax 3367 #print "bath_grid",bath_grid 3365 3366 3368 3367 bath_grid = bath_grid[kmin:kmax,lmin:lmax] 3369 3368 #print "bath_grid",bath_grid … … 3377 3376 latitudes = latitudes[kmin:kmax] 3378 3377 longitudes = longitudes[lmin:lmax] 3379 3380 # reverse order of lat, so the fist lat represents the first grid row3381 latitudes.reverse() 3382 3378 number_of_latitudes = len(latitudes) 3379 number_of_longitudes = len(longitudes) 3380 3381 3383 3382 #Work out the times 3384 3383 if len(elevation_files) > 1: … … 3530 3529 _, v_momentum_grid = _read_asc(vcur_dir + os.sep + vcur_files[j]) 3531 3530 3531 #print "elevation_grid",elevation_grid 3532 3532 #cut matrix to desired size 3533 3533 elevation_grid = elevation_grid[kmin:kmax,lmin:lmax] 3534 3534 u_momentum_grid = u_momentum_grid[kmin:kmax,lmin:lmax] 3535 3535 v_momentum_grid = v_momentum_grid[kmin:kmax,lmin:lmax] 3536 #print "elevation_grid",elevation_grid 3536 3537 # handle missing values 3537 3538 missing = (elevation_grid == elevation_meta['NODATA_value']) … … 3550 3551 for k in range(number_of_latitudes): #Y direction 3551 3552 for l in range(number_of_longitudes): #X direction 3552 #w = zscale*amplitudes[j,k,l]/100 + mean_stage3553 3553 w = zscale*elevation_grid[k,l] + mean_stage 3554 3554 stage[j,i] = w … … 3563 3563 minlon=None, maxlon=None): 3564 3564 """ 3565 return max, min indexes of the lat and long arrays to cover the area3565 return max, min indexes (for slicing) of the lat and long arrays to cover the area 3566 3566 specified with min/max lat/long 3567 3567 … … 3571 3571 has a section outside of the latitudes/longitudes area.) 3572 3572 3573 assume latitudess & longitudes are sorted, from low to high 3574 """ 3575 3576 3577 #Cut out a smaller extent. 3573 assume latitudess & longitudes are sorted, 3574 long - from low to high (west to east, eg 148 - 151) 3575 lat - from high to low (north to south, eg -35 - -38) 3576 """ 3577 3578 # reverse order of lat, so it's in ascending order 3579 latitudes.reverse() 3580 largest_lat_index = len(latitudes)-1 3581 #Cut out a smaller extent. 3578 3582 if minlat == None: 3579 lat_min_index = 03583 lat_min_index = 0 3580 3584 else: 3581 3585 lat_min_index = searchsorted(latitudes, minlat)-1 3582 3586 if lat_min_index <0: 3583 lat_min_index = 03587 lat_min_index = 0 3584 3588 3585 3589 3586 3590 if maxlat == None: 3587 lat_max_index = l en(latitudes)3591 lat_max_index = largest_lat_index #len(latitudes) 3588 3592 else: 3589 lat_max_index = searchsorted(latitudes, maxlat)+1 3593 lat_max_index = searchsorted(latitudes, maxlat) 3594 if lat_max_index > largest_lat_index: 3595 lat_max_index = largest_lat_index 3596 3590 3597 if minlon == None: 3591 3598 lon_min_index = 0 … … 3598 3605 lon_max_index = len(longitudes) 3599 3606 else: 3600 lon_max_index = searchsorted(longitudes, maxlon)+1 3601 3607 lon_max_index = searchsorted(longitudes, maxlon) 3608 3609 #Take into account that the latitude list was reversed 3610 latitudes.reverse() # Python passes by reference, need to swap back 3611 lat_min_index, lat_max_index = largest_lat_index - lat_max_index , \ 3612 largest_lat_index - lat_min_index 3613 lat_max_index = lat_max_index + 1 # taking into account how slicing works 3614 lon_max_index = lon_max_index + 1 # taking into account how slicing works 3615 3602 3616 return lat_min_index, lat_max_index, lon_min_index, lon_max_index 3603 3617
Note: See TracChangeset
for help on using the changeset viewer.