From 6b70097f7f42bf58a451f815911097c647cb762a Mon Sep 17 00:00:00 2001 From: Andrew Singleton <36473866+andrew-MET@users.noreply.github.com> Date: Fri, 2 Feb 2024 13:25:37 +0100 Subject: [PATCH] Merge develop (#110) * Revert to develop status * Fix bugs in getting wrf domain * Version to 0.2.2 and update NEWS.md --- DESCRIPTION | 10 +++++----- NEWS.md | 12 +++++++++++- R/get_domain_netcdf.R | 19 +++++++++++++------ R/get_wrf_projection.R | 25 ++++++++++++++++++++----- 4 files changed, 49 insertions(+), 17 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 881b3ff..528d894 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 [aut, cre]", "Alex Deckmyn [aut]" @@ -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 @@ -48,13 +48,13 @@ Suggests: maps, DT, roxygen2, - harpVis (>= 0.2.0) + harpVis (>= 0.2.2) Remotes: harphub/harpData, harphub/meteogrid, harphub/Rgrib2, - harphub/harpVis@v0.2.1, - harphub/harpCore@v0.2.1 + harphub/harpVis@v0.2.2, + harphub/harpCore@v0.2.2 URL: https://github.com/harphub/harpIO BugReports: https://github.com/harphub/harpIO/issues VignetteBuilder: knitr diff --git a/NEWS.md b/NEWS.md index 12299a5..0b71479 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/get_domain_netcdf.R b/R/get_domain_netcdf.R index e8ab889..17d6e0f 100644 --- a/R/get_domain_netcdf.R +++ b/R/get_domain_netcdf.R @@ -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) diff --git a/R/get_wrf_projection.R b/R/get_wrf_projection.R index ef981fe..219a8da 100644 --- a/R/get_wrf_projection.R +++ b/R/get_wrf_projection.R @@ -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 ) @@ -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 }