opendrift
opendrift copied to clipboard
Time step must be negative if duration is negative.
Discussed in https://github.com/OpenDrift/opendrift/discussions/762
Originally posted by camines November 9, 2021 Hello to all,
I'm trying to run the model with some forcings that I have on a Flash Drive. All run good, until I'm initializing with o.run().
I was using by first an other o.run() configuration, but with even the simpler it just show me a bug.
`ValueError Traceback (most recent call last)
~/opendrift/opendrift/models/basemodel.py in run(self, time_step, steps, time_step_output, duration, end_time, outfile, export_variables, export_buffer_length, stop_on_error) 2228 2229 if np.sign(duration.total_seconds()) * np.sign(time_step.total_seconds()) < 0: -> 2230 raise ValueError("Time step must be negative if duration is negative.") 2231 2232 self.expected_steps_output = duration.total_seconds() / \
ValueError: Time step must be negative if duration is negative. `
Here is how Im seeding :
o.seed_cone(lon=[-74, -75], lat=[11.5, 12], number=10000, radius=[0, 2000], time=[reader_curr_2010_2015.start_time, reader_curr_2010_2015.start_time+timedelta(days=30)])
Can someone give me a hint!!!
Thanks
from opendrift.models.plastdrift import PlastDrift #Here the code is loaded
from opendrift.readers import reader_netCDF_CF_generic #Here the readers are loaded
from opendrift.readers import reader_global_landmask #Here the reader for the mask, as basic
from datetime import datetime, timedelta
o = PlastDrift(loglevel=50)
#Land model
reader_landmask = reader_global_landmask.Reader(extent=[-90, 5, -57, 25]) # lonmin, latmin, lonmax, latmax
#currents model
reader_curr_2020 = reader_netCDF_CF_generic.Reader('/media/u301568/F0E9-334E/Forcings/global-analysis-forecast-phy-001-024_1634651494113.nc')
reader_curr_2010_2015 = reader_netCDF_CF_generic.Reader('/media/u301568/F0E9-334E/Forcings/global-reanalysis-phy-001-030-daily_1635261042077.nc')
reader_curr_2015_2019 = reader_netCDF_CF_generic.Reader('/home/zmaw/u301568/Downloads/global-reanalysis-phy-001-030-daily_1635262883527.nc')
#wind model
reader_wind = reader_netCDF_CF_generic.Reader('/media/u301568/F0E9-334E/Forcings/KNMI-GLO-WIND_L3-REP-OBS_METOP-A_ASCAT_12_DES_1635154734614.nc')
#Waves model
reader_wave_2020 = reader_netCDF_CF_generic.Reader('/media/u301568/F0E9-334E/Forcings/global-analysis-forecast-wav-001-027_1635159054594.nc')
reader_wave_2010_2019 = reader_netCDF_CF_generic.Reader('/media/u301568/F0E9-334E/Forcings/global-reanalysis-wav-001-032_1635158237589.nc')
o.add_reader([reader_landmask, reader_curr_2020, reader_wind, reader_wave_2020, reader_wave_2010_2019, reader_curr_2010_2015, reader_curr_2015_2019])
#Here to make a line of elements
o.seed_cone(lon=[-74, -75], lat=[11.5, 12], number=10000, radius=[0, 2000],
time=[reader_curr_2010_2015.start_time, reader_curr_2010_2015.start_time+timedelta(days=30)])
o.set_config('drift:advection_scheme', 'runge-kutta')
#Elements drift with 2% of wind speed, aditional from current. Apparently doesent work in PlastDrift
o.set_config('seed:wind_drift_factor', .02)
#stranding
o.set_config('general:coastline_action', 'stranding')
o.run(outfile='PlastDrift3.nc', time_step= 3600, time_step_output=3600*6)
@camines I moved your question from the "discussion" section to this issue.
I recommend always using loglevel=0 to see what is going on.
Then you will see that you forgot to provide the duration of the simulation, which can be done e.g. like this
o.run(outfile='PlastDrift3.nc', time_step=3600, time_step_output=3600*6, duration=timedelta(hours=24))
Thanks for your answers.
I´m trying to run the model from the beggining to the end of the readers (10 years, seeding every month). Until now I had no problem running Opendrift, but its my first time using long forcing data downloaded from Copernicus.
With the loglevel=0, I realize that one of my readers is not in the time range I want, so this tip helped me a lot.
Ill keep trying, and if I find some issue, Ill come back here
Thanks a lot your fast reply