I have a large chunk of code that saves an image sequence, including some fancy items like a precise image width/height and viewpoint (i.e. going 'full screen') and two optional mattes - one for a label and one for a colour bar. Since beta2 the saving does not work correctly anymore, like (with the delay activated prior to saving, see below):
Windows 8.1
1st saved image contains 1st frame of sequence
2nd saved image contains 1st frame of sequence
3rd saved image contains 2nd frame of seuqnece
...
Windows 7
1st saved image contains last frame of sequence
2nd saved image contains 1st frame of sequence
3rd saved image contains 2nd frame of seuqnece
...
I.e., irrespective of the Windows version, the 1st image is wrong and the successive images lag by one time slot. The lag is a serious problem when I include the slot time in the label matte (what I usualy do!).
Find below the code reduced to those lines that reproduce the irregularities. Under Windows 7 I have tested it both in beta2 and beta1. It works fine in beta1!
You will note an outcommented delay in the code prior to the start of image saving. In beta2 with the delay activated you get what is reported above. In beta2 with the delay de-activated the first image is empty in both Window7 and 8.1, while in beta1 and Windows 7 the sequence is saved correctly (not tested with Windows 8.1). Looks like, since beta2, there is a lack of synchronisation between my code and the underlying machinery.
cheers, HP
Code: Select all
def t(relPath):
# derive absolute save path
homeDir=os.path.expanduser('~') # OS-independent root of save path
imPath=homeDir+relPath
# if path does not exist, create it
if not os.path.exists(imPath):
os.makedirs(imPath)
print "image(s) saved in: ",imPath
# get display controls
imDisplay=activeDisplay()
# get parameters of image sequence
imAnim=imDisplay.getAnimation()
imTimes=imAnim.getTimes()
imSteps=imAnim.getNumSteps()
# start saving from beginning of sequence
imAnim.setCurrent(0)
# not needed before beta2
# time.sleep(5)
# go through sequence and save frames
for image in range(imSteps):
idx=imAnim.getCurrent()
strTime=str(imTimes[image]) # compose date-time string for filename
HH,mm,SS=imTimes[image].timeString().split(":")
yyyy,MM,dd=imTimes[image].dateString().split("-")
dString=yyyy+MM+dd+HH+mm
fileName=imPath+dString+".png"
print idx,' ',fileName
writeImageAtIndex(fileName,idx)
# imDisplay.captureImage(fileName)
imAnim.takeStep() # step on
return
def writeImageAtIndex(fname, idx, params='', quality=1.0):
"""Captures a particular animation step from the active display.
Args:
fname: Filename for the captured image.
idx: Zero-based index of the desired animation step.
params: IDV ISL directives. Default value is "".
quality: Image quality (for formats like JPEG). Values may be
between 0.0 and 1.0. Default value is 1.0.
Returns:
Nothing.
"""
from ucar.unidata.idv.ui import ImageGenerator
isl = ImageGenerator.makeXmlFromString(params)
xml = '<image file="%s" animation_index="%s" quality="%s">%s</image>' % \
(fname, idx, quality, isl)
elem = islInterpreter.makeElement(xml)
macros = islInterpreter.applyMacros(fname)
islInterpreter.captureImage(macros, elem)