Skip to content
Snippets Groups Projects
Commit 53e8fd7a authored by Petter Källström's avatar Petter Källström
Browse files

plot_window: changed type(obj)==xxx to isinstance(obj, xxx)

parent 6ff479dd
No related branches found
No related tags found
1 merge request!312Draft: Added support for plotting result from many simulations. Solves #209
Pipeline #95831 passed
...@@ -67,17 +67,17 @@ class PlotWindow(QWidget): ...@@ -67,17 +67,17 @@ class PlotWindow(QWidget):
########### Flattening sim_result, if it is a list of results ####### ########### Flattening sim_result, if it is a list of results #######
# take: sim_result (possibly on form ['name1', simres1, 'name2', simres2, ...] # take: sim_result (possibly on form ['name1', simres1, 'name2', simres2, ...]
# generate: sim_result (dict) # generate: sim_result (dict)
if type(sim_result) == Simulation: if isinstance(sim_result, Simulation):
sim_result = sim_result._results sim_result = sim_result._results
assert type(sim_result) == dict, TypeError( assert isinstance(sim_result, dict), TypeError(
"Parsing sim_result as a Simulation, but the _result seems broken." "Parsing sim_result as a Simulation, but the _result seems broken."
) )
elif type(sim_result) == list: elif isinstance(sim_result, list):
new_result = dict() new_result = dict()
nr = 0 # value number. Used for automatic names. nr = 0 # value number. Used for automatic names.
name = None name = None
for element in sim_result: for element in sim_result:
if type(element) == str: if isinstance(element, str):
assert not name, Exception( assert not name, Exception(
"Parsing sim_result as a list. Did you provide two names after" "Parsing sim_result as a list. Did you provide two names after"
" each other?" " each other?"
...@@ -87,11 +87,11 @@ class PlotWindow(QWidget): ...@@ -87,11 +87,11 @@ class PlotWindow(QWidget):
if not name: if not name:
nr = nr + 1 nr = nr + 1
name = "(res" + str(nr) + ")" name = "(res" + str(nr) + ")"
if type(element) == dict: if isinstance(element, dict):
res = element res = element
elif type(element) == Simulation: elif isinstance(element, Simulation):
res = element._results res = element._results
assert type(res) == dict, TypeError( assert isinstance(res, dict), TypeError(
f"Parsing sim_result as a list. Result '{name}' is a" f"Parsing sim_result as a list. Result '{name}' is a"
" Simulation, and its _result seems broken." " Simulation, and its _result seems broken."
) )
...@@ -110,10 +110,10 @@ class PlotWindow(QWidget): ...@@ -110,10 +110,10 @@ class PlotWindow(QWidget):
" in the list?" " in the list?"
) )
sim_result = new_result sim_result = new_result
elif type(sim_result) != dict: elif not isinstance(sim_result, dict):
raise TypeError( raise TypeError(
"sim_result must be a dict, Simulation or list. Found" "sim_result must be a dict, Simulation or list."
f" {type(sim_result)}" f" Found {type(sim_result)}"
) )
########### Categorizing/sorting/renaming sim_results: ############## ########### Categorizing/sorting/renaming sim_results: ##############
...@@ -335,7 +335,7 @@ def start_simulation_dialog( ...@@ -335,7 +335,7 @@ def start_simulation_dialog(
# Simple test of the dialog # Simple test of the dialog
if __name__ == "__main__": if __name__ == "__main__":
sim_res1 = { res1 = {
'0': [1.5, 1.6, 1.5, 1], '0': [1.5, 1.6, 1.5, 1],
'1': [1.0, 2.0, 1.5, 1.1], '1': [1.0, 2.0, 1.5, 1.1],
'add1': [1.5, 1.5, 1, 1], 'add1': [1.5, 1.5, 1, 1],
...@@ -347,7 +347,7 @@ if __name__ == "__main__": ...@@ -347,7 +347,7 @@ if __name__ == "__main__":
't2': [1, 1, 2, 1], 't2': [1, 1, 2, 1],
't3': [1, 1, 1, 2], 't3': [1, 1, 1, 2],
} }
sim_res2 = { res2 = {
'0': [0.5, 0.6, 0.5, 0], '0': [0.5, 0.6, 0.5, 0],
'1': [0.0, 1.0 + 0.3j, 0.5, 0.1j], '1': [0.0, 1.0 + 0.3j, 0.5, 0.1j],
'add1': [0.5, 0.5, 0, 0], 'add1': [0.5, 0.5, 0, 0],
...@@ -359,11 +359,9 @@ if __name__ == "__main__": ...@@ -359,11 +359,9 @@ if __name__ == "__main__":
't2': [0, 0, 1, 0], 't2': [0, 0, 1, 0],
't3': [0, 0, 0, 1], 't3': [0, 0, 0, 1],
} }
sim_res3 = { res3 = {
'0': np.random.rand(200).tolist(), '0': np.random.rand(200).tolist(),
'1': np.random.rand(200).tolist(), '1': np.random.rand(200).tolist(),
} }
# start_simulation_dialog(sim_res3) # start_simulation_dialog(res3)
start_simulation_dialog( start_simulation_dialog(['Real', res1, 'Cpx', res2, res3], "Test data")
['simReal', sim_res1, 'simCpx', sim_res2, sim_res3], "Test data"
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment