@@ -463,33 +463,46 @@ def set_print_interval(
463463
464464 return None
465465
466- def set_start_date_print (
466+ def set_print_period (
467467 self ,
468- start_date : str ,
468+ begin_date : str ,
469+ end_date : str ,
469470 ) -> None :
470471 '''
471- Set the start date in the `print.prt` file to define when output files begin recording simulation results.
472+ Set the start and end date in the `print.prt` file to define when output files begin recording simulation results.
472473
473474 Args:
474- start_date (str): Start date in `DD-Mon-YYYY` format (e.g., 01-Jun-2010).
475+ begin_date (str): Start date in `DD-Mon-YYYY` format (e.g., 01-Jun-2010).
476+ end_date (str): End date in `DD-Mon-YYYY` format (e.g., 31-Dec-2020).
475477 '''
476478
477479 # Check input variables type
478480 validators ._variable_origin_static_type (
479481 vars_types = typing .get_type_hints (
480- obj = self .set_start_date_print
482+ obj = self .set_print_period
481483 ),
482484 vars_values = locals ()
483485 )
484486
485487 # Convert date string to datetime.date object
486- start_dt = utils ._date_str_to_object (
487- date_str = start_date
488+ begin_dt = utils ._date_str_to_object (
489+ date_str = begin_date
490+ )
491+ end_dt = utils ._date_str_to_object (
492+ date_str = end_date
493+ )
494+
495+ # Check begin date is earlier than end date
496+ validators ._date_begin_earlier_end (
497+ begin_date = begin_dt ,
498+ end_date = end_dt
488499 )
489500
490501 # Extract years and Julian days
491- start_day = start_dt .timetuple ().tm_yday
492- year_year = start_dt .year
502+ start_day = begin_dt .timetuple ().tm_yday
503+ start_year = begin_dt .year
504+ end_day = end_dt .timetuple ().tm_yday
505+ end_year = end_dt .year
493506
494507 # File path of print.prt
495508 print_prt_path = self .root_folder / 'print.prt'
@@ -500,7 +513,7 @@ def set_start_date_print(
500513
501514 nth_line = 3
502515 columns = lines [nth_line - 1 ].split ()
503- lines [nth_line - 1 ] = f"{ columns [0 ]:<12} { start_day :<11} { year_year :<11} { columns [ 3 ] :<10} { columns [ 4 ] :<10} { columns [5 ]} \n "
516+ lines [nth_line - 1 ] = f"{ columns [0 ]:<12} { start_day :<11} { start_year :<11} { end_day :<10} { end_year :<10} { columns [5 ]} \n "
504517
505518 # Modify print.prt file
506519 with open (print_prt_path , 'w' ) as file :
@@ -722,40 +735,44 @@ def _apply_swat_configuration(
722735 simulation_timestep : typing .Optional [int ] = None ,
723736 warmup : typing .Optional [int ] = None ,
724737 print_prt_control : typing .Optional [dict [str , dict [str , bool ]]] = None ,
725- start_date_print : typing .Optional [str ] = None ,
738+ begin_date_print : typing .Optional [str ] = None ,
739+ end_date_print : typing .Optional [str ] = None ,
726740 print_interval : typing .Optional [int ] = None
727741 ) -> None :
728742 '''
729743 Set begin and end year for the simulation, the warm-up period, and toggles the elements in print.prt file
730744 '''
731745
732- # Ensure both begin and end dates are provided together
733- if (begin_date is None ) != (end_date is None ):
734- raise ValueError (
735- "Both 'begin_date' and 'end_date' must be provided together, "
736- f"got begin_date={ begin_date } , end_date={ end_date } "
737- )
746+ validators ._ensure_together (begin_date = begin_date , end_date = end_date )
747+ validators ._ensure_together (begin_date_print = begin_date_print , end_date_print = end_date_print )
738748
739- if start_date_print is not None and (begin_date is None or end_date is None ):
749+ # Validate dependencies between simulation and print periods
750+ if (begin_date_print or end_date_print ) and not (begin_date and end_date ):
740751 raise ValueError (
741- "'start_date_print' cannot be set unless both 'begin_date' and 'end_date' are also provided. "
742- f"got start_date_print= { start_date_print } , begin_date= { begin_date } , end_date= { end_date } "
752+ "'begin_date_print'/'end_date_print' cannot be set unless "
753+ "' begin_date' and ' end_date' are also provided. "
743754 )
744755
745756 # Validate date relationships
746- if start_date_print is not None and begin_date is not None and end_date is not None :
757+ if begin_date_print and end_date_print and begin_date and end_date :
747758 begin_dt = utils ._date_str_to_object (begin_date )
748759 end_dt = utils ._date_str_to_object (end_date )
749- start_print_dt = utils ._date_str_to_object (start_date_print )
760+ start_print_dt = utils ._date_str_to_object (begin_date_print )
761+ end_print_dt = utils ._date_str_to_object (end_date_print )
750762
751763 validators ._date_within_range (
752764 date_to_check = start_print_dt ,
753765 begin_date = begin_dt ,
754766 end_date = end_dt
755767 )
768+ validators ._date_within_range (
769+ date_to_check = end_print_dt ,
770+ begin_date = begin_dt ,
771+ end_date = end_dt
772+ )
756773
757774 # Set simulation range time
758- if begin_date is not None and end_date is not None :
775+ if begin_date and end_date :
759776 self .set_simulation_period (
760777 begin_date = begin_date ,
761778 end_date = end_date
@@ -809,9 +826,10 @@ def _apply_swat_configuration(
809826 ** key_dict
810827 )
811828
812- if start_date_print is not None :
813- self .set_start_date_print (
814- start_date = start_date_print
829+ if begin_date_print and end_date_print :
830+ self .set_print_period (
831+ begin_date = begin_date_print ,
832+ end_date = end_date_print
815833 )
816834
817835 if print_interval is not None :
@@ -871,7 +889,8 @@ def run_swat(
871889 simulation_timestep : typing .Optional [int ] = None ,
872890 warmup : typing .Optional [int ] = None ,
873891 print_prt_control : typing .Optional [dict [str , dict [str , bool ]]] = None ,
874- start_date_print : typing .Optional [str ] = None ,
892+ begin_date_print : typing .Optional [str ] = None ,
893+ end_date_print : typing .Optional [str ] = None ,
875894 print_interval : typing .Optional [int ] = None ,
876895 skip_validation : bool = False
877896 ) -> pathlib .Path :
@@ -947,7 +966,9 @@ def run_swat(
947966 }
948967 ```
949968
950- start_date_print (str): Number of years at the beginning of the simulation to not print output
969+ begin_date_print (str): The start date for printing the output
970+
971+ end_date_print (str): The end date for printing the output
951972
952973 print_interval (int): Print interval within the period. For example, if interval = 2, output will be printed for every other day.
953974
@@ -993,7 +1014,8 @@ def run_swat(
9931014 simulation_timestep = simulation_timestep ,
9941015 warmup = warmup ,
9951016 print_prt_control = print_prt_control ,
996- start_date_print = start_date_print ,
1017+ begin_date_print = begin_date_print ,
1018+ end_date_print = end_date_print ,
9971019 print_interval = print_interval
9981020 )
9991021
0 commit comments