Dear Larch developers (Matt), I believe I found an error in the mback function where I get a NameError saying the name ‘f1_chantler’ is not defined. I found that simply adding f1_chantler to the larch_plugins.xray import section in mback.py fixes the problem. I have included the modified mback.py code, my input data (SigScan226827.txt), project code (mback_test.py), and the error I received (mback_error.txt). I am running python 2.7 with anaconda as my manager, macOS Sierra v10.12, on a mid-2015 15” MacBook pro. I hope this report is correct and helpful. Regards, Sean Sean Fackler, PhD Joint Center for Artificial Photosynthesis Lawrence Berkeley National Lab 1 Cyclotron Rd Mail Stop 30R0205 Berkeley CA, 94720 Mobile: 609-613-8734
Hi Sean,
On Wed, Oct 12, 2016 at 7:36 PM, Sean Fackler
Dear Larch developers (Matt),
I believe I found an error in the mback function where I get a NameError saying the name ‘f1_chantler’ is not defined. I found that simply adding f1_chantler to the larch_plugins.xray import section in mback.py fixes the problem. I have included the modified mback.py code, my input data (SigScan226827.txt), project code (mback_test.py), and the error I received (mback_error.txt).
I am running python 2.7 with anaconda as my manager, macOS Sierra v10.12, on a mid-2015 15” MacBook pro. I hope this report is correct and helpful.
Regards,
Sean
Sean Fackler, PhD Joint Center for Artificial Photosynthesis Lawrence Berkeley National Lab 1 Cyclotron Rd Mail Stop 30R0205 Berkeley CA, 94720 Mobile: 609-613-8734
Sorry for the trouble and thanks for the complete report. You're absolutely right, f1_chantler was just missing. Fix in github master. --Matt
Dear Matt, I’ve been working to implement Larch functions as a Python library. During the implementation I found a number of things I needed to do including: 1. Identifiying a functions’ python callable name, i.e. _group as a python callable function instead of group as the larch function. 2. The need to pass '_larch = mylarch’ in the said function or I get the 'AttributeError: 'NoneType' object has no attribute ‘symtable’ ‘ 3. The need to run the script through the Python console as oppose to running as a script. You can see my sample script with data attached. Keep in mind I am a Python novice. So for point 3 in particular I don’t understand the difference between running some selected code in the Python console and running the whole script in the shell (I am using PyCharm CE). I checked my Python interpreter with sys.executable (path) and sys.version_info (version) which are the same between the console and interpreter which were initial issues I found online. Is the interpreter somehow not seeing the xraylarch library? Finally: 1. Is there an easier way to use the larch functions as a python library? 2. Is a larch group basically a python dictionary? If so, this could be made clearer in the documentation. I am interested to contribute to the documentation if that’s of interest/help. I am running MacOS Sierra 10.12.1 on a mid-2015 15" MacBook Pro with Python 2.7. Ron and Alpha: Maybe you have some ideas to the above points? Thanks everyone for any help. Sean
On Oct 12, 2016, at 7:19 PM, Matt Newville
wrote: Hi Sean,
On Wed, Oct 12, 2016 at 7:36 PM, Sean Fackler
mailto:swfackler@lbl.gov> wrote: Dear Larch developers (Matt), I believe I found an error in the mback function where I get a NameError saying the name ‘f1_chantler’ is not defined. I found that simply adding f1_chantler to the larch_plugins.xray import section in mback.py fixes the problem. I have included the modified mback.py code, my input data (SigScan226827.txt), project code (mback_test.py), and the error I received (mback_error.txt).
I am running python 2.7 with anaconda as my manager, macOS Sierra v10.12, on a mid-2015 15” MacBook pro. I hope this report is correct and helpful.
Regards,
Sean
Sean Fackler, PhD Joint Center for Artificial Photosynthesis Lawrence Berkeley National Lab 1 Cyclotron Rd Mail Stop 30R0205 Berkeley CA, 94720 Mobile: 609-613-8734 tel:609-613-8734
Sorry for the trouble and thanks for the complete report. You're absolutely right, f1_chantler was just missing. Fix in github master.
--Matt
_______________________________________________ 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
Hi Sean,
On Tue, Nov 1, 2016 at 1:39 PM, Sean Fackler
Dear Matt,
I’ve been working to implement Larch functions as a Python library. During the implementation I found a number of things I needed to do including:
You can use Larch functions from Python, of course. Normally, you'd do something like import larch from larch_plugins.xafs import pre_edge, mback
1. Identifiying a functions’ python callable name, i.e. _group as a python callable function instead of group as the larch function.
I'm not sure I understand. You shouldn't need "a function's python callable name", you should just need the function. Maybe I misunderstand. If you need a larch Group, you should be able to do import larch agroup = larch.Group(name='mygroupname', xdata = range(100), label='hello')
2. The need to pass '_larch = mylarch’ in the said function or I get the 'AttributeError: 'NoneType' object has no attribute ‘symtable’ ‘
Yes, many of the larch plugin functions either require or are much happier with an instance of a larch session passed in as the '_larch' argument. It's kind of a feature ;).
3. The need to run the script through the Python console as oppose to running as a script.
I'm not sure I understand what this means. You should be able to run a python program from any environment.
You can see my sample script with data attached. Keep in mind I am a Python novice. So for point 3 in particular *I don’t understand the difference between running some selected code in the Python console and running the whole script in the shell *(I am using PyCharm CE). I checked my Python interpreter with sys.executable (path) and sys.version_info (version) which are the same between the console and interpreter which were initial issues I found online. Is the interpreter somehow not seeing the xraylarch library?
Hmm, that doesn't make a lot of sense to me either. What errors do you get when you run your script? I don't use PyCharm, so maybe that's not seeing all of the modules from anaconda? Is PyCharm seeing your anaconda distribution? A few comments on your script: a) there should be no need to do a os.chdir() to any folder, especially not to source code folders. b) doing from xxx import * is bound to lead to confusion. Import what you need, and don't import what you don't need. Finally: 1. Is there an easier way to use the larch functions as a python
library?
Is the above suggestion better?
2. Is a larch group basically a python dictionary?
Actually, it's basically an empty class: class Group: def __init__(self, **kws): .... mygroup = Group() mygroup.x = 1 mygroup.y = 'a string' even in more detail, it's an empty class. In most cases it would probably be OK to substitute almost any class instance as a Group. In Larch, I tend to make as many things as possible "group-like" so that accessing elements is easy.
If so, this could be made clearer in the documentation. I am interested to contribute to the documentation if that’s of interest/help.
Sure! The docs are definitely in need of some serious work.
I am running MacOS Sierra 10.12.1 on a mid-2015 15" MacBook Pro with Python 2.7.
Ron and Alpha: Maybe you have some ideas to the above points?
Thanks everyone for any help.
Sean
The attached modified version of your script works for me from a Terminal (The fit's not very good, yet, but it did run). On Mac OSX with anaconda, you probably have to run this as "pythonw import_fit.py" (note: pythonw, not python). Hope that helps, --Matt
Hi Matt,
On Nov 1, 2016, at 2:00 PM, Matt Newville
wrote: Hi Sean,
On Tue, Nov 1, 2016 at 1:39 PM, Sean Fackler
mailto:swfackler@lbl.gov> wrote: Dear Matt, I’ve been working to implement Larch functions as a Python library. During the implementation I found a number of things I needed to do including:
You can use Larch functions from Python, of course. Normally, you'd do something like
import larch from larch_plugins.xafs import pre_edge, mback
1. Identifiying a functions’ python callable name, i.e. _group as a python callable function instead of group as the larch function.
I'm not sure I understand. You shouldn't need "a function's python callable name", you should just need the function. Maybe I misunderstand.
If you need a larch Group, you should be able to do import larch agroup = larch.Group(name='mygroupname', xdata = range(100), label='hello')
Thanks for showing me the precise command.
2. The need to pass '_larch = mylarch’ in the said function or I get the 'AttributeError: 'NoneType' object has no attribute ‘symtable’ ‘
Yes, many of the larch plugin functions either require or are much happier with an instance of a larch session passed in as the '_larch' argument. It's kind of a feature ;).
3. The need to run the script through the Python console as oppose to running as a script.
I'm not sure I understand what this means. You should be able to run a python program from any environment.
You can see my sample script with data attached. Keep in mind I am a Python novice. So for point 3 in particular I don’t understand the difference between running some selected code in the Python console and running the whole script in the shell (I am using PyCharm CE). I checked my Python interpreter with sys.executable (path) and sys.version_info (version) which are the same between the console and interpreter which were initial issues I found online. Is the interpreter somehow not seeing the xraylarch library?
Hmm, that doesn't make a lot of sense to me either. What errors do you get when you run your script?
I don't use PyCharm, so maybe that's not seeing all of the modules from anaconda? Is PyCharm seeing your anaconda distribution?
When I run the script I get the following error from the same script “import_fit.py": "Traceback (most recent call last): File "/Users/SeanFackler/PycharmProjects/msp_sean/import_fit.py", line 10, in <module> from larch_plugins.lineshapes import gaussian ImportError: No module named larch_plugins.lineshapes Process finished with exit code 1” Somehow it can’t load the module lineshapes. But selecting all the code and running it in the Python console works fine. I checked as before and it appears to be seeing the same anaconda Python interpreter. Pycharm also appears to see the anaconda distribution.
A few comments on your script: a) there should be no need to do a os.chdir() to any folder, especially not to source code folders. b) doing from xxx import * is bound to lead to confusion. Import what you need, and don't import what you don't need.
Thanks for those helpful comments. The asterisks was an attempt to get plotter working on my system :)
Finally: 1. Is there an easier way to use the larch functions as a python library?
Is the above suggestion better?
2. Is a larch group basically a python dictionary?
Actually, it's basically an empty class:
class Group: def __init__(self, **kws): ....
mygroup = Group() mygroup.x = 1 mygroup.y = 'a string'
even in more detail, it's an empty class. In most cases it would probably be OK to substitute almost any class instance as a Group.
In Larch, I tend to make as many things as possible "group-like" so that accessing elements is easy.
Indeed I had no problem replacing larch groups as dictionaries so the group-like accessing of elements is more general than a dictionary I guess. That’s useful!
If so, this could be made clearer in the documentation. I am interested to contribute to the documentation if that’s of interest/help.
Sure! The docs are definitely in need of some serious work.
Let me know how best I could contribute. For starters I can help with typos and the like.
I am running MacOS Sierra 10.12.1 on a mid-2015 15" MacBook Pro with Python 2.7.
Ron and Alpha: Maybe you have some ideas to the above points?
Thanks everyone for any help.
Sean
The attached modified version of your script works for me from a Terminal (The fit's not very good, yet, but it did run). On Mac OSX with anaconda, you probably have to run this as "pythonw import_fit.py" (note: pythonw, not python).
Hope that helps,
That works perfectly! I just ran it in the Interpreter normally (no pythonw). I guess it’s just the way I was importing things. Thank you, Sean
--Matt
_______________________________________________ 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
Hi Sean,
On Tue, Nov 1, 2016 at 5:35 PM, Sean Fackler
Hi Matt,
On Nov 1, 2016, at 2:00 PM, Matt Newville
wrote: Hi Sean,
On Tue, Nov 1, 2016 at 1:39 PM, Sean Fackler
wrote: Dear Matt,
I’ve been working to implement Larch functions as a Python library. During the implementation I found a number of things I needed to do including:
You can use Larch functions from Python, of course. Normally, you'd do something like
import larch from larch_plugins.xafs import pre_edge, mback
1. Identifiying a functions’ python callable name, i.e. _group as a python callable function instead of group as the larch function.
I'm not sure I understand. You shouldn't need "a function's python callable name", you should just need the function. Maybe I misunderstand.
If you need a larch Group, you should be able to do import larch agroup = larch.Group(name='mygroupname', xdata = range(100), label='hello')
Thanks for showing me the precise command.
2. The need to pass '_larch = mylarch’ in the said function or I get the 'AttributeError: 'NoneType' object has no attribute ‘symtable’ ‘
Yes, many of the larch plugin functions either require or are much happier with an instance of a larch session passed in as the '_larch' argument. It's kind of a feature ;).
3. The need to run the script through the Python console as oppose to running as a script.
I'm not sure I understand what this means. You should be able to run a python program from any environment.
You can see my sample script with data attached. Keep in mind I am a Python novice. So for point 3 in particular *I don’t understand the difference between running some selected code in the Python console and running the whole script in the shell *(I am using PyCharm CE). I checked my Python interpreter with sys.executable (path) and sys.version_info (version) which are the same between the console and interpreter which were initial issues I found online. Is the interpreter somehow not seeing the xraylarch library?
Hmm, that doesn't make a lot of sense to me either. What errors do you get when you run your script?
I don't use PyCharm, so maybe that's not seeing all of the modules from anaconda? Is PyCharm seeing your anaconda distribution?
When I run the script I get the following error from the same script “import_fit.py":
"Traceback (most recent call last): File "/Users/SeanFackler/PycharmProjects/msp_sean/import_fit.py", line 10, in <module> from larch_plugins.lineshapes import gaussian ImportError: No module named larch_plugins.lineshapes
Process finished with exit code 1”
I think that should be from larch_plugins.math.lineshapes import gaussian with "math"
Somehow it can’t load the module lineshapes. But selecting all the code and running it in the Python console works fine. I checked as before and it appears to be seeing the same anaconda Python interpreter. Pycharm also appears to see the anaconda distribution.
Hm, are you sure that's the same version of "import_fit.py"?
A few comments on your script: a) there should be no need to do a os.chdir() to any folder, especially not to source code folders. b) doing from xxx import * is bound to lead to confusion. Import what you need, and don't import what you don't need.
Thanks for those helpful comments. The asterisks was an attempt to get plotter working on my system :)
Finally: 1. Is there an easier way to use the larch functions as a python
library?
Is the above suggestion better?
2. Is a larch group basically a python dictionary?
Actually, it's basically an empty class:
class Group: def __init__(self, **kws): ....
mygroup = Group() mygroup.x = 1 mygroup.y = 'a string'
even in more detail, it's an empty class. In most cases it would probably be OK to substitute almost any class instance as a Group.
In Larch, I tend to make as many things as possible "group-like" so that accessing elements is easy.
Indeed I had no problem replacing larch groups as dictionaries so the group-like accessing of elements is more general than a dictionary I guess. That’s useful!
OK, great!
If so, this could be made clearer in the documentation. I am interested to contribute to the documentation if that’s of interest/help.
Sure! The docs are definitely in need of some serious work.
Let me know how best I could contribute. For starters I can help with typos and the like.
Any work or suggestions on the docs would be greatly appreciated!
I am running MacOS Sierra 10.12.1 on a mid-2015 15" MacBook Pro with Python 2.7.
Ron and Alpha: Maybe you have some ideas to the above points?
Thanks everyone for any help.
Sean
The attached modified version of your script works for me from a Terminal (The fit's not very good, yet, but it did run). On Mac OSX with anaconda, you probably have to run this as "pythonw import_fit.py" (note: pythonw, not python).
Hope that helps,
That works perfectly! I just ran it in the Interpreter normally (no pythonw). I guess it’s just the way I was importing things.
Thank you,
Sean
--Matt
_______________________________________________ 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 _______________________________________________ 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
participants (2)
-
Matt Newville
-
Sean Fackler