Skip to content

Commit 9331416

Browse files
Keep the cached cdipdir value after it's checked, and reuse it if it exists, rather then fetching the same value several times
1 parent 5a7c1db commit 9331416

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

pyspedas/cotrans_tools/cotrans_lib.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,11 @@ def cdipdir_vect(time_in=None, iyear=None, idoy=None):
304304

305305
for i in range(len(idoy)):
306306
# check the cache before re-calculating the dipole direction
307-
if cdipdir_cache.get(1000*iyear[i] + idoy[i]) != None:
308-
d1.append(cdipdir_cache.get(iyear[i] + idoy[i])[0])
309-
d2.append(cdipdir_cache.get(iyear[i] + idoy[i])[1])
310-
d3.append(cdipdir_cache.get(iyear[i] + idoy[i])[2])
307+
cached_value = cdipdir_cache.get(1000*iyear[i]+idoy[i])
308+
if cached_value != None:
309+
d1.append(cached_value[0])
310+
d2.append(cached_value[1])
311+
d3.append(cached_value[2])
311312
continue
312313
_d1, _d2, _d3 = cdipdir(None, iyear[i], idoy[i])
313314
d1.append(_d1)

0 commit comments

Comments
 (0)