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

Better debugging for model2netcdf.ED2 #3078

Merged
merged 13 commits into from
Jan 10, 2023
Merged

Better debugging for model2netcdf.ED2 #3078

merged 13 commits into from
Jan 10, 2023

Conversation

Aariq
Copy link
Collaborator

@Aariq Aariq commented Dec 19, 2022

Description

  1. wraps ncdf4::ncvar_put() so that the variable name is printed before any warnings it gives
  2. changes behavior of an on.exit() to remove warnings about closing nc connection multiple times

(I also snuck in removing an incorrect usage of ...)

Motivation and Context

Currently model2netcdf.ED2() prints a lot of warnings of the form

"ncvar_put: warning: you asked to write xxx values, but the passed data array has yyy entries!"

These warnings are uninformative in this context because the variable name is not printed anywhere.

Before
> model2netcdf.ED2("completed_runs/MANDIFORE-PNW-4538/outdir/out/ENS-00001-1000020684/", settings = settings)
2022-12-19 21:40:29 INFO   [model2netcdf.ED2] : 
   ----- Processing year: 2002 
2022-12-19 21:40:29 INFO   [read_E_files] : 
   *** Reading -E- file *** 
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
2022-12-19 21:40:38 INFO   [model2netcdf.ED2] : 
   *** Writing netCDF file *** 
[1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!"
[1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!"
[1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!"
[1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!"
[1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!"
[1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!"
[1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!"
2022-12-19 21:40:38 INFO   [model2netcdf.ED2] : 
   ----- Processing year: 2003 
2022-12-19 21:40:38 INFO   [read_E_files] : 
   *** Reading -E- file *** 
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
2022-12-19 21:40:46 INFO   [model2netcdf.ED2] : 
   *** Writing netCDF file *** 

After
model2netcdf.ED2("completed_runs/MANDIFORE-PNW-4538/outdir/out/ENS-00001-1000020684/", settings = settings)
2022-12-19 21:47:34 INFO   [model2netcdf.ED2] : 
   ----- Processing year: 2002 
2022-12-19 21:47:34 INFO   [read_E_files] : 
   *** Reading -E- file *** 
2022-12-19 21:47:43 INFO   [model2netcdf.ED2] : 
   *** Writing netCDF file *** 
With 'AGB_PFT': [1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!" 
With 'BSEEDS': [1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!" 
With 'DBH': [1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!" 
With 'DDBH': [1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!" 
With var 'NPP_PFT': [1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!" 
With 'TRANSP_PFT': [1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!" 
With 'DENS': [1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!" 
2022-12-19 21:47:43 INFO   [model2netcdf.ED2] : 
   ----- Processing year: 2003 
2022-12-19 21:47:43 INFO   [read_E_files] : 
   *** Reading -E- file *** 
2022-12-19 21:47:50 INFO   [model2netcdf.ED2] : 
   *** Writing netCDF file *** 

Review Time Estimate

  • Immediately
  • Within one week
  • When possible

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • My name is in the list of CITATION.cff
  • I have updated the CHANGELOG.md.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

…tting replaced with a new file ever time through the loop, there's only one exit action that needs to happen---nc_close(nc).
@Aariq Aariq marked this pull request as ready for review December 19, 2022 21:56
@Aariq Aariq added the Status: Ready Pull request ready for merge, or issue ready to be closed label Dec 21, 2022
@dlebauer dlebauer merged commit 21184bb into develop Jan 10, 2023
@Aariq Aariq deleted the ncvar_put-debug branch January 10, 2023 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Ready Pull request ready for merge, or issue ready to be closed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants