UMEP-dev / SuPy

SUEWS that speaks Python
https://supy.readthedocs.io/
GNU General Public License v3.0
13 stars 7 forks source link

"Invalid cross-device link" error for the command "suews-convert" #40

Closed CrayonAki closed 1 year ago

CrayonAki commented 3 years ago

Describe the bug When I used the command "suews-convert" in order to make the input files for SUEWS v2017b compatible for SUEWS v2020a (which I knew I should not do so because v2017b was not included in the version options for this command but I just tried), an error occurred during the process "2019b --> 2020a" as the following:

To Reproduce

File "/home/yingqiz/anaconda3/lib/python3.8/site-packages/supy/util/_converter.py", line 243, in SUEWS_Converter_single convert_utf8(file_dst)
File "/home/yingqiz/anaconda3/lib/python3.8/site-packages/supy/util/_converter.py", line 478, in convert_utf8 path_dst.rename(path_src)
File "/home/yingqiz/anaconda3/lib/python3.8/pathlib.py", line 1366, in rename self._accessor.rename(self, target)
OSError: [Errno 18] Invalid cross-device link: '/tmp/tmp4a5e9382/out-UTF8.txt' -> '/mnt/c/SUEWS/SUEWS_2020a/Input_K/InitialConditionsBe1_2007.nml'

Expected behavior There seems to be some problems related to path_dst.rename(path_src) in supy/util/_converter.py

I saw someone reported that "os.rename only works if source and destination are on the same file system. You should use shutil.move instead." when I was looking for solution.

So I opened site-packages/supy/util/_converter.py and added import shutil at the beginning to shutil which is already in the python standard library, and I modified line 478 from "path_dst.rename()" to shutil.move(path_dst, path_src)

This seems working and I obtained the new converted .nml files, and initial condition and site description .txt files to my specified repository.

However, a new problem arose which was reported in problems.txt as the following:

Problem: RunControl.nml

ERROR! Program stopped: Something wrong in the rows of the file

There seems to be something to do with the RunControl.nml. Next, I checked this file, and compared it with the converted RunControl.nml file with the template RunControl.nml presented in SUEWS_2020a. They actually differed in content and indentation.

Anyway, I just tried to force SUEWS v2020a with the replacement of forcing meteorological data, and it worked. Later, I just modified the initial data, parameters and the RunControl.nml files based on the template files one by one, which worked efficiently in this situation where I was trying to run SUEWS v2020a with SUEWS v2017b data.

Version and platform (please complete the following information):

Additional context Just sharing my experience in case someone encounters the "Invalid cross-device link" error. And in case someone's trying to convert the SUEWS v2017b to SUEWS v2020a with "suews-convert" commad, this seems not working.

sunt05 commented 3 years ago

Hi @CrayonAki , many thanks for sharing the detailed steps in reproducing the issue and sharing the workaround!

Could you please share your input files of v2017b so I can fix the issue the next supy release?

github-actions[bot] commented 1 year ago

Stale issue message