예제 #1
0
    def ftp_publications(self, cascade=False):
        """ Return product generator. """
        if isinstance(self.datetimes, (list, tuple)):
            datetimes = self.datetimes
        else:
            # Generate datetimes from rangetext string.
            datetimes = utils.MultiDateRange(self.datetimes).iterdatetimes()
        combinations = utils.get_product_combinations(
            datetimes=datetimes,
            prodcodes=self.prodcodes,
            timeframes=self.timeframes,
        )
        for combination in combinations:
            nowcast = combination.pop('nowcast')
            if nowcast != self.nowcast:
                continue

            if nowcast:
                yield products.CopiedProduct(datetime=combination['datetime'])
                continue

            consistent = utils.consistent_product_expected(
                prodcode=combination['prodcode'],
                timeframe=combination['timeframe'],
            )
            product = products.CalibratedProduct(**combination)
            if not consistent:
                yield product
            if cascade:
                rps = products.Consistifier.get_rescaled_products(product)
                for rescaled_product in rps:
                    yield rescaled_product
예제 #2
0
def rescale(**kwargs):
    """ Create aggregates given some commandline arguments. """
    # Determine action
    task = tasks.rescale
    if kwargs['direct']:
        action = task
    else:
        action = task.delay
    # Determine derived arguments
    datetimes = utils.MultiDateRange(kwargs['range']).iterdatetimes()
    combinations = utils.get_product_combinations(
        datetimes=datetimes,
        prodcodes=kwargs['prodcodes'],
        timeframes=kwargs['timeframes'])
    # Execute or delay task
    for combination in combinations:
        action_kwargs = dict(result=None,
                             direct=kwargs['direct'],
                             cascade=kwargs['cascade'])
        rescale_kwargs = {
            k: v
            for k, v in combination.items()
            if k in ['datetime', 'prodcode', 'timeframe']
        }
        action_kwargs.update(rescale_kwargs)
        action(**action_kwargs)
예제 #3
0
def calibrate(**kwargs):
    """ Create calibrated products given some commandline arguments. """
    # Determine action
    task = tasks.calibrate
    if kwargs['direct']:
        action = task
    else:
        action = task.delay
    # Determine derived arguments
    declutter = dict(
        size=kwargs['declutter_size'],
        history=kwargs['declutter_history'],
    )
    datetimes = utils.MultiDateRange(kwargs['range']).iterdatetimes()
    combinations = utils.get_product_combinations(
        datetimes=datetimes,
        prodcodes=kwargs['prodcodes'],
        timeframes=kwargs['timeframes'],
    )
    # Execute or delay task
    for combination in combinations:
        if kwargs['nowcast'] != combination['nowcast']:
            continue
        action_kwargs = dict(result=None,
                             declutter=declutter,
                             radars=kwargs['radars'],
                             direct=kwargs['direct'],
                             cascade=kwargs['cascade'])
        action_kwargs.update(combination)
        action(**action_kwargs)
예제 #4
0
def sandbox(**kwargs):
    """ Print a value from various datafiles. """
    i, j = map(int, kwargs['indices'].split(','))
    datetimes = utils.MultiDateRange(kwargs['range']).iterdatetimes()
    combinations = utils.get_product_combinations(
        datetimes=datetimes,
        prodcodes=kwargs['prodcodes'],
        timeframes=kwargs['timeframes'],
    )
    for combination in combinations:
        # The calibrate
        calibrate = products.CalibratedProduct(**combination)
        with calibrate.get() as calibrate_h5:
            print('Calibrate: {}'.format(calibrate_h5['precipitation'][i, j]))
        # The rescaled
        if utils.consistent_product_expected(combination['prodcode'],
                                             combination['timeframe']):
            rescaled = products.ConsistentProduct(**combination)
            print(rescaled.path)
            with rescaled.get() as rescaled_h5:
                print('Rescaled: {}'.format(rescaled_h5['precipitation'][i,
                                                                         j], ))
        # The thredds
        thredds = products.ThreddsFile.get_for_product(calibrate)
        t = thredds._index(calibrate)
        with thredds.get() as thredds_h5:
            print('Thredds: {}'.format(thredds_h5['precipitation'][i, j, t], ))
        # The merged threddsfile
        thredds_m = products.ThreddsFile.get_for_product(calibrate, merge=True)
        t = thredds_m._index(calibrate)
        with thredds_m.get() as thredds_m_h5:
            print('Thredds(m): {} ({})'.format(
                thredds_m_h5['precipitation'][i, j, t],
                thredds_m_h5['available'][t]))
        # Opendap
        values = products.get_values_from_opendap(
            x=i,
            y=j,
            start_date=combination['datetime'],
            end_date=combination['datetime'],
        )
        print('Opendap: {}'.format(values))
예제 #5
0
def main():
    """ Create images for a range of products. """
    loghelper.setup_logging()

    # Get products according to args
    args = get_image_args()

    multidaterange = utils.MultiDateRange(args['range'])
    products = product_generator(product=args['product'],
                                 prodcode=args['prodcode'],
                                 timeframe=args['timeframe'],
                                 datetimes=multidaterange.iterdatetimes(),
                                 nowcast=args['nowcast'])

    create = dict(png=images.create_png, tif=images.create_tif)[args['format']]

    # Create images with those products
    kwargs = args.copy()
    map(kwargs.pop, ['range', 'product', 'timeframe', 'prodcode'])
    create(products, **kwargs)