- Timestamp:
- Oct 12, 2018, 8:18:25 PM (7 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r2179 r2184 139 139 # maxNcounts: Function to provide a value according to the maximum number of repeated values along a given axis 140 140 # minNcounts: Function to provide a value according to the minimum number of repeated values along a given axis 141 # mindist: Function to provide the minimum distance toa pair of lon,lat 141 142 # minmax_range: Function to provide a range for a given pair of minimum and maximum 142 143 # multi_index_mat: Function to provide the multiple coordinates of a given value inside a matrix … … 14593 14594 return cftimes, timeu 14594 14595 14596 def mindist(lonv,latv,lonvalue,latvalue): 14597 """ Function to proivde the minimum distance toa pair of lon,lat 14598 lonv: matrix with longitudes 14599 latv: matrix with longitudes 14600 lonvalue: longitude to look for 14601 latvalue: latitude to look for 14602 """ 14603 fname = 'mindist' 14604 14605 if len(lonv.shape) == 1: 14606 distlon = np.abs(lonv - lonvalue) 14607 distlat = np.abs(latv - latvalue) 14608 14609 mindifflon = np.min(distlon) 14610 mindifflat = np.min(distlat) 14611 ix = gen.index_vec(distlon, mindistlon) 14612 iy = gen.index_vec(distlat, mindistlat) 14613 else: 14614 dist = np.sqrt((lonv - lonvalue)**2 + (latv - latvalue)**2) 14615 mindist = np.min(dist) 14616 [iy, ix] = gen.index_mat(dist, mindist) 14617 14618 return [ix, iy], mindist 14619 14620 14595 14621 #quit() 14596 14622 -
trunk/tools/nc_var_tools.py
r2180 r2184 113 113 # maskvar: Function to mask a variable using a mask. It is assumed that mask[...,dimM,dimJ,dimK] and var[...,dimM,dimJ,dimK] share the last dimensions 114 114 # merge_files: Function to merge variables from two files 115 # mindist: Function to provide the minimum distance toa pair of lon,lat116 115 # ModelChar: Class object to determine major characterisitcs of a given model output 117 116 # model_characteristics: Functino to provide major characterisitcs of a given model output … … 24543 24542 #itime('WRFtime', '../PY/wrfout_d01_1995-01-01_00:00:00', 'Times') 24544 24543 24545 def mindist(lonv,latv,lonvalue,latvalue):24546 """ Function to proivde the minimum distance toa pair of lon,lat24547 lonv: matrix with longitudes24548 latv: matrix with longitudes24549 lonvalue: longitude to look for24550 latvalue: latitude to look for24551 """24552 fname = 'mindist'24553 24554 if len(lonv.shape) == 1:24555 distlon = np.abs(lonv - lonvalue)24556 distlat = np.abs(latv - latvalue)24557 24558 mindifflon = np.min(distlon)24559 mindifflat = np.min(distlat)24560 ix = gen.index_vec(distlon, mindistlon)24561 iy = gen.index_vec(distlat, mindistlat)24562 else:24563 dist = np.sqrt((lonv - lonvalue)**2 + (latv - latvalue)**2)24564 mindist = np.min(dist)24565 [iy, ix] = gen.index_mat(dist, mindist)24566 24567 return [ix, iy], mindist24568 24569 24544 def get_point(values, ncfile, variable): 24570 24545 """ Function to provide the closest grid point to a given lat,lon … … 24634 24609 onc.close() 24635 24610 # looking for minimum distance 24636 gridpoint, ndist = mindist(lonv,latv,lonvalue,latvalue)24611 gridpoint, ndist = gen.mindist(lonv,latv,lonvalue,latvalue) 24637 24612 24638 24613 print str(gridpoint[0])+','+str(gridpoint[1]), ndist
Note: See TracChangeset
for help on using the changeset viewer.