Hi Garret,


On Tue, Aug 4, 2020 at 9:55 AM Garret Bland <gbland@andrew.cmu.edu> wrote:
Hello!

I have a Python/Larch related question. I have been developing some python script via jupyter and incorporating Larch as a module. I was able to read an athena prj file with the following code

import larch as lc

athena_prj = lc.io.read_athena(prjfilename)

Python stores this object as a 'Group' object with each spectrum being an instance. I would like to go through more processing with all spectra.

Example:
for spectrum in  athena_prj:
     lc.xafs.find_e0(spectrum.energy, spectrum.mu, group = spectrum)

This does not work since the 'Group' object is not iterable. I tried to look up some other built-in functionality with python, but couldn't find an efficient way other than manually typing out each spectrum (athena_prj.spectrum1,  athena_prj.spectrum2, .... etc). Is there any built-in functionality in larch that can iterate this 'Group' object? 


Yeah, a Group is a pretty generic collection and so is not iterable.  There is a dir() function, but that is not really what you want because the group returned from read_athena() contains not only the "Athena Groups" (which is what you want to loop over) but also some extra data about the project file itself.   I think that what
you really want is to use the (magic-ish) `_athena_groups` data in the project file group:

    for spectrum_name, spectrum in athena.prj._athena_groups.items():
          lc.xafs.find_e0(spectrum.energy, spectrum.mu)

or if you're just looking to extract E0 for all the groups in the project file, perhaps:

    e0_vals = {name: lc.xafs.find_e0(spect) for name, spect in athena_prj._athena_groups.items()}

--Matt

PS: sorry, the word 'group' here probably has four different meanings. print(" ".join(["buffalo"]*8))!





Any help would be appreciated. Thank you for your time!
Garret 

--
Garret Bland
PhD Student
Carnegie Mellon University
Civil and Environmental Engineering
Porter Hall 201
Pittsburgh, PA, 15213
_______________________________________________
Ifeffit mailing list
Ifeffit@millenia.cars.aps.anl.gov
http://millenia.cars.aps.anl.gov/mailman/listinfo/ifeffit
Unsubscribe: http://millenia.cars.aps.anl.gov/mailman/options/ifeffit


--
--Matt Newville <newville at cars.uchicago.edu> 630-252-0431