Пример #1
0
def _parse_regions(regions, region, region_col):
    """
    Parse CLI regions inputs for ProjectPoints

    Parameters
    ----------
    regions : str
        json string or file path to .json containing regions of
        interest in the form {'region': 'region_column'}
    region : str
        Region to extract
    region_col : str
        Meta column to search for region

    Returns
    -------
    regions : dict
        Dictionary of region_col: regions to generate project points
    """
    msg = None
    if regions is not None:
        if regions.endwtih('.json'):
            regions = safe_json_load(regions)
        else:
            regions = dict_str_load(regions)

    if region is not None:
        if regions is None:
            regions = {region: region_col}
        else:
            if region in regions:
                msg = ("Multiple values for {}: {} were provided!".format(
                    region, region_col))
            else:
                regions.update({region: region_col})

    if regions is None:
        msg = ("At least a single 'region' and 'region-col' must be "
               "supplied in order to create ProjectPoints!")

    if msg is not None:
        logger.error(msg)
        raise ProjectPointsValueError(msg)

    return regions
Пример #2
0
def exclusions(ctx, excl_fpath, out_dir, sub_dir, excl_dict,
               area_filter_kernel, min_area, plot_type, cmap, plot_step,
               log_file, verbose, terminal):
    """
    Extract and plot reV exclusions mask
    """
    name = ctx.obj['NAME']
    if any([verbose, ctx.obj['VERBOSE']]):
        log_level = 'DEBUG'
    else:
        log_level = 'INFO'

    init_logger('reV', log_file=log_file, log_level=log_level)

    qa_dir = out_dir
    if sub_dir is not None:
        qa_dir = os.path.join(out_dir, sub_dir)

    if isinstance(excl_dict, str):
        excl_dict = dict_str_load(excl_dict)

    QaQc.exclusions_mask(excl_fpath,
                         qa_dir,
                         layers_dict=excl_dict,
                         min_area=min_area,
                         kernel=area_filter_kernel,
                         plot_type=plot_type,
                         cmap=cmap,
                         plot_step=plot_step)

    if terminal:
        status = {
            'dirout': out_dir,
            'job_status': 'successful',
            'finput': excl_fpath
        }
        Status.make_job_file(out_dir, 'qa-qc', name, status)
Пример #3
0
def direct(ctx, sc_points, trans_table, fixed_charge_rate, sc_features,
           transmission_costs, sort_on, offshore_trans_table, wind_dirs,
           n_dirs, downwind, offshore_compete, max_workers, out_dir, log_dir,
           simple, line_limited, verbose):
    """reV Supply Curve CLI."""
    name = ctx.obj['NAME']
    ctx.obj['SC_POINTS'] = sc_points
    ctx.obj['TRANS_TABLE'] = trans_table
    ctx.obj['FIXED_CHARGE_RATE'] = fixed_charge_rate
    ctx.obj['SC_FEATURES'] = sc_features
    ctx.obj['TRANSMISSION_COSTS'] = transmission_costs
    ctx.obj['SORT_ON'] = sort_on
    ctx.obj['OFFSHORE_TRANS_TABLE'] = offshore_trans_table
    ctx.obj['WIND_DIRS'] = wind_dirs
    ctx.obj['N_DIRS'] = n_dirs
    ctx.obj['DOWNWIND'] = downwind
    ctx.obj['MAX_WORKERS'] = max_workers
    ctx.obj['OFFSHORE_COMPETE'] = offshore_compete
    ctx.obj['OUT_DIR'] = out_dir
    ctx.obj['LOG_DIR'] = log_dir
    ctx.obj['SIMPLE'] = simple
    ctx.obj['LINE_LIMITED'] = line_limited
    ctx.obj['VERBOSE'] = verbose

    if ctx.invoked_subcommand is None:
        t0 = time.time()
        init_mult(
            name,
            log_dir,
            modules=[__name__, 'reV.supply_curve', 'reV.handlers', 'rex'],
            verbose=verbose)

        if isinstance(transmission_costs, str):
            transmission_costs = dict_str_load(transmission_costs)

        offshore_table = offshore_trans_table
        try:
            if simple:
                out = SupplyCurve.simple(sc_points,
                                         trans_table,
                                         fixed_charge_rate,
                                         sc_features=sc_features,
                                         transmission_costs=transmission_costs,
                                         sort_on=sort_on,
                                         wind_dirs=wind_dirs,
                                         n_dirs=n_dirs,
                                         downwind=downwind,
                                         max_workers=max_workers,
                                         offshore_trans_table=offshore_table,
                                         offshore_compete=offshore_compete)
            else:
                out = SupplyCurve.full(sc_points,
                                       trans_table,
                                       fixed_charge_rate,
                                       sc_features=sc_features,
                                       transmission_costs=transmission_costs,
                                       line_limited=line_limited,
                                       sort_on=sort_on,
                                       wind_dirs=wind_dirs,
                                       n_dirs=n_dirs,
                                       downwind=downwind,
                                       max_workers=max_workers,
                                       offshore_trans_table=offshore_table,
                                       offshore_compete=offshore_compete)
        except Exception as e:
            logger.exception('Supply curve compute failed. Received the '
                             'following error:\n{}'.format(e))
            raise e

        fn_out = '{}.csv'.format(name)
        fpath_out = os.path.join(out_dir, fn_out)
        out.to_csv(fpath_out, index=False)

        runtime = (time.time() - t0) / 60
        logger.info('Supply curve complete. Time elapsed: {:.2f} min. '
                    'Target output dir: {}'.format(runtime, out_dir))

        finput = [sc_points, trans_table]
        if sc_features is not None:
            finput.append(sc_features)

        if transmission_costs is not None:
            finput.append(transmission_costs)

        # add job to reV status file.
        status = {
            'dirout': out_dir,
            'fout': fn_out,
            'job_status': 'successful',
            'runtime': runtime,
            'finput': finput
        }
        Status.make_job_file(out_dir, 'supply-curve', name, status)
