|
1 |
| -#Code to prepare DOP data goes here |
2 |
| -library(lubridate) |
| 1 | +# Code to prepare DOP data goes here |
3 | 2 | library(tidyverse)
|
4 | 3 |
|
5 |
| -#read in dataset |
6 |
| -DOPx = read_csv("https://portal.edirepository.org/nis/dataviewer?packageid=edi.1187.4&entityid=0dbed7163901c12df414da0762d28a86", |
7 |
| - col_types=cols_only(Date="c", Latitude="d", Longitude="d", |
8 |
| - Station_Code="c", Conductivity="d", |
9 |
| - Temperature="d", Secchi="d", Start_Time="c", |
10 |
| - NO3 = "d", NH4 = "d",pH = "d", |
11 |
| - Chl_a = "d", PO4 = "d", Start_Depth = "d", |
12 |
| - Salinity = "d", Turbidity = "d", DOC = "d", |
13 |
| - DO="d")) |
| 4 | +# read in dataset |
| 5 | +download.file( |
| 6 | + "https://portal.edirepository.org/nis/dataviewer?packageid=edi.1187.4&entityid=0dbed7163901c12df414da0762d28a86", |
| 7 | + file.path(tempdir(), "DOP_ICF_TowData_2017-2022.csv"), |
| 8 | + mode = "wb", |
| 9 | + method = "libcurl" |
| 10 | +) |
14 | 11 |
|
15 |
| -DOP= DOPx %>% |
16 |
| - #standardize colom names |
17 |
| - rename(Depth = Start_Depth, |
18 |
| - Station = Station_Code, |
19 |
| - Chlorophyll = Chl_a, |
20 |
| - DissolvedOxygen = DO, |
21 |
| - DissNitrateNitrite = NO3, |
22 |
| - DissAmmonia = NH4, |
23 |
| - DissOrthophos = PO4) %>% |
24 |
| - #make a date-time column, convert feet to meters |
25 |
| - mutate( Date=parse_date_time(Date, c("%Y-%m-%d", "%m/%d/%Y"), tz="America/Los_Angeles"), |
26 |
| - Datetime = parse_date_time(if_else(is.na(Start_Time), NA_character_, paste(Date, Start_Time)), "%Y-%m-%d %H:%M:%S", tz="America/Los_Angeles"), |
27 |
| - |
28 |
| - Field_coords = TRUE, Source = "DOP", Depth = Depth*0.3048) %>% |
29 |
| - |
30 |
| - #select relevent columns |
31 |
| - #note - i'm not including microcystis because they use a different method |
32 |
| - select(Source, Station, Latitude, Longitude, |
33 |
| - Field_coords, Date, Datetime, |
34 |
| - Depth, Salinity, |
35 |
| - Temperature, Turbidity, Conductivity, |
36 |
| - pH, Chlorophyll, DissolvedOxygen, Secchi, |
37 |
| - DOC, DissNitrateNitrite, DissAmmonia, DissOrthophos) |
| 12 | +DOPx <- read_csv( |
| 13 | + file.path(tempdir(), "DOP_ICF_TowData_2017-2022.csv"), |
| 14 | + col_types = cols_only( |
| 15 | + Date = "c", |
| 16 | + Latitude = "d", |
| 17 | + Longitude = "d", |
| 18 | + Station_Code = "c", |
| 19 | + Habitat = "c", |
| 20 | + Conductivity = "d", |
| 21 | + Temperature = "d", |
| 22 | + Secchi = "d", |
| 23 | + Start_Time = "c", |
| 24 | + NO3 = "d", |
| 25 | + NH4 = "d", |
| 26 | + pH = "d", |
| 27 | + Chl_a = "d", |
| 28 | + PO4 = "d", |
| 29 | + Start_Depth = "d", |
| 30 | + Salinity = "d", |
| 31 | + Turbidity = "d", |
| 32 | + DOC = "d", |
| 33 | + DO = "d" |
| 34 | + ) |
| 35 | +) |
38 | 36 |
|
| 37 | +# Clean up data |
| 38 | +DOP <- DOPx %>% |
| 39 | + # standardize column names |
| 40 | + rename( |
| 41 | + Depth = Start_Depth, |
| 42 | + Station = Station_Code, |
| 43 | + Chlorophyll = Chl_a, |
| 44 | + DissolvedOxygen = DO, |
| 45 | + DissNitrateNitrite = NO3, |
| 46 | + DissAmmonia = NH4, |
| 47 | + DissOrthophos = PO4 |
| 48 | + ) %>% |
| 49 | + # make a date-time column, convert feet to meters |
| 50 | + mutate( |
| 51 | + Date = parse_date_time(Date, c("%Y-%m-%d", "%m/%d/%Y"), tz = "America/Los_Angeles"), |
| 52 | + Datetime = parse_date_time(if_else(is.na(Start_Time), NA_character_, paste(Date, Start_Time)), "%Y-%m-%d %H:%M:%S", tz = "America/Los_Angeles"), |
| 53 | + Field_coords = TRUE, |
| 54 | + Source = "DOP", |
| 55 | + Depth = Depth * 0.3048 |
| 56 | + ) %>% |
| 57 | + # select relevant columns |
| 58 | + # note - I'm not including Microcystis because they use a different method |
| 59 | + select( |
| 60 | + Source, |
| 61 | + Station, |
| 62 | + Latitude, |
| 63 | + Longitude, |
| 64 | + Field_coords, |
| 65 | + Date, |
| 66 | + Datetime, |
| 67 | + Depth, |
| 68 | + Salinity, |
| 69 | + Temperature, |
| 70 | + Turbidity, |
| 71 | + Conductivity, |
| 72 | + pH, |
| 73 | + Chlorophyll, |
| 74 | + DissolvedOxygen, |
| 75 | + Secchi, |
| 76 | + DOC, |
| 77 | + DissNitrateNitrite, |
| 78 | + DissAmmonia, |
| 79 | + DissOrthophos |
| 80 | + ) |
39 | 81 |
|
40 | 82 | usethis::use_data(DOP, overwrite = TRUE)
|
41 | 83 |
|
0 commit comments