ladisk / pyuff

This module defines an UFF class to manipulate with the UFF (Universal File Format) files.
Other
58 stars 40 forks source link

Error in caclulating x-axis for dataset 58 #75

Closed Crm1024 closed 1 year ago

Crm1024 commented 1 year ago

When calculating the x-axis for dataset 58, a bug exists if the abscissa is evenly spaced. For some combinations of parameters, a floating-point error is induced. The current code: dset['x'] = np.arange(min_val, min_val + n_val * d, d) fails if: min_val = 2.5e1 n_val = 101 d = 0.1 The returned array (deset['x']) has a length of 102, not 101 as it should have.

A more robust algorithm is something like: dset['x'] = min_val + np.arange(n_val) * d

(0.1 can't be represented exactly as a float. 101*0.1 = 10.100000000000001 meaning arange will create values up to and including 35.1, rather than excluding 35.1)

jankoslavic commented 1 year ago

@Crm1024 thank you for opening this issue. Indeed arange is not suggested for non-integer steps. Your suggestion looks ok. Will you prepare a PR or should I take care of this?

Crm1024 commented 1 year ago

@jankoslavic can you please take care of this. I have not used GitHub before and are not familiar with how to create a PR.

jankoslavic commented 1 year ago

@Crm1024 done with PR: https://github.com/ladisk/pyuff/pull/76

Would you need this to be pushed to pypi or can we wait a little?

jankoslavic commented 1 year ago

PS: I have added another PR and will not push it to pypi. you can upgrade:)

Crm1024 commented 1 year ago

Thank you for the quick response. It works perfectly now.