Пример #1
0
 def run(self):
     if self.config['data']:
         months = list(set(pmap(lambda dt: '%i/%i' % (dt.month, dt.year),
                                pmap(to_datetime, self.config['data']))))
         pmap(lambda (k, o): logging.debug('%s: %s' % (k, str(o))),
              self.config.items())
         logging.info("Months: %s", str(months))
         logging.info("Dataset: %i files.", len(self.config['data']))
         algorithm = importlib.import_module(self.config['algorithm'])
         algorithm.run(**self.config)
         logging.info("Process finished.")
Пример #2
0
 def run(self):
     if self.config['data']:
         months = list(set(pmap(lambda dt: '%i/%i' % (dt.month, dt.year),
                                pmap(to_datetime, self.config['data']))))
         map(lambda (k, o): logging.debug('%s: %s' % (k, str(o))),
             self.config.items())
         logging.info("Months: %s", str(months))
         logging.info("Dataset: %i files.", len(self.config['data']))
         algorithm = importlib.import_module(self.config['algorithm'])
         algorithm.run(**self.config)
         logging.info("Process finished.")
Пример #3
0
 def __init__(self, algorithm):
     super(OutputCache, self).__init__(algorithm)
     self.output = Loader(pmap(self.get_output_file, self.filenames))
     self.root = self.output.root
     with nc.loader(self.filenames, dimensions=DIMS) as images:
         map(algorithm.create_1px_dimensions, self.root.roots)
         self.root.getvar('time', source=images.getvar('time'))
         self.root.getvar('cloudindex',
                          'f4', source=images.getvar('data'))
         self.root.getvar('globalradiation',
                          'f4', source=images.getvar('data'))
Пример #4
0
 def extend_cache(self, filenames):
     cached_files = glob.glob('%s/*.nc' % self.temporal_path)
     not_cached = filter(lambda f: self.get_cached_file(f)
                         not in cached_files,
                         filenames)
     if not_cached:
         loader = Loader(not_cached)
         new_files = pmap(self.get_cached_file, not_cached)
         with nc.loader(new_files, dimensions=DIMS) as cache:
             self.algorithm.update_temporalcache(loader, cache)
         loader.dump()
Пример #5
0
 def update_temporalcache(self, loader, cache):
     lat, lon = loader.lat[0], loader.lon[0]
     self.declination[:] = self.getdeclination(self.gamma)
     # FIXME: There are two solar elevations.
     hourlyangle = self.gethourlyangle(lat, lon,
                                       self.decimalhour,
                                       self.gamma)
     self.solarangle[:] = self.getzenithangle(self.declination[:],
                                              loader.lat,
                                              hourlyangle)
     # FIXME: This rewrite the value of the solarelevations setted before.
     self.solarelevation[:] = self.getelevation(self.solarangle[:])
     self.excentricity[:] = self.getexcentricity(self.gamma)
     linke = np.vstack([pmap(lambda m: loader.linke[0, m[0][0] - 1, :],
                             self.months.tolist())])
     # The average extraterrestrial irradiance is 1367.0 Watts/meter^2
     # The maximum height of the non-transparent atmosphere is at 8434.5 mts
     bc = self.getbeamirradiance(1367.0, self.excentricity[:],
                                 self.solarangle[:], self.solarelevation[:],
                                 linke, loader.dem)
     dc = self.getdiffuseirradiance(1367.0, self.excentricity[:],
                                    self.solarelevation[:], linke)
     self.gc[:] = self.getglobalirradiance(bc, dc)
     satellitalzenithangle = self.getsatellitalzenithangle(
         loader.lat, loader.lon, self.algorithm.SAT_LON)
     atmosphericradiance = self.getatmosphericradiance(
         1367.0, self.algorithm.i0met, dc, satellitalzenithangle)
     self.atmosphericalbedo[:] = self.getalbedo(atmosphericradiance,
                                                self.algorithm.i0met,
                                                self.excentricity[:],
                                                satellitalzenithangle)
     satellitalelevation = self.getelevation(satellitalzenithangle)
     satellital_opticalpath = self.getopticalpath(
         self.getcorrectedelevation(satellitalelevation),
         loader.dem, 8434.5)
     satellital_opticaldepth = self.getopticaldepth(satellital_opticalpath)
     self.t_sat[:] = self.gettransmitance(linke, satellital_opticalpath,
                                          satellital_opticaldepth,
                                          satellitalelevation)
     solar_opticalpath = self.getopticalpath(
         self.getcorrectedelevation(self.solarelevation[:]),
         loader.dem, 8434.5)
     solar_opticaldepth = self.getopticaldepth(solar_opticalpath)
     self.t_earth[:] = self.gettransmitance(linke, solar_opticalpath,
                                            solar_opticaldepth,
                                            self.solarelevation[:])
     effectivealbedo = self.geteffectivealbedo(self.solarangle[:])
     self.cloudalbedo[:] = self.getcloudalbedo(effectivealbedo,
                                               self.atmosphericalbedo[:],
                                               self.t_earth[:],
                                               self.t_sat[:])
     nc.sync(cache)
Пример #6
0
 def __init__(self, algorithm):
     super(TemporalCache, self).__init__(algorithm)
     self.update_cache(self.filenames)
     self.cache = Loader(pmap(self.get_cached_file, self.filenames))
     self.root = self.cache.root
Пример #7
0
 def clean_cache(self, exceptions):
     cached_files = glob.glob('%s/*.nc' % self.temporal_path)
     old_cache = filter(lambda f: self.index[f] not in exceptions,
                        cached_files)
     pmap(os.remove, old_cache)
Пример #8
0
def wrapper(x):
    do_one(x[0], x[1])


if __name__ == '__main__':
    # name = 'ISS035-E-17200.JPG'
    # im = Image.open(name)
    # np_img = np.asarray(im.convert('L').getdata()).astype(np.float32)
    # w, h = im.size
    # np_img.shape = (h, w)
    # do_one(name, np_img)

    data_dirs = []
    for dirname in os.listdir(data_dir):
        if dirname.startswith('LuoJia1'):
            data_dirs.append(dirname)

    data_dirs.sort()

    print(data_dirs)

    images = pmap(get_img, data_dirs)

    pmap(wrapper, zip(data_dirs, images))

    # for (name, im) in zip(data_dirs, images):
    #     do_one(name, im)

    img = get_img('LuoJia1-01_LR201809083317_20180907212040_HDR_0033')