Changeset 2038
- Timestamp:
- Nov 18, 2005, 2:39:35 PM (19 years ago)
- Location:
- inundation/pyvolution
- Files:
-
- 2 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 -
inundation/pyvolution/test_data_manager.py
r2035 r2038 3393 3393 3394 3394 def test_get_min_max_indexes(self): 3395 latitudes = [ 0,1,2,3]3395 latitudes = [3,2,1,0] 3396 3396 longitudes = [0,10,20,30] 3397 3397 … … 3435 3435 #print "longitudes_news",longitudes_news 3436 3436 3437 self.failUnless(latitudes_new == [ 1, 2] and \3437 self.failUnless(latitudes_new == [2, 1] and \ 3438 3438 longitudes_news == [10, 20], 3439 3439 'failed') … … 3450 3450 #print "longitudes_news",longitudes_news 3451 3451 3452 self.failUnless(latitudes_new == [ 0,1, 2] and \3453 longitudes_news == [0, 10, 20],3452 self.failUnless(latitudes_new == [2, 1, 0] and \ 3453 longitudes_news == [0, 10, 20], 3454 3454 'failed') 3455 3455 ## 5th test … … 3463 3463 #print "longitudes_news",longitudes_news 3464 3464 3465 self.failUnless(latitudes_new == [ 0,1, 2] and \3466 longitudes_news == [0, 10, 20],3465 self.failUnless(latitudes_new == [2, 1, 0] and \ 3466 longitudes_news == [0, 10, 20], 3467 3467 'failed') 3468 3468 … … 3478 3478 #print "longitudes_news",longitudes_news 3479 3479 3480 self.failUnless(latitudes_new == [ 1, 2, 3] and \3480 self.failUnless(latitudes_new == [3, 2, 1] and \ 3481 3481 longitudes_news == [10, 20, 30], 3482 3482 'failed') … … 3496 3496 #print "longitudes_news",longitudes_news 3497 3497 3498 self.failUnless(latitudes_new == [ 1, 2] and \3498 self.failUnless(latitudes_new == [2, 1] and \ 3499 3499 longitudes_news == [10, 20], 3500 3500 'failed') … … 3504 3504 3505 3505 def test_get_min_max_indexes2(self): 3506 latitudes = [- 45,-40,-35,-30]3506 latitudes = [-30,-35,-40,-45] 3507 3507 longitudes = [148,149,150,151] 3508 3508 3509 m2d = array([[0,1,2,3],[4,5,6,7],[8,9,10,11],[12,13,14,15]]) 3510 3509 3511 # k - lat 3510 3512 # l - lon … … 3514 3516 #print "kmin",kmin;print "kmax",kmax 3515 3517 #print "lmin",lmin;print "lmax",lmax 3518 #print "m2d", m2d 3519 #print "latitudes", latitudes 3520 #print "longitudes",longitudes 3521 #print "latitudes[kmax]", latitudes[kmax] 3522 latitudes_new = latitudes[kmin:kmax] 3523 longitudes_new = longitudes[lmin:lmax] 3524 m2d = m2d[kmin:kmax,lmin:lmax] 3525 #print "m2d", m2d 3526 #print "latitudes_new", latitudes_new 3527 #print "longitudes_new",longitudes_new 3528 3529 self.failUnless(latitudes_new == [-30, -35, -40] and \ 3530 longitudes_new == [148, 149,150], 3531 'failed') 3532 self.failUnless(m2d == [[0,1,2],[4,5,6],[8,9,10]], 3533 'failed') 3534 3535 def test_get_min_max_indexes3(self): 3536 latitudes = [-30,-35,-40,-45,-50,-55,-60] 3537 longitudes = [148,149,150,151] 3538 3539 # k - lat 3540 # l - lon 3541 kmin, kmax, lmin, lmax = get_min_max_indexes (latitudes,longitudes, 3542 -43,-37,148.5,149.5) 3543 3544 3545 #print "kmin",kmin;print "kmax",kmax 3546 #print "lmin",lmin;print "lmax",lmax 3547 #print "latitudes", latitudes 3548 #print "longitudes",longitudes 3516 3549 latitudes_new = latitudes[kmin:kmax] 3517 3550 longitudes_news = longitudes[lmin:lmax] … … 3519 3552 #print "longitudes_news",longitudes_news 3520 3553 3521 self.failUnless(latitudes_new == [- 40, -35, -30] and \3554 self.failUnless(latitudes_new == [-35, -40, -45] and \ 3522 3555 longitudes_news == [148, 149,150], 3523 3556 'failed') 3524 3557 3525 def test_get_min_max_indexes 3(self):3526 latitudes = [- 60,-55,-50,-45,-40,-35,-30]3558 def test_get_min_max_indexes4(self): 3559 latitudes = [-30,-35,-40,-45,-50,-55,-60] 3527 3560 longitudes = [148,149,150,151] 3528 3561 3529 3562 # k - lat 3530 3563 # l - lon 3531 kmin, kmax, lmin, lmax = get_min_max_indexes (latitudes,longitudes, 3532 -37,-27,147,149.5) 3564 kmin, kmax, lmin, lmax = get_min_max_indexes (latitudes,longitudes) 3533 3565 3534 3566 3535 3567 #print "kmin",kmin;print "kmax",kmax 3536 3568 #print "lmin",lmin;print "lmax",lmax 3569 #print "latitudes", latitudes 3570 #print "longitudes",longitudes 3537 3571 latitudes_new = latitudes[kmin:kmax] 3538 3572 longitudes_news = longitudes[lmin:lmax] … … 3540 3574 #print "longitudes_news",longitudes_news 3541 3575 3542 self.failUnless(latitudes_new == [-40, -35, -30]and \3543 longitudes_news == [148, 149,150],3576 self.failUnless(latitudes_new == latitudes and \ 3577 longitudes_news == longitudes, 3544 3578 'failed') 3545 3579 3546 3580 #------------------------------------------------------------- 3547 3581 if __name__ == "__main__": 3548 #suite = unittest.makeSuite(Test_Data_Manager,'test_ get_min_max_indexes')3582 #suite = unittest.makeSuite(Test_Data_Manager,'test_asc_csiro2sww4') 3549 3583 suite = unittest.makeSuite(Test_Data_Manager,'test') 3550 3584 #suite = unittest.makeSuite(Test_Data_Manager,'xxxtest')
Note: See TracChangeset
for help on using the changeset viewer.