One the great enhancements that PyFerret offers to Ferret is updated graphics, with the ability to directly create produce publication quality images. As with traditional Ferret, there is the option of whether you want the images displayed (for interactive work) or if you just want the images to be created and saved to file (when running scripts). By default, PyFerret will produce high-quality displayed images that can be saved for use in documents and publications. But there is also a draft-quality mode that may display images faster and is required for proper on-the-fly animation. While images can be saved in any of the supported formats using the Ferret command FRAME /FILE=(filename) /FORMAT=(format), the interactive display applications have a menu item for saving images. The display applications also have a menu item allowing you to scale the displayed image, and scroll bars appear if the image exceeds the size of the display window.
The graphics quality of displayed windows is controlled with the value of the /QUALITY= option when creating a new window using SET WINDOW.
Note: previous version of PyFerret had a SET GRAPHICS command. That command no longer exists and, instead, options to SET WINDOW are now used.
High-quality displayed images
By default, PyFerret creates high-quality displayed images. One can also specify /QUALITY=HIGH to ensure PyFerret is using high-quality displayed images. All the "drawing commands" are saved in memory, and the image is then rendered on your console or saved to file from these saved drawing commands. These images can be saved in vector image formats, such as PostScript, PDF (Portable Document Format), or SVG (Scalable Vector Graphics), or as raster images, such as PNG, after the image has been displayed. A high-quality (large) raster image can be obtained from an existing image just by scaling; thus avoiding the need to reset the Ferret window size and re-doing the Ferret drawing.
yes? ! do not worry about the plot size, just the aspect ratio
yes? ! the following is the default
yes? set window /quality=high /aspect=0.75:axis 1
yes? use coads_climatology
yes? shade /Y=65S:65N /T=15-MAR sst
yes? go land 1
yes? ! specify the desired height in inches of the PDF image
yes? frame /file="sst_highq.pdf" /yinches=4.5
yes? ! specify the desired height in pixels of the PNG image
yes? frame /file="sst_highq.png" /ypixels=2250
Draft-quality displayed images
To quickly display small images on your console, or to properly render on-the-fly animations, use the /QUALITY=DRAFT option of SET WINDOW. This option quickly creates a raster image in memory and then displays this image on your console. Smaller images display quickly (still not as quickly as Ferret using XGKS), although they may look rather ragged when examined closely. Larger images will be of higher quality; however, they will take longer to display, especially on remote terminals. These images can only be saved in raster image formats, such as PNG (Portable Network Graphics) and do not scale very cleanly.
Here is a Ferret session in PyFerret where we explicitly set draft-quality graphics and create an on-the-fly animation of the sea surface temperature:
yes? use coads_climatology
yes? set window /quality=draft 1
yes? repeat /L=1:12 /loop=5 /animate shade /Y=65S:65N sst
Creating images without displaying them
If you just want to creating images without displaying them, you use the command-line option -nodisplay (or one of equivalent Ferret command-line options -unmapped or -gif). With this option, all the "drawing commands" are saved to memory without displaying any graphics windows. These graphics commands are then used when you save the image to file. This is the fastest way to create an image from PyFerret (although, again, it is still somewhat slower than Ferret using XGKS). Images can be saved at any time in vector image formats (such as PostScript, PDF, or SVG) or in the PNG raster image format.
$ pyferret -nodisplay
yes? use coads_climatology
yes? shade /Y=65S:65N /T=15-MAR sst
yes? go land 1
yes? ! specify the desired height in inches of the PDF image
yes? frame /file="sst_nodisplay.pdf" /yinches=4.5
yes? ! specify the desired height in pixels of the PNG image
yes? frame /file="sst_nodisplay.png" /ypixels=2250
yes? quit
$
Anti-aliasing
Anti-aliasing is a technique used to improve the appearance of images by altering displayed (or printed) pixels so edges smoother. Creating an image with anti-aliasing does take somewhat longer than creating an image without anti-aliasing, so again there is a trade-off between performance and appearance. By default, high-quality and -nodisplay graphics perform anti-aliasing (since one usually wants the best-looking image in these case), but draft graphics does not (since one usually wants the fastest-generated image in this case). You can add either the /ANTIALIAS or /NOANTIALIAS option to the SET WINDOW command to turn anti-aliasing on and off.
Transparency in PyFerret images
For image formats that support transparency (such and PNG), one can save images with a transparent background using the /TRANSPARENT option to the FRAME /FILE=filename command. Unlike traditional Ferret, which converts the white background to transparent, PyFerret starts with a transparent background and draws all the elements on that background. Thus lines and other items drawn in white will remain white in an image saved with a transparent background. Another option is to specify the /COLOR or the /OPACITY option of SET WINDOW to set the background color or opacity. The color specified can include an opacity ("alpha") value.
Hiding, minimizing, and killing the display window
The display windows in PyFerret are designed to be created and destroyed by Ferret. If you close the window using the mouse (select what is typically an 'X' button in the window frame), you are actually only hiding the window. When something new is drawn to this window, the window will reappear.
To "hide" the window until a later time at your choosing, minimize the window instead (select what is typically the '_' or '–' button in the window frame). The window will remain minimized until you choose to show the window again. When a display window is minimized, updates to the displayed content from any drawing in progress will be postponed (or ignored) until the window is displayed again.
If something goes terribly wrong in PyFerret (such as a crash) where a display window remains open when it should have been closed, there is an Exit menu item under the Help menu which will actually shut down the display application. Normally you should never need to do this; thus, the reason Exit is in the unusual location. Exiting the display application in this way does not inform Ferret of this change, and can cause a crash if Ferret is still working properly.