-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PyFerret graphics output (PDF, PS, PNG) #1439
Comments
Comment by @karlmsmith on 3 Jul 2014 04:07 UTC So displayed and -nodisplay for PDFs are nearly identical in graphics display. For (3), the sizes had been tweaked to make the default page size 10.5" x 8.5" to fit on a letter-size page. I could reset these so the defaults match that of traditional Ferret (10.8" x 8.8" I think) if that is desirable. Since the user can specify the final size and pyferret will scale the image, seems like a reasonable think to do for consistency. For (4) and (5), the files from displayed images are produced by the Qt graphics software, whereas the files from -nodisplay images are produced by Cairo graphics software. So there is little hope in the underlying contents of images files being nearly the same; there is even differences between versions of Cairo (RHEL5 uses Cairo v1.2 and RHEL6 uses Cario v1.8, the latter does better compression than the former). The fuzziness in -nodisplay PNG plots had been noticed before and some effort was made to resolve the problem (which resulted in the change of behavior of set win /size). The reason is Qt does a better job with anti-aliasing than Cairo. If one makes a larger plot with proportionally thicker lines (e.g., set win /xinch=20 /thick=2) and then save as the regular size image (e.g., frame /xinch=10) then sharper image are obtained with -nodisplay. But sometimes this can makes lines too "sharp", so not sure whether to try to do any of this automatically. It does appear the PNG line thickness appears to be thicker than that of the PDFs. Appears to be more than just from antialiasing differences. So may need some tweaking of the default line thickness, at least with PNG plots, may be needed. Given that the page is now always "shrink-wrapped" to the image, I do wonder how important is supporting positioning, orientation, and additional margins; e.g., Office programs do a much better job for positioning an image within a larger document. |
Comment by @AndrewWittenberg on 4 Jul 2014 00:29 UTC With (4), the display & nodisplay graphics look very similar in size now within PyFerret, at least for PS and PDF graphics. But for PNG for some reason, the default sizes are different (with nodisplay a bit smaller) -- could this difference be eliminated? It almost looks like the Cairo (nodisplay) graphics draw an outline around each grid cell of a SHADE, so that the cells expand slightly (relative to Qt/display) into data-void regions like land. In data-rich regions (like the middle of the Pacific), these outlines overlap each other, and the order in which they're drawn results in us seeing only the bottom-left part of each cell outline so that each cell appears to shift downward & to the left as we go from a Qt PDF to a Cairo PDF. (E.g. switching back & forth in acroread, using Ctrl-Tab.) It seems that the Cairo (nodisplay) graphics are better in at least one sense, namely at the interfaces between grid cells of a SHADE. With Qt (display) I see the familiar blending-toward-background problem (which in the case of a white background, lightens up the interfaces between cells, making a "grid" appear in the plot). This is familiar from vanilla Ferret. The Cairo (nodisplay) graphics don't have that problem at all. Is this related to the antialiasing differences that you mentioned? Regarding (5), it'd still be very helpful to have the page-layout syntax that I described. You're right that Office would be great for manipulating a single figure; but we need to think about our automated figure generation, which creates thousands of figures. We want to be able to print any one of these PS or PDF figures at will, on letter paper, and have things looking nice, without the graphic sitting way up in one corner of the page. If you can think of a postprocessing tool (psutils?) outside of Ferret that would do all this in a scriptable way, that'd be fine too. |
Comment by @karlmsmith on 14 Jul 2014 20:29 UTC For Qt/display, since the cosmetic pen is a Qt term, Qt understands this cosmetic line concept and handles it for me. But this also means I am not sure what width is used for PDFs. For Cairo/nodisplay, there is no such cosmetic pen concept, so I draw it one pixel wide. With my pretend resolution of 96 DPI, this ends up being 72/96 (0.75) of a point wide for PDFs. But this is definitely thicker than what Qt uses for PDF. I can switch to not using the cosmetic pen in Qt and instead specify the width directly. But it sounds like I need to make the width thinner that it is with Cairo to minimize the shift due to order-of-drawing and still cover the gaps between rectangles/polygons. For external tools to manipulate PDF and/or PS.... pdftops can be used to center a PDF on a page of any size desired (and convert back to PDF with ps2pdf)
pstops can be inserted for finer manipulation
The pdftops command makes a PS on my desired final page size (letter sized) but with -nocenter leaves it at the bottom left corner - PS coordinates (0,0). The pstops command then moves it 1.25" to the right and 5.75" up to give the 6"x4" image on a letter-sized page with a 1.25" left, right, and top margins. The pstops command can also be used to rotate and scale the image. If I get multi-page output into PyFerret, then multiple images could also be combined onto one page. |
Comment by @AndrewWittenberg on 2 Aug 2014 00:22 UTC By default the script will center and auto-rotate the figure to best fit an 8.5" wide x 11" tall page, setting the BoundingBox and PageOrientation so that it will display properly (upright and cropped) in GhostView. That way the PostScript file can be printed directly, without it sitting way up in one corner of the printed page. Additional arguments are provided to (a) expand/shrink the figure to the full page (minus a specified minimum margin); (b) specify the rotation explicitly; (c) specify the page dimensions explicitly; and (d) specify the exact size of the figure on the page. This script enables PyFerret to reproduce the output of vanilla Ferret very closely, at least in "display" mode (Qt4 graphics). So if it's not too much work, I'd suggest incorporating all of these features into the syntax of the FRAME command. There are still a number of problems with the "nodisplay" (Cairo) graphics, as I'll point out in the next comment. Comments? Suggestions?
|
Comment by @AndrewWittenberg on 2 Aug 2014 01:01 UTC In the new output tree, there's a now a much closer match between the Ferret and PyFerret graphics, mostly resolving issues (1)-(3) above. But issues (4) and (5) remain. One remaining graphics difference between versions (comparing ferret/display/ against pyferret/display/) is that they appear to have slightly different aspect ratios for the plot region, perhaps due to different margins around the graphics. Can we eliminate those differences? In vanilla Ferret the nodisplay graphics were bitwise identical to the displayed versions. But in PyFerret, the nodisplay (Cairo) graphics are much different (and seemingly worse) than the displayed (Qt4) versions. The Cairo graphics produce vastly bigger PostScript files (by up to a factor of 30!) than vanilla Ferret, such that even a simple plot like the one in my example becomes a 10Mb file. Very slow to produce, and slow to open and view. Looking inside the PostScript files, the Cairo output has loads and loads of repeated phrases -- not sure what these are. For some reason, the Cairo graphics also get rasterized in the PostScript output, and have darker lines. And for an unknown reason, the pyferret/*/asp_0.77/plot.ps gets rotated on its side compared to the Qt4 result (really puzzling, since the asp_0.3 case looks ok). The PNG output also differs between Cairo and Qt4; the Cairo output has smaller pixel dimensions. How can that be, when XPIXEL/YPIXEL are set the same in the two cases? |
Comment by @karlmsmith on 25 Sep 2014 22:37 UTC Removed setting a fallback resolution in vector graphics files so that (hopefully) it will never put raster images into vector files. This might have just been a "just in case" image that was never really used and should not have been in there. But takes up space and we don't need it. Found a bug (hopefully fixed now) in no-display saving of PostScript where the image scaling was not being performed when a landscape image was rotated for saving. Will build and test on RHEL6 machines at PMEL and GFDL. |
Comment by @AndrewWittenberg on 1 Oct 2014 23:13 UTC Closing this ticket, and moving remaining Cairo (nodisplay) graphics issues to ticket #2202. |
Attachment from @AndrewWittenberg on 8 Apr 2014 22:38 UTC |
Attachment from @AndrewWittenberg on 2 Aug 2014 01:02 UTC |
Reported by @AndrewWittenberg on 8 Apr 2014 22:36 UTC
This report crystallizes some graphics issues previously described in #2086 and #2007. This is the main thing preventing our transition to PyFerret at GFDL, and so is at the very top of our priority list.
I'll attempt to attach a gzipped tar file of the full demo, and if that doesn't work, I'll email it to you separately.
In your working directory, save the attached scripts as:
Now "cd" into the ferret subdirectory and run the "mytest.csh"; then repeat for the pyferret subdirectory. This should produce a tree of figures:
For backward compatibility, we'd like to be able to reproduce all the graphics in the ferret/ directory -- as closely as possible in dimensions, alignment, orientation.
First off, you'll note that the graphics generation syntax & pipeline are VASTLY simpler in PyFerret -- yay!
But there are a number of critical remaining issues:
The "pyferret -nodisplay" output for PDF is "shrink-wrapped" about the figure, which may usually (but not always) be preferable to expanding the margins to a letter-sized page.
In cases where the PyFerret graphics don't run off the page, there are still differences of plot sizes and margins, and colorbar widths, between vanilla Ferret and PyFerret. Can these differences be minimized?
In vanilla Ferret, graphics produced with or without a display were bitwise-identical, or very nearly so. Not the case yet in PyFerret. While these display/nodisplay differences are fairly minor in PyFerret (i.e. less than 15%), it'd be good to minimize them if it's not too difficult. In addition, the PNGs produced by "pyferret" with a display are somehow clearer than those produced by "pyferret -nodisplay", which are a bit fuzzy. Why?
The vector (PS, PDF) files produced by "pyferret" are twice the size of those produced by either "pyferret -nodisplay" or vanilla Ferret. Why?
To address (1) & (2), it'd help to have a way to rotate, resize-to-fit, and center a graphic (with dimensions xinch,yinch) on a given output page (with dimensions pxinch,pyinch):
where
The XALIGN,YALIGN values would be mirror those used to align text labels in Ferret.
Migrated-From: http://dunkel.pmel.noaa.gov/trac/ferret/ticket/2167
The text was updated successfully, but these errors were encountered: