Skip to content

Commit

Permalink
Merge develop (#110)
Browse files Browse the repository at this point in the history
* Revert to develop status

* Fix bugs in getting wrf domain

* Version to 0.2.2 and update NEWS.md
  • Loading branch information
andrew-MET authored Feb 2, 2024
1 parent 6f2063c commit 6b70097
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 17 deletions.
10 changes: 5 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: harpIO
Title: IO functions and data wrangling for harp
Version: 0.2.1
Version: 0.2.2
Authors@R: as.person(c(
"Andrew Singleton <[email protected]> [aut, cre]",
"Alex Deckmyn <[email protected]> [aut]"
Expand All @@ -9,7 +9,7 @@ Description: Functions for reading and writing data in the harp framework.
Readable formats include grib, netCDF, FA, vfld, vobs, SQLite FCTABLE files and
writeable formats are SQLite FCTABLE files.
Depends:
harpCore (>= 0.2.1),
harpCore (>= 0.2.2),
R (>= 3.3.1)
License: Apache License (>= 2.0)
Encoding: UTF-8
Expand Down Expand Up @@ -48,13 +48,13 @@ Suggests:
maps,
DT,
roxygen2,
harpVis (>= 0.2.0)
harpVis (>= 0.2.2)
Remotes:
harphub/harpData,
harphub/meteogrid,
harphub/Rgrib2,
harphub/[email protected].1,
harphub/[email protected].1
harphub/[email protected].2,
harphub/[email protected].2
URL: https://github.com/harphub/harpIO
BugReports: https://github.com/harphub/harpIO/issues
VignetteBuilder: knitr
Expand Down
12 changes: 11 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# harpIO 0.2.2

* HOTFIX Released 2nd February 2024

* New parameters added to OBSOUL reading.

* Partial fix of bug that resulted in errors when extracting domain information
from WRF output files - care should be taken when reading data from WRF files
as this is not fully tested.

# harpIO 0.2.1

* HOTFIX Released 5th December 2024
* HOTFIX Released 5th December 2023

* This version includes some improvements for reading NetCDF files and bug fixes

Expand Down
19 changes: 13 additions & 6 deletions R/get_domain_netcdf.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,19 @@ get_domain_netcdf <- function(file_name, opts) {
stop("Cannot retrieve DY from WRF file.", call. = FALSE)
}
dy <- dy[["value"]]
if (is.null(lon_var)) {
stop("'lon_var' must be passed for WRF files.", call. = FALSE)
}
if (is.null(lat_var)) {
stop("'lat_var' must be passed for WRF files.", call. = FALSE)
}
clon <- ncdf4::ncatt_get(nc_id, 0, "CEN_LON")[["value"]]
clat <- ncdf4::ncatt_get(nc_id, 0, "CEN_LAT")[["value"]]
if (was_closed) ncdf4::nc_close(nc_id)
return(
harpCore::define_domain(
centre_lon = clon,
centre_lat = clat,
nxny = c(nx, ny),
dxdy = c(dx, dy),
proj = proj4
)
)

} else {
if (nc_id[["dim"]][[x_dim]][["create_dimvar"]]) {
x <- ncdf4::ncvar_get(nc_id, x_dim)
Expand Down
25 changes: 20 additions & 5 deletions R/get_wrf_projection.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,22 @@ get_wrf_projection <- function(wrf_file) {

proj4_string <- switch(
as.character(wrf_proj),
"0" = paste0("+proj=eqc +lon_0=", lon0, " +lat0=", lat0, " +lat_ts=", lat1),
"1" = paste0("+proj=lcc +lon_0=", lon0, " +lat0=", lat0, " +lat_1=", lat1, " +lat_2=", lat2),
"2" = paste0("+proj=stere +lon_0=", lon0, " +lat0=", lat0, " +lat_ts=", lat1),
"3" = paste0("+proj=merc +lon_0=", lon0, " +lat_ts=", lat1),
"0" = paste0(
"+proj=eqc +lon_0=", lon0, " +lat_0=", lat0, " +lat_ts=", lat1,
" +R=6370000 +a=6370000 +b=6370000"
),
"1" = paste0(
"+proj=lcc +lon_0=", lon0, " +lat_0=", lat0, " +lat_1=", lat1,
" +lat_2=", lat2, " +R=6370000 +a=6370000 +b=6370000"
),
"2" = paste0(
"+proj=stere +lon_0=", lon0, " +lat_0=", lat0, " +lat_ts=", lat1,
" +R=6370000 +a=6370000 +b=6370000"
),
"3" = paste0(
"+proj=merc +lon_0=", lon0, " +lat_ts=", lat1,
" +R=6370000 +a=6370000 +b=6370000"
),
"6" = "+proj=latlong",
NA
)
Expand All @@ -47,6 +59,9 @@ get_wrf_projection <- function(wrf_file) {

if (was_closed) ncdf4::nc_close(wrf_id)

paste(proj4_string, "+R=6.371e+06")
if (!grepl(" \\+R=", proj4_string) && !grepl(" \\+a=", proj4_string)) {
return(paste(proj4_string, "+R=6.371e+06"))
}
proj4_string

}

0 comments on commit 6b70097

Please sign in to comment.