ePSIC-DLS / particlespy

Package for analysing particles in electron microscopy data sets.
GNU General Public License v3.0
19 stars 9 forks source link

particles list object save method raises error #44

Closed M0hsend closed 4 years ago

M0hsend commented 4 years ago

Attempting to run particles.save('test') on a particle list object that contains particles detected raises the following error: AttributeError: 'Particle' object has no attribute 'area' However, running p_list = particles.list p_list[0].properties, gives:

{'area': {'value': 56.490550618150905, 'units': 'nm^2'}, 'equivalent circular diameter': {'value': 4.784846686462774, 'units': 'nm'}, 'x': {'value': 8.424239937447378, 'units': 'nm'}, 'y': {'value': 191.8036727938458, 'units': 'nm'}, 'major axis length': {'value': 10.208740688714816, 'units': 'nm'}, 'minor axis length': {'value': 7.652065364638314, 'units': 'nm'}, 'circularity': {'value': 0.7200370328004669, 'units': None}, 'eccentricity': {'value': 0.6619362187105898, 'units': None}, 'solidity': {'value': 0.9408999328408327, 'units': None}, 'intensity': {'value': 41439413.119718365, 'units': None}, 'intensity_max': {'value': 108358.20422535215, 'units': None}, 'intensity_std': {'value': 0.012036269232102728, 'units': None}, 'frame': {'value': None, 'units': None}}

particles.plot_area() plots the areas fine, so these attribute is present.

This is on a Windows machine on anaconda env and version 0.4.1 of ParticleSpy

M0hsend commented 4 years ago

I guess change this function could work:

def save_plist(p_list,filename):
    f = h5py.File(filename,'w')
    for i, particle in enumerate(p_list.list):
        p_group = f.create_group("Particle "+str(i))

        p_group.attrs["Area"] = particle.properties['area']['value']
        p_group.attrs["Area units"] = particle.properties['area']['units']
        p_group.attrs["Circularity"] = particle.properties['circularity']['value']
        #p_group.attrs["Zone"] = particle.zone

        p_group.create_dataset("Mask",data=particle.mask)

        if hasattr(particle, 'image'):
            p_group.create_dataset("Image",data=particle.image.data)

    f.close()

Just need to expand to include all attributes.

TomSlater commented 4 years ago

You're right, I didn't change the save function when I changed the particles properties. You're welcome to create a PR for this Mohsen or I'm happy to change it too.

M0hsend commented 4 years ago

Sure, happy to put together a PR. You also have a save method that just calls save_plist. You want to keep it this way?

TomSlater commented 4 years ago

Yes, I think keep it like that.

If you could update the load function too that would be great!