Beispiel #1
0
 def _get_aggregate(self):
     """ Return Aggregate object. """
     return scans.Aggregate(radars=self.radars,
                            datetime=self.datetime,
                            timeframe=self.timeframe,
                            declutter=self.declutter,
                            basedir=config.AGGREGATE_DIR,
                            multiscandir=config.MULTISCAN_DIR,
                            grid=scans.BASEGRID)
Beispiel #2
0
def aggregate(result,
              datetime,
              timeframe,
              nowcast,
              radars,
              declutter,
              direct=False,
              cascade=False):
    """ Create aggregates and optionally cascade to depending products. """
    loghelper.setup_logging(logfile_name='radar_aggregate.log')
    logging.info(20 * '-' + ' aggregate ' + 20 * '-')
    try:
        # Create aggregates
        aggregate_kwargs = dict(radars=radars,
                                declutter=declutter,
                                datetime=datetime,
                                timeframe=timeframe)
        if nowcast:
            aggregate_kwargs.update(
                dict(basedir=config.NOWCAST_AGGREGATE_DIR,
                     multiscandir=config.NOWCAST_MULTISCAN_DIR,
                     grid=scans.NOWCASTGRID))
        else:
            aggregate_kwargs.update(
                dict(basedir=config.AGGREGATE_DIR,
                     multiscandir=config.MULTISCAN_DIR,
                     grid=scans.BASEGRID))

        aggregate = scans.Aggregate(**aggregate_kwargs)

        aggregate.make()
        # Cascade when requested
        if cascade:
            combinations = utils.get_product_combinations(
                datetimes=[datetime],
                timeframes=[timeframe],
            )
            for combination in combinations:
                calibrate_kwargs = dict(result=None,
                                        radars=radars,
                                        declutter=declutter,
                                        direct=direct,
                                        cascade=cascade)
                calibrate_kwargs.update(combination)
                if direct:
                    calibrate(**calibrate_kwargs)
                else:
                    calibrate.delay(**calibrate_kwargs)
    except Exception as e:
        logging.exception(e)
    logging.info(20 * '-' + ' aggregate complete ' + 20 * '-')
Beispiel #3
0
def product_generator(product, prodcode, timeframe, datetimes, nowcast):
    """ Return product generator. """
    if product == 'a':
        aggregate_kwargs = dict(declutter=None, radars=config.ALL_RADARS)
        combinations = utils.get_aggregate_combinations(
            datetimes=datetimes,
            timeframes=timeframe,
        )
        for combination in combinations:
            if nowcast != combination['nowcast']:
                continue
            if nowcast:
                aggregate_kwargs.update(
                    dict(basedir=config.NOWCAST_AGGREGATE_DIR,
                         multiscandir=config.NOWCAST_MULTISCAN_DIR,
                         grid=scans.NOWCASTGRID,
                         datetime=combination['datetime'],
                         timeframe=combination['timeframe']))
            else:
                aggregate_kwargs.update(
                    dict(basedir=config.AGGREGATE_DIR,
                         multiscandir=config.MULTISCAN_DIR,
                         grid=scans.BASEGRID,
                         datetime=combination['datetime'],
                         timeframe=combination['timeframe']))

            yield scans.Aggregate(**aggregate_kwargs)
    else:
        combinations = utils.get_product_combinations(prodcodes=prodcode,
                                                      datetimes=datetimes,
                                                      timeframes=timeframe)
        for combination in combinations:
            if nowcast != combination.pop('nowcast'):
                continue
            if nowcast:
                yield products.CopiedProduct(datetime=combination['datetime'])
            else:
                if product == 'b':
                    yield products.CalibratedProduct(**combination)
                else:
                    yield products.ConsistentProduct(**combination)