Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
fawda123 committed Aug 21, 2024
2 parents 93fb6f4 + 3c77a14 commit c0575d1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 36 deletions.
45 changes: 45 additions & 0 deletions R/dat_proc.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ library(tidyverse)
library(lubridate)
library(here)
library(rsmartsheet)
library(readxl)
library(httr)
library(jsonlite)
library(sf)
library(tbeptools)

cenkey <- Sys.getenv("census_key")
smrkey <- Sys.getenv("smartsheets_key")
Expand Down Expand Up @@ -215,4 +220,44 @@ dcgdat <- dcgraw %>%

save(dcgdat, file = here('data/dcgdat.RData'))

# k brevis data -------------------------------------------------------------------------------


# query api
path <- 'https://gis.ncdc.noaa.gov/arcgis/rest/services/ms/HABSOS_CellCounts/MapServer/0/query?'

request <- GET(
url = path,
query= list(
# where = "STATE_ID='FL'",
where = "LATITUDE < 28.2 AND LATITUDE > 27 AND LONGITUDE > -83.4 AND LONGITUDE < -82.08",
outFields = 'DESCRIPTION,SAMPLE_DATE,LATITUDE,LONGITUDE,SALINITY,SALINITY_UNIT,WATER_TEMP,WATER_TEMP_UNIT,GENUS,SPECIES,CATEGORY,CELLCOUNT,CELLCOUNT_UNIT',
f = 'pjson'
)
)

response <- content(request, as = "text", encoding = "UTF-8")
results <- fromJSON(response, flatten = T)

# format data
kbrdat <- results$features %>%
rename_all(function(x) gsub('^attributes\\.', '', x)) %>%
rename_all(tolower) %>%
mutate(
date = format(sample_date, scientific = F),
date = as.numeric(gsub('000$', '', date)),
date = as.POSIXct(date, origin = c('1970-01-01'), tz = 'UTC'),
date = as.Date(date)
) %>%
select(
date, station = description, sal_ppt = salinity, temp_c = water_temp, kb_100kcelll = cellcount, longitude, latitude
) %>%
gather('var', 'val', -date, -station, -longitude, -latitude) %>%
separate(var, c('var', 'uni'), sep = '_') %>%
filter(!is.na(val)) %>%
st_as_sf(coords = c('longitude', 'latitude'), crs = 4326) %>%
.[tbshed, ] %>%
.[tbseg, ]

save(kbrdat, file = here::here('data/kbrdat.RData'))

37 changes: 1 addition & 36 deletions R/hab_fib_scratch.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,42 +108,7 @@ p1 <- ggplot(toplo, aes(x = yr, y = pyro, group = yr)) +

# karenia -------------------------------------------------------------------------------------

# query api
path <- 'https://gis.ncdc.noaa.gov/arcgis/rest/services/ms/HABSOS_CellCounts/MapServer/0/query?'

request <- GET(
url = path,
query= list(
# where = "STATE_ID='FL'",
where = "LATITUDE < 28.2 AND LATITUDE > 27 AND LONGITUDE > -83.4 AND LONGITUDE < -82.08",
outFields = 'DESCRIPTION,SAMPLE_DATE,LATITUDE,LONGITUDE,SALINITY,SALINITY_UNIT,WATER_TEMP,WATER_TEMP_UNIT,GENUS,SPECIES,CATEGORY,CELLCOUNT,CELLCOUNT_UNIT',
f = 'pjson'
)
)

response <- content(request, as = "text", encoding = "UTF-8")
results <- fromJSON(response, flatten = T)

# format data
kbrdat <- results$features %>%
rename_all(function(x) gsub('^attributes\\.', '', x)) %>%
rename_all(tolower) %>%
mutate(
date = format(sample_date, scientific = F),
date = as.numeric(gsub('000$', '', date)),
date = as.POSIXct(date, origin = c('1970-01-01'), tz = 'UTC'),
date = as.Date(date)
) %>%
select(
date, station = description, sal_ppt = salinity, temp_c = water_temp, kb_100kcelll = cellcount, longitude, latitude
) %>%
gather('var', 'val', -date, -station, -longitude, -latitude) %>%
separate(var, c('var', 'uni'), sep = '_') %>%
filter(!is.na(val)) %>%
st_as_sf(coords = c('longitude', 'latitude'), crs = 4326) %>%
.[tbshed, ] %>%
.[tbseg, ]

load(file = here::here('data/kbrdat.RData'))

# habdat p1
toplo <- kbrdat %>%
Expand Down
Binary file added data/kbrdat.RData
Binary file not shown.

0 comments on commit c0575d1

Please sign in to comment.