Replies: 1 comment 1 reply
-
|
Hey Benoit, below is a script I wrote to retrieve all data from the azmpdata package for a specified station. I think your idea to search the package using a location is a great idea. AZMP Data Station LookupJeff Jackson Station Lookup function for azmpdata package# Script to query the azmpdata package to find all data for a user specified station.
#
# Jeff Jackson
# Created On: 22-JAN-2021
# Last Updated: 24-JAN-2021
# Example:
#
# > hl2 <- station_lookup("HL2")
# [1] "The following dataset contains data about the specified station HL2: Derived_Annual_Stations"
# [2] "The following dataset contains data about the specified station HL2: Derived_Monthly_Stations"
# [3] "The following dataset contains data about the specified station HL2: Derived_Occupations_Sections"
# [4] "The following dataset contains data about the specified station HL2: Derived_Occupations_Stations"
# [5] "The following dataset contains data about the specified station HL2: Discrete_Occupations_Sections"
# [6] "The following dataset contains data about the specified station HL2: Discrete_Occupations_Stations"
# [7] "The following dataset contains data about the specified station HL2: Phytoplankton_Annual_Stations"
# [8] "The following dataset contains data about the specified station HL2: Phytoplankton_Occupations_Stations"
# [9] "The following dataset contains data about the specified station HL2: Zooplankton_Annual_Stations"
# [10] "The following dataset contains data about the specified station HL2: Zooplankton_Occupations_Sections"
# [11] "The following dataset contains data about the specified station HL2: Zooplankton_Occupations_Stations"
# >
station_lookup <- function(Station) {
library(azmpdata)
library(dplyr)
# Get a list of all data sets in the azmpdata package
dataSet <- data(package = "azmpdata")
# Extract just the names of the data sets
dataSetName <- dataSet$results[,3]
# Identify the data frames that contain a "station" column
ix <- unlist(lapply(dataSetName, function(x) "station" %in% colnames(eval(parse(text=x)))))
subSet <- dataSetName[ix]
# Filter the data frames to extract the data for the specified station
subSetData <- lapply(subSet, function(x) eval(parse(text=x)) %>% filter(station == Station))
# Remove any data frames that are empty
iy <- which(lapply(subSetData, function(x) nrow(x) > 0) == TRUE)
subSet <- subSet[iy]
subSetData <- subSetData[iy]
# Return the list of the data frames in the azmpdata package that contain data for
# the user specified station; along with a list of the subsetted data frames
# for that station.
return(list(subSet, subSetData))
}hl2 <- station_lookup("HL2")# To create the data frames with the same names only subset for the specified
# station, run the following code on the R command line:
ssn <- hl2[[1]]
ssd <- hl2[[2]]
for (i in 1:length(ssn)) {
assign(ssn[i], ssd[[i]])
}
ls(pattern = "Dis|Der|Phy|Zoo")head(Discrete_Occupations_Stations)
head of the Discrete_Occupations_Stations for only HL2 station data. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
A question that came up in presenting the package to a group of potential users today:
Is it possible to search through data by location?
Eg. Show all data which was collected at HL-2
This is something @casaultb and @clayton33 have talked about before and we have not yet had time to implement this into variable_lookup(). Would be a great development if someone has the time. I do not think it would be too difficult to implement if we can connect the spatial lookup tables in multivaR.
How it might be possible:
connect to spatial lookup tables in multivaR
get the lat/lons for the area which user is searching (eg. if they input HL2, return the coordinates for HL2)
search through azmpdata metadata columns for those coordinates (or potentially a padded box around the area)
merge dataframes which match the coordinates
return a mega-dataframe which includes all data from a specific location
Beta Was this translation helpful? Give feedback.
All reactions