Skip to content

Commit

Permalink
new release after bugs fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangy6x committed Jan 13, 2021
1 parent f5dec82 commit 9ebc864
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 48 deletions.
31 changes: 23 additions & 8 deletions ImagingReso/_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@
from six.moves.urllib.request import urlopen
import sys

x_type_list = ['energy', 'lambda', 'time', 'number']
y_type_list = ['transmission', 'attenuation', 'sigma', 'sigma_raw', 'mu_per_cm']
time_unit_list = ['s', 'us', 'ns']
export_type_list = ['df', 'csv', 'clip']
h_bond_list = ['H2', 'C4H10', 'C16H34', 'C4H6', 'CH4', 'C2H6', 'C3H8', 'C2H4']
h_dict = {
'H2': 'Hydrogen gas',
'C4H10': 'Butane',
'C16H34': 'Cetane',
'C4H6': 'Butadiene',
'CH4': 'Methane',
'C2H6': 'Ethane',
'C3H8': 'Propane',
'C2H4': 'Ethylene'
}


def download_from_github(fname, path):
"""
Expand Down Expand Up @@ -465,21 +481,20 @@ def get_interpolated_data(df: pd.DataFrame, e_min=np.nan, e_max=np.nan, e_step=n
y_axis_function = interp1d(x=df['E_eV'], y=df['Sig_b'], kind='linear')
try:
y_axis = y_axis_function(x_axis)
except ValueError:
except ValueError as err:
a_min = round(ev_to_angstroms(e_max), 6)
a_max = round(ev_to_angstroms(e_min), 6)
data_e_min = round(min(df['E_eV']), 6)
data_e_max = round(max(df['E_eV']), 6)
data_a_min = round(ev_to_angstroms(data_e_max), 6)
data_a_max = round(ev_to_angstroms(data_e_min), 6)
raise ValueError(
"Oops, the experimental data does not cover the specified range ({}, {}) eV or ({}, {}) \u212B,"
u" please adjust to numbers within ({}, {}) eV or ({}, {}) \u212B.".format(e_min, e_max,
a_min, a_max,
data_e_min, data_e_max,
data_a_min, data_a_max))
errmsg = "Oops, the experimental data does not cover the specified range ({}, {}) eV or ({}, {}) \u212B, please adjust to numbers within ({}, {}) eV or ({}, {}) \u212B.".format(
e_min, e_max,
a_min, a_max,
data_e_min, data_e_max,
data_a_min, data_a_max)
raise Exception(errmsg) from err
sys.exit(1)

return {'x_axis': x_axis, 'y_axis': y_axis}


Expand Down
53 changes: 18 additions & 35 deletions ImagingReso/resonance.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,6 @@
from ImagingReso import _utilities
import plotly.tools as tls

x_type_list = ['energy', 'lambda', 'time', 'number']
y_type_list = ['transmission', 'attenuation', 'sigma', 'sigma_raw', 'mu_per_cm']
time_unit_list = ['s', 'us', 'ns']
export_type_list = ['df', 'csv', 'clip']
h_bond_list = ['H2', 'C4H10', 'C16H34', 'C4H6', 'CH4', 'C2H6', 'C3H8', 'C2H4']
h_dict = {
'H2': 'Hydrogen gas',
'C4H10': 'Butane',
'C16H34': 'Cetane',
'C4H6': 'Butadiene',
'CH4': 'Methane',
'C2H6': 'Ethane',
'C3H8': 'Propane',
'C2H4': 'Ethylene'
}


class Resonance(object):
e_min = 1e-5
Expand Down Expand Up @@ -549,19 +533,18 @@ def __get_sigmas(self):
# _dict_sigma_isotopes_sum = {}
_sigma_all_isotopes = 0
_energy_all_isotpes = 0

for _iso, _file, _ratio in _iso_file_ratio:
stack_sigma[_compound][_element][_iso] = {}
# print(_iso, _file, _ratio)
if _compound in h_bond_list:
if _compound in _utilities.h_bond_list:
if _iso == '1-H':
_utilities.is_element_in_database(element='H', database='Bonded_H')
_database_folder_h = os.path.join(_file_path, 'reference_data', 'Bonded_H')
sigma_file = os.path.join(_database_folder_h, 'H-{}.csv'.format(_compound))
print("NOTICE:\n"
"Your entry contains chemicals in {}, \n"
"'1-H' cross-section has been replaced by corresponding bonded H cross-sections "
"reported at https://doi.org/10.1103/PhysRev.76.1750".format(h_bond_list))
"Your entry {} contains bonded H, and has experimental data available. \n"
"Therefore, '1-H' cross-section has been replaced by the data "
"reported at https://doi.org/10.1103/PhysRev.76.1750".format(_compound))
else:
sigma_file = os.path.join(_database_folder, _file)
else:
Expand Down Expand Up @@ -640,12 +623,12 @@ def plot(self, y_axis='attenuation', x_axis='energy',
:type alpha: float
"""
if x_axis not in x_type_list:
raise ValueError("Please specify the x-axis type using one from '{}'.".format(x_type_list))
if time_unit not in time_unit_list:
raise ValueError("Please specify the time unit using one from '{}'.".format(time_unit_list))
if y_axis not in y_type_list:
raise ValueError("Please specify the y-axis type using one from '{}'.".format(y_type_list))
if x_axis not in _utilities.x_type_list:
raise ValueError("Please specify the x-axis type using one from '{}'.".format(_utilities.x_type_list))
if time_unit not in _utilities.time_unit_list:
raise ValueError("Please specify the time unit using one from '{}'.".format(_utilities.time_unit_list))
if y_axis not in _utilities.y_type_list:
raise ValueError("Please specify the y-axis type using one from '{}'.".format(_utilities.y_type_list))
# figure size
# plt.figure(figsize=(8, 8))

Expand Down Expand Up @@ -850,14 +833,14 @@ def export(self, output_type='df', filename=None, x_axis='energy', y_axis='atten
:return: simulated resonance signals or sigma in the form of 'clipboard' or '.csv file' or 'pd.DataFrame'
"""
if x_axis not in x_type_list:
raise ValueError("Please specify the x-axis type using one from '{}'.".format(x_type_list))
if time_unit not in time_unit_list:
raise ValueError("Please specify the time unit using one from '{}'.".format(time_unit_list))
if y_axis not in y_type_list:
raise ValueError("Please specify the y-axis type using one from '{}'.".format(y_type_list))
if output_type not in export_type_list:
raise ValueError("Please specify export type using one from '{}'.".format(export_type_list))
if x_axis not in _utilities.x_type_list:
raise ValueError("Please specify the x-axis type using one from '{}'.".format(_utilities.x_type_list))
if time_unit not in _utilities.time_unit_list:
raise ValueError("Please specify the time unit using one from '{}'.".format(_utilities.time_unit_list))
if y_axis not in _utilities.y_type_list:
raise ValueError("Please specify the y-axis type using one from '{}'.".format(_utilities.y_type_list))
if output_type not in _utilities.export_type_list:
raise ValueError("Please specify export type using one from '{}'.".format(_utilities.export_type_list))
# stack from self
_stack_signal = self.stack_signal
_stack = self.stack
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def read_file(filename):

setup(
name="ImagingReso",
version="1.7.2",
version="1.7.3",
author="Yuxuan Zhang, Jean Bilheux",
author_email="[email protected], [email protected]",
packages=find_packages(exclude=['tests', 'notebooks']),
Expand Down
12 changes: 8 additions & 4 deletions tests/ImagingReso/resonance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,22 +728,26 @@ def test_axis_type_and_time_unit(self):
class Bonded_H(unittest.TestCase):
database = '_data_for_unittest'

def setUp(self):
_energy_min = 0.004
def test_raises(self):
_energy_min = 0.002
_energy_max = 1
_energy_step = 0.01
o_reso = Resonance(energy_min=_energy_min, energy_max=_energy_max, energy_step=_energy_step,
database=self.database)
self.o_reso = o_reso
self.assertRaises(Exception)

def test_H_sigma(self):
_energy_min = 0.004
_energy_max = 1
_energy_step = 0.01
o_reso = Resonance(energy_min=_energy_min, energy_max=_energy_max, energy_step=_energy_step,
database=self.database)
_layer_1 = 'H2'
_thickness_1 = 0.025 # mm
_layer_2 = 'H'
_thickness_2 = 0.01
_layer_3 = 'CH4'
_thickness_3 = 0.01
o_reso = self.o_reso
o_reso.add_layer(formula=_layer_1, thickness=_thickness_1)
o_reso.add_layer(formula=_layer_2, thickness=_thickness_2)
o_reso.add_layer(formula=_layer_3, thickness=_thickness_3)
Expand Down

0 comments on commit 9ebc864

Please sign in to comment.