def interpolate_LUTs(self):
"""
interpolates look up table files (.lut)
"""
filepaths = sorted(glob.glob(self.LUT_path+os.path.sep+'*.lut'))
if filepaths:
print('\n...Running n-dimensional interpolation may take a several minutes (only need to do this once)...')
try:
for fpath in filepaths:
fname = os.path.basename(fpath)
fid, ext = os.path.splitext(fname)
ilut_filepath = os.path.join(self.iLUT_path,fid+'.ilut')
if os.path.isfile(ilut_filepath):
print('iLUT file already exists (skipping interpolation): {}'.format(fname))
else:
print('Interpolating: '+fname)
# load look up table
LUT = pickle.load(open(fpath,"rb"))
# input variables (all permutations)
invars = LUT['config']['invars']
inputs = list(product(invars['solar_zs'],
invars['H2Os'],
invars['O3s'],
invars['AOTs'],
invars['alts']))
# output variables (6S correction coefficients)
outputs = LUT['outputs']
# piecewise linear interpolant in n-dimensions
t = time.time()
interpolator = LinearNDInterpolator(inputs,outputs)
print('Interpolation took {:.2f} (secs) = '.format(time.time()-t))
# save new interpolated LUT file
pickle.dump(interpolator, open(ilut_filepath, 'wb' ))
except:
print('interpolation error')
else:
print('look up tables files (.lut) not found in LUTs directory:\n{}'.format(self.LUT_path))
interpolated_lookup_tables.py 文件源码
python
阅读 31
收藏 0
点赞 0
评论 0
评论列表
文章目录