Changeset 2184 in lmdz_wrf for trunk


Ignore:
Timestamp:
Oct 12, 2018, 8:18:25 PM (7 years ago)
Author:
lfita
Message:

Moving mindist' from 'nc_var_tools' to 'generic_tools'

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r2179 r2184  
    139139# maxNcounts: Function to provide a value according to the maximum number of repeated values along a given axis
    140140# 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
    141142# minmax_range: Function to provide a range for a given pair of minimum and maximum
    142143# multi_index_mat: Function to provide the multiple coordinates of a given value inside a matrix
     
    1459314594    return cftimes, timeu
    1459414595
     14596def 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
    1459514621#quit()
    1459614622
  • trunk/tools/nc_var_tools.py

    r2180 r2184  
    113113# 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
    114114# merge_files: Function to merge variables from two files
    115 # mindist: Function to provide the minimum distance toa pair of lon,lat
    116115# ModelChar: Class object to determine major characterisitcs of a given model output
    117116# model_characteristics: Functino to provide major characterisitcs of a given model output
     
    2454324542#itime('WRFtime', '../PY/wrfout_d01_1995-01-01_00:00:00', 'Times')
    2454424543
    24545 def mindist(lonv,latv,lonvalue,latvalue):
    24546     """ Function to proivde the minimum distance toa pair of lon,lat
    24547      lonv: matrix with longitudes
    24548      latv: matrix with longitudes
    24549      lonvalue: longitude to look for
    24550      latvalue: latitude to look for
    24551     """
    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], mindist
    24568 
    2456924544def get_point(values, ncfile, variable):
    2457024545    """ Function to provide the closest grid point to a given lat,lon
     
    2463424609    onc.close()
    2463524610    # looking for minimum distance
    24636     gridpoint, ndist = mindist(lonv,latv,lonvalue,latvalue)
     24611    gridpoint, ndist = gen.mindist(lonv,latv,lonvalue,latvalue)
    2463724612
    2463824613    print str(gridpoint[0])+','+str(gridpoint[1]), ndist
Note: See TracChangeset for help on using the changeset viewer.