mehmetbercan / NSGA-II_Python_for_SWAT_model

Multi-Site and -Objective calibration method for SWAT model
38 stars 22 forks source link

Few Errors #1

Closed yirugi closed 7 years ago

yirugi commented 7 years ago

Hi Mehmet,

I found few errors while I'm trying to run test models.

  1. The 'ExampleTest.py' has the hard coded path: SWATtxtinoutDirectory = os.path.join(os.getcwd(), 'swatTest') I think the 'swatTest' should be removed? I removed it and continued test though.

  2. I can't run 'python setup' on our SWATShare linux system without administrator's help. So, I tried to install and run it in my system which is MACOSX. But, when I run it, it failed to choose which script should be chosen. nsga2_mid.cmd or nsga2_mid.sh. In mac system, it should choose .sh script, but it chose .cmd.

Here's output I've got so far.

pal-nat186-91-50:TxtInOut yirugi$ python ../../../../NSGA-II_Python_for_SWAT_model/ExampleModel/ExampleTest.py
Operating System is darwin

---------------------------------------------
Generation:  LHS   Simulation:  1
---------------------------------------------
/Users/yirugi/data/RCAC/nsga/testmodel/testmodels+obsdataformat/hydrology/TxtInOut/nsga2_mid.cmd: line 1: ::: command not found
/Users/yirugi/data/RCAC/nsga/testmodel/testmodels+obsdataformat/hydrology/TxtInOut/nsga2_mid.cmd: line 3: SWAT_ParameterEdit.py: command not found
/Users/yirugi/data/RCAC/nsga/testmodel/testmodels+obsdataformat/hydrology/TxtInOut/nsga2_mid.cmd: line 6: ::: command not found
/Users/yirugi/data/RCAC/nsga/testmodel/testmodels+obsdataformat/hydrology/TxtInOut/nsga2_mid.cmd: line 8: swat.exe: command not found
/Users/yirugi/data/RCAC/nsga/testmodel/testmodels+obsdataformat/hydrology/TxtInOut/nsga2_mid.cmd: line 11: ::: command not found
/Users/yirugi/data/RCAC/nsga/testmodel/testmodels+obsdataformat/hydrology/TxtInOut/nsga2_mid.cmd: line 13: Extract_rch.py: command not found
Traceback (most recent call last):
  File "../../../../NSGA-II_Python_for_SWAT_model/ExampleModel/ExampleTest.py", line 11, in <module>
    NSGAII.CreateInitialPopulation()
  File "/usr/local/lib/python2.7/site-packages/nsga2lib-2.2-py2.7.egg/nsga2lib/nsga2.py", line 201, in CreateInitialPopulation
    SWATutilities.CalculateObjectiveFunctions(InitialLHSpop,self.Outlet_Obsdata,self.FuncOpt,self.FuncOptAvr,self.parname,"LHS",self.SWATdir)
  File "/usr/local/lib/python2.7/site-packages/nsga2lib-2.2-py2.7.egg/nsga2lib/SWATutilities.py", line 226, in CalculateObjectiveFunctions
    modelrchf = open(os.path.join(SWATdir,"model.out"),'r')
IOError: [Errno 2] No such file or directory: '/Users/yirugi/data/RCAC/nsga/testmodel/testmodels+obsdataformat/hydrology/TxtInOut/model.out'

