def __init__(self, bandname, satname='himawari8'): """ """ self.satname = satname self.bandname = bandname self.filenames = {} self.rsr = None conf = get_config() options = {} for option, value in conf.items(self.satname + '-ahi', raw=True): options[option] = value for option, value in conf.items('general', raw=True): options[option] = value self.output_dir = options.get('rsr_dir', './') self._get_bandfilenames(**options) LOG.debug("Filenames: " + str(self.filenames)) if os.path.exists(self.filenames[bandname]): self.requested_band_filename = self.filenames[bandname] self._load() else: raise IOError("Couldn't find an existing file for this band: " + str(self.bandname)) # To be compatible with VIIRS.... self.filename = self.requested_band_filename
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()
def __init__(self, bandname, platform_name='Suomi-NPP'): """Init""" self.platform_name = platform_name self.bandname = bandname self.filename = None self.rsr = None conf = get_config() options = {} for option, value in conf.items('viirs', raw=True): options[option] = value for option, value in conf.items('general', raw=True): options[option] = value self.output_dir = options.get('rsr_dir', './') self._get_bandfile(**options) LOG.debug("Filename: %s", str(self.filename)) self._load()
def __init__(self, wavespace='wavelength'): """ Read the seviri relative spectral responses for all channels and all MSG satellites. Optional input: 'wavespace'. Equals 'wavelength' (units of micron's) on default. Can be 'wavenumber' in which case the unit is in cm-1. """ conf = get_config() options = {} for option, value in conf.items('seviri', raw=True): options[option] = value self.seviri_path = options.get('path') if not os.path.exists(self.seviri_path): self.seviri_path = os.path.join(DATA_PATH, options.get('filename')) for option, value in conf.items('general', raw=True): options[option] = value self.output_dir = options.get('rsr_dir', './') self.rsr = None self._load() self.wavespace = wavespace if wavespace not in ['wavelength', 'wavenumber']: raise AttributeError("wavespace has to be either " + "'wavelength' or 'wavenumber'!") self.unit = 'micrometer' if wavespace == 'wavenumber': # Convert to wavenumber: self.convert2wavenumber() self.central_wavenumber = None self.central_wavelength = None self.get_centrals()
def __init__(self, bandname, platform_name, sort=True): """Init Modis RSR """ self.platform_name = platform_name self.bandname = bandname self.filenames = {} self.requested_band_filename = None self.is_sw = False if bandname in SHORTWAVE_BANDS: self.is_sw = True self.scales = {} for bname in MODIS_BAND_NAMES: self.filenames[bname] = None self.rsr = None self._sort = sort conf = get_config() options = {} for option, value in conf.items(self.platform_name + '-modis', raw=True): options[option] = value for option, value in conf.items('general', raw=True): options[option] = value self.output_dir = options.get('rsr_dir', './') self._get_bandfilenames(**options) LOG.debug("Filenames: %s", str(self.filenames)) if os.path.exists(self.filenames[bandname]): self.requested_band_filename = self.filenames[bandname] self._load() else: raise IOError("Couldn't find an existing file for this band: " + str(self.bandname))
def __init__(self, platform_name, instrument, band, solar_flux=None, **kwargs): """Init""" super(Calculator, self).__init__(platform_name, instrument, band, method=1, **kwargs) self.bandname = None self.bandwavelength = None if isinstance(band, str): self.bandname = BANDNAMES.get(band, band) elif isinstance(band, (int, long, float)): self.bandwavelength = band if self.bandname is None: epsilon = 0.1 channel_list = [channel for channel in self.rsr if abs( self.rsr[channel]['det-1']['central_wavelength'] - self.bandwavelength) < epsilon] self.bandname = BANDNAMES.get(channel_list[0], channel_list[0]) options = {} conf = get_config() for option, value in conf.items(platform_name + '-' + instrument, raw=True): options[option] = value if solar_flux is None: self._get_solarflux() else: self.solar_flux = solar_flux self._rad3x = None self._rad3x_t11 = None self._solar_radiance = None self._rad3x_correction = 1.0 self._r3x = None self._e3x = None if 'detector' in kwargs: self.detector = kwargs['detector'] else: self.detector = 'det-1' resp = self.rsr[self.bandname][self.detector]['response'] wv_ = self.rsr[self.bandname][self.detector][self.wavespace] self.rsr_integral = np.trapz(resp, wv_) if 'tb2rad_lut_filename' in options: self.lutfile = options['tb2rad_lut_filename'] if not self.lutfile.endswith('.npz'): self.lutfile = self.lutfile + '.npz' if not os.path.exists(os.path.dirname(self.lutfile)): LOG.warning( "Directory %s does not exist! Check config file" % os.path.dirname(self.lutfile)) self.lutfile = os.path.join( '/tmp', os.path.basename(self.lutfile)) LOG.info("lut filename: " + str(self.lutfile)) if not os.path.exists(self.lutfile): self.make_tb2rad_lut(self.bandname, self.lutfile) self.lut = self.read_tb2rad_lut(self.lutfile) LOG.info("LUT file created") else: self.lut = self.read_tb2rad_lut(self.lutfile) LOG.info("File was there and has been read!") else: LOG.info("No lut filename available in config file. " "No lut will be used") self.lutfile = None self.lut = None