Пример #1
0
    def test_blackbody_wn(self):
        """Calculate the blackbody radiation from wavenumbers and temperatures."""
        wavenumber = 90909.1  # 11 micron band
        black = blackbody_wn((wavenumber, ), [300., 301])
        self.assertEqual(black.shape[0], 2)
        self.assertAlmostEqual(black[0], WN_RAD_11MICRON_300KELVIN)
        self.assertAlmostEqual(black[1], WN_RAD_11MICRON_301KELVIN)

        temp1 = blackbody_wn_rad2temp(wavenumber, black[0])
        self.assertAlmostEqual(temp1, 300.0, 4)
        temp2 = blackbody_wn_rad2temp(wavenumber, black[1])
        self.assertAlmostEqual(temp2, 301.0, 4)

        t__ = blackbody_wn_rad2temp(wavenumber, [0.001, 0.0009])
        expected = [290.3276916, 283.76115441]
        self.assertAlmostEqual(t__[0], expected[0])
        self.assertAlmostEqual(t__[1], expected[1])

        radiances = np.array([0.001, 0.0009, 0.0012, 0.0018]).reshape(2, 2)
        t__ = blackbody_wn_rad2temp(wavenumber, radiances)
        expected = np.array(
            [290.3276916, 283.76115441, 302.4181330,
             333.1414164]).reshape(2, 2)
        self.assertAlmostEqual(t__[1, 1], expected[1, 1], 5)
        self.assertAlmostEqual(t__[0, 0], expected[0, 0], 5)
        self.assertAlmostEqual(t__[0, 1], expected[0, 1], 5)
        self.assertAlmostEqual(t__[1, 0], expected[1, 0], 5)

        assertNumpyArraysEqual(t__, expected)
Пример #2
0
    def test_blackbody_wn(self):
        """Calculate the blackbody radiation from wavenumbers and
        temperatures
        """
        wavenumber = 90909.1  # 11 micron band
        black = blackbody_wn((wavenumber, ), [300., 301])
        self.assertEqual(black.shape[0], 2)
        self.assertAlmostEqual(black[0], WN_RAD_11MICRON_300KELVIN)
        self.assertAlmostEqual(black[1], WN_RAD_11MICRON_301KELVIN)

        temp1 = blackbody_wn_rad2temp(wavenumber, black[0])
        self.assertAlmostEqual(temp1, 300.0, 4)
        temp2 = blackbody_wn_rad2temp(wavenumber, black[1])
        self.assertAlmostEqual(temp2, 301.0, 4)

        t__ = blackbody_wn_rad2temp(wavenumber, [0.001, 0.0009])
        expected = [290.3276916, 283.76115441]
        self.assertAlmostEqual(t__[0], expected[0])
        self.assertAlmostEqual(t__[1], expected[1])

        radiances = np.array([0.001, 0.0009, 0.0012, 0.0018]).reshape(2, 2)
        t__ = blackbody_wn_rad2temp(wavenumber, radiances)
        expected = np.array([290.3276916, 283.76115441,
                             302.4181330, 333.1414164]).reshape(2, 2)
        self.assertAlmostEqual(t__[1, 1], expected[1, 1], 5)
        self.assertAlmostEqual(t__[0, 0], expected[0, 0], 5)
        self.assertAlmostEqual(t__[0, 1], expected[0, 1], 5)
        self.assertAlmostEqual(t__[1, 0], expected[1, 0], 5)

        assertNumpyArraysEqual(t__, expected)
Пример #3
0
 def test_blackbody_wn(self):
     """Calculate the blackbody radiation from wavenumbers and
     temperatures
     """
     wavenumber = 90909.1  # 11 micron band
     black = blackbody_wn((wavenumber, ), [300., 301])
     print black
     self.assertEqual(black.shape[0], 2)
     self.assertAlmostEqual(black[0], WN_RAD_11MICRON_300KELVIN)
     self.assertAlmostEqual(black[1], WN_RAD_11MICRON_301KELVIN)
Пример #4
0
    def test_blackbody_wn(self):
        """
        Calculate the blackbody radiation from wavenumbers and temperatures
        """

        wavenumber = 90909.1  # 11 micron band
        b = blackbody_wn((wavenumber, ), [300., 301])
        print b
        self.assertEqual(b.shape[0], 2)
        self.assertAlmostEqual(b[0], WN_RAD_11MICRON_300KELVIN)
        self.assertAlmostEqual(b[1], WN_RAD_11MICRON_301KELVIN)
Пример #5
0
    def tb2radiance(self, tb_, bandname, lut=None):
        """Get the radiance from the brightness temperature (Tb) given the
        band name. 
        """
        from scipy import integrate

        if self.wavespace == WAVE_NUMBER:
            unit = 'W/m^2 sr^-1 (m^-1)^-1'
            scale = 1.0
        else:
            unit = 'W/m^2 sr^-1 m^-1'
            scale = 1.0

        if not bandname and not np.any(lut):
            raise SyntaxError('Either a band name or a lut needs '
                              'to be provided as input to the function call!')

        if lut:
            ntb = (tb_ * self.tb_scale).astype('int16')
            start = int(lut['tb'][0] * self.tb_scale)
            retv = {}
            bounds = 0, lut['radiance'].shape[0] - 1
            index = np.clip(ntb - start, bounds[0], bounds[1])
            retv['radiance'] = lut['radiance'][index]
            if retv['radiance'].ravel().shape[0] == 1:
                retv['radiance'] = retv['radiance'][0]
            retv['unit'] = unit
            retv['scale'] = scale
            return retv

        if self.wavespace == WAVE_LENGTH:
            wv_ = (self.rsr[bandname][self.detector]['wavelength'] *
                   self._wave_si_scale)
            resp = self.rsr[bandname][self.detector]['response']
            planck = blackbody(wv_, tb_) * resp
        elif self.wavespace == WAVE_NUMBER:
            wv_ = (self.rsr[bandname][self.detector]['wavenumber'] *
                   self._wave_si_scale)
            resp = self.rsr[bandname][self.detector]['response']
            planck = blackbody_wn(wv_, tb_) * resp
        else:
            raise NotImplementedError('%s representation of '
                                      'rsr data not supported!' %
                                      str(self.wavespace))

        radiance = integrate.trapz(planck, wv_) / np.trapz(resp, wv_)
        return {'radiance': radiance,
                'unit': unit,
                'scale': scale}
Пример #6
0
    def tb2radiance(self, tb_, bandname, lut=None):
        """Get the radiance from the brightness temperature (Tb) given the
        band name. 
        """
        from scipy import integrate

        if self.wavespace == WAVE_NUMBER:
            unit = 'W/m^2 sr^-1 (m^-1)^-1'
            scale = 1.0
        else:
            unit = 'W/m^2 sr^-1 m^-1'
            scale = 1.0

        if not bandname and not np.any(lut):
            raise SyntaxError('Either a band name or a lut needs ' +
                              'to be provided as input to the function call!')

        if lut:
            ntb = (tb_ * self.tb_scale).astype('int16')
            start = int(lut['tb'][0] * self.tb_scale)
            retv = {}
            retv['radiance'] = lut['radiance'][ntb - start]
            retv['unit'] = unit
            retv['scale'] = scale
            return retv

        if self.wavespace == WAVE_LENGTH:
            wv_ = (self.rsr[bandname][self.detector]['wavelength'] *
                   self._wave_si_scale)
            resp = self.rsr[bandname][self.detector]['response']
            planck = blackbody(wv_, tb_) * resp
        elif self.wavespace == WAVE_NUMBER:
            wv_ = (self.rsr[bandname][self.detector]['wavenumber'] *
                   self._wave_si_scale)
            resp = self.rsr[bandname][self.detector]['response']
            planck = blackbody_wn(wv_, tb_) * resp
        else:
            raise NotImplementedError(str(self.wavespace) +
                                      ' representation of ' +
                                      'rsr data not supported!')

        radiance = integrate.trapz(planck, wv_) / np.trapz(resp, wv_)

        return {'radiance': radiance,
                'unit': unit,
                'scale': scale}