interpolated_LUTs.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:6S_emulator 作者: samsammurphy 项目源码 文件源码
def interpolate_LUTs(self):
    """
    interpolate look up tables
    """

    filepaths = sorted(glob.glob(self.LUTs_dir+os.path.sep+'*.lut'))

    if filepaths:

      print('running n-dimensional interpolation may take a few minutes...')

      try:

        for fpath in filepaths:

          fname = os.path.basename(fpath)
          fid, ext = os.path.splitext(fname)
          ilut_filepath = os.path.join(self.iLUTs_dir,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('LUTs directory: ',self.LUTs_dir)
      print('LUT files (.lut) not found in LUTs directory, try downloading?')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号