Skip to content

Commit

Permalink
corrected potential comparison bug
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenaH84 committed Jun 19, 2024
1 parent b7ddfd6 commit 753b525
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 22 deletions.
56 changes: 40 additions & 16 deletions streamlit/app_scripts/app_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -4919,24 +4919,49 @@ def find_max_length_array_y_axis(self,arrays):

return arrays


def find_closest_value_index(self,array, value):
"""Find the index of the value in the array that is closest to the specified value."""
if isinstance(array, np.ndarray):
diff = np.abs(array - value)
idx = np.where(diff <= np.diff(array).min())[0]
if idx.size > 0:
return idx[diff[idx].argmin()]
elif isinstance(array, list):
min_diff = float('inf')
closest_index = None
for i, elem in enumerate(array):
diff = abs(elem - value)
if diff <= min_diff:
min_diff = diff
closest_index = i
if isinstance(array, (np.ndarray, list)):
# Convert the array to a numpy array for uniform handling
array = np.array(array)
mask = ~np.isnan(array)

# Filter the array to exclude NaN values
valid_array = array[mask]

# Compute the absolute difference with the valid array
diff = np.abs(valid_array - value)

# Find the index of the minimum difference in the valid array
closest_index_in_valid_array = np.argmin(diff)

# Map the index back to the original array
closest_index = np.where(mask)[0][closest_index_in_valid_array]

return closest_index
return None
else:
st.write("Type not handled:", type(array))
return None

# def find_closest_value_index(self,array, value):
# """Find the index of the value in the array that is closest to the specified value."""
# if isinstance(array, np.ndarray):
# diff = np.abs(array - value)
# idx = np.where(diff <= np.diff(array).min())[0]
# if idx.size > 0:
# return idx[diff[idx].argmin()]
# elif isinstance(array, list):
# min_diff = float('inf')
# closest_index = None
# for i, elem in enumerate(array):
# diff = abs(elem - value)
# if diff <= min_diff:
# min_diff = diff
# closest_index = i
# return closest_index
# else:
# st.write("type " + type(array)+"not handled")
# return None

def view_plots_static(_self,time,state):

Expand Down Expand Up @@ -5588,7 +5613,6 @@ def create_subplot(_self,x_data, y_data, title, x_label, y_label, x_min=None, y_
fig = go.Figure(layout=go.Layout(
autosize=True
))

if isinstance(_self.selected_data_sets, list) and len(_self.selected_data_sets) > 1:

for i,x in enumerate(x_data):
Expand Down
6 changes: 3 additions & 3 deletions streamlit/input_files/battmo_formatted_input.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"diffusionModelType": "full",
"SolidDiffusion": {
"activationEnergyOfDiffusion": 5000.0,
"activationEnergyOfDiffusion": 70000.0,
"referenceDiffusionCoefficient": 3.9e-14,
"particleRadius": 1e-06,
"N": 10
Expand Down Expand Up @@ -133,7 +133,7 @@
"bruggemanCoefficient": 1.5
},
"Electrolyte": {
"initialConcentration": 1000.0,
"initialConcentration": 1800.0,
"specificHeatCapacity": 1518.0,
"thermalConductivity": 0.099,
"density": 1200,
Expand Down Expand Up @@ -170,7 +170,7 @@
"Control": {
"controlPolicy": "CCCV",
"initialControl": "charging",
"numberOfCycles": 1,
"numberOfCycles": 10,
"CRate": 1.0,
"DRate": 1.0,
"lowerCutoffVoltage": 2.4,
Expand Down
6 changes: 3 additions & 3 deletions streamlit/input_files/linked_data_input.json
Original file line number Diff line number Diff line change
Expand Up @@ -1929,7 +1929,7 @@
"@type": "emmo:Energy",
"value": {
"@type": "emmo:Numerical",
"hasNumericalData": 5000.0
"hasNumericalData": 70000.0
},
"unit": {
"label": "JoulePerMole",
Expand Down Expand Up @@ -5961,7 +5961,7 @@
"@type": "string",
"value": {
"@type": "emmo:Numerical",
"hasNumericalData": 1000.0
"hasNumericalData": 1800.0
},
"unit": {
"label": "MolPerLiter",
Expand Down Expand Up @@ -6357,7 +6357,7 @@
"@type": "emmo:NumberOfEntities",
"value": {
"@type": "emmo:Numerical",
"hasNumericalData": 1
"hasNumericalData": 10
},
"unit": {
"label": "UnitOne",
Expand Down
Binary file modified streamlit/output_files/battmo_results.hdf5
Binary file not shown.

0 comments on commit 753b525

Please sign in to comment.