vcs icon indicating copy to clipboard operation
vcs copied to clipboard

vector plot magnitude broken?

Open doutriaux1 opened this issue 6 years ago • 22 comments

I am using CDAT 8.0 to create plots using vcs. I'm facing two major problems while plotting.

1).On plotting a vector plot using vcs, I am not able to set the reference value of the vector in the plot. I am using the following steps to create vector. myvec = x.createvector('myvec') myvec.scale = 1 myvec.reference = 300 The plot does not show the reference value to be 300 and picks up a random number. I have tried changing the scale value also where the value changes but still shows a random number in the plot. I am attaching a plot where on bottom left corner of each plot the value of vector is provided (555.5, 266.9,496.1) while my reference value is set to 300. My question is, how is this resultant value of vector calculated and how is it controlled. As per my understanding, this number is related to setting of the reference value or scale. Please advice on what and where I am going wrong in my understanding.

2). On saving any plot created through vcs, the PDF and postscript files are getting corrupted. I am only able to save a .png file where the quality of the plot is not very good. On saving in any other format, it takes very long to create the file (almost 10 minutes) and the file looks funny with all lines formed all over the plot. Please let me know why and how to resolve this problem.

I am attaching 1 plot (.ps format) showing both the above issues mentioned. Please let me know how to solve these issues and get the desired plot.

Thanking you in advance.

doutriaux1 avatar Feb 11 '19 15:02 doutriaux1

Thanks @doutriaux1, I'll take a look.

ping @danlipsa @aashish24

scottwittenburg avatar Feb 11 '19 15:02 scottwittenburg

@doutriaux1 Maybe I'm just missing them? I don't see any attachments.

scottwittenburg avatar Feb 12 '19 03:02 scottwittenburg

Hi @scottwittenburg , Im attaching the plot here. There are extra lines on the plot and the vector values are different for each plot. faulty

roshni1991 avatar Feb 12 '19 07:02 roshni1991

@aashish24 I think you introduced option on magnitude a while back, can you comment on this?

https://github.com/CDAT/vcs/blob/master/vcs/vector.py#L63

doutriaux1 avatar Feb 12 '19 14:02 doutriaux1

@aashish24 I meant these options: https://github.com/CDAT/vcs/blob/master/vcs/vector.py#L342

doutriaux1 avatar Feb 12 '19 14:02 doutriaux1

@aashish24 and somewhere there: https://github.com/CDAT/vcs/blob/master/vcs/vcsvtk/vectorpipeline.py#L123-L126

@aashish24 we need to add these to the doc string i think.

doutriaux1 avatar Feb 12 '19 14:02 doutriaux1

In order to reproduce the issue with vector export taking so long, will it be possible for you to share the vcs script and associated data with us, @roshni1991? Otherwise, it may require more time just to get to where we can see the same problem you are seeing. Have you experienced this problem @doutriaux1? Do you know a reliable reproducer for the long export time?

scottwittenburg avatar Feb 12 '19 21:02 scottwittenburg

And @roshni1991 I just want to be clear about the purpose of the reference attribute. If you set it, for example, to 300, then you expect the number 300 to be printed in the legend, and the arrow to be as long as required to make that true?

scottwittenburg avatar Feb 13 '19 00:02 scottwittenburg

Hi @scottwittenburg, as per my understanding the reference attribute is used for the purpose you have mentioned but it is not true when I use it to plot. I want the number 300 for example to be printed in the legend. I tried changing the vector scaleoption @aashish24. The value is still not 300. Also, to understand the problem I have attached a folder with test.py file and related figures. test.zip

roshni1991 avatar Feb 13 '19 12:02 roshni1991

@roshni1991 thx for the feedback, you are right the behaviour is indeed broken, we just needed to confirm with you that it was the expected behaviour.

doutriaux1 avatar Feb 13 '19 13:02 doutriaux1

@roshni1991 we expect to fix this shortly, thx for spotting it.

doutriaux1 avatar Feb 13 '19 13:02 doutriaux1

Thanks for the pdf/ps reproduction script @roshni1991, however, I'm currently unable to reproduce the issue you're having. I am running into some other problem though, so I'm curious what version of vcs you're using when you have the export problems? If you're in a terminal where the conda environment is activated, run the command below. If you can report back the results, I think that would be helpful. Thanks!

$ conda list | grep vtk-cdat
# packages in environment at /data/scott/Documents/miniconda2/envs/vtk-cdat-py3-debug:
vtk-cdat                  8.2.0.rc2.289.8.0.2019.01.16.12.48.g14c0bb6  py36h413fb2d_0    cdat/label/nightly

scottwittenburg avatar Feb 14 '19 20:02 scottwittenburg

@scottwittenburg Im using the following version of vcs: vtk-cdat 8.0.1.8.0 py27_mesalib_1 [mesalib] cdat Hope this helps!

roshni1991 avatar Feb 15 '19 08:02 roshni1991

Thanks for that version information @roshni1991.

@danlipsa @doutriaux1 Do either of you recognize the version numbers well enough to know whether that vtk-cdat listed above is from before the Context2D merge or after? Either way, it looks to be several versions back from whatever was installed in my environment.

Anyway, I finally figured out what was happening on my system locally when I tried the repro script uploaded above. The issue I saw was that no pdf was generated at all, but a bunch of error messages were printed to the terminal, looking like this:

