Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precipitation data #413

Open
FelipeCarrillo opened this issue Oct 12, 2022 · 10 comments
Open

Precipitation data #413

FelipeCarrillo opened this issue Oct 12, 2022 · 10 comments
Assignees

Comments

@FelipeCarrillo
Copy link

I wonder if this is a bug or data is not available after August 31, 2021. I am trying to download data from 2011 to 2021 but I only get half of 2021. See my script below:
library(rnoaa)

create a data frame for Prince William latitude and longitude

lat_lon_df <- data.frame(id = "pw",
lat = 60.690545,
lon = -147.097055)

find 10 closest monitors to Prince William

mon_near_pw <-
meteo_nearby_stations(
lat_lon_df = lat_lon_df,
lat_colname = "lat",
lon_colname = "lon",
var = "PRCP",
year_min = 2011,
year_max = 2021,
limit = 20,
)

mon_near_pw

#3,9,11,14 Get rainfall data from Cannery Creek, Esther Island, Cordova, and Port San Juan
pw_prcp_dat <-
meteo_pull_monitors(
monitors = mon_near_pw$pw$id[c(1,3,11,14)],
date_min = "2011-01-01",
date_max = "2021-12-31",
var = "PRCP"
)

final <- pw_prcp_dat %>%
pivot_wider(names_from= id,values_from=prcp) %>% data.frame()
head(final)
dim(final)

#Rename stations with more meaningful names
names(final)[2:5] <- c("cannery_creek","esther_island","cordova_n","sanjuan_chenega")
head(final)
tail(final)
#Get the total rainfall of the sound
final$total_prcp <- rowSums(cbind(final$cannery_creek, final$esther_island, final$cordova_n,final$sanjuan_chenega),na.rm=T)
dim(final)

@djhocking
Copy link
Collaborator

I am not sure yet but I suspect that it's a change to the API as with the NCDC data I'm working on with issue #412

@djhocking djhocking self-assigned this Oct 20, 2022
@FelipeCarrillo
Copy link
Author

Would the data pull fix on #412 work for my problem? ncdc2?
Or meteo_nearby_stations is completely different?

@djhocking
Copy link
Collaborator

I was hoping this was going to be an easier problem to solve but the API has completely changed and it's broken most of the functions in the package. They still work for now, but only for old data as you've found. Essentially, every function needs to be rewritten. So it's a related problem but will require a unique solution. I unfortunately don't have a timeframe for the solution.

@FelipeCarrillo
Copy link
Author

Can I pull data with ncdc2 instead?

@FelipeCarrillo
Copy link
Author

FelipeCarrillo commented Oct 27, 2022

Thanks for checking into it. Let me know if you find a workaround. These data is very important as I need to update a fish model soon to predict salmon returns to the PWS area for commercial fishing. Thanks

@djhocking
Copy link
Collaborator

djhocking commented Oct 29, 2022

So I think it should work for you if you since you have a vector of station ID. Give your code a try like this:

lat_lon_df <- data.frame(id = "pw",
                         lat = 60.690545,
                         lon = -147.097055)

mon_near_pw <-
  meteo_nearby_stations(
    lat_lon_df = lat_lon_df,
    lat_colname = "lat",
    lon_colname = "lon",
    var = "PRCP",
    year_min = 2011,
    year_max = 2021,
    limit = 20,
  )

rnoaa:::ncdc2(datasetid='daily-summaries', 
      datatypeid = 'PRCP', 
      stationid = mon_near_pw$pw$id[c(1,3,11,14)], 
      startdate = '2011-01-01', 
      enddate = '2013-12-01')$data |> 
  dplyr::rename(id = station) |> 
  dplyr::mutate(prcp = prcp * 10)

This code renames things to match your old code and converts the precipitation values back to the same units as from the old code I believe.

Very neat project. I actually work for NMFS and not on the weather-side of NOAA.

@FelipeCarrillo
Copy link
Author

FelipeCarrillo commented Oct 29, 2022

Trying it. Will let you know if it works.
Great!!! I work for USFWS and am a fish head :)

@djhocking
Copy link
Collaborator

djhocking commented Oct 29, 2022 via email

@FelipeCarrillo
Copy link
Author

Works great. I can pull data now up to December 2021.

@FelipeCarrillo
Copy link
Author

I also noticed that the NOAA temperature API is not updating. https://www.ndbc.noaa.gov/histsearch.php?station=46061&year=2021&f1=wtmp&t1a=lt&v1a=100&t1b=&v1b=&c1=&f2=&t2a=&v2a=&t2b=&v2b=&c2=&f3=&t3a=&v3a=&t3b=&v3b=
It stops at 2021 (see screenshot). Is this related to ncdc or is a total different issue?
noaa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants