Changeset 2212 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Nov 2, 2018, 7:01:51 PM (6 years ago)
Author:
lfita
Message:

Addding the `range_faces' with all its glory...

Location:
trunk/tools
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/diag_tools.py

    r2209 r2212  
    13701370    return var1, var2, vardims, varvdims
    13711371
    1372 def Forcompute_range_faces(lon, lat, hgt, face, dimns, dimvns):
     1372def Forcompute_range_faces(lon, lat, hgt, face, Nfilt, dimns, dimvns):
    13731373    """ Function to compute faces [uphill, valley, downhill] of sections of a mountain
    13741374      rage, along a given face
     
    13771377      [lat]= latitude values (assuming [y,x]) [degrees north]
    13781378      [hgt]= height values (assuming [y,x]) [m]
     1379      face= which face (axis along which produce slices) to use to compute the faces: WE, SN
     1380      Nfilt= number of grid points to use to filter the topographic values
    13791381      [dimns]= list of the name of the dimensions of [smois]
    13801382      [dimvns]= list of the name of the variables with the values of the
     
    13911393        dy = hgt.shape[0]
    13921394
    1393         facest=fdin.module_fordiagnostics.compute_range_faces(lon=lon[:].transpose(),\
    1394           lat=lat[:].transpose(), hgt=hgt[:].transpose(), face=face, d1=dx, d2=dy)
    1395         faces = facest.transpose()
     1395        dhgtt, peakst, valleyst, ofacest, ffacest =                                  \
     1396          fdin.module_fordiagnostics.compute_range_faces(lon=lon[:].transpose(),     \
     1397          lat=lat[:].transpose(), hgt=hgt[:].transpose(), face=face, nfilt=Nfilt,    \
     1398          d1=dx, d2=dy)
     1399        dhgt = dhgtt.transpose()
     1400        peaks = peakst.transpose()
     1401        valleys = valleyst.transpose()
     1402        origfaces = ofacest.transpose()
     1403        filtfaces = ffacest.transpose()
    13961404    else:
    13971405        print errormsg
     
    14001408        quit(-1)
    14011409
    1402     return faces, vardims, varvdims
     1410    return dhgt, peaks, valleys, origfaces, filtfaces, vardims, varvdims
    14031411
    14041412####### ###### ##### #### ### ## # END Fortran diagnostics
  • trunk/tools/diagnostics.py

    r2209 r2212  
    101101
    102102# Variables not to check
    103 NONcheckingvars = ['accum', 'cllmh', 'deaccum', 'face:WE', 'face:SN', 'TSrhs',       \
     103NONcheckingvars = ['accum', 'cllmh', 'deaccum', 'face', 'TSrhs',                     \
    104104  'TStd', 'TSwds', 'TSwss',                                                          \
    105105  'WRFbils',                                                                         \
     
    415415            if depvars[0] == 'accum': diagn='accum'
    416416            for depv in depvars:
     417                # Checking without extra arguments of a depending variable (':', separated)
     418                if depv.find(':') != -1: depv=depv.split(':')[0]
    417419                if not ncobj.variables.has_key(depv) and not                         \
    418420                  gen.searchInlist(NONcheckingvars, depv) and                        \
     
    679681        ncvar.insert_variable(ncobj, 'hurs', diagout, diagoutd, diagoutvd, newnc)
    680682
    681 # range_faces: LON, LAT, HGT, 'face:['WE'/'SN']'
     683# range_faces: LON, LAT, HGT, 'face:['WE'/'SN']:[Nptfilt]'
    682684    elif diagn == 'range_faces':
    683685           
     
    685687        var1 = ncobj.variables[depvars[1]][:]
    686688        var2 = ncobj.variables[depvars[2]][:]
    687         var3 = depvars[3].split(':')[1]
    688 
     689        face = depvars[3].split(':')[1]
     690        Nptfilt = depvars[3].split(':')[2]
     691
     692        dnamesvar = list(ncobj.variables[depvars[0]].dimensions)
     693        dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames)
    689694        lon, lat = gen.lonlat2D(var0, var1)
    690695        if len(var2.shape) == 3:
     
    692697            print '  ' + diagn + ": shapping to 2D variable '" + depvars[2] + "' !!"
    693698            hgt = var2[0,:,:]
     699            dnamesvar.pop(0)
     700            dvnamesvar.pop(0)           
    694701        else:
    695702            hgt = var2[:]
    696703
    697         dnamesvar = list(ncobj.variables[depvars[0]].dimensions)
    698         dvnamesvar = ncvar.var_dim_dimv(dnamesvar,dnames,dvnames)
    699 
    700         diagout, diagoutd, diagoutvd = diag.Forcompute_range_faces(lon, lat, hgt,    \
    701           var3, dnamesvar, dvnamesvar)
    702 
    703         # Removing the nonChecking variable-dimensions from the initial list
    704         varsadd = []
    705         diagoutvd = list(dvnames)
    706         for nonvd in NONchkvardims:
    707             if gen.searchInlist(dvnames,nonvd): diagoutvd.remove(nonvd)
    708             varsadd.append(nonvd)
    709         ncvar.insert_variable(ncobj, 'range_faces', diagout, diagoutd, diagoutvd,    \
     704        dhgt, peaks, valleys, origfaces, diagout, diagoutd, diagoutvd =              \
     705          diag.Forcompute_range_faces(lon, lat, hgt, face, Nptfilt, dnamesvar,       \
     706          dvnamesvar)
     707
     708        # Removing the nonChecking variable-dimensions from the initial list
     709        varsadd = []
     710        diagoutvd = list(dvnames)
     711        for nonvd in NONchkvardims:
     712            if gen.searchInlist(dvnames,nonvd): diagoutvd.remove(nonvd)
     713            varsadd.append(nonvd)
     714
     715        ncvar.insert_variable(ncobj, 'hgtderivdeg', dhgt, diagoutd, diagoutvd,       \
    710716          newnc)
     717        ovar = newnc.variables['orogderivdeg']
     718        if face == 'WE': axis = 'lon'
     719        elif face == 'SN': axis = 'lat'
     720        ncvar.set_attribute(ovar, 'deriv', axis)
     721
     722        ncvar.insert_variable(ncobj, 'peak', peaks, diagoutd, diagoutvd, newnc)
     723        ncvar.insert_variable(ncobj, 'valley', valleys, diagoutd, diagoutvd, newnc)
     724
     725        ncvar.insert_variable(ncobj, 'rangefaces', diagout, diagoutd, diagoutvd,    \
     726          newnc)
     727        newnc.renameVariable('rangefaces', 'rangefacesfilt')
     728        ovar = newnc.variables['rangefacesfilt']
     729        ncvar.set_attribute(ovar, 'face', face)
     730        ncvar.set_attributek(ovar, 'grid_points_filter', Nptfilt, 'I')
     731
     732        ncvar.insert_variable(ncobj, 'rangefaces', origfaces, diagoutd, diagoutvd,  \
     733          newnc)
     734        ovar = newnc.variables['rangefaces']
     735        ncvar.set_attribute(ovar, 'face', face)
    711736
    712737# mrso: total soil moisture SMOIS, DZS
  • trunk/tools/module_ForDiagnostics.f90

    r2209 r2212  
    949949  END SUBROUTINE compute_fog_FRAML50
    950950
    951   SUBROUTINE compute_range_faces(d1, d2, lon, lat, hgt, face, faces)
     951  SUBROUTINE compute_range_faces(d1, d2, lon, lat, hgt, face, Nfilt, derivhgt, peaks, valleys,        &
     952    origfaces, filtfaces)
    952953! Subroutine to compute faces [uphill, valleys, downhill] of a mountain range along a given face
    953954
    954955    IMPLICIT NONE
    955956
    956     INTEGER, INTENT(in)                                  :: d1, d2
     957    INTEGER, INTENT(in)                                  :: d1, d2, Nfilt
    957958    REAL(r_k), DIMENSION(d1,d2), INTENT(in)              :: lon, lat, hgt
    958959    CHARACTER(len=*)                                     :: face
    959     INTEGER, DIMENSION(d1,d2), INTENT(out)               :: faces
     960    REAL(r_k), DIMENSION(d1,d2), INTENT(out)             :: derivhgt
     961    INTEGER, DIMENSION(d1,d2), INTENT(out)               :: origfaces, filtfaces, peaks, valleys
    960962 
    961963! Local
    962964    INTEGER                                              :: i, j
     965    INTEGER                                              :: Npeaks, Nvalleys
     966    INTEGER, DIMENSION(d1)                               :: ipeaks1, ivalleys1
     967    INTEGER, DIMENSION(d2)                               :: ipeaks2, ivalleys2
    963968
    964969!!!!!!! Variables
     
    966971! lat: latitude [degrees north]
    967972! hgt: topograpical height [m]
     973! face: which face (axis along which produce slices) to use to compute the faces: WE, SN
     974! Nfilt: number of grid points to use to filter the topographic values
     975! derivhgt: topograpic derivative along axis [m deg-1]
     976! peaks: peak point
     977! valleys: valley point
     978! origfaces: original faces (-1, downhill; 0: valley; 1: uphill)
     979! filtfaces: filtered faces (-1, downhill; 0: valley; 1: uphill)
    968980
    969981    fname = 'compute_range_faces'
    970982
     983    peaks = 0
     984    valleys = 0
    971985    IF (TRIM(face) == 'WE') THEN
    972986      DO j=1, d2
    973         CALL var_range_faces(d1, lon(:,j), lat(:,j), hgt(:,j), faces(:,j))
     987        PRINT *,'Lluis:',j
     988        CALL var_range_faces(d1, lon(:,j), lat(:,j), hgt(:,j), Nfilt, derivhgt(:,j), Npeaks,          &
     989          ipeaks1, Nvalleys, ivalleys1, origfaces(:,j), filtfaces(:,j))
     990        DO i=1, Npeaks
     991          peaks(ipeaks1(i),j) = 1
     992        END DO
     993        DO i=1, Nvalleys
     994          valleys(ivalleys1(i),j) = 1
     995        END DO
    974996      END DO
    975997    ELSE IF (TRIM(face) == 'SN') THEN
    976998      DO i=1, d1
    977         CALL var_range_faces(d2, lon(i,:), lat(i,:), hgt(i,:), faces(i,:))
     999        CALL var_range_faces(d2, lon(i,:), lat(i,:), hgt(i,:), Nfilt, derivhgt(i,:), Npeaks,          &
     1000          ipeaks2, Nvalleys, ivalleys2, origfaces(i,:), filtfaces(i,:))
     1001        DO j=1, Npeaks
     1002          peaks(i,ipeaks2(j)) = 1
     1003        END DO
     1004        DO j=1, Nvalleys
     1005          valleys(i,ivalleys2(j)) = 1
     1006        END DO
    9781007      END DO
    9791008    ELSE
  • trunk/tools/module_ForDiagnosticsVars.f90

    r2209 r2212  
    99  USE module_definitions
    1010  USE module_generic
     11  USE module_scientific
    1112
    1213  IMPLICIT NONE
     
    15791580  END SUBROUTINE var_fog_FRAML50
    15801581
    1581   SUBROUTINE var_range_faces(d, lon, lat, hgt, faces)
     1582  SUBROUTINE var_range_faces(d, lon, lat, hgt, filt, dhgt, Npeaks, ipeaks, Nvalleys, ivalleys,        &
     1583    faces0, faces)
    15821584! Subroutine to compute faces [uphill, valleys, downhill] of a monuntain range along a face
    15831585
    15841586    IMPLICIT NONE
    15851587
    1586     INTEGER, INTENT(in)                                  :: d
    1587     REAL, DIMENSION(d), INTENT(in)                       :: lon, lat, hgt
    1588     INTEGER, DIMENSION(d), INTENT(out)                   :: faces
     1588    INTEGER, INTENT(in)                                  :: d, filt
     1589    REAL(r_k), DIMENSION(d), INTENT(in)                  :: lon, lat, hgt
     1590    REAL(r_k), DIMENSION(d), INTENT(out)                 :: dhgt
     1591    INTEGER, DIMENSION(d), INTENT(out)                   :: ipeaks, ivalleys, faces0, faces
     1592    INTEGER, INTENT(out)                                 :: Npeaks, Nvalleys
    15891593
    15901594! Local
    1591     INTEGER                                              :: i, Nfaces, Npeaks
     1595    INTEGER                                              :: i, j, k, l, m
     1596    INTEGER                                              :: iface
     1597    INTEGER                                              :: Nfaces, Nfaces1, Npeaks1, Nvalleys1
     1598    INTEGER                                              :: fbeg, fend
    15921599    INTEGER, DIMENSION(1)                                :: ihmax
    1593     REAL                                                 :: hgtmax
    1594     INTEGER, DIMENSION(d)                                :: ddhgt, Ndhgt, ipeaks
    1595     REAL, DIMENSION(d)                                   :: dhgt, peaks
     1600    REAL(r_k)                                            :: hgtmax
     1601    INTEGER, DIMENSION(d)                                :: ddhgt, Ndhgt
     1602    INTEGER, DIMENSION(d)                                :: faces1, Ndhgt1, ipeaks1, ivalleys1
     1603    REAL(r_k), DIMENSION(d)                              :: peaks, valleys, peaks1, valleys1
     1604    LOGICAL                                              :: peakwithin, valleywithin
    15961605
    15971606!!!!!!! Variables
     
    15991608! lat: latitude [degrees north]
    16001609! hgt: topograpical height [m]
     1610! filt: number of grid points to use to filter the topographic values. used to define:
     1611!   the minimum length of a given section
     1612!   running mean filter
    16011613
    16021614    fname = 'var_range_faces'
     
    16101622    PRINT *, 'height max:', hgtmax, 'location:', ihmax
    16111623
     1624    ! Filtering height [NOT needed]
     1625    ! CALL runmean_F1D(d, hgt, filt, 'progressfill', hgtrunmean)
     1626
    16121627    ! range slope
    16131628    dhgt(1:d) = hgt(2:d) - hgt(1:d-1)
     
    16151630    PRINT *, 'slope:', dhgt
    16161631
    1617     ! Classification
     1632    ! Initial classification
    16181633    Npeaks = 0
     1634    Nvalleys = 0
    16191635    DO i=1, d-1
    16201636      IF (dhgt(i) > 0.) THEN
    1621         faces(i) = 1
     1637        faces0(i) = 1
    16221638      ELSE IF (dhgt(i) < 0.) THEN
    1623         faces(i) = -1
     1639        faces0(i) = -1
    16241640      ELSE
    1625         faces(i) = 0
     1641        faces0(i) = 0
    16261642      END IF
    16271643      ! peaks
     
    16311647        ipeaks(Npeaks) = i+1
    16321648      END IF
     1649      ! valleys
     1650      IF (dhgt(i) < 0. .AND. dhgt(i+1) > 0.) THEN
     1651        Nvalleys = Nvalleys + 1
     1652        valleys(Nvalleys) = hgt(i+1)
     1653        ivalleys(Nvalleys) = i+1
     1654      END IF
    16331655    END DO
    16341656
    1635     PRINT *, 'faces:', faces
     1657    PRINT *, 'faces:', faces0
    16361658    PRINT *, Npeaks, ' peaks:', peaks(1:Npeaks), ' ipeak:', ipeaks(1:Npeaks)
     1659    PRINT *, Nvalleys, ' valleys:', valleys(1:Nvalleys), ' ivalley:', ivalleys(1:Nvalleys)
    16371660
    16381661    ! tendency of the slope
     
    16411664    Ndhgt(Nfaces) = 1
    16421665    DO i=2, d-1
    1643       IF (faces(i) /= faces(i-1)) THEN
     1666      IF (faces0(i) /= faces0(i-1)) THEN
    16441667        Nfaces = Nfaces + 1
    16451668        Ndhgt(Nfaces) = 1
     
    16531676    PRINT *, Nfaces, ' length faces:', Ndhgt(1:Nfaces)
    16541677
    1655     PRINT *, '# lon[0] lat[1] heights[2] slope[3] faces[4] ddhgt[5]'
     1678    ! classification using filt.
     1679    !   On that section of the hill smaller than the selected filter. Replace values by the ones from
     1680    !     the previous section (except if it is already valley!)
     1681    !     e.g.: filt= 3
     1682    !       faces0 = 0, 0, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1 -1, -1, 0, 0
     1683    !       faces = 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1 -1, -1, 0, 0
     1684    faces1 = faces0
     1685    Nfaces1 = 1
     1686    Npeaks1 = 0
     1687    Nvalleys1 = 0
     1688    Ndhgt1(1) = Ndhgt(1)
     1689    DO i=2, Nfaces
     1690      fbeg = SUM(Ndhgt(1:i-1))
     1691      fend = fbeg + Ndhgt(i)
     1692      peakwithin = .FALSE.
     1693      valleywithin = .FALSE.
     1694      DO j=1, Npeaks
     1695        IF (ipeaks(j) == fbeg) THEN
     1696          k = j
     1697          peakwithin = .TRUE.
     1698          EXIT
     1699        END IF
     1700      END DO
     1701      DO j=1, Nvalleys
     1702        IF (ivalleys(j) == fbeg) THEN
     1703          m = j
     1704          valleywithin = .TRUE.
     1705          EXIT
     1706        END IF
     1707      END DO
     1708
     1709      IF (Ndhgt(i) < filt) THEN
     1710        PRINT *, 'Lluis replacing !!!', i, ':', fbeg, fend, '<>', faces0(fbeg-1)
     1711        IF (faces0(fbeg) /= 0) faces1(fbeg:fend) = faces0(fbeg-1)
     1712        Ndhgt1(Nfaces1) = Ndhgt1(Nfaces1) + fend - fbeg + 1
     1713        peakwithin = .FALSE.
     1714        valleywithin = .FALSE.
     1715      ELSE
     1716        Nfaces1 = Nfaces1 + 1
     1717        Ndhgt1(Nfaces1) = Ndhgt(i)
     1718      END IF
     1719
     1720      IF (peakwithin) THEN
     1721        Npeaks1 = Npeaks1 + 1
     1722        peaks1(Npeaks1) = peaks(k)
     1723      END IF
     1724      IF (valleywithin) THEN
     1725        Nvalleys1 = Nvalleys1 + 1
     1726        valleys1(Nvalleys1) = valleys(m)
     1727      END IF
     1728    END DO
     1729
     1730    ! Introducing valleys between peaks lower than the highest peak in the section
     1731    faces = faces1
     1732    IF (Npeaks1 > 1) THEN
     1733      DO i=1,Npeaks1,2
     1734        fbeg = ipeaks1(i)
     1735        fend = ipeaks1(i+1)
     1736        faces(fbeg:fend) = 0
     1737      END DO   
     1738    END IF
     1739
     1740    PRINT *, '# lon[0] lat[1] heights[2] slope[3] faces0[4] faces1[5] faces1[6] ddhgt[7]'
    16561741    DO i=1, d
    1657       PRINT *, lon(i), lat(i), hgt(i), dhgt(i), faces(i), ddhgt(i)
     1742      PRINT *, lon(i), lat(i), hgt(i), dhgt(i), faces0(i), faces1(i), faces(i), ddhgt(i)
    16581743    END DO
    16591744
  • trunk/tools/variables_values.dat

    r2209 r2212  
    296296HGT, orog, orography,  0., 3000., surface|altitude, m,terrain, $orog$, orog
    297297HGT_M, orog, orography,  0., 3000., surface|altitude, m,terrain, $orog$, orog
     298orogderivdeg, orogderivdeg, orography_derivative_degrees,  0., 3000., derivative|along|degree|coordinate|of|surface|altitude, mdeg-1,seismic, $orog_{deri}^{deg}$, orog_deriv_deg
     299hgtderivdeg, orogderivdeg, orography_derivative_degrees,  0., 3000., derivative|along|degree|coordinate|of|surface|altitude, mdeg-1,seismic, $orog_{deri}^{deg}$, orog_deriv_deg
     300peak, peak, peak_point, 0., 1., peak|grd|point, 1, Binary, $peak$, peak
    298301plfc, plfc, pressure_level_free_convection, 100., 101000., pressure|of|level|free|convection, Pa, BuPu, $lfc^{p}$, lfc_p
    299302LFCP, plfc, pressure_level_free_convection, 100., 101000., pressure|of|level|free|convection, Pa, BuPu, $lfc^{p}$, lfc_p
     
    539542Meridional wind, va, northward_wind, -30., 30., northward|wind, ms-1, seismic, $va$, va
    540543LVITV, va, northward_wind, -30., 30., northward|wind, ms-1, seismic, $va$, va
     544valley, valley, valley_point, 0., 1., valley|grd|point, 1, Binary, $valley$, valley
    541545vas, vas, northward_wind, -30., 30., northward|10m|wind, ms-1, seismic, $vas$, vas
    542546VAS, vas, northward_wind, -30., 30., northward|10m|wind, ms-1, seismic, $vas$, vas
Note: See TracChangeset for help on using the changeset viewer.