def main(ctx, wave_h5, out_dir, log_file, verbose): """ WaveX Command Line Interface """ ctx.ensure_object(dict) if not os.path.exists(out_dir): os.makedirs(out_dir) ctx.obj['H5'] = wave_h5 ctx.obj['OUT_DIR'] = out_dir ctx.obj['CLS_KWARGS'] = {} ctx.obj['CLS'] = WaveX _, hsds = check_res_file(wave_h5) if hsds: ctx.obj['CLS_KWARGS']['hsds'] = hsds else: assert os.path.exists(wave_h5) if verbose: log_level = 'DEBUG' else: log_level = 'INFO' if log_file is not None: log_dir = os.path.dirname(log_file) if not os.path.exists(log_dir): os.makedirs(log_dir) init_logger('rex', log_file=log_file, log_level=log_level) logger.info('Extracting wave data from {}'.format(wave_h5)) logger.info('Outputs to be stored in: {}'.format(out_dir))
def main(ctx, resource_h5, out_dir, compute_tree, verbose): """ ResourceX Command Line Interface """ ctx.ensure_object(dict) ctx.obj['H5'] = resource_h5 ctx.obj['OUT_DIR'] = out_dir ctx.obj['CLS_KWARGS'] = {'compute_tree': compute_tree} multi_h5_res, hsds = check_res_file(resource_h5) if multi_h5_res: assert os.path.exists(os.path.dirname(resource_h5)) ctx.obj['CLS'] = MultiFileResourceX else: if hsds: ctx.obj['CLS_KWARGS']['hsds'] = hsds else: assert os.path.exists(resource_h5) ctx.obj['CLS'] = ResourceX name = os.path.splitext(os.path.basename(resource_h5))[0] init_mult(name, out_dir, verbose=verbose, node=True, modules=[ __name__, 'rex.resource_extraction.resource_extraction', 'rex.resource' ]) logger.info('Extracting Resource data from {}'.format(resource_h5)) logger.info('Outputs to be stored in: {}'.format(out_dir))
def get(cls, res_file, project_points, module, output_request=('cf_mean', ), downscale=None): """Get the SAM resource iterator object (single year, single file). Parameters ---------- res_file : str Single resource file (with full path) to retrieve. project_points : reV.config.ProjectPoints reV Project Points instance used to retrieve resource data at a specific set of sites. module : str SAM module name or reV technology to force interpretation of the resource file type. Example: module set to 'pvwatts' or 'tcsmolten' means that this expects a SolarResource file. If 'nsrdb' is in the res_file name, the NSRDB handler will be used. output_request : list | tuple, optional Outputs to retrieve from SAM, by default ('cf_mean', ) downscale : NoneType | str, optional Option for NSRDB resource downscaling to higher temporal resolution. Expects a string in the Pandas frequency format, e.g. '5min', by default None Returns ------- res : reV.resource.SAMResource Resource iterator object to pass to SAM. """ res_handler = cls._get_base_handler(res_file, module) if res_handler in (SolarResource, NSRDB): kwargs, args, res_handler = cls._make_solar_kwargs( res_handler, project_points, output_request, downscale=downscale) elif res_handler == WindResource: kwargs, args, res_handler = cls._make_wind_kwargs( res_handler, project_points, output_request) multi_h5_res, hsds = check_res_file(res_file) if multi_h5_res: res_handler, kwargs, res_file = cls._multi_file_mods( res_handler, kwargs, res_file) else: kwargs['hsds'] = hsds res = res_handler.preload_SAM(res_file, *args, **kwargs) return res
def main(ctx, solar_h5, out_dir, log_file, verbose): """ NSRDBX Command Line Interface """ ctx.ensure_object(dict) if not os.path.exists(out_dir): os.makedirs(out_dir) ctx.obj['H5'] = solar_h5 ctx.obj['OUT_DIR'] = out_dir ctx.obj['CLS_KWARGS'] = {} multi_h5_res, hsds = check_res_file(solar_h5) name = os.path.splitext(os.path.basename(solar_h5))[0] if 'nsrdb' in name: ctx.obj['CLS'] = NSRDBX else: ctx.obj['CLS'] = SolarX if multi_h5_res and not hsds: assert os.path.exists(os.path.dirname(solar_h5)) ctx.obj['CLS'] = MultiFileNSRDBX elif hsds: ctx.obj['CLS_KWARGS']['hsds'] = hsds else: assert os.path.exists(solar_h5) if verbose: log_level = 'DEBUG' else: log_level = 'INFO' if log_file is not None: log_dir = os.path.dirname(log_file) if not os.path.exists(log_dir): os.makedirs(log_dir) init_logger('rex', log_file=log_file, log_level=log_level) logger.info('Extracting solar data from {}'.format(solar_h5)) logger.info('Outputs to be stored in: {}'.format(out_dir))
def _econ_append_pc(pp, cf_file, sites_per_worker=None): """ Generate ProjectControls for econ append Parameters ---------- pp : reV.config.project_points.ProjectPoints ProjectPoints to adjust gids for cf_file : str reV generation capacity factor output file with path. sites_per_worker : int Number of sites to run in series on a worker. None defaults to the resource file chunk size. Returns ------- pc : reV.config.project_points.PointsControl PointsControl object instance. """ multi_h5_res, hsds = check_res_file(cf_file) if multi_h5_res: res_cls = MultiFileResource res_kwargs = {} else: res_cls = Resource res_kwargs = {'hsds': hsds} with res_cls(cf_file, **res_kwargs) as f: gid0 = f.meta['gid'].values[0] gid1 = f.meta['gid'].values[-1] i0 = pp.index(gid0) i1 = pp.index(gid1) + 1 pc = PointsControl.split(i0, i1, pp, sites_per_split=sites_per_worker) return pc
def __init__(self, points_control, res_file, output_request=('cf_mean', ), site_data=None, fout=None, dirout='./gen_out', drop_leap=False, mem_util_lim=0.4): """ Parameters ---------- points_control : reV.config.project_points.PointsControl Project points control instance for site and SAM config spec. res_file : str Filepath to single resource file, multi-h5 directory, or /h5_dir/prefix*suffix output_request : list | tuple Output variables requested from SAM. site_data : str | pd.DataFrame | None Site-specific input data for SAM calculation. String should be a filepath that points to a csv, DataFrame is pre-extracted data. Rows match sites, columns are input keys. Need a "gid" column. Input as None if no site-specific data. fout : str | None Optional .h5 output file specification. dirout : str | None Optional output directory specification. The directory will be created if it does not already exist. drop_leap : bool Drop leap day instead of final day of year during leap years mem_util_lim : float Memory utilization limit (fractional). This sets how many site results will be stored in-memory at any given time before flushing to disk. """ super().__init__(points_control, output_request, site_data=site_data, fout=fout, dirout=dirout, drop_leap=drop_leap, mem_util_lim=mem_util_lim) self._res_file = res_file self._sam_module = self.OPTIONS[self.tech] self._run_attrs['sam_module'] = self._sam_module.MODULE self._run_attrs['res_file'] = res_file self._multi_h5_res, self._hsds = check_res_file(res_file) if self.tech not in self.OPTIONS: msg = ('Requested technology "{}" is not available. ' 'reV generation can analyze the following ' 'SAM technologies: {}'.format(self.tech, list(self.OPTIONS.keys()))) logger.error(msg) raise KeyError(msg) # initialize output file self._init_fpath() self._init_h5() self._init_out_arrays()