Skip to content

Add support for Swedish radar data (fix #96) - #97

Merged
bart1 merged 11 commits into
mainfrom
96-swedish-radar-data
Aug 14, 2025
Merged

Add support for Swedish radar data (fix #96)#97
bart1 merged 11 commits into
mainfrom
96-swedish-radar-data

Conversation

@bart1

@bart1 bart1 commented Jul 17, 2025

Copy link
Copy Markdown
Collaborator

AI Summary

This pull request introduces support for downloading Swedish radar data, including a new function, tests, and documentation updates. The changes ensure compatibility with Swedish data sources and provide error handling for common issues.

Support for Swedish Radar Data:

  • Added a new function get_pvol_se in R/get_pvol_se.R to handle downloading and processing radar data from Sweden, including a radar mapping and error handling for invalid radar codes and unavailable data.
  • Updated select_get_pvol_function in R/get_pvol.R to include Sweden (cntry_code == "se") in the country-specific radar data retrieval logic.

Testing:

  • Added tests in tests/testthat/test-get_pvol_se.R to verify successful data retrieval for Sweden, proper handling of time range errors, and validation of radar codes.

Documentation:

  • Updated NEWS.md to announce support for downloading Swedish data.
  • Updated vignettes/supported_sources.Rmd to include Sweden in the list of supported countries, with details on data availability and licensing.

@bart1 bart1 linked an issue Jul 17, 2025 that may be closed by this pull request
@bart1
bart1 requested review from PietrH and peterdesmet July 17, 2025 20:07
@bart1 bart1 changed the title Add support for Swedish radar data (fix #94) Add support for Swedish radar data (fix #96) Jul 17, 2025
Comment thread R/get_pvol_se.R
Comment thread R/get_pvol_se.R
@PietrH

PietrH commented Jul 18, 2025

Copy link
Copy Markdown
Contributor

Just some quick questions, I didn't do a full review. I can come back to this next week.

Comment thread R/get_pvol_se.R
httr2::req_url_path_append(
glue::glue(url)
) |>
httr2::req_perform(path = tempfile(fileext = ".h5"), error_call = call),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to req_retry_getrad() or req_cache_getrad()?

Do we report progress when interactive for large files?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should not cache full pvol file, they are large and bulky and will make the cache run full too quickly. The retry I would only do when we notice frequent timeouts

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed on the caching.

What is the added cost of adding the retry? I think it would be nice if someone were to run this on a less reliable connection.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For retry I guess it could be done, risk being to unnecessarily delay the responses that are erroring. Without experience it is hard to say if certain errors do frequently occur and if they are resolved by retries. If your connection is really unstable downloading large files is maybe anyway not what you want to do.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to be inclusive of those who don't have a choice in the stability of their connection. If an error is permanent, then a retry would not add a lot of time since we are only fetching a single file in this case?

If you are envisioning users fetching a large number of files where the delay of possible retries is a problem, we should add package options to change the default retry behaviour so users can control it (or even just turn it off).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess retries could be added, I guess I'm a bit more of the school of trying to avoid to many complications that do not solve real world problems that have been encountered :). For pipelines you would anyway implement some retries, a few hours later for error that are transient on other timescales

Comment thread R/get_pvol_se.R Outdated
Comment thread R/get_pvol_se.R Outdated
)
}
radar_name <- get_pvol_se_radar_mapping[radar]
url <- glue::glue('/area/{radar_name}/product/qcvol/{lubridate::year(time)}/{lubridate::month(time)}/{{lubridate::day(time)}}/radar_{radar_name}_qcvol_{strftime(time, "%Y%m%d%H%M", tz="UTC" )}.h5')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably break this long string up with req_url_path_append(), file.path (Peter likes this one, I try to avoid it), or usage of glue .sep:

eg.

glue::glue("area","bewid","product","qcvol",2018,"04",16,"radar_bewid_qcvol_040417.h5", .sep = "/")

``

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks like a re-implementation of paste ;), I guess I do like the longer format strings as then it can be controlled through a package option :)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented options for control

Comment thread R/get_pvol_se.R
Comment thread tests/testthat/test-get_pvol_se.R
Comment thread R/get_pvol_se.R
Comment thread tests/testthat/test-get_pvol_se.R
Comment thread NEWS.md Outdated
@peterdesmet

Copy link
Copy Markdown
Member

Would be good if @CeciliaNilsson709 and/or Johan test this new functionality. @bart1, can you provide a quick example?

Co-authored-by: Peter Desmet <peter.desmet@inbo.be>
@bart1

bart1 commented Aug 11, 2025

Copy link
Copy Markdown
Collaborator Author

Would be good if @CeciliaNilsson709 and/or Johan test this new functionality. @bart1, can you provide a quick example?

There is an example in #96, @CeciliaNilsson709 do you plan to test this soon? otherwise I will just merge

@CeciliaNilsson709

Copy link
Copy Markdown
Contributor

I'll take a quick look at it now!

@CeciliaNilsson709

Copy link
Copy Markdown
Contributor

Seems to work fine for me, tried a few different radars and works for the last 24 hours. I don't get as many parameters though (DBZH, VRADH, TH and WRADH) so not the CCORH we discussed in #96 .

Haven't checked with SMHI about the qcvol get, will get back to you on that!

@bart1

bart1 commented Aug 11, 2025

Copy link
Copy Markdown
Collaborator Author

@CeciliaNilsson709 Thanks for checking! bioRad omits some of the parameters while reading. Here is an example:

devtools::load_all("~/getRad")
#> ℹ Loading getRad
bioRad::get_scan(get_pvol("seoer", Sys.time()-700),1)
#>                   Polar scan (class scan)
#> 
#>      parameters:  DBZH VRADH TH WRADH 
#> elevation angle:  1 deg
#>            dims:  480 bins x 360 rays
bioRad::get_scan(get_pvol("seoer", Sys.time()-700, param="all"),1)
#>                   Polar scan (class scan)
#> 
#>      parameters:  DBZH UVRADH CI SQIH CCORH VRADH TH LDR UPSPH CPA WRADH CID VRADDH USNRHC ULDR 
#> elevation angle:  1 deg
#>            dims:  480 bins x 360 rays

@bart1
bart1 merged commit d0225f7 into main Aug 14, 2025
7 of 8 checks passed
@bart1

bart1 commented Aug 14, 2025

Copy link
Copy Markdown
Collaborator Author

The check error was related to to many request at the dutch repository

@bart1
bart1 deleted the 96-swedish-radar-data branch August 15, 2025 11:00
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

Successfully merging this pull request may close these issues.

Swedish radar data is open

4 participants