Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_SDA_coecoclass: add method="all" #301

Merged
merged 6 commits into from
Oct 28, 2023
Merged

get_SDA_coecoclass: add method="all" #301

merged 6 commits into from
Oct 28, 2023

Conversation

brownag
Copy link
Member

@brownag brownag commented Sep 18, 2023

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:

  • Make robust to local (SQLite) or remote (SDA_query()/MSSQL) data sources
  • Expose threshold argument /9via get_SDA_coecoclass())
  • Consider how to do custom extensions and aggregations within existing framework--e.g. calculate weighted average properties across all components within "site1". This may warrant a new function and/or use of get_SDA_property()

@brownag
Copy link
Member Author

brownag commented Oct 28, 2023

  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?).

@brownag brownag marked this pull request as ready for review October 28, 2023 00:27
@brownag brownag merged commit ec9e21c into master Oct 28, 2023
5 checks passed
@brownag brownag deleted the esagg branch December 13, 2023 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant