Example #1
0
    def test_blackbody_dask(self):
        """Calculate the blackbody radiation from wavelengths and temperatures with dask arrays."""
        import dask
        import dask.array as da
        tb_therm = da.from_array([[300., 301], [299, 298], [279, 286]],
                                 chunks=2)
        with dask.config.set(scheduler=CustomScheduler(0)):
            black = blackbody((10. * 1E-6, 11.e-6), tb_therm)
        self.assertIsInstance(black, da.Array)

        tb_therm = da.from_array([[300., 301], [0., 298], [279, 286]],
                                 chunks=2)
        with dask.config.set(scheduler=CustomScheduler(0)):
            black = blackbody((10. * 1E-6, 11.e-6), tb_therm)
        self.assertIsInstance(black, da.Array)
Example #2
0
    def test_blackbody(self):
        """Calculate the blackbody radiation from wavelengths and
        temperatures
        """
        black = blackbody((11. * 1E-6, ), [300., 301])
        self.assertEqual(black.shape[0], 2)
        self.assertAlmostEqual(black[0], RAD_11MICRON_300KELVIN)
        self.assertAlmostEqual(black[1], RAD_11MICRON_301KELVIN)

        black = blackbody(13. * 1E-6, 200.)
        self.assertTrue(np.isscalar(black))

        tb_therm = np.array([[300., 301], [299, 298], [279, 286]])
        black = blackbody((10. * 1E-6, 11.e-6), tb_therm)
        print black
        tb_therm = np.array([[300., 301], [0., 298], [279, 286]])
        black = blackbody((10. * 1E-6, 11.e-6), tb_therm)
        print black
Example #3
0
    def test_blackbody(self):
        """
        Calculate the blackbody radiation from wavelengths and temperatures 
        """

        b = blackbody((11. * 1E-6, ), [300., 301])
        self.assertEqual(b.shape[0], 2)
        self.assertAlmostEqual(b[0], RAD_11MICRON_300KELVIN)
        self.assertAlmostEqual(b[1], RAD_11MICRON_301KELVIN)

        b = blackbody(13. * 1E-6, 200.)
        self.assertTrue(np.isscalar(b))

        tb_therm = np.array([[300., 301], [299, 298], [279, 286]])
        b = blackbody((10. * 1E-6, 11.e-6), tb_therm)
        print b
        tb_therm = np.array([[300., 301], [0., 298], [279, 286]])
        b = blackbody((10. * 1E-6, 11.e-6), tb_therm)
        print b
Example #4
0
    def test_blackbody(self):
        """Calculate the blackbody radiation from wavelengths and temperatures."""
        wavel = 11. * 1E-6
        black = blackbody((wavel, ), [300., 301])
        self.assertEqual(black.shape[0], 2)
        self.assertAlmostEqual(black[0], RAD_11MICRON_300KELVIN)
        self.assertAlmostEqual(black[1], RAD_11MICRON_301KELVIN)

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

        black = blackbody(13. * 1E-6, 200.)
        self.assertTrue(np.isscalar(black))

        tb_therm = np.array([[300., 301], [299, 298], [279, 286]])
        black = blackbody((10. * 1E-6, 11.e-6), tb_therm)
        self.assertIsInstance(black, np.ndarray)

        tb_therm = np.array([[300., 301], [0., 298], [279, 286]])
        black = blackbody((10. * 1E-6, 11.e-6), tb_therm)
        self.assertIsInstance(black, np.ndarray)
Example #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}
    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}