2019-02-18 16:47:03.682 (   6.118s) [        D07A6700]     vtkPDFExporter.cxx:113    ERR| vtkPDFExporter (0x561e7962c080): LibHaru failed during PDF export. Error=0x105d detail=0
2019-02-18 16:47:03.685 (   6.121s) [        D07A6700]vtkPDFContextDevice2D.c:399   WARN| Error preparing libharu font object.
2019-02-18 16:47:03.685 (   6.121s) [        D07A6700]vtkPDFContextDevice2D.c:1324   ERR| vtkPDFContextDevice2D (0x561e794a0380): Error preparing to draw string: U
2019-02-18 16:47:03.896 (   6.333s) [        D07A6700]vtkPDFContextDevice2D.c:399   WARN| Error preparing libharu font object.
2019-02-18 16:47:03.896 (   6.333s) [        D07A6700]vtkPDFContextDevice2D.c:1324   ERR| vtkPDFContextDevice2D (0x561e794a0380): Error preparing to draw string: Zonal Wind
2019-02-18 16:47:03.896 (   6.333s) [        D07A6700]vtkPDFContextDevice2D.c:399   WARN| Error preparing libharu font object.
...

I looked up that first error code (0x105d) in the libharu documentation, and the corresponding problem given there is something like "This font cannot be embedded. (restricted by license)".

Stepping through with the debugger, it seems that because the test.py script sets text.font = 6 (in itself a rather mysterious incantation), that ends up pointing to the "AvantGarde-Book_Bold.ttf" font on my system. Glancing through the code that maps those numbers to fonts, however, indicated that I might get a different mapping than someone else, depending on what font files actually exist in the installed vcs egg. At any rate, I just removed that line setting the font number from the test script, and then I had no trouble exporting the plot to postscript and pdf. It seemed to take less than a second, rather than any number of minutes, and the results looked good to me (none of those lines through the title or anything).

So @roshni1991 I can think of a couple possibilities off the top of my head at this point: 1) you could try to install the latest vtk-cdat package and see if that fixes the issues you encountered, or 2) maybe the issue is related to having multiple plots on the same canvas, but the script you shared doesn't do that. Could you share the script you used to generate the three side-by-side plot image you attached above in this issue?

scottwittenburg avatar Feb 19 '19 00:02 scottwittenburg

@roshni1991 it seems the version of vtk-cdat you are using is the previous release, and your issues may be resolved by trying a more recent version. To create a test environment to try that out, you could try this:

conda create -n vtk-cdat-py2-test -c cdat/label/nightly -c conda-forge "python<3" vcs cdat cdms2

Once that is installed, activate that environment and try your pdf export example again.

scottwittenburg avatar Feb 19 '19 16:02 scottwittenburg

@scottwittenburg it lloks like it's a pre context2d version.

doutriaux1 avatar Feb 19 '19 17:02 doutriaux1

@doutriaux1 Yes I think so. I'll be curious to see if installing the latest nightly solves the pdf/ps export issue.

scottwittenburg avatar Feb 19 '19 17:02 scottwittenburg

@scottwittenburg I think you are right. I changed the font for the text text.font = 1 The plotting of pdf and postscript is taking a few seconds now(as compared to few minutes) and there are no strange lines over the text. I tried the test environment but the plots are different for postscript and pdf. Saving took even lesser time in the test environment. Also, if you look at the size of the plots created from the vcs environment in my computer and the test env, my env is creating heavier plots. Is this because the vcs is of older version? Im attaching a script where 5 plots can be created. I have also attached the plots from test and well as my environment.

test_5plots.zip

roshni1991 avatar Feb 21 '19 11:02 roshni1991

Hai, Is there any update on this issue, particularly saving as pdf / eps with a custom font ?. If I am using Helvetica local path font, then I am unable to save as pdf or postscript. How to resolve this issue.

$ conda list | grep vtk-cdat vtk-cdat 8.2.0rc2.8.1 py27h258435d_0 cdat/label/v81

Thanks.

arulalant avatar Apr 08 '20 19:04 arulalant

I don't think there has been any work done to resolve the issue, we were hoping that using the latest version (from after the context2d work was merged) would resolve it.

Perhaps if you share more details about what you're trying (the vcs code) and the specific problem you're seeing (error output), someone may recognize the problem or know of a workaround.

Hope this helps.

scottwittenburg avatar Apr 08 '20 19:04 scottwittenburg

I am loading Helvetica font as follows,

helvetica_font = os.path.join(fontdir, 'helvetica.ttf') v = vcs.init() v.addfont(helvetica_font, 'helvetica')

tt = v.createtexttable() tt.font = 'helvetica'

tlp = v.createtemplate() tlp.title.texttable = tt

v.plot(...) v.pdf('out.pdf')

I am getting the following error

ERROR: In ../IO/ExportPDF/vtkPDFContextDevice2D.cxx, line 1324 vtkPDFContextDevice2D (0x7fb273598c20): Error preparing to draw string: ECHAM6-3-LR

Generic Warning: In ../IO/ExportPDF/vtkPDFContextDevice2D.cxx, line 399 Error preparing libharu font object.

ERROR: In ../IO/ExportPDF/vtkPDFContextDevice2D.cxx, line 1324 vtkPDFContextDevice2D (0x7fb273598c20): Error preparing to draw string: MPI-M

Generic Warning: In ../IO/ExportPDF/vtkPDFContextDevice2D.cxx, line 399 Error preparing libharu font object.

Let me know if you want more information on this.

arulalant avatar Apr 08 '20 20:04 arulalant

Thanks for providing the details @arulalant. Based on that, it seems like exporting to PDF with custom fonts is broken.

By the way, somehow this issue got pretty far afield from the topic/title. Maybe it deserves to be it's own issue so it can be tracked more easily. Just my $0.02.

scottwittenburg avatar Apr 08 '20 20:04 scottwittenburg