def _parse_points(ctx): """ Parse project points from CLI inputs Parameters ---------- ctx : dict CLI context object Returns ------- points : slice | list | string | ProjectPoints ProjectPoints or points to initialize ProjectPoints """ tech = ctx.obj['TECH'] points = ctx.obj['POINTS'] sam_files = ctx.obj['SAM_FILES'] res_file = ctx.obj['RES_FILE'] curtailment = ctx.obj['CURTAILMENT'] lat_lon_fpath = ctx.obj.get('LAT_LON_FPATH', None) lat_lon_coords = ctx.obj.get('LAT_LON_COORDS', None) regions = ctx.obj.get('REGIONS', None) region = ctx.obj.get('REGION', None) region_col = ctx.obj.get('REGION_COL', 'state') i = 0 if points is not None: i += 1 if lat_lon_fpath is not None or lat_lon_coords: lat_lons = _parse_lat_lons(lat_lon_fpath, lat_lon_coords) points = ProjectPoints.lat_lon_coords(lat_lons, res_file, sam_files, tech=tech, curtailment=curtailment) i += 1 if region is not None or regions is not None: regions = _parse_regions(regions, region, region_col) points = ProjectPoints.regions(regions, res_file, sam_files, tech=tech, curtailment=curtailment) i += 1 msg = None if i == 0: msg = ("reV Gen requires one of 'points', 'lat-lon-fpath', " "'lat-lon-coords', 'regions', or 'region' and region-col' " "must be supplied to determine points to compute generation " "for!") elif i > 1: msg = ("reV Gen can only produce a unique set of Project Points for " "a single input value for ONE of 'points', 'lat-lon-fpath', " "'lat-lon-coords', 'regions', or 'region' and region-col'") if msg is not None: logger.error(msg) raise ProjectPointsValueError(msg) return points
def from_regions(ctx, regions, region, region_col): """Extract ProjectPoints for given geographic regions""" regions = _parse_regions(regions, region, region_col) logger.info('Creating ProjectPoints from {} and saving to {}'.format( regions, ctx.obj['FPATH'])) pp = ProjectPoints.regions(regions, ctx.obj['RES_FILE'], ctx.obj['SAM_FILE']) pp.df.to_csv(ctx.obj['FPATH'])
def test_duplicate_coords(): """ Test ProjectPoint.lat_lon_coords duplicate coords error """ res_file = os.path.join(TESTDATADIR, 'nsrdb/', 'ri_100_nsrdb_2012.h5') sam_files = os.path.join(TESTDATADIR, 'SAM/naris_pv_1axis_inv13_cs.json') with Resource(res_file) as f: meta = f.meta duplicates = meta.loc[[2, 3, 3, 4], ['latitude', 'longitude']].values with pytest.raises(RuntimeError): ProjectPoints.lat_lon_coords(duplicates, res_file, sam_files) regions = {'Kent': 'county', 'Rhode Island': 'state'} with pytest.raises(RuntimeError): ProjectPoints.regions(regions, res_file, sam_files)
def test_regions(counties): """ Test ProjectPoint.regions class method """ res_file = os.path.join(TESTDATADIR, 'nsrdb/', 'ri_100_nsrdb_2012.h5') sam_files = os.path.join(TESTDATADIR, 'SAM/naris_pv_1axis_inv13_cs.json') with Resource(res_file) as f: meta = f.meta baseline = meta.loc[meta['county'].isin(counties)].index.values.tolist() regions = {c: 'county' for c in counties} pp = ProjectPoints.regions(regions, res_file, sam_files) assert sorted(baseline) == pp.sites