Export data generated by HistorgramModifier

Hello,

I am writing to inquire about an issue I encountered while using the HistogramModifier in the python-ovito library, version 3.9.2. Specifically, I am trying to generate a histogram for the physical quantity “lost_neigh_time” (data attached). I set the bin_count to 500.

Afterwards, I used the ovito.io.export command to export the histogram data generated by the HistogramModifier. Additionally, I used the tables.xy() command to obtain the two-dimensional matrix of the histogram.

However, I noticed that the histogram matrices obtained from these two methods differ.

Attached is screenshot of the exported file data from the export command.
export

And a partial screenshot of the two-dimensional matrix obtained from the tables.xy() command.
tablexy

Could you please advise if there are any specific options that need to be set when using the ovito.io.export command? Here is my code.

import ovito

def main():

    print(ovito.version)
    ref_dump_file = "./dump_initial_neigh.colloid"

    pipeline = ovito.io.import_file(ref_dump_file)
    pipeline.modifiers.append(ovito.modifiers.HistogramModifier(bin_count=500, property="lost_neigh_time"))
    ovito.io.export_file(pipeline, "hist.txt", "txt/table", key="histogram[lost_neigh_time]")
    pipeline_atoms = pipeline.compute(0)
    hist = pipeline_atoms.tables["histogram[lost_neigh_time]"].xy()
    print(hist)

main()

Thank you in advance for your assistance.

dump_initial_neigh.colloid (196.5 KB)

Hi @dx_yu,

For what it’s worth I cannot reproduce your issue with the ovito 3.9.2 Python package and the dump file you provide. The results I get are identical both in the hist.txt file and the printed array. Here is a plot of both.

It also seems weird to me that you have a difference of a single digit in the last value you present in your snapshot. The value is also lower than the previous values while they are sorted in increasing order which makes no sense. The format difference is just cosmetic for the outputs.

I suspect you edited the file by accident.

1 Like

Thank you for your response. By “difference,” I refer to the last data rows in the two screenshots above. Following your suggestion, I also plotted two histograms on the same graph and still found some distinctions.

Perhaps, as you mentioned, certain operations I performed altered the data. I will carefully examine it again.
Once again, thank you for your reply.

Here is my code used for plotting:

import os
os.environ['OVITO_GUI_MODE'] = '1'
import ovito
import numpy as np
import matplotlib.pyplot as plt


def main():

    print(ovito.version)
    ref_dump_file = "./dump_initial_neigh.colloid"

    pipeline = ovito.io.import_file(ref_dump_file)
    pipeline.modifiers.append(ovito.modifiers.HistogramModifier(bin_count=500, property="lost_neigh_time"))
    # export data and read data
    ovito.io.export_file(pipeline, "hist.txt", "txt/table", key="histogram[lost_neigh_time]")
    export_mat = np.loadtxt("./hist.txt")
    # get table data
    pipeline_atoms = pipeline.compute(0)
    hist = pipeline_atoms.tables["histogram[lost_neigh_time]"].xy()
    # plot 
    plt.plot(export_mat[:, 0], export_mat[:, 1], ".", label="exported data")
    plt.plot(hist[:, 0], hist[:, 1], "x", label="table data")
    plt.legend()
    plt.show()


main()

I ran the code you provided in a jupyter notebook and got the same results as @Germain. For now I would assume that this is not an OVITO bug.

image

According to your suggestion, I installed Miniconda and tested it. I found that the issue indeed disappeared. However, I noticed that when running the python-ovito program installed with pip, the aforementioned problem occurs.

I can’t reproduce the issue either. I’ve tested it with Python 3.9 on macOS/arm64 with the PyPI package (ovito 3.9.2 and 3.10.0.dev).

Could you please attach the (faulty) hist.txt file for us? Thanks.

Thank you for your help. This is the hist.txt file and the python packages and its version that I got by using the pip list command.
hist.txt (5.3 KB)
pip_list.txt (3.1 KB)

Thanks. For your reference, I am attaching my version of hist.txt (4.9 KB), which contains the correct values.

It’s really unusual: On every 5th line of your file, a single digit seems to be missing in the first column. Everything else is identical in the two files. Frankly, I don’t have a good idea yet how something like this can even happen.

Mine:

# lost_neigh_time (500 data points):
# lost_neigh_time Count
12.4 33 
17.2 0 
22.0 28 
26.8 0 
31.6 43 
36.4 0 
41.2 45 
46.0 0         <--- 
50.8 42 
55.6 0 
60.4 52 
65.2 0 
70.0 61         <--- 
74.8 0 
79.6 47 
84.4 0 
89.2 49 
94.0 0         <--- 
98.8 57 
103.6 0 
108.4 66 
113.2 0 
118.0 66         <--- 
122.8 0 
127.6 0 

Yours:

# lost_neigh_time (500 data points):
# lost_neigh_time Count
12.4 33 
17.2 0 
22.0 28 
26.8 0 
31.6 43 
36.4 0 
41.2 45 
4.0 0         <---
50.8 42 
55.6 0 
60.4 52 
65.2 0 
7.0 61        <--- 
74.8 0 
79.6 47 
84.4 0 
89.2 49 
9.0 0         <--- 
98.8 57 
103.6 0 
108.4 66 
113.2 0 
11.0 66         <--- 
122.8 0 
127.6 0 

Surprisingly, no deviation is found on the 3rd line of both files (“22.0 28”).

I’m guessing it might have something to do with the operating system, the above example of what went wrong was run using win10, I ran the program again using Linux and had no problems.

Thank you very much for your effort investigating the problem. We have now discovered the origin of this issue. It is a bug in a third-party component (Boost library v1.78) used by the PyPI and desktop versions of OVITO for Windows. The conda package for Windows, and all versions on other OS platforms, are not affected. We will keep you posted once an updated build of the PyPI package becomes available.

1 Like

Here is the new build of the dev3.10.0 pre-release package for Windows, which is based on a more recent version of the Boost library and which should not exhibit the data export issue:

https://pypi.org/project/ovito/3.10.0.dev66/

We have also started preparations for a new patch version 3.9.3, which we plan to release in the next few days.

1 Like

@dx_yu, Just a brief reminder: Version 3.9.3 was released on November 1, 2023. Download here.

OK, Thank you.