Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Error in the calculation of the objetive function

449 views
Skip to first unread message

Nerea Bilbao

unread,
Feb 1, 2023, 3:15:35 PM2/1/23
to R-SWAT
Dear all,

I am encountering some problems that maybe you can help me to solve.

I just started using R-SWAT and I want to perform a sensitivity analysis of the monthly flow variable for SWAT+ data. I have followed the steps you indicate in the video tutorial (https://www.youtube.com/watch?v=UOknxfrzplY&t=2s) and I have been fulfilling the steps one by one without errors. I have run the model and it seems that it performs well according to the CurrentSimulationReport.txt.

However, I have problems with section 4. Evaluation of results. After defining the objective function and entering the observed flow data in the correct format, I click on the button to calculate the objective function and I get the results attached in the screenshots.

As you can see in the ss_02.png, the objective function does not change with each simulation.

What can be the origin of the problem? How can I solve it?

Thank you very much in advance 

ss_03.png
ss_02.png
ss_01.png

Tam Nguyen

unread,
Feb 2, 2023, 4:13:56 AM2/2/23
to R-SWAT
Hi Nerea,

I could be the case that you didn't tell SWAT+ to print out the output file at monthly so the output file is the same for all simulations. Please try to set this value is "yes". If the problem still persist, please let me know

Cheers,
Tam

Capture.PNG

Nerea Bilbao

unread,
Feb 2, 2023, 4:59:50 AM2/2/23
to R-SWAT

Hello Tam,

Thanks for the quick answer. If I understood you correctly you asked me to change the simulation in SWAT+ so that it prints me the file channel_sd_mon.txt. I have already done that and reproduced the sensitivity analysis process with R-SWAT again. I still have the same problem...

Tam Nguyen

unread,
Feb 2, 2023, 7:40:24 AM2/2/23
to R-SWAT
could you send me your RSWATproject.rds (and TxtInOut folder)?

Nerea Bilbao

unread,
Feb 2, 2023, 9:07:17 AM2/2/23
to R-SWAT
I shared with you a drive folder with the data you requested.
Thank you,

Tam Nguyen

unread,
Feb 3, 2023, 5:18:11 AM2/3/23
to R-SWAT
Hi Nerea,
I have checked the data that you shared. In the file.cio (Line 22, column 3 - attached below ) you didn't put the "calibration.cal". That why SWAT+ will not run with the provided parameter values in this file and you will got the same simulation for all simulations => so the model performance is the same

It should work if you replace the text "null" with "calibration.cal" in line 22 - column 3 in this file.cio file

Capture.PNG

Nerea Bilbao

unread,
Feb 3, 2023, 8:38:40 AM2/3/23
to R-SWAT
Hi Tam,

Solved! That was the problem. Thank you very much for your help and quick answers. RSWAT is a very complete tool.

Cheers
Message has been deleted

Tam Nguyen

unread,
Aug 1, 2023, 2:26:02 AM8/1/23
to R-SWAT
Hi Aseelabde....I run your project and it works (the objective function values are NOT the same) - please see attached sreenshot
Untitled.png
On Monday, July 31, 2023 at 11:52:01 PM UTC+2 aseelabde...@gmail.com wrote:
Hi Tam,

Thank you for the great R-SWAT tool!
I'm currently encountering a similar issue as Nerea. Despite following your suggestions, I haven't been able to resolve the problem, and I'm still getting the same results for the different parameter sets. Could you please assist me in identifying the potential cause behind this issue?

I have uploaded the R_SWAT and TextInOut folder to the following link.


Regards

Louise Malmquist

unread,
Aug 2, 2023, 4:29:31 AM8/2/23
to R-SWAT
Dear all

I also faced similar problems with the objective function. After reading through and testing the solutions provided here in the google group, the only solution that worked for me was to run R-SWAT from an external hard drive and keep my project file in the  C:/ folder, as suggested here: https://groups.google.com/g/r-swat/c/oEadVEnsxPk/m/3JKwCpNKAgAJ 

Hope it works.

Kind regards,
Louise

Rishabh Srikar

unread,
Nov 7, 2024, 8:07:04 AM11/7/24
to R-SWAT
Hi Dr Tam and others,

I am a relatively new SWAT/SWAT+ user, and I too have had this issue of the objective function not changing. I have already tried the two workarounds mentioned in this thread:
  1. Replacing null with calibration.cal 
  2. Running the executable from an external hard disk. 

A few things I should mention to give context:
  1. I am running RSWAT for a SWAT+ project that was initially created, set-up and run in the QSWAT+ and SWAT+ Editor ecosystem and therefore I am using the TxtInTxtOut folder directory from that run in the RSWAT interface for cal/val.
  2. Despite setting parameter ranges in RSWAT, there is no calibration.cal file in the above-mentioned TxtInTxtOut folder so although I have attempted Dr Tam's suggestion, I don't understand how it will work in my case and would deeply appreciate an explanation. 
  3. I have not at this stage separated my observed dataset into calibration and validation, i.e., my observed data at this stage only comprises of the calibration period (I did not think this would have any influence on the sensitivity and objective function calculation, but please correct me if I'm wrong).
I am also attaching screenshots of all the steps followed by me in the RSWAT interface if it helps. 

Thanks in advance and best regards, 
Rishabh
RSWAT_SS_2.png
RSWAT_SS_1.png
RSWAT_SS_5.png
RSWAT_SS_3.png
RSWAT_SS_4.png
RSWAT_SS_6.png

Tam Nguyen

unread,
Nov 8, 2024, 2:49:16 AM11/8/24
to R-SWAT
can you share with me your project

Rishabh Srikar

unread,
Nov 8, 2024, 10:27:44 AM11/8/24
to R-SWAT
Hi Dr Tam, 

Thank you for your prompt response! Please find attached the RSWAT project file and do let me know if I should furnish any additional information such as the QSWAT+ TxtInTxtOut folder that may be of help. 

Thanks again and best regards,
Rishabh
RSWATproject.rds

Tam Nguyen

unread,
Nov 8, 2024, 10:32:03 AM11/8/24
to R-SWAT
i cannot see the txtinout folder?

Daff gul

unread,
Nov 11, 2024, 12:55:56 PM11/11/24
to R-SWAT
Hello Dr. Tam

Could I please ask you to take a look at my work as well? I’ve replaced calibration.cal  and y in the files, but my objective function still isn’t optimized.

Here is the link to the files:



ould you let me know what I might be doing wrong?

Thank you in advance for your help.

Best regards,
Daff


Screenshot 2024-11-08 215638.png
Screenshot 2024-11-08 215355.png
Screenshot 2024-11-08 215441.png
Screenshot 2024-11-08 215534.png

Rishabh Srikar

unread,
Nov 11, 2024, 12:56:01 PM11/11/24
to R-SWAT
Hi Dr Tam,

Apologies, I only sent the RSWAT project earlier. Here is the link for my TxtInOut folder used in the run. 

I sincerely appreciate your time and kindly do let me know if you need any further information from my end.

Warm regards, 
Rishabh 

Tam Nguyen

unread,
Nov 11, 2024, 1:21:06 PM11/11/24
to R-SWAT
HI Rishabh, the solution is indeed in one of the previous messages within this discussion topic
1.PNG

Tam Nguyen

unread,
Nov 11, 2024, 1:37:27 PM11/11/24
to R-SWAT
Hi Daff, I cannot download your txtinout file (could you remove the exe file or output files since output files will be automatically created when I run it and it is very heavy)
Message has been deleted

Rishabh Srikar

unread,
Nov 12, 2024, 1:41:43 PM11/12/24
to R-SWAT
Hi Dr Tam, 
As always thank you for your prompt response. 

Similar to what Daff has described above, I have changed the null to calibration.cal in the TxtInOut folder with no luck. I think it is because despite the edit in file.cio, there is no calibration.cal file in the original TxtInOut folder therefore RSWAT isn't able to pick up any parameter ranges to test but this is just my understanding which could be wrong.

Best regards,
Rishabh

Daff gul

unread,
Nov 12, 2024, 1:41:47 PM11/12/24
to R-SWAT
Hello Dr. Tam, 

Thank you for your email.

I deleted the output files and the .exe file and hope I did it correctly in Textinout2. shared in the same folder in google drive. 

Once again, I appreciate your help.


Regards, 
Daff

Daff gul

unread,
Nov 19, 2024, 1:30:36 PM11/19/24
to R-SWAT
 Dr. Tam andRishabh Srikar

Please let me know if you could find solution for the problem. 

Thanks a lot. 

Daff gul

unread,
Dec 8, 2024, 2:25:47 PM12/8/24
to R-SWAT

Hello Dr. Tam and Rishabh,

I resolved the error and wanted to share my experience in case anyone else encounters the same issue—it might save some time.

The problem was that my run wasn’t updated, and the optimization wasn’t working. Initially, I didn’t pay attention to the swatplus.exe file. I had downloaded the executable file from the website, which wasn’t wrong, but it wasn’t the same version as the one installed on my system.

This time, I opened the file directly from the SWAT+ editor (see the attached screenshots) and used that executable file for running the process. It worked!

Although it was a simple mistake, it took me almost two weeks to figure it out. I hope this helps others avoid the same issue.

Good luck, everyone!

Best regards,

exe.file.png
swateditor .png

Daff gul

unread,
Dec 8, 2024, 2:25:47 PM12/8/24
to R-SWAT

Hello Dr. Tam and Rishabh,

I resolved the error and wanted to share my experience in case anyone else encounters the same issue—it might save some time.

The problem was that my run wasn’t updated, and the optimization wasn’t working. Initially, I didn’t pay attention to the swatplus.exe file. I had downloaded the executable file from the website, which wasn’t wrong, but it wasn’t the same version as the one installed on my system.

This time, I opened the file directly from the SWAT+ editor (see the attached screenshots) and used that executable file for running the process. It worked!

Although it was a simple mistake, it took me almost two weeks to figure it out. I hope this helps others avoid the same issue.

Good luck, everyone!

Bests, 

Daff


Rishabh Srikar

unread,
Dec 11, 2024, 1:55:41 PM12/11/24
to R-SWAT
Hi Dr Tam and Daff, 

Thanks for sharing this, Daff. I'm glad that you have been able to find a workaround that solves this issue. I tried the same but on the contrary, I've faced the reverse problem wherein the SWAT.exe installed as part of the Editor doesn't seem to be compatible within RSWAT (the run goes on indefinitely without producing outputs). However, an independently downloaded executable from the SWAT+ website works.

Replacing null with calibration.cal in the file.cio in the original TextInOut folder (the one created by Editor) does not work for me as there is no calibration.cal file in that folder. So, should we create a calibration.cal file by manual calibration in the Editor interface for it to be readable by file.cio? Or do we copy the calibration.cal files created in the TextInOut_x folders from the RSWAT working folder? Or some other way? 

Sincerely and best,
Rishabh
Message has been deleted

Tam Nguyen

unread,
Dec 11, 2024, 2:14:24 PM12/11/24
to R-SWAT
Hi Rishabh,
RSWAT does not care what is calibration.cal file. I just copy that file from the orginal TxtInOut folder to TxtInOut_[x] (where x is 1, 2, 3, ....number of cores/threads). If you copy the SWAT/SWAT+ executable file to the orginal TxtInOut and run SWAT manually, if SWAT can run => it means that your project setttings are ok and you can use RSWAT, if SWAT/SWAT+ cannot run, then you need to fix the SWAT/SWAT+ first

"SWAT run does not complete (goes on indefinitely". This happens if you define the parameter range (some parameters might be out of physical range and SWAT/SWAT+ does not report anything to the interface, RSWAT then also does not know anything, RSWAT just "think" that SWAT/SWAT+ is running. So you should check the parameter ranges in RSWAT interface and also in the "cal_parms.cal"

On Wednesday, December 11, 2024 at 7:55:41 PM UTC+1 Rishabh Srikar wrote:
Hi Daff and Dr Tam,

Thank you, Daff, for sharing your experience. I'm glad you have found a workaround for your issue. 

Unfortunately for me your suggestion did not work in my case. On the contrary, the SWAT+ executable used by SWAT+ Editor (i.e. the installed version) does not work within RSWAT for me. The RSWAT run does not complete (goes on indefinitely) and no files in the Output folder are generated. The way I get the SWAT+ run to execute within RSWAT is to use a downloadable revision that closely matches the installed version which in my case is the Rev 61.0.1.

Since the most common solution of replacing null with calibration.cal in file.cio has worked out for most people but me, my question is even after replacement there is no calibration.cal  file in the original TextInOut folder for file.cio to read. So, is it that I have to first get SWAT+ to create a calibration.cal  file in the SWAT+ Editor interface by manually calibrating there? 

Or do you copy/paste calibration.cal  from one of the TextInOut_x folders in the RSWAT working directory created during RSWAT run into the original TextInOut for file.cio to read?


On Monday, December 9, 2024 at 12:55:47 AM UTC+5:30 Daff gul wrote:

Rishabh Srikar

unread,
Dec 12, 2024, 8:17:57 AM12/12/24
to R-SWAT
Hi Dr Tam, 

Thank you so much for your reply. If I have understood you correctly:
  • I have replaced null with calibration.cal in file.cio in the original TxtInOut folder ensuring I have a calibration.cal in that original TxtInOut. There is also one calibration.cal file in each and every TxtInOut_x (RSWAT working folder) with one parameter set sampled randomly by uniform LHS.
  • I have set parameter ranges for selected variables as per cal_parms.cal  to ensure they were within the absolute physical bounds.
  • If a SWAT/SWAT+ executable can be run successfully manually (through CMD prompt), then that means my project setup is alright and I can proceed to run in RSWAT. In my case rev61.0.1_64rel.exe is the SWAT+ revision which runs successfully manually in the TxtInOut folder but does not perform a successful run in RSWAT. However, an independently downloaded revision swatplus-61.0.1-win-amd64.exe works in RSWAT. 
I still continue to face this problem. I am herewith attaching a link of TxtInOut which contains the abovementioned executables used as well as the RSWAT.rds project file. Could I request you to take another look if/whenever possible and let me know what I am missing?

I deeply appreciated your time,
Best,
Rishabh
RSWATproject.rds
Message has been deleted

Tam Nguyen

unread,
Dec 12, 2024, 8:37:15 AM12/12/24
to R-SWAT
Hi Risbabh, I run RSWAT for 2 parametersets with the rev61.0.1_64rel.exe  and it works, there is no problem, could you shared with me your CurrentSimulationReport.log to see RSWAT stops in which iteration

Rishabh Srikar

unread,
Dec 12, 2024, 9:56:52 AM12/12/24
to R-SWAT
Hi Dr Tam, 

I am attaching screenshots - 
  • When I run rev61.0.1_64rel.exe, no outputs (no CurrentSimulationReport.log and 'core' folders are created) - screenshots 1. 
  • However, swatplus-61.0.1-win-amd64.exe does complete run successfully - screenshots 2.
The log file attached is from a successful run using swatplus-61.0.1-win-amd64.exe. Every other setting is the same.

My main issue is even with a successful run using swatplus-61.0.1-win-amd64.exe, my objective function doesn't change despite changing null with calibration.cal in file.cio in the original TxtInOut folder and ensuring I have a calibration.cal in that original TxtInOut.

Thank you for your time, 
Best,
Rishabh
1. executable_error.png
2. executable_successful.png
1. Output_folder_empty.png
CurrentSimulationReport.log
2. Output_folder_with_successful_run.png

Tam Nguyen

unread,
Dec 12, 2024, 10:05:22 AM12/12/24
to R-SWAT
quite strange, when I run with the TxtInout data (using rev61.0.1_64rel.exe  in this data) and RSWATproject.rds settings (I extracted parameter to the attached file best.txt and run with user input parameter option) that you shared in the previous reply, RSWAT run successfull without any issues (attached the screen shot).

1. try install RSWAT again (this is unlikely - but anyway worth to try)?
2. try to run with the parameter values in the attached file

Capture.PNG
best.txt

Rishabh Srikar

unread,
Dec 13, 2024, 8:12:28 AM12/13/24
to R-SWAT
Hi Dr Tam, 

I understand. I deeply appreciate your response and the parameter file. I shall attempt what you suggest and report my experience. 

Best regards,
Rishabh
Reply all
Reply to author
Forward
0 new messages