Пример #4
0
def direct(ctx, excl_fpath, gen_fpath, econ_fpath, res_fpath, tm_dset,
           excl_dict, check_excl_layers, res_class_dset, res_class_bins,
           cf_dset, lcoe_dset, h5_dsets, data_layers, resolution, excl_area,
           power_density, area_filter_kernel, min_area, friction_fpath,
           friction_dset, out_dir, log_dir, verbose):
    """reV Supply Curve Aggregation Summary CLI."""
    name = ctx.obj['NAME']
    ctx.obj['EXCL_FPATH'] = excl_fpath
    ctx.obj['GEN_FPATH'] = gen_fpath
    ctx.obj['ECON_FPATH'] = econ_fpath
    ctx.obj['RES_FPATH'] = res_fpath
    ctx.obj['TM_DSET'] = tm_dset
    ctx.obj['EXCL_DICT'] = excl_dict
    ctx.obj['CHECK_LAYERS'] = check_excl_layers
    ctx.obj['RES_CLASS_DSET'] = res_class_dset
    ctx.obj['RES_CLASS_BINS'] = res_class_bins
    ctx.obj['CF_DSET'] = cf_dset
    ctx.obj['LCOE_DSET'] = lcoe_dset
    ctx.obj['H5_DSETS'] = h5_dsets
    ctx.obj['DATA_LAYERS'] = data_layers
    ctx.obj['RESOLUTION'] = resolution
    ctx.obj['EXCL_AREA'] = excl_area
    ctx.obj['POWER_DENSITY'] = power_density
    ctx.obj['AREA_FILTER_KERNEL'] = area_filter_kernel
    ctx.obj['MIN_AREA'] = min_area
    ctx.obj['FRICTION_FPATH'] = friction_fpath
    ctx.obj['FRICTION_DSET'] = friction_dset
    ctx.obj['OUT_DIR'] = out_dir
    ctx.obj['LOG_DIR'] = log_dir
    ctx.obj['VERBOSE'] = verbose

    if ctx.invoked_subcommand is None:
        t0 = time.time()
        init_mult(name,
                  log_dir,
                  modules=[__name__, 'reV.supply_curve'],
                  verbose=verbose)

        with h5py.File(excl_fpath, mode='r') as f:
            dsets = list(f)
        if tm_dset not in dsets:
            try:
                TechMapping.run(excl_fpath, res_fpath, tm_dset)
            except Exception as e:
                logger.exception('TechMapping process failed. Received the '
                                 'following error:\n{}'.format(e))
                raise e

        if isinstance(excl_dict, str):
            excl_dict = dict_str_load(excl_dict)

        if isinstance(data_layers, str):
            data_layers = dict_str_load(data_layers)

        try:
            summary = SupplyCurveAggregation.summary(
                excl_fpath,
                gen_fpath,
                tm_dset,
                econ_fpath=econ_fpath,
                excl_dict=excl_dict,
                res_class_dset=res_class_dset,
                res_class_bins=res_class_bins,
                cf_dset=cf_dset,
                lcoe_dset=lcoe_dset,
                h5_dsets=h5_dsets,
                data_layers=data_layers,
                resolution=resolution,
                excl_area=excl_area,
                power_density=power_density,
                area_filter_kernel=area_filter_kernel,
                min_area=min_area,
                friction_fpath=friction_fpath,
                friction_dset=friction_dset,
                check_excl_layers=check_excl_layers)

        except Exception as e:
            logger.exception('Supply curve Aggregation failed. Received the '
                             'following error:\n{}'.format(e))
            raise e

        fn_out = '{}.csv'.format(name)
        fpath_out = os.path.join(out_dir, fn_out)
        summary.to_csv(fpath_out)

        runtime = (time.time() - t0) / 60
        logger.info('Supply curve aggregation complete. '
                    'Time elapsed: {:.2f} min. Target output dir: {}'.format(
                        runtime, out_dir))

        finput = [excl_fpath, gen_fpath]
        if res_fpath is not None:
            finput.append(res_fpath)

        # add job to reV status file.
        status = {
            'dirout': out_dir,
            'fout': fn_out,
            'job_status': 'successful',
            'runtime': runtime,
            'finput': finput,
            'excl_fpath': excl_fpath,
            'excl_dict': excl_dict,
            'area_filter_kernel': area_filter_kernel,
            'min_area': min_area
        }
        Status.make_job_file(out_dir, 'supply-curve-aggregation', name, status)