Is there anything already coded in McIDAS-V which performs date conversions easily? I am looking for something like DATELIST (from McIDAS-X), which when entered at the command line, the current day would be returned in CCYYDDD and day full_month_name year and YYYY/MM/DD formats. Also, a date could be entered to get the julian date returned or a date offset from the current date.
Joleen
date conversions
Re: date conversions
Hi Joleen,
I'm told that there's no way to list different date formats (like the McIDAS-X command DATELIST). But there is a User Preference that lets you change the date format that appears in McV output (e.g., the layer label when you display an image). It's described here:
http://www.ssec.wisc.edu/mcidas/doc/mcv ... ences.html
Does that help?
Barry
I'm told that there's no way to list different date formats (like the McIDAS-X command DATELIST). But there is a User Preference that lets you change the date format that appears in McV output (e.g., the layer label when you display an image). It's described here:
http://www.ssec.wisc.edu/mcidas/doc/mcv ... ences.html
Does that help?
Barry
Re: date conversions
Hi Joleen -
If you don't know. You may override whatever is specified in the Preferences wherever you can use the %timestamp%. E.g. when saving time sequence of frames with View>Capture>Movie... I specify in the Filename Template: %time:yyyyMMddHHmm% in order to get compact filenames while I am using the %timestamp% macro as specified through Preferences (in my case "yyyy-MM-dd HH:mmz") for more readable layer labels.
HP
If you don't know. You may override whatever is specified in the Preferences wherever you can use the %timestamp%. E.g. when saving time sequence of frames with View>Capture>Movie... I specify in the Filename Template: %time:yyyyMMddHHmm% in order to get compact filenames while I am using the %timestamp% macro as specified through Preferences (in my case "yyyy-MM-dd HH:mmz") for more readable layer labels.
HP
Re: date conversions
Actually, because there is the conversion option in the User Preferences and the conversion is also handled when pulling data from the archive that I thought there might be something already hidden within McIDAS-V that is similar.
Joleen
Joleen
Re: date conversions
You can most easily use the Calendar class from Java...here's a little Jython:
>>> from java.util import Calendar
>>> cal = Calendar.getInstance()
>>> cal.set(2011,1,24)
>>> print cal.get(Calendar.DAY_OF_YEAR)
55
Note that months are Jan=0, Feb=1,...
>>> from java.util import Calendar
>>> cal = Calendar.getInstance()
>>> cal.set(2011,1,24)
>>> print cal.get(Calendar.DAY_OF_YEAR)
55
Note that months are Jan=0, Feb=1,...
Re: date conversions
Great! This is what I was looking for!
Joleen
Joleen
Re: date conversions
Attached is a version of datelist which replicates the McIDAS-X DATELIST functionality. Please post comments or concerns. Place this in the user McIDAS-V jython library and use in the jython shell. This will function in a similar to the McIDAS command line datelist. It should be fairly easy to use in a script. See documentation for further help.
Thank-you to Jonathan and Tom W. for the advice/help.
This is a note for me as well as new users: the help prints nicely with "print datelist.__doc__" It gets a little jumbled using dumpObj(datelist)
Joleen
Thank-you to Jonathan and Tom W. for the advice/help.
This is a note for me as well as new users: the help prints nicely with "print datelist.__doc__" It gets a little jumbled using dumpObj(datelist)
Joleen
- Attachments
-
- datelist.txt
- (6.37 KiB) Downloaded 449 times
Re: date conversions
Small change to the code.
The lines
# Force the user to enter year, jday and day as integers.
year, jday, day=int(year), int(jday), int(day)
should include the "inc" variable as well...
# Force the user to enter year, jday and day as integers.
year, jday, day, inc=int(year), int(jday), int(day), int(inc)
The lines
# Force the user to enter year, jday and day as integers.
year, jday, day=int(year), int(jday), int(day)
should include the "inc" variable as well...
# Force the user to enter year, jday and day as integers.
year, jday, day, inc=int(year), int(jday), int(day), int(inc)
Re: date conversions
Another request was made so that when a user enters a julian day which exceeds the number of days in the year, an error is issued. A valid date will still be returned.
In addition, if the user just wants the date printed immediately, I suggest a wrapper which calls datelist and prints the date.
In addition, if the user just wants the date printed immediately, I suggest a wrapper which calls datelist and prints the date.
Code: Select all
def pd(year=-1, month=-1, day=-1, jday=-1, inc=0, form=["default"]):
jd, status=datelist(year=-1, month=-1, day=-1, jday=-1, inc=0, form=["default"])
print jd
Re: date conversions
Update: "from types import *" line in datelist.py. That line should be removed. It is not necessary to make the type checking work correctly that import actually seems to fail when McV loads the datelist method.
Joleen
Joleen