def _parse_sc_points(sc_points, sc_features=None): """ Import supply curve point summary and add any additional features Parameters ---------- sc_points : str | pandas.DataFrame Path to .csv or .json or DataFrame containing supply curve sc_features : str | pandas.DataFrame Path to .csv or .json or DataFrame containing additional supply curve features, e.g. transmission multipliers, regions Returns ------- sc_points : pandas.DataFrame DataFrame of supply curve point summary with additional features added if supplied """ sc_points = parse_table(sc_points) logger.debug('Supply curve points table imported with columns: {}' .format(sc_points.columns.values.tolist())) if sc_features is not None: sc_features = parse_table(sc_features) merge_cols = [c for c in sc_features if c in sc_points] sc_points = sc_points.merge(sc_features, on=merge_cols, how='left') logger.debug('Adding Supply Curve Features table with columns: {}' .format(sc_features.columns.values.tolist())) if 'transmission_multiplier' in sc_points: col = 'transmission_multiplier' sc_points.loc[:, col] = sc_points.loc[:, col].fillna(1) logger.debug('Final supply curve points table has columns: {}' .format(sc_points.columns.values.tolist())) return sc_points
def _parse_summary(summary): """ Extract summary statistics Parameters ---------- summary : str | pd.DataFrame Path to .csv or .json or DataFrame to parse Returns ------- summary : pandas.DataFrame DataFrame of summary statistics """ try: summary = parse_table(summary) except ValueError as ex: logger.error(ex) raise return summary
def _parse_lat_lons(lat_lons): msg = ('Expecting a pair or multiple pairs of latitude and ' 'longitude coordinates!') if isinstance(lat_lons, str): lat_lons = parse_table(lat_lons) cols = [c for c in lat_lons if c.lower.startswith(('lat', 'lon'))] lat_lons = lat_lons[sorted(cols)].values elif isinstance(lat_lons, (list, tuple)): lat_lons = np.array(lat_lons) elif isinstance(lat_lons, (int, float)): msg += ' Recieved a single coordinate value!' logger.error(msg) raise ValueError(msg) if len(lat_lons.shape) == 1: lat_lons = np.expand_dims(lat_lons, axis=0) if lat_lons.shape[1] != 2: msg += ' Received {} coordinate values!'.format(lat_lons.shape[1]) logger.error(msg) raise ValueError(msg) return lat_lons
def _parse_trans_table(trans_table): """ Import transmission features table Parameters ---------- trans_table : pd.DataFrame | str Table mapping supply curve points to transmission features (either str filepath to table file or pre-loaded dataframe). Returns ------- trans_table : pd.DataFrame Loaded transmission feature table. """ trans_table = parse_table(trans_table) drop_cols = ['sc_gid', 'cap_left', 'sc_point_gid'] drop_cols = [c for c in drop_cols if c in trans_table] if drop_cols: trans_table = trans_table.drop(columns=drop_cols) return trans_table