Skip to content
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

Draft
wants to merge 28 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0a0270c
add test for process_pdos
Jun 23, 2021
d5c8552
fix the imports
Yaxuan-Lii Jun 29, 2021
553738f
removeed irrelevant files
Yaxuan-Lii Jul 1, 2021
5300d62
import is fixed
Yaxuan-Lii Jul 1, 2021
dab091b
try to remove irrelevant fils second time
Yaxuan-Lii Jul 1, 2021
d69d61b
remove irrelevant files second time
Yaxuan-Lii Jul 1, 2021
7984c15
delet irrelevant files
Yaxuan-Lii Jul 1, 2021
66b1c6f
remove irrelevant files
Yaxuan-Lii Jul 1, 2021
4fdafa7
delete .DS_Store
Yaxuan-Lii Jul 1, 2021
dca2d49
Modified test_process_pdos.py
Yaxuan-Lii Jul 2, 2021
eb079f6
add test.py
Yaxuan-Lii Jul 2, 2021
8190183
Restore some files that were accidentally deleted
ajjackson Jul 2, 2021
946efaa
use flake8 to optimise format
Yaxuan-Lii Jul 5, 2021
cd0f3c0
import cross-sections from CSV archives
Yaxuan-Lii Jul 15, 2021
8f48e5e
form modify
Yaxuan-Lii Jul 17, 2021
a959150
modify follow the comments
Yaxuan-Lii Jul 21, 2021
067c289
make corrections
Yaxuan-Lii Jul 21, 2021
a621ab0
make correction
Yaxuan-Lii Jul 21, 2021
13911d0
Revert changes to galore/__init__.py
ajjackson Jul 21, 2021
4fb993d
modified as comments
Yaxuan-Lii Aug 2, 2021
cd4dc0e
merge the change of galore/__init__.py
Yaxuan-Lii Aug 2, 2021
5c9c31c
add cli to install data and get cross sections
Yaxuan-Lii Aug 9, 2021
b138c4b
merge get_cross_sections_from_csv into get_cross_sections
Yaxuan-Lii Aug 10, 2021
bb8a526
modify and add new test
Yaxuan-Lii Aug 24, 2021
5cdb67b
add a IF statement
Yaxuan-Lii Aug 31, 2021
39651d5
modify as comments
Yaxuan-Lii Sep 9, 2021
a2441b5
modify as comments
Yaxuan-Lii Sep 9, 2021
f59b50a
mistakes fix
Yaxuan-Lii Sep 12, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 45 additions & 21 deletions galore/cli/galore_get_cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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' """)
Copy link
Member

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?

Copy link
Member

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.


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
Copy link
Member

Choose a reason for hiding this comment

The 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))
25 changes: 25 additions & 0 deletions galore/cli/galore_install_data.py
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':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way to do this is if reference in ('Scofield', 'Yeh'). What you have is fine here, but the other way is worth knowing if there are more options to compare 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another nice trick which is used elsewhere in the code is if reference.lower() in ('scofield', 'yeh'); this makes it case-insensitive so our user doesn't have to mess around with shift keys.


url,data_file_dir,data_file_path =galore.cross_sections.get_csv_file_path(reference)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow PEP8 guidelines for spacing around , and =, it makes the code easier to read.

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' ")
Copy link
Member

Choose a reason for hiding this comment

The 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. f"Reference '{reference}' was not recognised. Accepted values are 'Scofield' and 'Yeh'."

This can make it clearer if the user made a typo or a script inserted the wrong value.


Loading