Skip to content
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

vector plot magnitude broken? #386

Open
doutriaux1 opened this issue Feb 11, 2019 · 22 comments
Open

vector plot magnitude broken? #386

doutriaux1 opened this issue Feb 11, 2019 · 22 comments
Assignees
Labels
low Low Priority bug (but not enhancement)

Comments

@doutriaux1
Copy link
Contributor

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.

@scottwittenburg
Copy link
Collaborator

Thanks @doutriaux1, I'll take a look.

ping @danlipsa @aashish24

@scottwittenburg
Copy link
Collaborator

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

@roshni1991
Copy link

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

@doutriaux1
Copy link
Contributor Author

@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
Copy link
Contributor Author

@doutriaux1
Copy link
Contributor Author

@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.

@scottwittenburg
Copy link
Collaborator

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
Copy link
Collaborator

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?

@roshni1991
Copy link

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

@doutriaux1
Copy link
Contributor Author

@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
Copy link
Contributor Author

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

@scottwittenburg
Copy link
Collaborator

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

@roshni1991
Copy link

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

@scottwittenburg
Copy link
Collaborator

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
Copy link
Collaborator

@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.

@doutriaux1
Copy link
Contributor Author

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

@scottwittenburg
Copy link
Collaborator

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

@roshni1991
Copy link

@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

@scottwittenburg scottwittenburg added the low Low Priority bug (but not enhancement) label May 1, 2019
@arulalant
Copy link
Contributor

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.

@scottwittenburg
Copy link
Collaborator

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.

@arulalant
Copy link
Contributor

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.

@scottwittenburg
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
low Low Priority bug (but not enhancement)
Projects
None yet
Development

No branches or pull requests

4 participants