mdacli icon indicating copy to clipboard operation
mdacli copied to clipboard

Keep logical order when saving results

Open PicoCentauri opened this issue 4 years ago • 2 comments

If you want to plot data from a file stored in columns it is convention that x values have a lower column index compared to the y values. Currently this is not guaranteed. The current results handling proposed in #17 and #29 handle every possible type appearing in an MDAanalysis AnalysisClass. In our approach 1D arrays are stacked into 2D arrays and saved as CSV files. The logical structure is usually encoded inside the class docstring. For example, in lineardensity.py the docstring has the following structure

"""
    results.x.pos : numpy.ndarray
           mass density in [xyz] direction
    results.x.pos_std : numpy.ndarray
           standard deviation of the mass density in [xyz] direction
    results.x.char : numpy.ndarray
           charge density in [xyz] direction
    results.x.char_std : numpy.ndarray
           standard deviation of the charge density in [xyz] direction
"""

Saving these 1D arrays stacked into a 2D array keep this order.

PicoCentauri avatar May 20 '21 10:05 PicoCentauri

If you keep this order in the results dictionary. Won't it be kept on the side of mdacli ?

joaomcteixeira avatar May 20 '21 22:05 joaomcteixeira

But we don't know if the order in the results dictionary is the same as in the docstring. The order is based on how the developer of the module decides to initialize the attributes of results. See simple example below

a = {}
a["a"] = 1
a["b"] = 4

print(a.keys())

returns dict_keys(['a', 'b']) compared to

b = {}
b["b"] = 1
b["a"] = 4

print(b.keys())

which returns dict_keys(['b', 'a'])

PicoCentauri avatar May 21 '21 12:05 PicoCentauri