Extract Mobile Acoustic Data and Build a Report

Get a token for NABat Database

library(nabatr)
# Enter your NABat username here
username = 'NABat_Username'
token = get_nabat_gql_token(username)
token

# Note: if you leave run token = get_nabat_gql_token(),
#   it will prompt you for a username and then a password

Get Project dataframe which contains all of your NABat projects in the NABat Database

# Refresh token
token = get_refresh_token(token)
# Get your projects lookup table
project_df = get_projects(token)
# Display your projects lookup table
project_df

Get all Mobile Acoustic Surveys within a single Project set with project_id

# Refresh token
token = get_refresh_token(token)
# Fill in project id using the project_df lookup table
project_id = 000 # Set equal to one of your project ids

# Get survey dataframe 
ma_survey_df = get_ma_project_summary(token, 
                                      project_df, 
                                      project_id)

ma_proj_dates = unique(ma_survey_df$year)
# Display survey dataframe
ma_survey_df

Get all Mobile Acoustic Survey wav file data. Format: Mobile Acoustic Bulk Upload Template

# Select Year for project (defaults to 1st available year)
year = ma_proj_dates[1]

# Refresh token
token = get_refresh_token(token)
# Get mobile acoustic bulk upload format dataframe
ma_bulk_df = get_ma_bulk_wavs(token,
                              ma_survey_df,
                              year)
# Display mobile acoustic bulk upload format dataframe
ma_bulk_df

Get Mobile Acoustic dataframe broken up into nightly observed data and get species_df

token = get_refresh_token(token)
species_df = get_species(token)
# Get Acoustic stationary acoustic bulk dataframe
nightly_observed_list = get_observed_nights(ma_bulk_df)

Build a Mobile Acoustic Report

# Edit these two variables below to your local system (file_name, out_dir)
file_name = 'name_of_ma_report.docx'  
out_dir   = '/directory/to/download/report' # Make sure this ends without a '/'

ma_doc = build_ma_doc(out_dir = out_dir,
                      project_df = project_df,
                      project_id = project_id,
                      ma_bulk_df = ma_bulk_df,
                      species_df = species_df,
                      nightly_observed_list = nightly_observed_list,
                      year = year)

# Save out your report
print(ma_doc, target = paste0(out_dir, '/', file_name))


usgs/nabatr documentation built on Jan. 28, 2024, 7:10 a.m.