Skip to content

Commit

Permalink
allow an external cache of interpolators
Browse files Browse the repository at this point in the history
  • Loading branch information
segasai committed Jul 31, 2024
1 parent bfae18e commit 94c1cfa
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions py/rvspecfit/spec_inter.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ class interp_cache:
interps = {}


def getInterpolator(HR, config, warmup_cache=False):
def getInterpolator(HR, config, warmup_cache=False, cache=None):
""" Return the spectrum interpolation object for a given instrument
setup HR and config. This function also checks the cache
Expand All @@ -288,6 +288,9 @@ def getInterpolator(HR, config, warmup_cache=False):
Spectral configuration
config: dict
Configuration
cache: dict or None
Dictionary like object with the cache. If None, internal cache is
used instead.
warmup_cache: bool
If True we read the whole file to warm up the OS cache
Expand All @@ -297,8 +300,9 @@ def getInterpolator(HR, config, warmup_cache=False):
The spectral interpolator
"""
if HR not in interp_cache.interps:

if cache is None:
cache = interp_cache.interps
if HR not in cache:
savefile = (config['template_lib'] + '/' +
make_nd.INTERPOL_PKL_NAME % HR)
with open(savefile, 'rb') as fd0:
Expand Down Expand Up @@ -362,10 +366,8 @@ def getInterpolator(HR, config, warmup_cache=False):
creation_soft_version=creation_soft_version,
filename=savefile,
logstep=logstep)
interp_cache.interps[HR] = interpObj
else:
interpObj = interp_cache.interps[HR]
return interpObj
cache[HR] = interpObj
return cache[HR]


def getSpecParams(setup, config):
Expand Down

0 comments on commit 94c1cfa

Please sign in to comment.