pyschism
pyschism copied to clipboard
Issue with handling environment variables
I think the logic that is used to handle environment variables are wrong in the following code,
https://github.com/schism-dev/pyschism/blob/ee6d3553609f79c8468783a9c087eb99402f906e/pyschism/forcing/bctides/tpxo.py#L100
I am getting following error in my case,
Traceback (most recent call last):
File "/work2/noaa/nems/tufuk/COASTAL/ufs-coastal-app/ush/test.py", line 12, in <module>
_files = gen_bctides.execute(schism, datetime.strptime(cycle, '%Y-%m-%d %H:%M:%S'), 1, output_dir=rundir)
File "/work2/noaa/nems/tufuk/COASTAL/ufs-coastal-app/ush/utils/schism/gen_bctides.py", line 447, in execute
bctides.write(
File "/work2/noaa/nems/tufuk/COASTAL/ufs-coastal-app/python_test/envs/lib/python3.9/site-packages/pyschism/forcing/bctides/bctides.py", line 265, in write
f.write(str(self))
File "/work2/noaa/nems/tufuk/COASTAL/ufs-coastal-app/python_test/envs/lib/python3.9/site-packages/pyschism/forcing/bctides/bctides.py", line 139, in __str__
amp, phase = self.tides.get_elevation(constituent, vertices)
File "/work2/noaa/nems/tufuk/COASTAL/ufs-coastal-app/python_test/envs/lib/python3.9/site-packages/pyschism/forcing/bctides/tides.py", line 141, in get_elevation
return self.tidal_database.get_elevation(constituent, vertices)
File "/work2/noaa/nems/tufuk/COASTAL/ufs-coastal-app/python_test/envs/lib/python3.9/site-packages/pyschism/forcing/bctides/tpxo.py", line 43, in get_elevation
amp = self._get_interpolation(
File "/work2/noaa/nems/tufuk/COASTAL/ufs-coastal-app/python_test/envs/lib/python3.9/site-packages/pyschism/forcing/bctides/tpxo.py", line 125, in _get_interpolation
ncarray = self.h
File "/work2/noaa/nems/tufuk/COASTAL/ufs-coastal-app/python_test/envs/lib/python3.9/site-packages/pyschism/forcing/bctides/tpxo.py", line 104, in h
if not self._h_file.exists():
AttributeError: 'str' object has no attribute 'exists'
If you provide absolute path to the TPXO_ELEVATION and the file is in there then self._h_file would be string and self._h_file.exists() would fail since string has no exists method.. I think same logic is also used in other places and needs to be fixed. This code was working in some Python environment but it is giving error in others. So, I think that some Python versions is able to handle this situation but some others not. It would be nice to fix it.