CWorthy-ocean / C-Star

C-Star is a python package for setting up and running ocean model simulations, with a particular focus on marine carbon dioxide removal (mCDR) applications.
https://c-star.readthedocs.io
10 stars 4 forks source link

Cannot import python code in UCLA-roms submodule #53

Closed TomNicholas closed 1 month ago

TomNicholas commented 1 month ago

I'm trying to work on #42, but when I run pytest it fails because it tries to import code in the ucla-roms submodule, which throws this error.

_______________________________________________________ ERROR collecting cstar/externals/ucla-roms/Examples/code_check/test_roms.py _______________________________________________________
cstar/externals/ucla-roms/Examples/code_check/test_roms.py:59: in <module>
    filename_BM  = os.path.join(os.getcwd(),str(sys.argv[1]))  # read in with argument (maya or expanse)
E   IndexError: list index out of range
==========================================

In fact I can't even import that module directly:

In [1]: import Examples.code_check.test_roms
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[1], line 1
----> 1 import Examples.code_check.test_roms

File ~/Documents/Work/Code/ucla-roms/Examples/code_check/test_roms.py:59
     56 ntests = 1 # np.size(test_names)
     57 # -- WEC
     58 #filename_BM  = os.path.join(os.getcwd(),'benchmark.result')
---> 59 filename_BM  = os.path.join(os.getcwd(),str(sys.argv[1]))  # read in with argument (maya or expanse)
     60 filename_res = os.path.join(os.getcwd(),'test.log')
     61 filenames = [ filename_BM, filename_res ]

IndexError: list index out of range

What is that line doing?

dafyddstephenson commented 1 month ago

What you are looking at is part of the ucla-roms code written by somebody there, specifically: https://github.com/CESR-lab/ucla-roms/blob/main/Examples/code_check/test_roms.py

I'm not sure at what step in the procedure you are, but a clean copy of C-Star will not include ucla-roms. You can safely delete cstar/externals, where ROMS and MARBL will have been downloaded as part of your previous use. If you need externals to be there, we have a bigger problem and will have to issue a PR to CESR, presumably adding a name is main check to safeguard against that script being executed on import, as I gather it is was intended to be standalone.

To answer what it's doing, my understanding is it parses a "benchmark" file (which is just a log file from a known working ROMS run) and compares it with the log file from the run it just excuted. This line in particular sets the name of the benchmark file based on user input of what system they'd like to check on (for instance, there is now a benchmark.result_github file for when sys.argv[-1] is github, as in the CI routine).

Or you could try what these other folks are suggesting? thanks for the input fellas