-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Import cross sections from csv #41
base: master
Are you sure you want to change the base?
Changes from 25 commits
0a0270c
d5c8552
553738f
5300d62
dab091b
d69d61b
7984c15
66b1c6f
4fdafa7
dca2d49
eb079f6
8190183
946efaa
cd0f3c0
8f48e5e
a959150
067c289
a621ab0
13911d0
4fb993d
cd4dc0e
5c9c31c
b138c4b
bb8a526
5cdb67b
39651d5
a2441b5
f59b50a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,41 +22,65 @@ | |
from argparse import ArgumentParser | ||
import galore.cross_sections | ||
|
||
|
||
def main(): | ||
parser = get_parser() | ||
args = parser.parse_args() | ||
args = vars(args) | ||
run(**args) | ||
|
||
|
||
def get_parser(): | ||
parser = ArgumentParser() | ||
# parser.add_argument('energy', type=str, | ||
# help=""" | ||
# Photon energy, expressed as source type: "he2" for He (II), "alka" for | ||
# Al k-alpha, (values from Yeh/Lindau (1985)) or as energy in keV (values | ||
# from polynomial fit to Scofield (1973)).""") | ||
# parser.add_argument('elements', type=str, nargs='+', help=""" | ||
# Space-separated symbols for elements in material.""") | ||
|
||
parser.add_argument('energy', type=str, | ||
help=""" | ||
If you don't input dataset: | ||
Photon energy, expressed as source type: "he2" for He (II), "alka" for | ||
Al k-alpha, (values from Yeh/Lindau (1985)) or as energy in keV (values | ||
from polynomial fit to Scofield (1973)).""") | ||
parser.add_argument('elements', type=str, nargs='+', help=""" | ||
from polynomial fit to Scofield (1973)). | ||
if you input dataset: | ||
Photon energy, 1 to 1500keV for Scofield dataset, 10.2 to 8047.8 eV for Yeh dataset""") | ||
|
||
parser.add_argument('elements', nargs='+', | ||
help=""" | ||
Space-separated symbols for elements in material.""") | ||
|
||
parser.add_argument('--dataset', type=str, | ||
help= | ||
"""You can enter 'Scofield' or 'Yeh' """) | ||
|
||
return parser | ||
|
||
def run(energy, elements): | ||
cross_sections = galore.get_cross_sections(energy, elements) | ||
logging = galore.cross_sections.cross_sections_info(cross_sections) | ||
logging.info("Photoionisation cross sections per electron:") | ||
|
||
for element in elements: | ||
if 'warning' in cross_sections[element]: | ||
logging.warning(" {0}: {1}".format( | ||
element, cross_sections[element]['warning'])) | ||
else: | ||
orbitals = cross_sections[element] | ||
|
||
for orbital, value in orbitals.items(): | ||
if orbital == 'energy': | ||
pass | ||
if value is None: | ||
pass | ||
else: | ||
logging.info(" {0} {1}: {2:.3e}".format(element, | ||
|
||
def run(energy, elements, dataset=None): | ||
cross_sections = galore.get_cross_sections(energy, elements, dataset) | ||
if cross_sections is None: | ||
pass | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which scenario is this catching? Could there be a more helpful logging message in that case? Users don't like it when programs do nothing. |
||
else: | ||
logging = galore.cross_sections.cross_sections_info(cross_sections) | ||
logging.info("Photoionisation cross sections per electron:") | ||
|
||
for element in elements: | ||
|
||
if 'warning' in cross_sections[element]: | ||
logging.warning(" {0}: {1}".format( | ||
element, cross_sections[element]['warning'])) | ||
else: | ||
orbitals = cross_sections[element] | ||
|
||
for orbital, value in orbitals.items(): | ||
if orbital == 'energy': | ||
pass | ||
if value is None: | ||
pass | ||
else: | ||
logging.info(" {0} {1}: {2:.3e}".format(element, | ||
orbital, value)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from argparse import ArgumentParser | ||
import galore.cross_sections | ||
|
||
def main(): | ||
parser = get_parser() | ||
args = parser.parse_args() | ||
args = vars(args) | ||
run(**args) | ||
|
||
def get_parser(): | ||
parser = ArgumentParser() | ||
parser.add_argument('reference', type=str, | ||
help=""" 'Scofield' or 'Yeh'""") | ||
|
||
return parser | ||
|
||
def run(reference): | ||
if reference == 'Scofield' or reference == 'Yeh': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another way to do this is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another nice trick which is used elsewhere in the code is |
||
|
||
url,data_file_dir,data_file_path =galore.cross_sections.get_csv_file_path(reference) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please follow PEP8 guidelines for spacing around |
||
galore.cross_sections.galore_install_data(url,data_file_dir,data_file_path) | ||
ajjackson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
else: | ||
print("You can enter reference 'Scofield' or 'Yeh' ") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The wording can be a bit firmer here, and it's also useful to give feedback. e.g. This can make it clearer if the user made a typo or a script inserted the wrong value. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't clearer than the previous formatting, I think autopep8 is sneaking in again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would still be good to use
choices
here, then Argparse is responsible for handling bad user input.