### Install hillr Package from GitHub Source: https://github.com/jeffcnz/hillr/blob/master/README.md Installs the hillr R package directly from its GitHub repository using the devtools package. Ensure devtools is installed and any previous versions of hillr are removed before installation. ```R devtools::install_github("jeffcnz/hillr") ``` -------------------------------- ### Get Hilltop Measurements for a Site Source: https://github.com/jeffcnz/hillr/blob/master/README.md Fetches a list of all available measurements for a given site from a Hilltop server. This helps in identifying the types of data that can be retrieved for a specific location. ```R measurements <- getHilltopMeasurements(endpoint = "https://data.hbrc.govt.nz/Envirodata/EMARDiscrete.hts?", site = "Maraetotara Lagoon") ``` -------------------------------- ### Get Hilltop Measurements for a Site (R) Source: https://context7.com/jeffcnz/hillr/llms.txt Retrieves all available measurements and their metadata for a specific monitoring site. Includes data source, units, time range, and data type. Returns a data frame of measurements. ```r # Get all measurements available at a site measurements <- getHilltopMeasurements( endpoint = "https://data.hbrc.govt.nz/Envirodata/EMARDiscrete.hts?", site = "Maraetotara Lagoon" ) print(measurements) # View specific columns measurements[, c("MeasurementName", "Units", "From", "To")] ``` -------------------------------- ### Get Hilltop Server Sites Source: https://github.com/jeffcnz/hillr/blob/master/README.md Retrieves a list of all available sites from a specified Hilltop server endpoint. This function is useful for discovering which locations have data available on the server. ```R sites <- getHilltopSites(endpoint = "https://data.hbrc.govt.nz/Envirodata/EMARDiscrete.hts?") ``` -------------------------------- ### Get Hilltop Site List (R) Source: https://context7.com/jeffcnz/hillr/llms.txt Retrieves a list of all available monitoring sites from a Hilltop server endpoint. Can be filtered by measurement type and includes location coordinates if specified. Returns a data frame of sites. ```r library(hillr) # Get all sites from the endpoint sites <- getHilltopSites( endpoint = "https://data.hbrc.govt.nz/Envirodata/EMARDiscrete.hts?" ) head(sites) # Get only sites that have E. Coli measurements ecoli_sites <- getHilltopSites( endpoint = "https://data.hbrc.govt.nz/Envirodata/EMARDiscrete.hts?", measurement = "E. Coli", location = TRUE ) ``` -------------------------------- ### Get Basic Hilltop Discrete Data Source: https://github.com/jeffcnz/hillr/blob/master/README.md Retrieves discrete time series data for a specific site and measurement within a given date range from a Hilltop server. This function is suitable for simple data requests. ```R eColi <- getHilltopData(endpoint = "https://data.hbrc.govt.nz/Envirodata/EMARDiscrete.hts?", site = "Maraetotara Lagoon", measurement = "E. Coli", from = "1/1/2018", to = "1/10/2018") ``` -------------------------------- ### Get Full Hilltop Data with Metadata Source: https://github.com/jeffcnz/hillr/blob/master/README.md Retrieves comprehensive time series data, potentially for multiple sites and measurements, along with associated metadata, from a Hilltop server within a specified date range. This is the preferred function for advanced data retrieval. ```R data <- fullGetHilltopData(endpoint = "https://data.hbrc.govt.nz/Envirodata/EMARDiscrete.hts?", sites = c("Maraetotara Lagoon", "Ngaruroro River at Fernhill"), measurements = c("E. Coli", "Nitrate Nitrogen"), from = "1/1/2017", to = "1/10/2017", option = "WQ") ``` -------------------------------- ### Get Hilltop Data from Multiple Sites/Measurements (R) Source: https://context7.com/jeffcnz/hillr/llms.txt Retrieves time series data from multiple sites and measurements in a single request using the `fullGetHilltopData` function. Supports water quality sample metadata and continuous measurements with date range filtering. Returns a combined data frame. ```r # Get water quality data from multiple sites and measurements wq_data <- fullGetHilltopData( endpoint = "https://data.hbrc.govt.nz/Envirodata/EMARDiscrete.hts?", sites = c("Maraetotara Lagoon", "Ngaruroro River at Fernhill", "Tutaekuri River at Puketapu"), measurements = c("E. Coli", "Nitrate Nitrogen", "Total Phosphorus"), from = "1/1/2017", to = "1/10/2017", option = "WQ" ) # Returns combined dataframe with all sites and measurements # option = "WQ" includes water quality sample metadata print(head(wq_data)) ``` -------------------------------- ### Get Hilltop Time Series Data (R) Source: https://context7.com/jeffcnz/hillr/llms.txt Retrieves time series data for a specific site and measurement from a Hilltop server. Supports date range filtering and various statistical processing methods (e.g., Average, Total, Extrema) with interval options. Returns a data frame of time series values. ```r # Get discrete water quality sample data ecoli_data <- getHilltopData( endpoint = "https://data.hbrc.govt.nz/Envirodata/EMARDiscrete.hts?", site = "Maraetotara Lagoon", measurement = "E. Coli", from = "1/1/2018", to = "1/10/2018" ) print(ecoli_data) # Get continuous data with statistics # Calculate daily average from 15-minute data daily_avg <- getHilltopData( endpoint = "https://data.hbrc.govt.nz/Envirodata/EMAR.hts?", site = "Clive River at Whanawhana", measurement = "Flow", from = "1/1/2023", to = "31/1/2023", method = "Average", interval = "1 Day", alignment = "00:00" ) # Get daily total rainfall rainfall <- getHilltopData( endpoint = "https://data.hbrc.govt.nz/Envirodata/EMAR.hts?", site = "Napier EWS", measurement = "Rainfall", from = "1/1/2023", to = "31/3/2023", method = "Total", interval = "1 Day", dateOnly = "Yes" ) # Get extrema statistics (min, mean, max) extrema <- getHilltopData( endpoint = "https://data.hbrc.govt.nz/Envirodata/EMAR.hts?", site = "Tutaekuri River", measurement = "Water Temperature", from = "1/1/2023", to = "31/12/2023", method = "Extrema", interval = "1 Month", gapTolerance = "Interval" ) # Returns columns: Time, Minimum, Mean, Maximum, Missing, Time of Minimum, Time of Maximum ``` -------------------------------- ### Explore Measurements at a Site using getHilltopMeasurements() Source: https://context7.com/jeffcnz/hillr/llms.txt Explores the available measurements for a specific monitoring site. This function helps users understand what data parameters are recorded at a given location. It requires the site name as input and returns a list of measurement details. ```r getHilltopMeasurements(siteName = "ExampleSite") ``` -------------------------------- ### Build Hilltop Site List URL in R Source: https://context7.com/jeffcnz/hillr/llms.txt Constructs a URL to retrieve a list of available sites from a Hilltop server, optionally including location data (latitude and longitude). This function is useful for discovering monitoring sites within a specific measurement context. It requires the server endpoint, measurement, and a flag to indicate if location data is needed. ```r # Build URL to get site list site_list_url <- buildSiteListUrl( endpoint = "https://data.hbrc.govt.nz/Envirodata/EMARDiscrete.hts?", measurement = "E. Coli", location = TRUE ) print(site_list_url) # "https://data.hbrc.govt.nz/Envirodata/EMARDiscrete.hts?Service=Hilltop&Request=SiteList&Measurement=E.%20Coli&Location=LatLong" ``` -------------------------------- ### Build Low-Level Hilltop URLs Source: https://context7.com/jeffcnz/hillr/llms.txt Provides functions for building low-level URLs for custom data retrieval scenarios. This is intended for advanced users who need fine-grained control over the data request to the Hilltop server. It returns a formatted URL string. ```r buildHilltopUrl(siteName = "ExampleSite", measurementName = "Temperature") ``` -------------------------------- ### Retrieve Batch Data using fullGetHilltopData() Source: https://context7.com/jeffcnz/hillr/llms.txt Performs batch requests to retrieve data for multiple site-measurement combinations. This function is optimized for efficiently downloading data from various locations and parameters simultaneously. It accepts a list of requests and returns a consolidated data frame. ```r fullGetHilltopData(startDate = "2023-01-01", endDate = "2023-12-31", sites = c("SiteA", "SiteB"), measurements = c("Flow", "Level")) ``` -------------------------------- ### Discover Hilltop Sites using getHilltopSites() Source: https://context7.com/jeffcnz/hillr/llms.txt Retrieves a list of available monitoring sites from a Hilltop server. This function is the first step in identifying relevant data sources within the database. It returns site information that can be used in subsequent data retrieval calls. ```r getHilltopSites() ``` -------------------------------- ### Fetch Standard Hilltop Data in R Source: https://context7.com/jeffcnz/hillr/llms.txt Retrieves continuous time-series data with standard metadata from a Hilltop server. Requires specifying the server endpoint, target sites, measurements, and the desired date range. The 'option' parameter can be set to 'Standard' for typical data retrieval. ```r # Get continuous data with standard metadata flow_data <- fullGetHilltopData( endpoint = "https://data.hbrc.govt.nz/Envirodata/EMAR.hts?", sites = c("Ngaruroro River at Fernhill", "Tutaekuri River at Puketapu"), measurements = c("Flow", "Stage"), from = "1/1/2023", to = "7/1/2023", option = "Standard" ) ``` ```r # Get monthly averages for multiple sites monthly_data <- fullGetHilltopData( endpoint = "https://data.hbrc.govt.nz/Envirodata/EMAR.hts?", sites = c("Site A", "Site B", "Site C"), measurements = "Water Temperature", from = "1/1/2022", to = "31/12/2022", method = "Average", interval = "1 Month", option = "None" ) ``` -------------------------------- ### Build Hilltop Data Request URL in R Source: https://context7.com/jeffcnz/hillr/llms.txt Constructs a URL for requesting time-series data from a Hilltop server. This function allows detailed specification of the request, including site, measurement, date range, aggregation method (e.g., 'Average'), interval (e.g., '1 Day'), alignment, and whether to include quality information. ```r # Build URL to get time series data data_url <- buildDataRequestUrl( endpoint = "https://data.hbrc.govt.nz/Envirodata/EMAR.hts?", site = "Ngaruroro River at Fernhill", measurement = "Flow", from = "1/1/2023", to = "31/1/2023", method = "Average", interval = "1 Day", alignment = "00:00", showQuality = "Yes" ) ``` -------------------------------- ### Build Ensemble Statistics Request URL in R Source: https://context7.com/jeffcnz/hillr/llms.txt Constructs a URL to request ensemble statistics for environmental data. Requires specifying the endpoint, site, measurement, date range, and desired statistic (e.g., MonthlyPDF). ```r ensemble_url <- buildEnsembleStatsRequestUrl( endpoint = "https://data.hbrc.govt.nz/Envirodata/EMAR.hts?", site = "Tutaekuri River", measurement = "Water Temperature", from = "1/1/2010", to = "31/12/2020", statistic = "MonthlyPDF", lowerPercentile = 25, upperPercentile = 75 ) ``` -------------------------------- ### Parse Hilltop XML Responses in R Source: https://context7.com/jeffcnz/hillr/llms.txt Provides low-level functions to parse XML responses from Hilltop servers. Useful for custom data workflows or specialized formats. Includes validation, data type determination, and extraction of measurements, time series, data sources, site lists, and measurement lists. ```r # Build data request URL url <- buildDataRequestUrl( endpoint = "https://data.hbrc.govt.nz/Envirodata/EMARDiscrete.hts?", site = "Maraetotara Lagoon", measurement = "E. Coli", from = "1/1/2023", to = "31/3/2023" ) # Parse XML and check for errors parsed_xml <- hillXmlParse(url) # Check if XML is valid Hilltop XML is_valid <- is.hilltopXml(parsed_xml) print(is_valid) # TRUE # Determine the data type data_type <- hillXmlDataType(parsed_xml) print(data_type) # "WQData" or "SimpleTimeSeries" or "DepthProfile" # Extract measurement data from parsed XML measurement_data <- hilltopMeasurement(parsed_xml) # Extract just the time series values timeseries_df <- hilltopMeasurementToDF(parsed_xml) # Extract data source metadata datasource_metadata <- hilltopDataSourceToDF(parsed_xml) # Parse site list XML sites_url <- buildSiteListUrl( endpoint = "https://data.hbrc.govt.nz/Envirodata/EMARDiscrete.hts?" ) sites_xml <- hillXmlParse(sites_url) sites_df <- hilltopSiteList(sites_xml) # Parse measurement list XML meas_url <- buildMeasurementListUrl( endpoint = "https://data.hbrc.govt.nz/Envirodata/EMARDiscrete.hts?", site = "Maraetotara Lagoon" ) meas_xml <- hillXmlParse(meas_url) measurements_full <- hilltopDsMeasListFull(meas_xml) ``` -------------------------------- ### Build Hilltop Measurement List URL in R Source: https://context7.com/jeffcnz/hillr/llms.txt Generates a URL to query the available measurements for a specific site on a Hilltop server. This function helps in identifying the types of data that can be retrieved for a particular monitoring location. It requires the server endpoint and the site name. ```r # Build URL to get measurement list for a site meas_list_url <- buildMeasurementListUrl( endpoint = "https://data.hbrc.govt.nz/Envirodata/EMARDiscrete.hts?", site = "Maraetotara Lagoon" ) ``` -------------------------------- ### Error Handling and Data Quality in R Source: https://context7.com/jeffcnz/hillr/llms.txt Demonstrates robust error handling and quality code interpretation for data reliability. The package automatically handles server errors and includes quality codes in the data, which can be filtered or disabled as needed. ```r # The package automatically handles errors from the server tryCatch({ data <- getHilltopData( endpoint = "https://data.hbrc.govt.nz/Envirodata/EMARDiscrete.hts?", site = "NonExistentSite", measurement = "E. Coli", from = "1/1/2023", to = "31/1/2023" ) }, error = function(e) { message("Error occurred: ", e$message) # Handle error appropriately }) # Quality codes are automatically included with data # For water quality data: QualityCode column # For continuous data: QualityCode column (formerly Q1) data_with_quality <- getHilltopData( endpoint = "https://data.hbrc.govt.nz/Envirodata/EMARDiscrete.hts?", site = "Maraetotara Lagoon", measurement = "E. Coli", from = "1/1/2023", to = "31/3/2023", showQuality = "Yes" ) # Filter data by quality code good_quality <- data_with_quality[data_with_quality$QualityCode == 600, ] # Disable quality codes if not needed data_no_quality <- getHilltopData( endpoint = "https://data.hbrc.govt.nz/Envirodata/EMARDiscrete.hts?", site = "Maraetotara Lagoon", measurement = "E. Coli", from = "1/1/2023", to = "31/3/2023", showQuality = "No" ) ``` -------------------------------- ### Fetch Ensemble Statistics for Multiple Sites/Measurements in R Source: https://context7.com/jeffcnz/hillr/llms.txt Retrieves ensemble statistics for multiple sites and measurements simultaneously using the `fullGetHilltopEnsembleStats` function. This enables comparative analysis across different locations and parameters. Options for specifying statistic type, percentiles, and whether to group by year are available. ```r # Get monthly ensemble statistics for multiple sites multi_ensemble <- fullGetHilltopEnsembleStats( endpoint = "https://data.hbrc.govt.nz/Envirodata/EMAR.hts?", sites = c("Ngaruroro River at Fernhill", "Tutaekuri River at Puketapu", "Clive River at Whanawhana"), measurements = c("Flow", "Stage"), from = "1/1/2010", to = "31/12/2020", statistic = "MonthlyPDF", lowerPercentile = 10, upperPercentile = 90, byYear = FALSE ) # Returns combined dataframe with ensemble statistics for all combinations # Get yearly ensemble statistics for water quality parameters wq_ensemble <- fullGetHilltopEnsembleStats( endpoint = "https://data.hbrc.govt.nz/Envirodata/EMARDiscrete.hts?", sites = c("Maraetotara Lagoon", "Ngaruroro River at Fernhill"), measurements = c("E. Coli", "Nitrate Nitrogen"), from = "1/1/2015", to = "31/12/2022", statistic = "MonthlyPDF", byYear = TRUE ) ``` -------------------------------- ### Handle Depth Profile Data in R Source: https://context7.com/jeffcnz/hillr/llms.txt Retrieves and parses vertical depth profile measurements, commonly used for lake or reservoir water quality. It can be used directly or via the `getHilltopData` function which automatically detects depth profiles. ```r # Get depth profile data # Depth profiles require special handling depth_url <- buildDataRequestUrl( endpoint = "https://data.hbrc.govt.nz/Envirodata/EMARDiscrete.hts?", site = "Lake Tutira", measurement = "Temperature Profile", from = "1/1/2023", to = "31/3/2023" ) # Parse depth profile data depth_data <- hilltopDepthProfile(depth_url) print(head(depth_data)) # Agency Site Measurement Time Depth Value # HBRC Lake Tutira Temperature Profile 2023-01-15 10:00:00 0 18.5 # HBRC Lake Tutira Temperature Profile 2023-01-15 10:00:00 1 18.3 # HBRC Lake Tutira Temperature Profile 2023-01-15 10:00:00 2 17.8 # HBRC Lake Tutira Temperature Profile 2023-01-15 10:00:00 5 15.2 # Or use getHilltopData which automatically detects depth profiles depth_data_auto <- getHilltopData( endpoint = "https://data.hbrc.govt.nz/Envirodata/EMARDiscrete.hts?", site = "Lake Tutira", measurement = "Temperature Profile", from = "1/1/2023", to = "31/3/2023" ) ``` -------------------------------- ### Retrieve Single Site-Measurement Data using getHilltopData() Source: https://context7.com/jeffcnz/hillr/llms.txt Retrieves time series data for a specific measurement at a single site. This function is suitable for targeted data acquisition for analysis or plotting. It requires site name, measurement name, and date range as input, returning a tidy data frame. ```r getHilltopData(siteName = "ExampleSite", measurementName = "WaterLevel", startDate = "2023-01-01", endDate = "2023-12-31") ``` -------------------------------- ### Calculate Daily Extrema Ensemble Statistics in R Source: https://context7.com/jeffcnz/hillr/llms.txt Retrieves daily extrema ensemble statistics, providing the minimum, mean, and maximum values for each day of the year across all specified years. This function is useful for understanding daily variability and extreme event patterns. It requires the server endpoint, site, measurement, and date range. ```r # Get daily extrema ensemble statistics daily_extrema <- getHilltopEnsembleStats( endpoint = "https://data.hbrc.govt.nz/Envirodata/EMAR.hts?", site = "Tutaekuri River", measurement = "Water Temperature", from = "1/1/2015", to = "31/12/2022", statistic = "DailyExtrema" ) # Returns min, mean, max for each day of year across all years ``` -------------------------------- ### Parse Hilltop XML Data Source: https://context7.com/jeffcnz/hillr/llms.txt Offers functions for parsing XML data directly from Hilltop server responses. This is useful for custom workflows where direct XML manipulation is required. It takes an XML string as input and returns parsed data structures. ```r parseHilltopXml(xmlString) ``` -------------------------------- ### Calculate Monthly PDF Ensemble Statistics in R Source: https://context7.com/jeffcnz/hillr/llms.txt Calculates monthly probability distribution function (PDF) ensemble statistics for a given site and measurement. It requires specifying the server endpoint, site, measurement, date range, and desired percentiles (e.g., 25th and 75th). The output includes statistics like Mean, Median, StdDev, and percentiles for each month across all years. ```r # Get monthly PDF (probability distribution function) ensemble statistics monthly_stats <- getHilltopEnsembleStats( endpoint = "https://data.hbrc.govt.nz/Envirodata/EMAR.hts?", site = "Ngaruroro River at Fernhill", measurement = "Flow", from = "1/1/2010", to = "31/12/2020", statistic = "MonthlyPDF", lowerPercentile = 25, upperPercentile = 75 ) # Returns statistics for each month across all years print(monthly_stats) # periodID Mean Median StdDev LowerPercentile UpperPercentile Site Measurement # January 12.5 10.2 5.3 8.5 15.2 Site Name Flow # February 10.8 9.5 4.8 7.2 13.5 Site Name Flow ``` -------------------------------- ### Analyze Long-Term Patterns using getHilltopEnsembleStats() Source: https://context7.com/jeffcnz/hillr/llms.txt Calculates ensemble statistics to analyze long-term patterns in time series data. This function is useful for trend analysis and understanding typical behaviors over extended periods. It requires site and measurement details, returning aggregated statistical summaries. ```r getHilltopEnsembleStats(siteName = "ExampleSite", measurementName = "Turbidity", startDate = "2000-01-01", endDate = "2023-12-31") ``` -------------------------------- ### Calculate Yearly Ensemble Statistics (Monthly PDF) in R Source: https://context7.com/jeffcnz/hillr/llms.txt Generates monthly PDF ensemble statistics, with an option to return results for each year separately. Setting 'byYear = TRUE' includes 'Year' and 'Date' columns in the output, allowing for year-specific trend analysis. This is useful for comparing monthly patterns across different years. ```r # Get ensemble statistics for each year separately yearly_stats <- getHilltopEnsembleStats( endpoint = "https://data.hbrc.govt.nz/Envirodata/EMAR.hts?", site = "Clive River", measurement = "Flow", from = "1/1/2010", to = "31/12/2020", statistic = "MonthlyPDF", byYear = TRUE ) # Returns monthly statistics for each year separately with Year and Date columns ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.