So, I guess the #36 line of nsga2.py should be modified to this:

        if "linux" or "darwin" in sys.platform.lower():
            print ("Operating System is {0}".format(sys.platform))
            shutil.copy2(os.path.join(libpath,"ScriptsForSWATtxt","nsga2_mid.sh"), SWATtxtinoutFolderDirectory)
            shutil.copy2(os.path.join(libpath,"ScriptsForSWATtxt","swat2012_627"), SWATtxtinoutFolderDirectory)
            shutil.copy2(os.path.join(libpath,"ScriptsForSWATtxt","Makefile"), SWATtxtinoutFolderDirectory)
        elif "win" in sys.platform.lower():
            print ("Operating System is {0}".format(sys.platform))
            shutil.copy2(os.path.join(libpath,"ScriptsForSWATtxt","nsga2_mid.cmd"), SWATtxtinoutFolderDirectory)
            shutil.copy2(os.path.join(libpath,"ScriptsForSWATtxt","swat.exe"), SWATtxtinoutFolderDirectory)            
        else: #goes with windows for now
            shutil.copy2(os.path.join(libpath,"ScriptsForSWATtxt","nsga2_mid.cmd"), SWATtxtinoutFolderDirectory)
            shutil.copy2(os.path.join(libpath,"ScriptsForSWATtxt","swat.exe"), SWATtxtinoutFolderDirectory)

Note that 'darwin' also has 'win' string, so I changed the sequence of if statement.

  1. This is not an error but, is it possible to make your script run without installation? As I mentioned, we need a permission for installing something, so it would be better if we could avoid installation.

Thanks! I Luk

yirugi commented 7 years ago

I'll test on linux system anyway. I'll let you know results.

yirugi commented 7 years ago

I've tried to install and run in my linux system, but it also failed.

yirugi@yirugi-ubuntu16:~/workspace/nsga/testmodels+obsdataformat/hydrology/TxtInOut$ python ExampleTest.py
Traceback (most recent call last):
  File "ExampleTest.py", line 10, in <module>
    NSGAII=nsga2.nsga2(SWATtxtinoutDirectory)
  File "/usr/local/lib/python2.7/dist-packages/nsga2lib-2.2-py2.7.egg/nsga2lib/nsga2.py", line 33, in __init__
    shutil.copy2(os.path.join(libpath,"ScriptsForSWATtxt","Extract_rch.py"), SWATtxtinoutFolderDirectory)
  File "/usr/lib/python2.7/shutil.py", line 130, in copy2
    copyfile(src, dst)
  File "/usr/lib/python2.7/shutil.py", line 82, in copyfile
    with open(src, 'rb') as fsrc:
IOError: [Errno 2] No such file or directory: '/usr/local/lib/python2.7/dist-packages/nsga2lib-2.2-py2.7.egg/nsga2lib/ScriptsForSWATtxt/Extract_rch.py'
yirugi@yirugi-ubuntu16:~/workspace/nsga/testmodels+obsdataformat/hydrology/TxtInOut$ ls /usr/local/lib/python2.7/dist-packages/nsga2lib-2.2-py2.7.egg/nsga2lib/ScriptsForSWATtxt/
ls: cannot access '/usr/local/lib/python2.7/dist-packages/nsga2lib-2.2-py2.7.egg/nsga2lib/ScriptsForSWATtxt/': No such file or directory

yirugi@yirugi-ubuntu16:~/workspace/nsga/testmodels+obsdataformat/hydrology/TxtInOut$ ls /usr/local/lib/python2.7/dist-packages/nsga2lib-2.2-py2.7.egg/nsga2lib/
__init__.py   nsga2.py   nsga2utilities.py   SWATutilities.py
__init__.pyc  nsga2.pyc  nsga2utilities.pyc  SWATutilities.pyc
mehmetbercan commented 7 years ago

Hi I Luk,

Thanks for taking a look at this! The model I emailed to you is slightly different than this. So, expect I will respond here based on what is on git-hub as we are discussing it here. I will go through your comment bullets.

  1. The 'ExampleTest.py' is an example script and designed to be used as a template for specific needs. The 'ExampleTest.py' uses that path to run SWAT model within 'swatTest' folder. With the current directory setup, it should work fine. You probably had different folder setup.

  2. Linux and Darwin are different in how they work but they both uses Unix. I have not tested the script on Darwin but I believe the change you made is enough with my recent changes that I made on the setup.py. You probably wont get the error you mentioned on your last message as the change addressed that error.

  3. I do not see bullet 3.

  4. This bullet has noting to do with the script on git-hub and should not be discussed here but If you read the email, I had already told that you do not need to install the library.

Thanks! Mehmet