peri-source / peri

Parameter Extraction from Reconstructing Images
https://peri-source.github.io/peri-docs/
MIT License
9 stars 7 forks source link

Clearer error message when PlatonicSpheresCollection is initialized with bad positions. #5

Open briandleahy opened 7 years ago

briandleahy commented 7 years ago

Currently, it's possible to create a state with particles well outside the padded region, without any error being thrown. However as soon as an update on the particles is attempted, an UpdateError gets raised because the particles are outside the box. This is confusing to the user.

I think a MWE would be (not by a computer with PERI)

from peri.comp import objs
from peri import states, util, models

pos = np.array([10,10,1000]).reshape(-1,3)
obj = objs.PlatonicSpheresCollection(pos, 5.0)
st = states.ImageState(util.NullImage(shape=(30,30,30)), [obj], models.ParticlesOnlyModel())

# no problem

st.update('sph-0-x', st.get_values('sph-0-x') - 1e-3)  # problem

I think the best solution is to check for bad particles the first time that PlatonicSpheresCollection has set_shape called, and raise an error then if there are bad positions / positions outside the padded image shape. Thoughts?