def test_normalize_boxing():
    mask = gen_test.generate_test_image2(hspy=False)
    image = gen_test.generate_test_image2(hspy=True)

    params = PAnalysis.parameters()
    params.generate(store_im=True)

    particles = PAnalysis.ParticleAnalysis(image, params, mask=mask)

    particles.normalize_boxing()

    assert particles.list[0].image.data.shape == (68, 68)
def test_particleanalysis():
    image = gen_test.generate_test_image(hspy=True)
    mask = gen_test.generate_test_image(hspy=False)
    eds = gen_test.generate_test_eds()
    si = gen_test.generate_test_si()
    eels = gen_test.generate_test_si('EELS')

    ac = [image, eds, si, eels]

    params = PAnalysis.parameters()
    params.generate(store_im=True)
    params.generate_eds(eds_method='CL',
                        elements=['Au', 'Pd'],
                        factors=[1.0, 1.0],
                        store_maps=True)

    p_list = PAnalysis.ParticleAnalysis(ac, params, mask=mask)

    p = p_list.list[0]

    nptest.assert_almost_equal(p.properties['area']['value'], 20069.0)
    assert p.properties['area']['units'] == 'nm^2'
    nptest.assert_almost_equal(p.properties['circularity']['value'],
                               0.9095832157785668)
    nptest.assert_almost_equal(
        p.properties['equivalent circular diameter']['value'],
        159.8519453221949)
    assert p.properties['equivalent circular diameter']['units'] == 'nm'
    #assert p.zone == None
    nptest.assert_allclose(p.mask, mask)
    nptest.assert_allclose(p.image.data, image.data[16:184, 16:184])
    au_map = eds.get_lines_intensity()[0]
    nptest.assert_allclose(p.maps['Au'].data, au_map.data[16:184, 16:184])
    eds_particle = eds.transpose() * mask
    eds_particle = eds_particle.transpose()
    eds_particle_spectrum = eds_particle.sum()
    nptest.assert_allclose(p.spectrum['EDS_TEM'].data,
                           eds_particle_spectrum.data)
    nptest.assert_allclose(p.composition['Au'], 46.94530019)
    nptest.assert_allclose(p.properties['x']['value'], 100.)
    nptest.assert_allclose(p.properties['y']['value'], 100.)
    nptest.assert_allclose(p.properties['bbox_area']['value'], 25281.0)
    nptest.assert_allclose(p.properties['bbox_length']['value'],
                           224.8599564173221)
    assert p.properties['bbox_area']['units'] == 'nm^2'
    assert p.properties['bbox_length']['units'] == 'nm'
    assert p.bbox == (21, 21, 180, 180)