Skip to content
Snippets Groups Projects

hs2modis: fix crash in Cris2Modis

Open Fazlul Shahriar requested to merge fshahriar/intercal:modissrf into master
1 file
+ 34
3
Compare changes
  • Side-by-side
  • Inline
+ 34
3
import itertools
import numpy as np
from intercal.modis_srf import ModisSrfCatalog
from pyhdf import SD
from intercal.srf import WavelengthSrf
from intercal.util import wn2wl
class ModisSrfCatalog(object):
def __init__(self, srf_path):
self.srfs = self.read_srfs(srf_path)
def get(self, band):
return self.srfs[band]
def read_srfs(self, srf_path):
sd = SD.SD(srf_path)
# work around a weird issue with modis_terra.srf.nc. indexing the
# SDS with [:] returns [20 0 0 ...], but doing it this way works
# fine. no idea why
band = list(sd.select('channel_list'))
nu_begin = sd.select('begin_frequency')[:]
nu_end = sd.select('end_frequency')[:]
srfs = {}
for band, nu_begin, nu_end in zip(band, nu_begin, nu_end):
F = sd.select('channel_%s_response' % band)[:][::-1]
lambda_ = wn2wl(np.linspace(nu_begin, nu_end, len(F)))[::-1]
srfs[band] = WavelengthSrf(lambda_, F)
sd.end()
return srfs
class Airs2Modis(object):
@@ -36,7 +68,7 @@ class Airs2Modis(object):
# 2. an array with the channel wavenumbers
# 3. an array with the channel noise equivalent delta temperatures
# at 250K
#
#
def read_airs_chan_data(filename):
# loop through lines in the text file:
@@ -97,4 +129,3 @@ def convert_to_wavelength_based_radiance(nu, rad_nu):
lambda_ = 10000.0 / nu
rad_lambda = rad_nu * 1e-7 * nu**2
return lambda_[::-1], rad_lambda[...,::-1]
Loading