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

model2netcdf.ED2() only converts data for first PFT #2974

Closed
Aariq opened this issue Jul 20, 2022 · 7 comments · Fixed by #2985
Closed

model2netcdf.ED2() only converts data for first PFT #2974

Aariq opened this issue Jul 20, 2022 · 7 comments · Fixed by #2985
Assignees

Comments

@Aariq
Copy link
Collaborator

Aariq commented Jul 20, 2022

Bug Description

I open one of the .h5 files output by ED2 and confirm that there are multiple PFTs listed, then run model2netcdf.ED2() where pfts = settings$pfts, and the resulting .ncvar file only lists the first PFT. The .nc file also only has data for one PFT. I think I tracked this down to this line, which would only read the first pft name.

pft_names <- pfts$pft$name

This should be something like pft_names <-pfts %>% purrr::map(~.x[["name"]]) or whatever the base R equivalent is.

To Reproduce

It can be reproduced with just one of the .h5 files output by ED2, but the example I'm using is on a server and I'm not sure how to share it. I put that single h5 file in a dir called "testing" and ran this:

library(ncdf4)
library(PEcAn.ED2)
settings <-
  list(
    run = list(
      site = list(
        lat = 35.9588,
        lon = -84.2874
      ),
      start.date = "2019/03/01",
      end.date = "2019/09/01"),
    pfts = list(
      pft = list(
        name = "SetariaWT",
        ed2_pft_number = "1"
      ),
      pft = list(
        name = "ebifarm.c3grass",
        ed2_pft_number = "5"
      )
    )
  )

before <- nc_open("testing/analysis-E-2019-03-00-000000-g01.h5")
ncvar_get(before, "PFT")
## [1] 1 5
nc_close(before)

model2netcdf.ED2(outdir = "testing",
  settings$run$site$lat,
  settings$run$site$lon,
  settings$run$start.date,
  settings$run$end.date,
  settings$pfts 
)

# 2022-07-20 20:54:11 INFO   [debugscript.R#28: model2netcdf.ED2] : 
#   ----- Processing year: 2019 
# 2022-07-20 20:54:11 INFO   [fcn] : 
#   *** Reading -E- file *** 
# 2022-07-20 20:54:11 INFO   [debugscript.R#28: model2netcdf.ED2] : 
#   *** Writing netCDF file *** 

after <- nc_open("testing/2019.nc")
ncvar_get(after, "PFT")
# [1] 1
nc_close(after)

Expected behavior

Should convert data for all PFTs

@Aariq Aariq self-assigned this Jul 20, 2022
@dlebauer
Copy link
Member

There are already some sample output files in https://github.com/PecanProject/pecan/tree/develop/models/ed/tests/testthat/data, if those don't meet your needs - e.g. doesn't have multiple pfts, consider adding a (small) new one that does.

@Aariq
Copy link
Collaborator Author

Aariq commented Jul 20, 2022

I did eventually find those. I'll check tomorrow to see if one has multiple PFTs

@dlebauer
Copy link
Member

Try setting NL%ATTACH_METADATA to 1 for generating test data; otherwise the outputs and their dimensions are difficult to interpret.

@Aariq
Copy link
Collaborator Author

Aariq commented Jul 21, 2022

Looks like the current ED output in testthat/data doesn't work at all unfortunately and all tests are currently skipped. Might need help generating new test output.

@Aariq
Copy link
Collaborator Author

Aariq commented Jul 21, 2022

Related to #774?

@Aariq
Copy link
Collaborator Author

Aariq commented Jul 21, 2022

Won't fix until #1329 is (partially) dealt with.

@Aariq
Copy link
Collaborator Author

Aariq commented Jul 22, 2022

So I won't be able to get the tests working because this function is more broken than I can handle without downgrading my R version (see #2981). Should I go ahead and make a PR with the fix to line 954 anyway?

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

Successfully merging a pull request may close this issue.

2 participants