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

Add fetchLDM() - access Kellogg Soil Survey Lab Data Mart via Soil Data Access or local SQLite snapshot #243

Merged
merged 31 commits into from
Apr 8, 2022

Conversation

brownag
Copy link
Member

@brownag brownag commented Apr 7, 2022

fetchLDM() development began in May 2021 when Soil Data Access began providing laboratory data. The method was later extended to work with a local data source such as an SQLite snapshot. It has been tested fairly extensively and is now ready to be made public.

#' Query data from Kellogg Soil Survey Laboratory Data Mart via Soil Data Access or local SQLite snapshot
#'
#' LDM model diagram: https://jneme910.github.io/Lab_Data_Mart_Documentation/Documents/SDA_KSSL_Data_model.html
#'
#' param x A vector of values to find in column specified by what, default NULL uses no constraints on what
#' param what A single column name from tables: lab_combine_nasis_ncss, lab_webmap, lab_site, lab_pedon or lab_area
#' param bycol A single column name from lab_layer used for processing chunks; default: "pedon_key"
#' param tables Avector of table names; Default is "lab_physical_properties", "lab_chemical_properties", "lab_calculations_including_estimates_and_default_values", and "lab_rosetta_Key". May also include one or more of: "lab_mir", "lab_mineralogy_glass_count", "lab_major_and_trace_elements_and_oxides", "lab_xray_and_thermal" but it will be necessary to select appropriate prep_code and analyzed_size_frac for your analysis (see Details).
#' param chunk.size Number of pedons per chunk (for queries that may exceed maxJsonLength)
#' param ntries Number of tries (times to halve chunk.size) before returning NULL; default 3
#' param layer_type Default: "horizon", "layer", and "reporting layer"
#' param prep_code Default: "S" and "". May also include one or more of: "F", "HM", "HM_SK" "GP", "M", "N", or "S"
#' param analyzed_size_frac Default: "<2 mm" and "". May also include one or more of: "<0.002 mm", "0.02-0.05 mm", "0.05-0.1 mm", "0.1-0.25 mm", "0.25-0.5 mm", "0.5-1 mm", "1-2 mm", "0.02-2 mm", "0.05-2 mm"
#' param dsn Data source name; either a path to a SQLite database, an open DBIConnection or (default) NULL (to use soilDB::SDA_query)
#'
#' details If the chunk.size parameter is set too large and the Soil Data Access request fails, the algorithm will re-try the query with a smaller (halved) chunk.size argument. This will be attempted up to 3 times before returning NULL
#'
#' Currently the lab_area tables are joined only for the "Soil Survey Area" related records.
#'
#' When requesting data from "lab_major_and_trace_elements_and_oxides", "lab_mineralogy_glass_count", or "lab_xray_and_thermal" multiple preparation codes (prep_code) or size fractions (analyzed_size_frac) are possible. The default behavior of fetchLDM() is to attempt to return a topologically valid (minimal overlaps) SoilProfileCollection. This is achieved by setting prep_code="S" ("sieved") and analyzed_size_frac="<2 mm". You may specify alternate or additional preparation codes or fractions as needed, but note that this may cause "duplication" of some layers where measurements were made with different preparation or on fractionated samples
#'
#' return a SoilProfileCollection for a successful query, a try-error if no site/pedon locations can be found or NULL for an empty lab_layer (within sites/pedons) result

brownag and others added 30 commits February 10, 2022 12:25
…ensitive queries, probably not efficient without indexed column
@brownag brownag merged commit 7c9967a into master Apr 8, 2022
@brownag brownag deleted the fetchLDM branch April 18, 2022 17:44
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