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

fix numpy NaN issue #420

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions addie/processing/mantid/master_table/mass_density_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class MassDensityWindow(QMainWindow):
chemical_formula_defined = False
geometry_dimensions_defined = False

total_number_of_atoms = np.NaN
total_molecular_mass = np.NaN
total_number_of_atoms = np.nan
total_molecular_mass = np.nan

column = 0

Expand Down
34 changes: 17 additions & 17 deletions addie/processing/mantid/master_table/master_table_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
},
},
"Material": "",
"Density": {"MassDensity": np.NaN,
"Density": {"MassDensity": np.nan,
"UseMassDensity": True,
"NumberDensity": np.NaN,
"NumberDensity": np.nan,
"UseNumberDensity": False,
"Mass": np.NaN,
"Mass": np.nan,
"UseMass": False},
"PackingFraction": np.NaN,
"PackingFraction": np.nan,
"Geometry": {"Shape": "",
"Radius": np.NaN,
"Radius2": np.NaN,
"Height": np.NaN,
"Radius": np.nan,
"Radius2": np.nan,
"Height": np.nan,
},
"AbsorptionCorrection": {"Type": "",
},
Expand All @@ -60,7 +60,7 @@
"Sample": copy.deepcopy(_element),
"Normalization": copy.deepcopy(_element),
"Calibration": {"Filename": ""},
"HighQLinearFitRange": np.NaN,
"HighQLinearFitRange": np.nan,
"Merging": {"QBinning": [],
"SumBanks": [],
"Characterizations": "",
Expand Down Expand Up @@ -104,7 +104,7 @@ def __init__(self, parent=None):

self.calibration = str(self.parent.processing_ui.calibration_file.text())

self.NA_list = ["None", "N/A", "", np.NaN]
self.NA_list = ["None", "N/A", "", np.nan]

def export(self, filename='', row=None):
"""create dictionary of all rows unless `row` argument is specified,
Expand Down Expand Up @@ -293,11 +293,11 @@ def _retrieve_element_infos(self, element='sample', row=-1):
radius2 = str(
self.parent.master_table_list_ui[key][element]['geometry']['radius2']['value'].text())

dict_element["Geometry"]["Radius"] = np.NaN if (
dict_element["Geometry"]["Radius"] = np.nan if (
radius in self.__nan_list) else float(radius)
dict_element["Geometry"]["Radius2"] = np.NaN if (
dict_element["Geometry"]["Radius2"] = np.nan if (
radius2 in self.__nan_list) else float(radius2)
dict_element["Geometry"]["Height"] = np.NaN if (
dict_element["Geometry"]["Height"] = np.nan if (
height in self.__nan_list) else float(height)

column += 1
Expand Down Expand Up @@ -613,20 +613,20 @@ def density_selection_for_reduction(self, dictionary):
# key

dictionary.pop('Density')
dictionary['MassDensity'] = np.NaN if (mass_density in self.__nan_list) else float(mass_density)
dictionary['MassDensity'] = np.nan if (mass_density in self.__nan_list) else float(mass_density)

return dictionary

def _remove_keys_from_with_nan_values(
self, dictionary, selected_values=None):
"""Remove keys in a dictionary if the value is NaN
"""Remove keys in a dictionary if the value is nan

:param dictionary: Dictionary with keys we want to check
:type dictionary: dict
:param selected_values: Dictionary with keys we want to check
:type dictionary: dict

:return: Dictionary with keys removed where value is NaN
:return: Dictionary with keys removed where value is nan
:rtype: dict
"""
# Set default to check all keys unless selected_values defined
Expand All @@ -643,7 +643,7 @@ def _remove_keys_from_with_nan_values(
",".join(dictionary.keys()))
raise Exception(err_string)

# Remove keys with NaN values
# Remove keys with nan values
for key in selected_values:
try:
if np.isnan(dictionary[key]):
Expand Down Expand Up @@ -727,7 +727,7 @@ def geometry_selection_for_reduction(self, dictionary):
print("No Geometry found, default geometry added:", geometry)
return dictionary

# Remove all NaN values from Geometry
# Remove all nan values from Geometry
dictionary['Geometry'] = self._remove_keys_from_with_nan_values(
dictionary['Geometry'])

Expand Down
4 changes: 2 additions & 2 deletions addie/processing/mantid/master_table/table_row_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ def insert_row(self, row=-1,
_mass_density_infos = {'number_density': copy.deepcopy(_mass_density_options),
'mass_density': copy.deepcopy(_mass_density_options),
'mass': copy.deepcopy(_mass_density_options),
'molecular_mass': np.NaN,
'total_number_of_atoms': np.NaN,
'molecular_mass': np.nan,
'total_number_of_atoms': np.nan,
}
_material_infos = {'mantid_format': None,
'addie_format': None}
Expand Down
10 changes: 5 additions & 5 deletions addie/utilities/math_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def oneAndOnlyOneTrue(iterable):
raise


def volume_of_cylinder(radius=np.NaN, height=np.NaN):
def volume_of_cylinder(radius=np.nan, height=np.nan):
"""Computes volume of a cylinder

:param radius: Radius of cylinder (in units of length)
Expand All @@ -92,7 +92,7 @@ def volume_of_cylinder(radius=np.NaN, height=np.NaN):
return np.float(np.pi) * np.float(radius)**2 * np.float(height)


def volume_of_sphere(radius=np.NaN):
def volume_of_sphere(radius=np.nan):
"""Computes volume of a sphere

:param radius: Radius of sphere (in units of length)
Expand All @@ -105,9 +105,9 @@ def volume_of_sphere(radius=np.NaN):


def volume_of_hollow_cylinder(
inner_radius=np.NaN,
outer_radius=np.NaN,
height=np.NaN):
inner_radius=np.nan,
outer_radius=np.nan,
height=np.nan):
"""Computes volume of a hollow cylinder

:param inner_radius: Inner radius of cylinder (in units of length)
Expand Down
Loading