示例#1
0
    def get_effective_wavelength(self, bandname):
        """Get the effective wavelength with Rayleigh scattering in mind"""
        try:
            rsr = RelativeSpectralResponse(self.platform_name, self.sensor)
        except(IOError, OSError):
            LOG.exception(
                "No spectral responses for this platform and sensor: %s %s", self.platform_name, self.sensor)
            if isinstance(bandname, (float, integer_types)):
                LOG.warning(
                    "Effective wavelength is set to the requested band wavelength = %f", bandname)
                return bandname

            msg = ("Can't get effective wavelength for band %s on platform %s and sensor %s" %
                   (str(bandname), self.platform_name, self.sensor))
            raise KeyError(msg)

        if isinstance(bandname, str):
            bandname = BANDNAMES.get(self.sensor, BANDNAMES['generic']).get(bandname, bandname)
        elif isinstance(bandname, (float, integer_types)):
            if not(0.4 < bandname < 0.8):
                raise BandFrequencyOutOfRange(
                    'Requested band frequency should be between 0.4 and 0.8 microns!')
            bandname = get_bandname_from_wavelength(self.sensor, bandname, rsr.rsr)

        wvl, resp = rsr.rsr[bandname][
            'det-1']['wavelength'], rsr.rsr[bandname]['det-1']['response']

        cwvl = get_central_wave(wvl, resp, weight=1. / wvl**4)
        LOG.debug("Band name: %s  Effective wavelength: %f", bandname, cwvl)

        return cwvl
示例#2
0
def convert2hdf5(platform_name):
    """Retrieve original RSR data and convert to internal hdf5 format"""

    import h5py

    ahi = AhiRSR(platform_name)
    filename = os.path.join(ahi.output_dir,
                            "rsr_ahi_{platform}.h5".format(platform=platform_name))

    with h5py.File(filename, "w") as h5f:
        h5f.attrs['description'] = 'Relative Spectral Responses for AHI'
        h5f.attrs['platform_name'] = platform_name
        h5f.attrs['sensor'] = 'ahi'
        h5f.attrs['band_names'] = AHI_BAND_NAMES.values()

        for chname in AHI_BAND_NAMES.values():

            grp = h5f.create_group(chname)
            wvl = ahi.rsr[chname][
                'wavelength'][~np.isnan(ahi.rsr[chname]['wavelength'])]
            rsp = ahi.rsr[chname][
                'response'][~np.isnan(ahi.rsr[chname]['wavelength'])]
            grp.attrs['central_wavelength'] = get_central_wave(wvl, rsp)
            arr = ahi.rsr[chname]['wavelength']
            dset = grp.create_dataset('wavelength', arr.shape, dtype='f')
            dset.attrs['unit'] = 'm'
            dset.attrs['scale'] = 1e-06
            dset[...] = arr
            arr = ahi.rsr[chname]['response']
            dset = grp.create_dataset('response', arr.shape, dtype='f')
            dset[...] = arr
示例#3
0
def convert2hdf5(platform_id, sat_number):
    """Retrieve original RSR data and convert to internal hdf5 format"""

    import h5py

    satellite_id = platform_id + str(sat_number)

    ahi = AhiRSR('ch1', satellite_id)
    filename = os.path.join(ahi.output_dir,
                            "rsr_ahi_%s%d.h5" % (platform_id, sat_number))

    with h5py.File(filename, "w") as h5f:
        h5f.attrs['description'] = 'Relative Spectral Responses for AHI'
        h5f.attrs['platform'] = platform_id
        h5f.attrs['sat_number'] = sat_number
        h5f.attrs['band_names'] = AHI_BAND_NAMES

        for chname in AHI_BAND_NAMES:
            ahi = AhiRSR(chname, satellite_id)
            grp = h5f.create_group(chname)
            wvl = ahi.rsr[
                'det-1']['wavelength'][~np.isnan(ahi.rsr['det-1']['wavelength'])]
            rsp = ahi.rsr[
                'det-1']['response'][~np.isnan(ahi.rsr['det-1']['wavelength'])]
            grp.attrs['central_wavelength'] = get_central_wave(wvl, rsp)
            arr = ahi.rsr['det-1']['wavelength']
            dset = grp.create_dataset('wavelength', arr.shape, dtype='f')
            dset.attrs['unit'] = 'm'
            dset.attrs['scale'] = 1e-06
            dset[...] = arr
            arr = ahi.rsr['det-1']['response']
            dset = grp.create_dataset('response', arr.shape, dtype='f')
            dset[...] = arr
示例#4
0
    def get_effective_wavelength(self, bandname):
        """Get the effective wavelength with Rayleigh scattering in mind"""
        try:
            rsr = RelativeSpectralResponse(self.platform_name, self.sensor)
        except(IOError, OSError):
            LOG.exception(
                "No spectral responses for this platform and sensor: %s %s", self.platform_name, self.sensor)
            if isinstance(bandname, (float, integer_types)):
                LOG.warning(
                    "Effective wavelength is set to the requested band wavelength = %f", bandname)
                return bandname
            return None

        if isinstance(bandname, str):
            bandname = BANDNAMES.get(self.sensor, BANDNAMES['generic']).get(bandname, bandname)
        elif isinstance(bandname, (float, integer_types)):
            if not(0.4 < bandname < 0.8):
                raise BandFrequencyOutOfRange(
                    'Requested band frequency should be between 0.4 and 0.8 microns!')
            bandname = get_bandname_from_wavelength(self.sensor, bandname, rsr.rsr)

        wvl, resp = rsr.rsr[bandname][
            'det-1']['wavelength'], rsr.rsr[bandname]['det-1']['response']

        cwvl = get_central_wave(wvl, resp, weight=1. / wvl**4)
        LOG.debug("Band name: %s  Effective wavelength: %f", bandname, cwvl)

        return cwvl
示例#5
0
def convert2hdf5(platform_name):
    """Retrieve original RSR data and convert to internal hdf5 format"""
    import h5py

    avhrr = AvhrrRSR('ch1', platform_name)
    filename = os.path.join(avhrr.output_dir,
                            "rsr_avhrr_%s.h5" % platform_name)

    with h5py.File(filename, "w") as h5f:
        h5f.attrs['description'] = 'Relative Spectral Responses for AVHRR'
        h5f.attrs['platform_name'] = platform_name
        h5f.attrs['band_names'] = AVHRR_BAND_NAMES

        for chname in AVHRR_BAND_NAMES:
            avhrr = AvhrrRSR(chname, satellite_id)
            grp = h5f.create_group(chname)
            wvl = avhrr.rsr['wavelength'][~np.isnan(avhrr.rsr['wavelength'])]
            rsp = avhrr.rsr['response'][~np.isnan(avhrr.rsr['wavelength'])]
            grp.attrs['central_wavelength'] = get_central_wave(wvl, rsp)
            arr = avhrr.rsr['wavelength']
            dset = grp.create_dataset('wavelength', arr.shape, dtype='f')
            dset.attrs['unit'] = 'm'
            dset.attrs['scale'] = 1e-06
            dset[...] = arr
            arr = avhrr.rsr['response']
            dset = grp.create_dataset('response', arr.shape, dtype='f')
            dset[...] = arr
示例#6
0
def convert2hdf5(platform_id, sat_number):
    """Retrieve original RSR data and convert to internal hdf5 format"""

    import h5py

    satellite_id = platform_id + str(sat_number)

    avhrr = AvhrrRSR('ch1', satellite_id)
    filename = os.path.join(avhrr.output_dir,
                            "rsr_avhrr_%s%d.h5" % (platform_id, sat_number))

    with h5py.File(filename, "w") as h5f:
        h5f.attrs['description'] = 'Relative Spectral Responses for AVHRR'
        h5f.attrs['platform'] = platform_id
        h5f.attrs['sat_number'] = sat_number
        h5f.attrs['band_names'] = AVHRR_BAND_NAMES

        for chname in AVHRR_BAND_NAMES:
            avhrr = AvhrrRSR(chname, 'noaa18')
            grp = h5f.create_group(chname)
            wvl = avhrr.rsr['wavelength'][~np.isnan(avhrr.rsr['wavelength'])]
            rsp = avhrr.rsr['response'][~np.isnan(avhrr.rsr['wavelength'])]
            grp.attrs['central_wavelength'] = get_central_wave(wvl, rsp)
            arr = avhrr.rsr['wavelength']
            dset = grp.create_dataset('wavelength', arr.shape, dtype='f')
            dset.attrs['unit'] = 'm'
            dset.attrs['scale'] = 1e-06
            dset[...] = arr
            arr = avhrr.rsr['response']
            dset = grp.create_dataset('response', arr.shape, dtype='f')
            dset[...] = arr
示例#7
0
def convert2hdf5(platform_name):
    """Retrieve original RSR data and convert to internal hdf5 format"""

    import h5py

    ahi = AhiRSR(platform_name)
    filename = os.path.join(
        ahi.output_dir, "rsr_ahi_{platform}.h5".format(platform=platform_name))

    with h5py.File(filename, "w") as h5f:
        h5f.attrs['description'] = 'Relative Spectral Responses for AHI'
        h5f.attrs['platform_name'] = platform_name
        h5f.attrs['sensor'] = 'ahi'
        h5f.attrs['band_names'] = AHI_BAND_NAMES.values()

        for chname in AHI_BAND_NAMES.values():

            grp = h5f.create_group(chname)
            wvl = ahi.rsr[chname]['wavelength'][
                ~np.isnan(ahi.rsr[chname]['wavelength'])]
            rsp = ahi.rsr[chname]['response'][
                ~np.isnan(ahi.rsr[chname]['wavelength'])]
            grp.attrs['central_wavelength'] = get_central_wave(wvl, rsp)
            arr = ahi.rsr[chname]['wavelength']
            dset = grp.create_dataset('wavelength', arr.shape, dtype='f')
            dset.attrs['unit'] = 'm'
            dset.attrs['scale'] = 1e-06
            dset[...] = arr
            arr = ahi.rsr[chname]['response']
            dset = grp.create_dataset('response', arr.shape, dtype='f')
            dset[...] = arr
示例#8
0
def convert2hdf5(platform_name):
    """Retrieve original RSR data and convert to internal hdf5 format"""
    import h5py

    modis = ModisRSR('20', platform_name)
    mfile = os.path.join(
        modis.output_dir,
        "rsr_modis_{platform}.h5".format(platform=platform_name))

    with h5py.File(mfile, "w") as h5f:
        h5f.attrs['description'] = 'Relative Spectral Responses for MODIS'
        h5f.attrs['platform_name'] = platform_name
        h5f.attrs['band_names'] = MODIS_BAND_NAMES

        for chname in MODIS_BAND_NAMES:
            modis = ModisRSR(chname, platform_name)
            grp = h5f.create_group(chname)
            grp.attrs['number_of_detectors'] = len(modis.rsr.keys())
            # Loop over each detector to check if the sampling wavelengths are
            # identical:
            det_names = [detector_name for detector_name in modis.rsr.keys()]
            wvl = modis.rsr[det_names[0]]['wavelength']
            wvl_is_constant = True
            for det in det_names[1:]:
                if wvl.shape != modis.rsr[det]['wavelength'].shape:
                    wvl_is_constant = False
                    break
                elif not np.allclose(wvl, modis.rsr[det]['wavelength']):
                    wvl_is_constant = False
                    break

            if wvl_is_constant:
                arr = modis.rsr[det_names[0]]['wavelength']
                dset = grp.create_dataset('wavelength', arr.shape, dtype='f')
                dset.attrs['unit'] = 'm'
                dset.attrs['scale'] = 1e-06
                dset[...] = arr

            # Loop over each detector:
            for det in modis.rsr:
                det_grp = grp.create_group(det)
                wvl = modis.rsr[det]['wavelength'][
                    ~np.isnan(modis.rsr[det]['wavelength'])]
                rsp = modis.rsr[det]['response'][
                    ~np.isnan(modis.rsr[det]['wavelength'])]
                det_grp.attrs['central_wavelength'] = get_central_wave(
                    wvl, rsp)
                if not wvl_is_constant:
                    arr = modis.rsr[det]['wavelength']
                    dset = det_grp.create_dataset('wavelength',
                                                  arr.shape,
                                                  dtype='f')
                    dset.attrs['unit'] = 'm'
                    dset.attrs['scale'] = 1e-06
                    dset[...] = arr

                arr = modis.rsr[det]['response']
                dset = det_grp.create_dataset('response', arr.shape, dtype='f')
                dset[...] = arr
示例#9
0
def convert2hdf5(platform_name):
    """Retrieve original RSR data and convert to internal hdf5 format"""
    import h5py

    modis = ModisRSR('20', platform_name)
    mfile = os.path.join(modis.output_dir,
                         "rsr_modis_{platform}.h5".format(platform=platform_name))

    with h5py.File(mfile, "w") as h5f:
        h5f.attrs['description'] = 'Relative Spectral Responses for MODIS'
        h5f.attrs['platform_name'] = platform_name
        h5f.attrs['band_names'] = MODIS_BAND_NAMES

        for chname in MODIS_BAND_NAMES:
            modis = ModisRSR(chname, platform_name)
            grp = h5f.create_group(chname)
            grp.attrs['number_of_detectors'] = len(modis.rsr.keys())
            # Loop over each detector to check if the sampling wavelengths are
            # identical:
            det_names = modis.rsr.keys()
            wvl = modis.rsr[det_names[0]]['wavelength']
            wvl_is_constant = True
            for det in det_names[1:]:
                if not np.alltrue(wvl == modis.rsr[det]['wavelength']):
                    wvl_is_constant = False
                    break

            if wvl_is_constant:
                arr = modis.rsr[det_names[0]]['wavelength']
                dset = grp.create_dataset('wavelength', arr.shape, dtype='f')
                dset.attrs['unit'] = 'm'
                dset.attrs['scale'] = 1e-06
                dset[...] = arr

            # Loop over each detector:
            for det in modis.rsr:
                det_grp = grp.create_group(det)
                wvl = modis.rsr[det]['wavelength'][
                    ~np.isnan(modis.rsr[det]['wavelength'])]
                rsp = modis.rsr[det]['response'][
                    ~np.isnan(modis.rsr[det]['wavelength'])]
                det_grp.attrs[
                    'central_wavelength'] = get_central_wave(wvl, rsp)
                if not wvl_is_constant:
                    arr = modis.rsr[det]['wavelength']
                    dset = det_grp.create_dataset(
                        'wavelength', arr.shape, dtype='f')
                    dset.attrs['unit'] = 'm'
                    dset.attrs['scale'] = 1e-06
                    dset[...] = arr

                arr = modis.rsr[det]['response']
                dset = det_grp.create_dataset('response', arr.shape, dtype='f')
                dset[...] = arr
示例#10
0
 def convert(self):
     """Convert spectral response functions from wavelength to wavenumber."""
     if self._wavespace == WAVE_LENGTH:
         rsr, info = convert2wavenumber(self.rsr)
         for band in rsr.keys():
             for det in rsr[band].keys():
                 self.rsr[band][det][WAVE_NUMBER] = rsr[
                     band][det][WAVE_NUMBER]
                 self.rsr[band][det]['response'] = rsr[
                     band][det]['response']
                 self.unit = info['unit']
                 self.si_scale = info['si_scale']
         self._wavespace = WAVE_NUMBER
         for band in rsr.keys():
             for det in rsr[band].keys():
                 self.rsr[band][det]['central_wavenumber'] = \
                     get_central_wave(self.rsr[band][det][WAVE_NUMBER], self.rsr[band][det]['response'])
                 del self.rsr[band][det][WAVE_LENGTH]
     else:
         errmsg = "Conversion from {wn} to {wl} not supported yet".format(wn=WAVE_NUMBER, wl=WAVE_LENGTH)
         raise NotImplementedError(errmsg)
示例#11
0
    def convert(self):
        """Convert spectral response functions from wavelength to wavenumber"""

        from pyspectral.utils import (convert2wavenumber, get_central_wave)
        if self._wavespace == WAVE_LENGTH:
            rsr, info = convert2wavenumber(self.rsr)
            for band in rsr.keys():
                for det in rsr[band].keys():
                    self.rsr[band][det][WAVE_NUMBER] = rsr[
                        band][det][WAVE_NUMBER]
                    self.rsr[band][det]['response'] = rsr[
                        band][det]['response']
                    self.unit = info['unit']
                    self.si_scale = info['si_scale']
            self._wavespace = WAVE_NUMBER
            for band in rsr.keys():
                for det in rsr[band].keys():
                    self.rsr[band][det]['central_wavenumber'] = \
                        get_central_wave(self.rsr[band][det][WAVE_NUMBER], self.rsr[band][det]['response'])
                    del self.rsr[band][det][WAVE_LENGTH]
        else:
            errmsg = "Conversion from {wn} to {wl} not supported yet".format(wn=WAVE_NUMBER, wl=WAVE_LENGTH)
            raise NotImplementedError(errmsg)
    3.7065142, 3.716509, 3.7264658, 3.7364102, 3.7463682,
    3.7563652, 3.7664226, 3.7763396, 3.7863384, 3.7964207,
    3.8063589, 3.8163606, 3.8264089, 3.8364836, 3.8463381,
    3.8563975, 3.8664163, 3.8763755, 3.8864797, 3.8964978,
    3.9064275, 3.9164873, 3.9264729, 3.9364026, 3.9465107,
    3.9535347], dtype='double')

TEST_RSR['20']['det-1']['response'] = np.array([
    0.01, 0.0118, 0.01987, 0.03226, 0.05028, 0.0849,
    0.16645, 0.33792, 0.59106, 0.81815, 0.96077, 0.92855,
    0.86008, 0.8661, 0.87697, 0.85412, 0.88922, 0.9541,
    0.95687, 0.91037, 0.91058, 0.94256, 0.94719, 0.94808,
    1., 0.92676, 0.67429, 0.44715, 0.27762, 0.14852,
    0.07141, 0.04151, 0.02925, 0.02085, 0.01414, 0.01], dtype='double')

TEST_RSR['20']['det-1']['central_wavelength'] = get_central_wave(TEST_RSR['20']['det-1']['wavelength'],
                                                                 TEST_RSR['20']['det-1']['response'])


SEV_RSR = {'IR3.9': {}}
SEV_RSR['IR3.9']['det-1'] = {}
WAVN = np.array([2083.33325195, 2091.00048828, 2098.72387695, 2106.50488281,
                 2114.34375, 2122.24121094, 2130.19775391, 2138.21435547,
                 2146.29101562, 2154.42944336, 2162.62963867, 2170.89257812,
                 2179.21899414, 2187.609375, 2196.06494141, 2204.58569336,
                 2213.17285156, 2221.82714844, 2230.54956055, 2239.34082031,
                 2248.20141602, 2257.13256836, 2266.13500977, 2275.20947266,
                 2284.35668945, 2293.57788086, 2302.87402344, 2312.24584961,
                 2321.6940918, 2331.21972656, 2340.82421875, 2350.5078125,
                 2360.27197266, 2370.11743164, 2380.0456543, 2390.05737305,
                 2400.15356445, 2410.33544922, 2420.60449219, 2430.9609375,
                 2441.40625, 2451.94189453, 2462.5690918, 2473.28857422,
示例#13
0
def main():
    """Main"""
    import sys
    import h5py

    handler = logging.StreamHandler(sys.stderr)

    formatter = logging.Formatter(fmt=_DEFAULT_LOG_FORMAT,
                                  datefmt=_DEFAULT_TIME_FORMAT)
    handler.setFormatter(formatter)
    handler.setLevel(logging.DEBUG)
    LOG.setLevel(logging.DEBUG)
    LOG.addHandler(handler)

    platform_name = "NOAA-20"
    #platform_name = "Suomi-NPP"
    viirs = ViirsRSR('M1', platform_name)
    filename = os.path.join(viirs.output_dir,
                            "rsr_viirs_{0}.h5".format(platform_name))

    with h5py.File(filename, "w") as h5f:
        h5f.attrs['description'] = 'Relative Spectral Responses for VIIRS'
        h5f.attrs['platform_name'] = platform_name
        h5f.attrs['sensor'] = 'viirs'
        h5f.attrs['band_names'] = VIIRS_BAND_NAMES

        for chname in VIIRS_BAND_NAMES:

            viirs = ViirsRSR(chname, platform_name)
            grp = h5f.create_group(chname)
            grp.attrs['number_of_detectors'] = len(viirs.rsr.keys())
            # Loop over each detector to check if the sampling wavelengths are
            # identical:
            det_names = viirs.rsr.keys()
            wvl = viirs.rsr[det_names[0]]['wavelength']
            wvl, idx = np.unique(wvl, return_index=True)
            wvl_is_constant = True
            for det in det_names[1:]:
                det_wvl = np.unique(viirs.rsr[det]['wavelength'])
                if not np.alltrue(wvl == det_wvl):
                    LOG.warning(
                        "Wavelngth arrays are not the same among detectors!")
                    wvl_is_constant = False

            if wvl_is_constant:
                arr = wvl
                dset = grp.create_dataset('wavelength', arr.shape, dtype='f')
                dset.attrs['unit'] = 'm'
                dset.attrs['scale'] = 1e-06
                dset[...] = arr

            # Loop over each detector:
            for det in viirs.rsr:
                det_grp = grp.create_group(det)
                wvl = viirs.rsr[det]['wavelength'][
                    ~np.isnan(viirs.rsr[det]['wavelength'])]
                rsp = viirs.rsr[det]['response'][
                    ~np.isnan(viirs.rsr[det]['wavelength'])]
                wvl, idx = np.unique(wvl, return_index=True)
                rsp = np.take(rsp, idx)
                LOG.debug("wvl.shape: %s", str(wvl.shape))
                det_grp.attrs['central_wavelength'] = get_central_wave(
                    wvl, rsp)
                if not wvl_is_constant:
                    arr = wvl
                    dset = det_grp.create_dataset('wavelength',
                                                  arr.shape,
                                                  dtype='f')
                    dset.attrs['unit'] = 'm'
                    dset.attrs['scale'] = 1e-06
                    dset[...] = arr

                dset = det_grp.create_dataset('response', rsp.shape, dtype='f')
                dset[...] = rsp
示例#14
0
def main():
    """Main"""
    import sys
    import h5py

    handler = logging.StreamHandler(sys.stderr)

    formatter = logging.Formatter(fmt=_DEFAULT_LOG_FORMAT,
                                  datefmt=_DEFAULT_TIME_FORMAT)
    handler.setFormatter(formatter)
    handler.setLevel(logging.DEBUG)
    LOG.setLevel(logging.DEBUG)
    LOG.addHandler(handler)

    platform_name = "Suomi-NPP"
    viirs = ViirsRSR('M1', 'Suomi-NPP')
    filename = os.path.join(viirs.output_dir,
                            "rsr_viirs_%s.h5" % platform_name)

    with h5py.File(filename, "w") as h5f:
        h5f.attrs['description'] = 'Relative Spectral Responses for VIIRS'
        h5f.attrs['platform_name'] = platform_name
        h5f.attrs['band_names'] = VIIRS_BAND_NAMES

        for chname in VIIRS_BAND_NAMES:
            viirs = ViirsRSR(chname)
            grp = h5f.create_group(chname)
            grp.attrs['number_of_detectors'] = len(viirs.rsr.keys())
            # Loop over each detector to check if the sampling wavelengths are
            # identical:
            det_names = viirs.rsr.keys()
            wvl = viirs.rsr[det_names[0]]['wavelength']
            wvl, idx = np.unique(wvl, return_index=True)
            wvl_is_constant = True
            for det in det_names[1:]:
                det_wvl = np.unique(viirs.rsr[det]['wavelength'])
                if not np.alltrue(wvl == det_wvl):
                    LOG.warning(
                        "Wavelngth arrays are not the same among detectors!")
                    wvl_is_constant = False

            if wvl_is_constant:
                arr = wvl
                dset = grp.create_dataset('wavelength', arr.shape, dtype='f')
                dset.attrs['unit'] = 'm'
                dset.attrs['scale'] = 1e-06
                dset[...] = arr

            # Loop over each detector:
            for det in viirs.rsr:
                det_grp = grp.create_group(det)
                wvl = viirs.rsr[det]['wavelength'][
                    ~np.isnan(viirs.rsr[det]['wavelength'])]
                rsp = viirs.rsr[det]['response'][
                    ~np.isnan(viirs.rsr[det]['wavelength'])]
                wvl, idx = np.unique(wvl, return_index=True)
                rsp = np.take(rsp, idx)
                LOG.debug("wvl.shape: %s", str(wvl.shape))
                det_grp.attrs[
                    'central_wavelength'] = get_central_wave(wvl, rsp)
                if not wvl_is_constant:
                    arr = wvl
                    dset = det_grp.create_dataset(
                        'wavelength', arr.shape, dtype='f')
                    dset.attrs['unit'] = 'm'
                    dset.attrs['scale'] = 1e-06
                    dset[...] = arr

                dset = det_grp.create_dataset('response', rsp.shape, dtype='f')
                dset[...] = rsp
示例#15
0
def generate_metimage_file(platform_name):
    """Retrieve original RSR data and convert to internal hdf5 format.
    """
    import h5py

    bandnames = METIMAGE_BAND_NAMES
    instr = MetImageRSR(bandnames[0], platform_name)
    instr_name = instr.instrument.replace('/', '')
    filename = os.path.join(instr.output_dir,
                            "rsr_{0}_{1}.h5".format(instr_name,
                                                    platform_name))

    with h5py.File(filename, "w") as h5f:
        h5f.attrs['description'] = ('Relative Spectral Responses for ' +
                                    instr.instrument.upper())
        h5f.attrs['platform_name'] = platform_name
        h5f.attrs['band_names'] = bandnames

        for chname in bandnames:
            metimage = MetImageRSR(chname, platform_name)
            grp = h5f.create_group(chname)
            grp.attrs['number_of_detectors'] = len(metimage.rsr.keys())
            # Loop over each detector to check if the sampling wavelengths are
            # identical:
            det_names = list(metimage.rsr.keys())
            wvl = metimage.rsr[det_names[0]]['wavelength']
            wvl, idx = np.unique(wvl, return_index=True)
            wvl_is_constant = True
            for det in det_names[1:]:
                det_wvl = np.unique(metimage.rsr[det]['wavelength'])
                if not np.alltrue(wvl == det_wvl):
                    LOG.warning(
                        "Wavelngth arrays are not the same among detectors!")
                    wvl_is_constant = False

            if wvl_is_constant:
                arr = wvl
                dset = grp.create_dataset('wavelength', arr.shape, dtype='f')
                dset.attrs['unit'] = 'm'
                dset.attrs['scale'] = 1e-06
                dset[...] = arr

            # Loop over each detector:
            for det in metimage.rsr:
                det_grp = grp.create_group(det)
                wvl = metimage.rsr[det]['wavelength'][
                    ~np.isnan(metimage.rsr[det]['wavelength'])]
                rsp = metimage.rsr[det]['response'][
                    ~np.isnan(metimage.rsr[det]['wavelength'])]
                wvl, idx = np.unique(wvl, return_index=True)
                rsp = np.take(rsp, idx)
                LOG.debug("wvl.shape: %s", str(wvl.shape))
                det_grp.attrs[
                    'central_wavelength'] = get_central_wave(wvl, rsp)
                if not wvl_is_constant:
                    arr = wvl
                    dset = det_grp.create_dataset(
                        'wavelength', arr.shape, dtype='f')
                    dset.attrs['unit'] = 'm'
                    dset.attrs['scale'] = 1e-06
                    dset[...] = arr

                dset = det_grp.create_dataset('response', rsp.shape, dtype='f')
                dset[...] = rsp
示例#16
0
def generate_metimage_file(platform_name):
    """Retrieve original RSR data and convert to internal hdf5 format.
    """
    import h5py

    bandnames = METIMAGE_BAND_NAMES
    instr = MetImageRSR(bandnames[0], platform_name)
    instr_name = instr.instrument.replace('/', '')
    filename = os.path.join(instr.output_dir,
                            "rsr_{0}_{1}.h5".format(instr_name, platform_name))

    with h5py.File(filename, "w") as h5f:
        h5f.attrs['description'] = ('Relative Spectral Responses for ' +
                                    instr.instrument.upper())
        h5f.attrs['platform_name'] = platform_name
        h5f.attrs['band_names'] = bandnames

        for chname in bandnames:
            metimage = MetImageRSR(chname, platform_name)
            grp = h5f.create_group(chname)
            grp.attrs['number_of_detectors'] = len(metimage.rsr.keys())
            # Loop over each detector to check if the sampling wavelengths are
            # identical:
            det_names = list(metimage.rsr.keys())
            wvl = metimage.rsr[det_names[0]]['wavelength']
            wvl, idx = np.unique(wvl, return_index=True)
            wvl_is_constant = True
            for det in det_names[1:]:
                det_wvl = np.unique(metimage.rsr[det]['wavelength'])
                if not np.alltrue(wvl == det_wvl):
                    LOG.warning(
                        "Wavelngth arrays are not the same among detectors!")
                    wvl_is_constant = False

            if wvl_is_constant:
                arr = wvl
                dset = grp.create_dataset('wavelength', arr.shape, dtype='f')
                dset.attrs['unit'] = 'm'
                dset.attrs['scale'] = 1e-06
                dset[...] = arr

            # Loop over each detector:
            for det in metimage.rsr:
                det_grp = grp.create_group(det)
                wvl = metimage.rsr[det]['wavelength'][
                    ~np.isnan(metimage.rsr[det]['wavelength'])]
                rsp = metimage.rsr[det]['response'][
                    ~np.isnan(metimage.rsr[det]['wavelength'])]
                wvl, idx = np.unique(wvl, return_index=True)
                rsp = np.take(rsp, idx)
                LOG.debug("wvl.shape: %s", str(wvl.shape))
                det_grp.attrs['central_wavelength'] = get_central_wave(
                    wvl, rsp)
                if not wvl_is_constant:
                    arr = wvl
                    dset = det_grp.create_dataset('wavelength',
                                                  arr.shape,
                                                  dtype='f')
                    dset.attrs['unit'] = 'm'
                    dset.attrs['scale'] = 1e-06
                    dset[...] = arr

                dset = det_grp.create_dataset('response', rsp.shape, dtype='f')
                dset[...] = rsp
示例#17
0
    3.8063589, 3.8163606, 3.8264089, 3.8364836, 3.8463381, 3.8563975,
    3.8664163, 3.8763755, 3.8864797, 3.8964978, 3.9064275, 3.9164873,
    3.9264729, 3.9364026, 3.9465107, 3.9535347
],
                                                 dtype='double')

TEST_RSR['20']['det-1']['response'] = np.array([
    0.01, 0.0118, 0.01987, 0.03226, 0.05028, 0.0849, 0.16645, 0.33792, 0.59106,
    0.81815, 0.96077, 0.92855, 0.86008, 0.8661, 0.87697, 0.85412, 0.88922,
    0.9541, 0.95687, 0.91037, 0.91058, 0.94256, 0.94719, 0.94808, 1., 0.92676,
    0.67429, 0.44715, 0.27762, 0.14852, 0.07141, 0.04151, 0.02925, 0.02085,
    0.01414, 0.01
],
                                               dtype='double')

TEST_RSR['20']['det-1']['central_wavelength'] = get_central_wave(
    TEST_RSR['20']['det-1']['wavelength'], TEST_RSR['20']['det-1']['response'])

SEV_RSR = {'IR3.9': {}}
SEV_RSR['IR3.9']['det-1'] = {}
WAVN = np.array([
    2083.33325195, 2091.00048828, 2098.72387695, 2106.50488281, 2114.34375,
    2122.24121094, 2130.19775391, 2138.21435547, 2146.29101562, 2154.42944336,
    2162.62963867, 2170.89257812, 2179.21899414, 2187.609375, 2196.06494141,
    2204.58569336, 2213.17285156, 2221.82714844, 2230.54956055, 2239.34082031,
    2248.20141602, 2257.13256836, 2266.13500977, 2275.20947266, 2284.35668945,
    2293.57788086, 2302.87402344, 2312.24584961, 2321.6940918, 2331.21972656,
    2340.82421875, 2350.5078125, 2360.27197266, 2370.11743164, 2380.0456543,
    2390.05737305, 2400.15356445, 2410.33544922, 2420.60449219, 2430.9609375,
    2441.40625, 2451.94189453, 2462.5690918, 2473.28857422, 2484.10180664,
    2495.01025391, 2506.01416016, 2517.11645508, 2528.31713867, 2539.61816406,
    2551.02050781, 2562.52587891, 2574.13525391, 2585.8503418, 2597.67236328,
示例#18
0
                if not np.alltrue(wvl == viirs.rsr[det_names[0]]['wavelength']):
                    wvl_is_constant = False

            if wvl_is_constant:
                arr = viirs.rsr[det_names[0]]['wavelength']
                dset = grp.create_dataset('wavelength', arr.shape, dtype='f')
                dset.attrs['unit'] = 'm'
                dset.attrs['scale'] = 1e-06
                dset[...] = arr

            # Loop over each detector:
            for det in viirs.rsr:
                det_grp = grp.create_group(det)
                wvl = viirs.rsr[det]['wavelength'][
                    ~np.isnan(viirs.rsr[det]['wavelength'])]
                rsp = viirs.rsr[det]['response'][
                    ~np.isnan(viirs.rsr[det]['wavelength'])]
                det_grp.attrs[
                    'central_wavelength'] = get_central_wave(wvl, rsp)
                if not wvl_is_constant:
                    arr = viirs.rsr[det]['wavelength']
                    dset = det_grp.create_dataset(
                        'wavelength', arr.shape, dtype='f')
                    dset.attrs['unit'] = 'm'
                    dset.attrs['scale'] = 1e-06
                    dset[...] = arr

                arr = viirs.rsr[det]['response']
                dset = det_grp.create_dataset('response', arr.shape, dtype='f')
                dset[...] = arr