Hi HP -
I added the following lines to your function before your "for loop":
Code: Select all
# calculating second time to pass through loadADDEImage
# this is necesary so a range can be used, since the user may
# not enter an exact time of the image down to the second. This
# is done using timedelta, which is part of datetime, but not
# VisAD.DateTime. First, we create an actual datetime object
# using timeFirstImage which is a variable passed through the
# function, then apply a timedelta of 1 minute.
from datetime import datetime as DT
first_dt = DT.strptime(timeFirstImage, "%Y-%m-%d %H:%M:%SUTC")
second_dt = first_dt +datetime.timedelta(seconds=60)
# second_dt includes yyyy-mm-dd which we want to remove so we only
# have hh:mm:ss. To do this, I'll change the second_dt datetime
# object to a string and remove the first 11 characters
second_dt_str = str(second_dt)[11:]
And I modified your bandData=loadADDEImage line to:
Code: Select all
bandData=loadADDEImage(day=dayString,
time=(timeString,second_dt_str),**addeParams)
... note that I changed the time= part to set the second time to second_dt_str
The majority of the code above are comments, but there's a summary:
- loadADDEImage accepts a time range. To get things working, I decided that passing a time range of one minute though loadADDEImage would cover this case where the seconds weren't correct.
- I found that you can create a datetime timedelta object (through some Google searching). To utilize this, I first created a datetime object from the timeFirstImage string that the user passes through the function by using datetime/strptime. I then used datetime.timedelta to add 60 seconds to this time, which I defined as second_dt.
- At this point, second_dt includes yyyy-mm-dd, which can't be included in the time= keyword of loadADDEImage. I'm sure there are ways that you can re-format this datetime object to remove the yyyy-mm-dd, but I just converted it to a string and chopped off the first 11 characters and defined it as second_dt_str. After this, the string is in the format of "HH:mm:ss".
- I utilized this second_dt_str object by including it in the loadADDEImage command, setting it as the second value passed through time=
With these changes, I'm able to run the following line from the Jython Shell. This would have errored before in the past, since the actual time of the image is 12:00:35, not 12:00:00:
Code: Select all
sequence_sBand('2017-09-06 12:00:00UTC',1,900,'geoarc.ssec.wisc.edu','AGOES16','FD',14,'TEMP',(19.9,-66.7),(2500,3100),(1,1))
If you want to, you could customize this further by adding a new keyword to your sequence_sBand() function where a user could include this timedelta value instead of hard-coding it to 60 seconds inside the function. loadADDEImage will search the server for all times in the dataset between the times passed through the function and return the most recent one. For example, if you ran a loadADDEImage call where you have time=('12:00:O00','14:00:00') pointing towards 1-minute GOES-16 mesoscale data, the 13:59:54 time is returned.
Another scenario I'm considering is if you specify a time very close to the changing of a day (for example, '23:59:40'). At this point, you would want to modify your loadADDEImage command further by setting day= to be a range as well. This is because the timedelta of one minute would change to a different date. For example, you could pull the day of the second_dt_str using:
And then modify your loadADDEImage command to:
Code: Select all
bandData=loadADDEImage(day=(dayString,second_day),
time=(timeString,second_dt_str),**addeParams)
If you give this a try and it doesn't work, or if you have any questions, please let me know.
Thanks -
Bob