You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"""Converts anything in the current history dictionary into a numpy array along with the time this cache was made. This is useful for speeding up animating functions which require slicing the history data but repeatedly converting to arrays is expensive. This is called automatically by the plot_trajectory function if the history data has not been cached yet.
1087
-
TODO This should probably be improved, right now it will convert and cache _all_ history data, even if only some of it is needed."""
try: #will skip if for any reason this key cannot be converted to an array, so you can still save random stuff into the history dict without breaking this function
"""Returns the history dataframe as a dictionary of numpy arrays (as opposed to lists). This getter-function only updates the self._history_arrays if the Agent/Neuron has updates since the last time it was called. This avoids expensive repeated conversion of lists to arrays during animations."""
1086
+
if(self._last_history_array_cache_time!=self.t):
1087
+
self._history_arrays= {}
1088
+
self._last_history_array_cache_time=self.t
1089
+
forkeyinself.history.keys():
1090
+
try: #will skip if for any reason this key cannot be converted to an array, so you can still save random stuff into the history dict without breaking this function
self._history_arrays= {} # this dictionary is the same as self.history except the data is in arrays not lists BUT it should only be accessed via its getter-function `self.get_history_arrays()`. This is because the lists are only converted to arrays when they are accessed, not on every step, so as to save time.
129
+
127
130
self.colormap="inferno"# default colormap for plotting ratemaps
128
131
129
132
ifratinabox.verboseisTrue:
@@ -347,6 +350,7 @@ def plot_rate_map(
347
350
"""
348
351
#Set kwargs (TODO make lots of params accessible here as kwargs)
bin_size=kwargs.get("bin_size", 0.04) #only relevant if you are plotting by method="history"
350
354
351
355
352
356
# GET DATA
@@ -367,25 +371,25 @@ def plot_rate_map(
367
371
method="history"
368
372
369
373
ifmethod=="history"orspikes==True:
370
-
t=np.array(self.history["t"])
374
+
history_data=self.get_history_arrays() # converts lists to arrays (if this wasn't just done) and returns them in a dict same as self.history but with arrays not lists
375
+
t=history_data["t"]
371
376
# times to plot
372
377
iflen(t) ==0:
373
-
print(
374
-
"Can't plot rate map by method='history' since there is no available data to plot. "
375
-
)
378
+
print("Can't plot rate map by method='history', nor plot spikes, since there is no available data to plot. ")
376
379
return
377
380
t_end=t_endort[-1]
378
381
position_data_agent=kwargs.get("position_data_agent", self.Agent) # In rare cases you may like to plot this cells rate/spike data against the position of a diffferent Agent. This kwarg enables that.
#rather than just "nan-ing" the regions where no data was observed we'll plot ontop a "mask" overlay which blocks with a grey square regions where no data was observed. The benefit of this technique is it still allows us to use "bicubic" interpolation which is much smoother than the default "nearest" interpolation.
486
+
binary_colors= [(0,0,0,0),ratinabox.LIGHTGREY] #transparent if theres data, grey if there isn't
"""Returns the history dataframe as a dictionary of numpy arrays (as opposed to lists). This getter-function only updates the self._history_arrays if the Agent/Neuron has updates since the last time it was called. This avoids expensive repeated conversion of lists to arrays during animations."""
771
+
if (self._last_history_array_cache_time!=self.Agent.t):
772
+
self._history_arrays= {}
773
+
self._last_history_array_cache_time=self.Agent.t
774
+
forkeyinself.history.keys():
775
+
try: #will skip if for any reason this key cannot be converted to an array, so you can still save random stuff into the history dict without breaking this function
0 commit comments