NGEET / fates

repository for the Functionally Assembled Terrestrial Ecosystem Simulator (FATES)
Other
105 stars 92 forks source link

Indexing fix in multiple python scripts #1287

Open mpaiao opened 5 days ago

mpaiao commented 5 days ago

Minor updates on multiple python scripts, for indexing and for using netcdf from scipy.io libraries

Description:

I don't know if this is only happening on my computer, but FatesPFTIndexSwapper.py started to issue the following indexing error when it attempted to copy scalars:

Creating Variable:  fates_canopy_closure_thresh
Traceback (most recent call last):
  File "/path_to/E3SM/components/elm/src/external_models/fates/tools/FatesPFTIndexSwapper.py", line 296, in <module>
    main(sys.argv)
    ~~~~^^^^^^^^^^
  File "/path_to/Models/E3SM/components/elm/src/external_models/fates/tools/FatesPFTIndexSwapper.py", line 207, in main
    out_var.assignValue(float(fp_in.variables.get(key).data))
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/scipy/io/_netcdf.py", line 943, in assignValue
    self.data[:] = value
    ~~~~~~~~~^^^
IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed
<sys>:0: RuntimeWarning: Cannot close a netcdf_file opened with mmap=True, when netcdf_variables or arrays referring to its data still exist. All data arrays obtained from such files refer directly to data on disk, and must be copied before the file can be cleanly closed. (See netcdf_file docstring for more information on mmap.)

The suggested change in the code seems to work fine (though I still get the RuntimeWarning message). I made similar updates in a few other scripts. I also updated ncvarsort.py to use scipy.

Collaborators:

Expectation of Answer Changes:

No change in the FATES code, just the tool.

Checklist

If this is your first time contributing, please read the CONTRIBUTING document.

All checklist items must be checked to enable merging this pull request:

Contributor

Integrator

Documentation

Test Results:

CTSM (or) E3SM (specify which) test hash-tag:

CTSM (or) E3SM (specify which) baseline hash-tag:

FATES baseline hash-tag:

Test Output: