コード例 #1
0
ファイル: avhrr_rsr.py プロジェクト: djhoese/pyspectral
    def __init__(self, bandname, platform_name):

        super(AvhrrRSR, self).__init__(
            bandname, platform_name,
            AVHRR_BAND_NAMES[INSTRUMENTS[platform_name]])

        self.instrument = INSTRUMENTS.get(platform_name, 'avhrr/3')

        self._get_options_from_config()
        self._get_bandfilenames()

        LOG.debug("Filenames: %s", str(self.filenames))
        if self.filenames[bandname] and os.path.exists(self.filenames[bandname]):
            self.requested_band_filename = self.filenames[bandname]
            if self.instrument == 'avhrr/1':
                self._load(scale=0.001)
            else:
                self._load()

        else:
            LOG.warning("Couldn't find an existing file for this band: %s",
                        str(self.bandname))

        # To be compatible with VIIRS....
        self.filename = self.requested_band_filename
コード例 #2
0
ファイル: avhrr_rsr.py プロジェクト: pytroll/pyspectral
    def __init__(self, bandname, platform_name):

        super(AvhrrRSR, self).__init__(
            bandname, platform_name,
            AVHRR_BAND_NAMES[INSTRUMENTS[platform_name]])

        self.instrument = INSTRUMENTS.get(platform_name, 'avhrr/3')

        self._get_options_from_config()
        self._get_bandfilenames()

        LOG.debug("Filenames: %s", str(self.filenames))
        if self.filenames[bandname] and os.path.exists(self.filenames[bandname]):
            self.requested_band_filename = self.filenames[bandname]
            if self.instrument == 'avhrr/1':
                self._load(scale=0.001)
            else:
                self._load()

        else:
            LOG.warning("Couldn't find an existing file for this band: %s",
                        str(self.bandname))

        # To be compatible with VIIRS....
        self.filename = self.requested_band_filename
コード例 #3
0
ファイル: agri_rsr.py プロジェクト: adybbroe/pyspectral
    def __init__(self, bandname, platform_name):
        """Initialise the FY-4 AGRI relative spectral response data"""
        super(AGRIRSR, self).__init__(bandname, platform_name, FY4A_BAND_NAMES)

        self.instrument = INSTRUMENTS.get(platform_name, 'agri')

        self._get_options_from_config()
        self._get_bandfilenames()

        LOG.debug("Filenames: %s", str(self.filenames))
        if self.filenames[bandname] and os.path.exists(self.filenames[bandname]):
            self.requested_band_filename = self.filenames[bandname]
            scale = BANDNAME_SCALE2MICROMETERS.get(bandname)
            if scale:
                self._load(scale=scale)
            else:
                LOG.error(
                    "Failed determine the scale used to convert to wavelength in micrometers - channel = %s", bandname)
                raise AttributeError('no scale for bandname %s', bandname)

        else:
            LOG.warning("Couldn't find an existing file for this band: %s",
                        str(self.bandname))

        self.filename = self.requested_band_filename
コード例 #4
0
ファイル: rsr_reader.py プロジェクト: zxdawn/pyspectral
    def _check_instrument(self):
        """Check and try fix instrument name if needed"""
        instr = INSTRUMENTS.get(self.platform_name, self.instrument.lower())
        if instr != self.instrument.lower():
            self.instrument = instr
            LOG.warning("Inconsistent instrument/satellite input - " +
                        "instrument set to %s", self.instrument)

        self.instrument = self.instrument.lower().replace('/', '')
コード例 #5
0
ファイル: rsr_reader.py プロジェクト: caiyunapp/pyspectral
    def set_instrument(self, h5f):
        """Set the instrument name."""
        if self.instrument:
            return

        try:
            self.instrument = h5f.attrs['sensor']
            self.instrument = convert2str(self.instrument)
        except KeyError:
            LOG.warning("No sensor name specified in HDF5 file")
            self.instrument = INSTRUMENTS.get(self.platform_name)
コード例 #6
0
ファイル: rayleigh.py プロジェクト: michaelaye/pyspectral
    def __init__(self, platform_name, sensor, **kwargs):
        self.platform_name = platform_name
        self.sensor = sensor
        self.coeff_filename = None

        atm_type = kwargs.get('atmosphere', 'us-standard')
        if atm_type not in ATMOSPHERES:
            raise AttributeError(
                'Atmosphere type not supported! ' +
                'Need to be one of {}'.format(str(ATMOSPHERES)))

        aerosol_type = kwargs.get('aerosol_type', 'marine_clean_aerosol')

        if aerosol_type not in AEROSOL_TYPES:
            raise AttributeError(
                'Aerosol type not supported! ' +
                'Need to be one of {0}'.format(str(AEROSOL_TYPES)))

        rayleigh_dir = RAYLEIGH_LUT_DIRS[aerosol_type]

        if atm_type not in ATMOSPHERES.keys():
            LOG.error("Atmosphere type %s not supported", atm_type)

        LOG.info("Atmosphere chosen: %s", atm_type)

        # Try fix instrument naming
        instr = INSTRUMENTS.get(platform_name, sensor)
        if instr != sensor:
            sensor = instr
            LOG.warning(
                "Inconsistent sensor/satellite input - " + "sensor set to %s",
                sensor)

        self.sensor = sensor.replace('/', '')

        ext = atm_type.replace(' ', '_')
        lutname = "rayleigh_lut_{0}.h5".format(ext)
        self.reflectance_lut_filename = os.path.join(rayleigh_dir, lutname)
        if not os.path.exists(self.reflectance_lut_filename):
            LOG.warning("No lut file %s on disk",
                        self.reflectance_lut_filename)
            LOG.info("Will download from internet...")
            download_luts(aerosol_type=aerosol_type)

        if (not os.path.exists(self.reflectance_lut_filename)
                or not os.path.isfile(self.reflectance_lut_filename)):
            raise IOError(
                'pyspectral file for Rayleigh scattering correction ' +
                'does not exist! Filename = ' +
                str(self.reflectance_lut_filename))

        LOG.debug('LUT filename: %s', str(self.reflectance_lut_filename))
コード例 #7
0
    def __init__(self, platform_name, instrument):
        self.platform_name = platform_name
        self.instrument = instrument
        self.filename = None
        self.rsr = {}
        self.description = "Unknown"
        self.band_names = None
        self.unit = '1e-6 m'
        self.si_scale = 1e-6  # How to scale the wavelengths to become SI unit
        self._wavespace = WAVL

        conf = get_config()

        options = {}
        for option, value in conf.items('general', raw=True):
            options[option] = value

        # Try fix instrument naming
        instr = INSTRUMENTS.get(platform_name, instrument)
        if instr != instrument:
            instrument = instr
            LOG.warning("Inconsistent instrument/satellite input - " +
                        "instrument set to %s", instrument)

        instrument = instrument.replace('/', '')

        rsr_dir = options['rsr_dir']
        self.filename = expanduser(os.path.join(rsr_dir, 'rsr_%s_%s.h5' %
                                                (instrument, platform_name)))

        LOG.debug('Filename: %s', str(self.filename))

        if not os.path.exists(self.filename) or not os.path.isfile(self.filename):
            # Try download from the internet!
            LOG.warning("No rsr file %s on disk", self.filename)
            if 'download_from_internet' in options and options['download_from_internet'] == 'True':
                LOG.info("Will download from internet...")
                download_rsr()

        if not os.path.exists(self.filename) or not os.path.isfile(self.filename):
            raise IOError('pyspectral RSR file does not exist! Filename = ' +
                          str(self.filename) +
                          '\nFiles matching instrument and satellite platform' +
                          ': ' +
                          str(glob(os.path.join(rsr_dir, '*%s*%s*.h5' %
                                                (instrument, platform_name)))))

        self.load()
コード例 #8
0
    def __init__(self, platform_name, sensor, **kwargs):
        """Initialize class and determine LUT to use."""
        atm_type = kwargs.get('atmosphere', 'us-standard')
        aerosol_type = kwargs.get('aerosol_type', 'marine_clean_aerosol')

        super(Rayleigh, self).__init__(aerosol_type, atm_type)

        self.platform_name = platform_name
        self.sensor = sensor
        self.coeff_filename = None

        # Try fix instrument naming
        instr = INSTRUMENTS.get(platform_name, sensor)
        if instr != sensor:
            sensor = instr
            LOG.warning(
                "Inconsistent sensor/satellite input - " + "sensor set to %s",
                sensor)

        self.sensor = sensor.replace('/', '')

        rayleigh_dir = RAYLEIGH_LUT_DIRS[aerosol_type]

        ext = atm_type.replace(' ', '_')
        lutname = "rayleigh_lut_{0}.h5".format(ext)
        self.reflectance_lut_filename = os.path.join(rayleigh_dir, lutname)

        if not self._lutfiles_version_uptodate and self.do_download:
            LOG.info("Will download from internet...")
            download_luts(aerosol_type=aerosol_type)

        if (not os.path.exists(self.reflectance_lut_filename)
                or not os.path.isfile(self.reflectance_lut_filename)):
            raise IOError(
                'pyspectral file for Rayleigh scattering correction ' +
                'does not exist! Filename = ' +
                str(self.reflectance_lut_filename))

        LOG.debug('LUT filename: %s', str(self.reflectance_lut_filename))
        self._rayl = None
        self._wvl_coord = None
        self._azid_coord = None
        self._satz_sec_coord = None
        self._sunz_sec_coord = None
コード例 #9
0
ファイル: rayleigh.py プロジェクト: pytroll/pyspectral
    def __init__(self, platform_name, sensor, **kwargs):
        """Initialize class and determine LUT to use."""

        atm_type = kwargs.get('atmosphere', 'us-standard')
        aerosol_type = kwargs.get('aerosol_type', 'marine_clean_aerosol')

        super(Rayleigh, self).__init__(aerosol_type, atm_type)

        self.platform_name = platform_name
        self.sensor = sensor
        self.coeff_filename = None

        # Try fix instrument naming
        instr = INSTRUMENTS.get(platform_name, sensor)
        if instr != sensor:
            sensor = instr
            LOG.warning("Inconsistent sensor/satellite input - " +
                        "sensor set to %s", sensor)

        self.sensor = sensor.replace('/', '')

        rayleigh_dir = RAYLEIGH_LUT_DIRS[aerosol_type]

        ext = atm_type.replace(' ', '_')
        lutname = "rayleigh_lut_{0}.h5".format(ext)
        self.reflectance_lut_filename = os.path.join(rayleigh_dir, lutname)

        if not self._lutfiles_version_uptodate and self.do_download:
            LOG.info("Will download from internet...")
            download_luts(aerosol_type=aerosol_type)

        if (not os.path.exists(self.reflectance_lut_filename) or
                not os.path.isfile(self.reflectance_lut_filename)):
            raise IOError('pyspectral file for Rayleigh scattering correction ' +
                          'does not exist! Filename = ' +
                          str(self.reflectance_lut_filename))

        LOG.debug('LUT filename: %s', str(self.reflectance_lut_filename))
        self._rayl = None
        self._wvl_coord = None
        self._azid_coord = None
        self._satz_sec_coord = None
        self._sunz_sec_coord = None
コード例 #10
0
ファイル: cocts_rsr.py プロジェクト: pytroll/pyspectral
    def __init__(self, bandname, platform_name):

        super(COCTS_RSR, self).__init__(bandname, platform_name, COCTS_BAND_NAMES)

        self.instrument = INSTRUMENTS.get(platform_name, 'cocts')

        self._get_options_from_config()
        self._get_bandfilenames()

        LOG.debug("Filenames: %s", str(self.filenames))
        if self.filenames[bandname] and os.path.exists(self.filenames[bandname]):
            self.requested_band_filename = self.filenames[bandname]
            self._load(bandname)

        else:
            LOG.warning("Couldn't find an existing file for this band: %s",
                        str(self.bandname))

        # To be compatible with VIIRS....
        self.filename = self.requested_band_filename
コード例 #11
0
ファイル: cocts_rsr.py プロジェクト: adybbroe/pyspectral
    def __init__(self, bandname, platform_name):

        super(COCTS_RSR, self).__init__(bandname, platform_name, COCTS_BAND_NAMES)

        self.instrument = INSTRUMENTS.get(platform_name, 'cocts')

        self._get_options_from_config()
        self._get_bandfilenames()

        LOG.debug("Filenames: %s", str(self.filenames))
        if self.filenames[bandname] and os.path.exists(self.filenames[bandname]):
            self.requested_band_filename = self.filenames[bandname]
            self._load(bandname)

        else:
            LOG.warning("Couldn't find an existing file for this band: %s",
                        str(self.bandname))

        # To be compatible with VIIRS....
        self.filename = self.requested_band_filename
コード例 #12
0
ファイル: virr_rsr.py プロジェクト: rolle-at-work/pyspectral
    def __init__(self, bandname, platform_name):
        """Verify that file exists and can be read."""
        super(VirrRSR, self).__init__(bandname, platform_name,
                                      VIRR_BAND_NAMES[platform_name])

        self.instrument = INSTRUMENTS.get(platform_name, 'virr')
        self._get_options_from_config()
        self._get_bandfilenames()

        LOG.debug("Filenames: %s", str(self.filenames))
        if self.filenames[bandname] and os.path.exists(
                self.filenames[bandname]):
            self.requested_band_filename = self.filenames[bandname]
            self._load()
        else:
            LOG.warning("Couldn't find an existing file for this band: %s",
                        str(self.bandname))

        # To be compatible with VIIRS....
        self.filename = self.requested_band_filename
コード例 #13
0
ファイル: rsr_reader.py プロジェクト: djhoese/pyspectral
    def load(self):
        """Read the internally formatet hdf5 relative spectral response data"""
        import h5py

        no_detectors_message = False
        with h5py.File(self.filename, 'r') as h5f:
            self.band_names = [
                b.decode('utf-8') for b in h5f.attrs['band_names'].tolist()
            ]
            self.description = h5f.attrs['description'].decode('utf-8')
            if not self.platform_name:
                try:
                    self.platform_name = h5f.attrs['platform_name'].decode(
                        'utf-8')
                except KeyError:
                    LOG.warning("No platform_name in HDF5 file")
                    try:
                        self.platform_name = h5f.attrs[
                            'platform'] + '-' + h5f.attrs['satnum']
                    except KeyError:
                        LOG.warning(
                            "Unable to determine platform name from HDF5 file content"
                        )
                        self.platform_name = None

            if not self.instrument:
                try:
                    self.instrument = h5f.attrs['sensor'].decode('utf-8')
                except KeyError:
                    LOG.warning("No sensor name specified in HDF5 file")
                    self.instrument = INSTRUMENTS.get(self.platform_name)

            for bandname in self.band_names:
                self.rsr[bandname] = {}
                try:
                    num_of_det = h5f[bandname].attrs['number_of_detectors']
                except KeyError:
                    if not no_detectors_message:
                        LOG.debug("No detectors found - assume only one...")
                    num_of_det = 1
                    no_detectors_message = True

                for i in range(1, num_of_det + 1):
                    dname = 'det-{0:d}'.format(i)
                    self.rsr[bandname][dname] = {}
                    try:
                        resp = h5f[bandname][dname]['response'][:]
                    except KeyError:
                        resp = h5f[bandname]['response'][:]

                    self.rsr[bandname][dname]['response'] = resp

                    try:
                        wvl = (
                            h5f[bandname][dname]['wavelength'][:] *
                            h5f[bandname][dname]['wavelength'].attrs['scale'])
                    except KeyError:
                        wvl = (h5f[bandname]['wavelength'][:] *
                               h5f[bandname]['wavelength'].attrs['scale'])

                    # The wavelength is given in micro meters!
                    self.rsr[bandname][dname]['wavelength'] = wvl * 1e6

                    try:
                        central_wvl = h5f[bandname][dname].attrs[
                            'central_wavelength']
                    except KeyError:
                        central_wvl = h5f[bandname].attrs['central_wavelength']

                    self.rsr[bandname][dname][
                        'central_wavelength'] = central_wvl
コード例 #14
0
ファイル: rsr_reader.py プロジェクト: pytroll/pyspectral
    def load(self):
        """Read the internally formatet hdf5 relative spectral response data"""
        import h5py

        no_detectors_message = False
        with h5py.File(self.filename, 'r') as h5f:
            self.band_names = [b.decode('utf-8') for b in h5f.attrs['band_names'].tolist()]
            self.description = h5f.attrs['description'].decode('utf-8')
            if not self.platform_name:
                try:
                    self.platform_name = h5f.attrs['platform_name'].decode('utf-8')
                except KeyError:
                    LOG.warning("No platform_name in HDF5 file")
                    try:
                        self.platform_name = h5f.attrs[
                            'platform'] + '-' + h5f.attrs['satnum']
                    except KeyError:
                        LOG.warning(
                            "Unable to determine platform name from HDF5 file content")
                        self.platform_name = None

            if not self.instrument:
                try:
                    self.instrument = h5f.attrs['sensor'].decode('utf-8')
                except KeyError:
                    LOG.warning("No sensor name specified in HDF5 file")
                    self.instrument = INSTRUMENTS.get(self.platform_name)

            for bandname in self.band_names:
                self.rsr[bandname] = {}
                try:
                    num_of_det = h5f[bandname].attrs['number_of_detectors']
                except KeyError:
                    if not no_detectors_message:
                        LOG.debug("No detectors found - assume only one...")
                    num_of_det = 1
                    no_detectors_message = True

                for i in range(1, num_of_det + 1):
                    dname = 'det-{0:d}'.format(i)
                    self.rsr[bandname][dname] = {}
                    try:
                        resp = h5f[bandname][dname]['response'][:]
                    except KeyError:
                        resp = h5f[bandname]['response'][:]

                    self.rsr[bandname][dname]['response'] = resp

                    try:
                        wvl = (h5f[bandname][dname]['wavelength'][:] *
                               h5f[bandname][dname][
                                   'wavelength'].attrs['scale'])
                    except KeyError:
                        wvl = (h5f[bandname]['wavelength'][:] *
                               h5f[bandname]['wavelength'].attrs['scale'])

                    # The wavelength is given in micro meters!
                    self.rsr[bandname][dname]['wavelength'] = wvl * 1e6

                    try:
                        central_wvl = h5f[bandname][
                            dname].attrs['central_wavelength']
                    except KeyError:
                        central_wvl = h5f[bandname].attrs['central_wavelength']

                    self.rsr[bandname][dname][
                        'central_wavelength'] = central_wvl
コード例 #15
0
    def __init__(self, platform_name, sensor, **kwargs):
        """Initialize class and determine LUT to use."""
        self.platform_name = platform_name
        self.sensor = sensor
        self.coeff_filename = None
        options = get_config()
        self.do_download = False
        self._lutfiles_version_uptodate = False

        atm_type = kwargs.get('atmosphere', 'us-standard')
        if atm_type not in ATMOSPHERES:
            raise AttributeError('Atmosphere type not supported! ' +
                                 'Need to be one of {}'.format(str(ATMOSPHERES)))

        aerosol_type = kwargs.get('aerosol_type', 'marine_clean_aerosol')
        self._aerosol_type = aerosol_type

        if aerosol_type not in AEROSOL_TYPES:
            raise AttributeError('Aerosol type not supported! ' +
                                 'Need to be one of {0}'.format(str(AEROSOL_TYPES)))

        rayleigh_dir = RAYLEIGH_LUT_DIRS[aerosol_type]

        if atm_type not in ATMOSPHERES.keys():
            LOG.error("Atmosphere type %s not supported", atm_type)

        LOG.info("Atmosphere chosen: %s", atm_type)

        # Try fix instrument naming
        instr = INSTRUMENTS.get(platform_name, sensor)
        if instr != sensor:
            sensor = instr
            LOG.warning("Inconsistent sensor/satellite input - " +
                        "sensor set to %s", sensor)

        self.sensor = sensor.replace('/', '')

        if 'download_from_internet' in options and options['download_from_internet']:
            self.do_download = True

        if (self._aerosol_type in ATM_CORRECTION_LUT_VERSION and
                self._get_lutfiles_version() == ATM_CORRECTION_LUT_VERSION[self._aerosol_type]['version']):
            self._lutfiles_version_uptodate = True

        ext = atm_type.replace(' ', '_')
        lutname = "rayleigh_lut_{0}.h5".format(ext)
        self.reflectance_lut_filename = os.path.join(rayleigh_dir, lutname)

        if not self._lutfiles_version_uptodate and self.do_download:
            LOG.info("Will download from internet...")
            download_luts(aerosol_type=aerosol_type)

        if (not os.path.exists(self.reflectance_lut_filename) or
                not os.path.isfile(self.reflectance_lut_filename)):
            raise IOError('pyspectral file for Rayleigh scattering correction ' +
                          'does not exist! Filename = ' +
                          str(self.reflectance_lut_filename))

        LOG.debug('LUT filename: %s', str(self.reflectance_lut_filename))
        self._rayl = None
        self._wvl_coord = None
        self._azid_coord = None
        self._satz_sec_coord = None
        self._sunz_sec_coord = None