Changeset 2687 in lmdz_wrf for trunk


Ignore:
Timestamp:
Aug 10, 2019, 11:56:56 AM (5 years ago)
Author:
lfita
Message:

Adding:

  • `lonlat_dist': Function to provide the distance in m between two lon,lat coordinates
  • `lonlat_Polyarea': Function to provide the area in m of an enclosed polygon in lon,lat coordinates
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r2683 r2687  
    1616from cStringIO import StringIO
    1717import sys
    18 import module_ForGen as gen
     18import module_ForDef as fdef
     19import module_ForGen as fgen
     20import module_ForSci as fsci
    1921
    2022main = 'nc_var_tools.py'
     
    168170# list_norepeatcombos: Function to all possible (Num-1)-combinations of a Num values without repetitions
    169171# lstring_values: Function to provide a new list-string from a string which is a list of word separated by a character if some values are repeated they are not included
     172# lonlat_dist: Function to provide the distance in m between two lon,lat coordinates
     173# lonlat_Polyarea: Function to provide the area in m of an enclosed polygon in lon,lat coordinates
    170174# make_colors: Function to create a palette of colors from a series of high and low values
    171175# mat_dimreshape: Function to reshape a matrix on a new one according to values along their dimensions
     
    847851    #sec4 = 3.*((I+4900.+(J-14.)/12.)/100.)/4.
    848852    #juliand = int(sec1 + sec2 + sec3 - sec4)
    849     juliand = gen.module_generic.jd(I,J,K)
     853    juliand = fgen.module_generic.jd(I,J,K)
    850854
    851855    juliand = juliand*1. + (hr + mi/60. + ss/3600.)/24.
     
    1690816912    return finalcol
    1690916913
     16914def lonlat_dist(lonlat1, lonlat2):
     16915    """ Function to provide the distance in m between two lon,lat coordinates
     16916        as ds = sqrt(dlon**2+dlat**2)*Earthradii*np.cos(latmean)*DegRad
     16917      lonlat1: list with longitude, latitude of point 1
     16918      lonlat2: list with longitude, latitude of point 2
     16919    >>> lonlat_dist([-70.073759, -38.773790], [-68.414071, -37.284390])
     16920    2.2299947572458443, 195290.18809
     16921    """
     16922    fname = 'lonlat_dist'
     16923
     16924    dlon = lonlat2[0] - lonlat1[0]
     16925    dlat = lonlat2[1] - lonlat1[1]
     16926
     16927    latmean = np.mean([lonlat1[1], lonlat2[1]])
     16928
     16929    ds = np.sqrt(dlon**2+dlat**2)
     16930    deg2km = fdef.module_definitions.earthradii*np.cos(latmean*np.pi/180.)*np.pi/180.
     16931
     16932    distkm = ds*deg2km
     16933
     16934    return ds, distkm
     16935
     16936def lonlat_Polyarea(poly):
     16937    """ Function to provide the area in m of an enclosed polygon in lon,lat
     16938          coordinates
     16939        as ds = ShoelaceArea*Earthradii*np.cos(latmean)*DegRad
     16940      polygon: list with the consecutive [longitude, latitude] verrtices of the
     16941        polygon
     16942    >>> lonlat_Polyarea([[-70.073759,-38.773790], [-69.993907,-37.264203],
     16943      [-68.414071,-37.284390], [-68.437593,-38.867590]])
     16944    -2.4892578125, -19081159952.039444
     16945    """
     16946    fname = 'lonlat_Polyarea'
     16947
     16948    apoly = np.array(poly)
     16949
     16950    area = fsci.module_scientific.shoelace_area_polygon(nvertex=4, poly=apoly)
     16951
     16952    latmean = np.mean(apoly[:,1])
     16953    deg2km = fdef.module_definitions.earthradii*np.cos(latmean*np.pi/180.)*np.pi/180.
     16954
     16955    areakm = area*deg2km*deg2km
     16956
     16957    return area, areakm
     16958
    1691016959#quit()
    1691116960
Note: See TracChangeset for help on using the changeset viewer.