ncss-tech / soilDB

soilDB: Simplified Access to National Cooperative Soil Survey Databases
http://ncss-tech.github.io/soilDB/
79 stars 19 forks source link

get_SDA_coecoclass: add `method="all"` #301

Closed brownag closed 8 months ago

brownag commented 10 months ago

The method performs a condition-based aggregation for each ecological site condition in the map unit, producing a "wide" data.frame result with as many columns as needed to portray all site conditions. Used to produce aggregate mapunit level (1:1 with mukey) ecological site composition summaries.

Ecological site conditions have been a recurring theme for me so I am now in this PR considering putting the code I use to boil down ES:mapunit relationships into soilDB.

For example:

soilDB::get_SDA_coecoclass(method = "all", areasymbols = "CA630") 
#> single result set, returning a data.frame
#>        mukey
#>   1: 1865918
#>   2: 1865926
#>   3: 1865927
#>   4: 1865928
#>   5: 1865929
#>  ---        
#> 124: 2924955
#> 125: 3225132
#> 126: 3225133
#> 127: 3225134
#> 128: 3225135
#>                                                                                   muname
#>   1:                         Goldwall-Toomes-Rock outcrop complex, 1 to 8 percent slopes
#>   2:                             Loafercreek-Gopheridge complex, 30 to 60 percent slopes
#>   3:                                  Crimeahouse-Sixbit complex, 3 to 15 percent slopes
#>   4:                                 Crimeahouse-Sixbit complex, 15 to 30 percent slopes
#>   5:                        Copperopolis-Whiterock complex, 2 to 8 percent slopes, rocky
#>  ---                                                                                    
#> 124: Psammentic Haploxerolls-Mollic Fluvaquents-Riverwash-complex, 0 to 8 percent slopes
#> 125:              Bonanza-Loafercreek complex, 3 to 15 percent slopes, low precipitation
#> 126:                     Bonanza-Loafercreek-Jasperpeak complex, 15 to 30 percent slopes
#> 127:                     Trabuco-Jasperpeak-Rock outcrop complex, 8 to 30 percent slopes
#> 128:                 Gopheridge-Jasperpeak-Rock outcrop complex, 30 to 60 percent slopes
#>      nationalmusym       site1
#>   1:         20mmx R018XI101CA
#>   2:         20mn5 F018XI201CA
#>   3:         20mn6 R018XI102CA
#>   4:         20mn7 R018XI102CA
#>   5:         20mn8 F018XI200CA
#>  ---                          
#> 124:         2x4d2 R018XX101CA
#> 125:         2z5lk R018XI163CA
#> 126:         2z5ll R018XI163CA
#> 127:         2z5lq F018XI205CA
#> 128:         2z5ln R018XI106CA
#>                                                                                      site1name
#>   1:                                                                  Shallow Latite Ridgetops
#>   2:                                                         Moderately Deep Thermic Foothills
#>   3: Thermic Ultramafic Foothills Extremely High Magnesium Content (Ca:Mg Ratio Less Than 0.5)
#>   4: Thermic Ultramafic Foothills Extremely High Magnesium Content (Ca:Mg Ratio Less Than 0.5)
#>   5:                                                                   Low Elevation Foothills
#>  ---                                                                                          
#> 124:                                           Mid Gradient Riparian Complex, 4Th Order Stream
#> 125:                                                                 Thermic Low Rolling Hills
#> 126:                                                                 Thermic Low Rolling Hills
#> 127:                                                                Thermic Granitic Foothills
#> 128:                                                 Steep Thermic Hillslopes and Canyon Walls
#>                                                        site1compname site1pct_r
#>   1:                            Goldwall, Toomes, Aquic Haploxeralfs         75
#>   2:                             Loafercreek, Gopheridge, Motherlode         84
#>   3:                                    Crimeahouse, Sixbit, Fancher         97
#>   4:                                             Crimeahouse, Sixbit         94
#>   5:                                         Copperopolis, Whiterock         83
#>  ---                                                                           
#> 124: Psammentic Haploxerolls, Mollic Fluvaquents, Ultic Haploxerolls         67
#> 125:                                                Bonanza, Redding         76
#> 126:                                Bonanza, Jasperpeak, Vistarobles         72
#> 127:                                                         Trabuco         55
#> 128:                                          Gopheridge, Jasperpeak         74
#>                                                        site1link        site2
#>   1: https://edit.jornada.nmsu.edu/catalogs/esd/018X/R018XI101CA Not assigned
#>   2: https://edit.jornada.nmsu.edu/catalogs/esd/018X/F018XI201CA Not assigned
#>   3: https://edit.jornada.nmsu.edu/catalogs/esd/018X/R018XI102CA Not assigned
#>   4: https://edit.jornada.nmsu.edu/catalogs/esd/018X/R018XI102CA Not assigned
#>   5: https://edit.jornada.nmsu.edu/catalogs/esd/018X/F018XI200CA Not assigned
#>  ---                                                                         
#> 124: https://edit.jornada.nmsu.edu/catalogs/esd/018X/R018XX101CA Not assigned
#> 125: https://edit.jornada.nmsu.edu/catalogs/esd/018X/R018XI163CA  F018XI208CA
#> 126: https://edit.jornada.nmsu.edu/catalogs/esd/018X/R018XI163CA  F018XI200CA
#> 127: https://edit.jornada.nmsu.edu/catalogs/esd/018X/F018XI205CA  F018XI200CA
#> 128: https://edit.jornada.nmsu.edu/catalogs/esd/018X/R018XI106CA Not assigned
#>                                site2name
#>   1:                        Not assigned
#>   2:                        Not assigned
#>   3:                        Not assigned
#>   4:                        Not assigned
#>   5:                        Not assigned
#>  ---                                    
#> 124:                        Not assigned
#> 125: Deep Low Rolling Hills and Terraces
#> 126:             Low Elevation Foothills
#> 127:             Low Elevation Foothills
#> 128:                        Not assigned
#>                                 site2compname site2pct_r
#>   1:                             Rock outcrop         20
#>   2:                 Rock outcrop, Mined land          6
#>   3:                 Rock outcrop, Mined land          3
#>   4:                 Rock outcrop, Mined land          6
#>   5:                 Rock outcrop, Mined land         12
#>  ---                                                    
#> 124: Riverwash, Anthraltic Xerorthents, Water         33
#> 125:                              Loafercreek         18
#> 126:                              Loafercreek         22
#> 127:                               Jasperpeak         24
#> 128:                 Rock outcrop, Mined land         16
#>                                                        site2link        site3
#>   1:                                                        <NA>  F018XI207CA
#>   2:                                                        <NA>  F018XI202CA
#>   3:                                                        <NA>         <NA>
#>   4:                                                        <NA>         <NA>
#>   5:                                                        <NA>  R018XI111CA
#>  ---                                                                         
#> 124:                                                        <NA>         <NA>
#> 125: https://edit.jornada.nmsu.edu/catalogs/esd/018X/F018XI208CA Not assigned
#> 126: https://edit.jornada.nmsu.edu/catalogs/esd/018X/F018XI200CA Not assigned
#> 127: https://edit.jornada.nmsu.edu/catalogs/esd/018X/F018XI200CA Not assigned
#> 128:                                                        <NA>  F018XI202CA
#>                              site3name            site3compname site3pct_r
#>   1:  Deep Volcanic Plateaus and Hills        Ultic Argixerolls          5
#>   2:     Deep Thermic Steep Hillslopes              Gardellones          5
#>   3:                              <NA>                     <NA>         NA
#>   4:                              <NA>                     <NA>         NA
#>   5: Low Gradient, Concave Depressions       Aquic Haploxeralfs          5
#>  ---                                                                      
#> 124:                              <NA>                     <NA>         NA
#> 125:                      Not assigned Rock outcrop, Mined land          6
#> 126:                      Not assigned Rock outcrop, Mined land          6
#> 127:                      Not assigned Rock outcrop, Mined land         14
#> 128:     Deep Thermic Steep Hillslopes                  Trabuco         10
#>                                                        site3link       site4
#>   1: https://edit.jornada.nmsu.edu/catalogs/esd/018X/F018XI207CA        <NA>
#>   2: https://edit.jornada.nmsu.edu/catalogs/esd/018X/F018XI202CA F018XI200CA
#>   3:                                                        <NA>        <NA>
#>   4:                                                        <NA>        <NA>
#>   5: https://edit.jornada.nmsu.edu/catalogs/esd/018X/R018XI111CA        <NA>
#>  ---                                                                        
#> 124:                                                        <NA>        <NA>
#> 125:                                                        <NA>        <NA>
#> 126:                                                        <NA>        <NA>
#> 127:                                                        <NA> F018XI201CA
#> 128: https://edit.jornada.nmsu.edu/catalogs/esd/018X/F018XI202CA        <NA>
#>                              site4name site4compname site4pct_r
#>   1:                              <NA>          <NA>         NA
#>   2:           Low Elevation Foothills    Jasperpeak          5
#>   3:                              <NA>          <NA>         NA
#>   4:                              <NA>          <NA>         NA
#>   5:                              <NA>          <NA>         NA
#>  ---                                                           
#> 124:                              <NA>          <NA>         NA
#> 125:                              <NA>          <NA>         NA
#> 126:                              <NA>          <NA>         NA
#> 127: Moderately Deep Thermic Foothills   Loafercreek          7
#> 128:                              <NA>          <NA>         NA
#>                                                        site4link site5
#>   1:                                                        <NA>  <NA>
#>   2: https://edit.jornada.nmsu.edu/catalogs/esd/018X/F018XI200CA  <NA>
#>   3:                                                        <NA>  <NA>
#>   4:                                                        <NA>  <NA>
#>   5:                                                        <NA>  <NA>
#>  ---                                                                  
#> 124:                                                        <NA>  <NA>
#> 125:                                                        <NA>  <NA>
#> 126:                                                        <NA>  <NA>
#> 127: https://edit.jornada.nmsu.edu/catalogs/esd/018X/F018XI201CA  <NA>
#> 128:                                                        <NA>  <NA>
#>      site5name site5compname site5pct_r site5link
#>   1:      <NA>          <NA>         NA      <NA>
#>   2:      <NA>          <NA>         NA      <NA>
#>   3:      <NA>          <NA>         NA      <NA>
#>   4:      <NA>          <NA>         NA      <NA>
#>   5:      <NA>          <NA>         NA      <NA>
#>  ---                                             
#> 124:      <NA>          <NA>         NA      <NA>
#> 125:      <NA>          <NA>         NA      <NA>
#> 126:      <NA>          <NA>         NA      <NA>
#> 127:      <NA>          <NA>         NA      <NA>
#> 128:      <NA>          <NA>         NA      <NA>

This is a generalization of the routine used for "ESPOLYGON" QA tool developed for QA/QC in southwest region.

TODO:

brownag commented 8 months ago
  1. Updated queries to be able to use local (SQLite/DBIconnection) or remote (SDA) sources.
  2. threshold argument for inclusion of site in summary exposed as top-level function argument
  3. For item 3, which will not be "fixed" in this PR, but has been "considered"--consider including a vector of cokey for each site. Either as a comma-separated list or list column. Including cokey would provide an avenue for selecting specific sets of components for downstream aggregation. Possibly get_SDA_property() could be extended to run within specific components (without aggregation), or across multiple specific components (with aggregation, but not necessarily all components in a MU, even potentially across multiple MUs?).