def get_wind_energy_output(self): ssc = pssc.PySSC() f = open(self.sam_export_json) self.dic = json.load(f) self.dic['wind_resource_filename'] = self.fp_srw wp_dat = pssc.dict_to_ssc_table(self.dic, "windpower") grid_dat = pssc.dict_to_ssc_table(self.dic, "grid") f.close() wp = Windpower.wrap(wp_dat) grid = Grid.from_existing(wp) grid.assign(Grid.wrap(grid_dat).export()) wp.execute() grid.execute() self.json_dict = wp.Outputs.export() # print(self.json_dict.keys()) # print (self.json_dict['gen']) self.df_output = pd.DataFrame() self.df_output[self.year] = self.json_dict['gen'] for col in self.df_output.columns: self.df_output[col] = preprocessing.minmax_scale( self.df_output[col].values.reshape(1, -1), feature_range=(0, 1), axis=1, copy=True).T if self.df_all is None: self.df_all = self.df_output.copy() else: self.df_all = pd.concat([self.df_all, self.df_output], axis=1)
def get_solar_energy_output(self): ssc = pssc.PySSC() f = open(self.sam_export_json) self.dic = json.load(f) self.dic['solar_resource_file'] = self.fp_srw ### uncomment if you want to change any model input parameters # self.dic['system_capacity'] = 20000 # self.dic['module_type'] = 0 # self.dic['dc_ac_ratio'] = 1.3 # self.dic['array_type'] = 2 # self.dic['tilt'] = 35 # self.dic['azimuth'] = 180 # self.dic['gcr'] = 0.40 # self.dic['losses'] = 14 # self.dic['en_snowloss'] = 0 # self.dic['inv_eff'] = 95 pv_dat = pssc.dict_to_ssc_table(self.dic, "pvwattsv7") grid_dat = pssc.dict_to_ssc_table(self.dic, "grid") f.close() pv = PVWatts.wrap(pv_dat) grid = Grid.from_existing(pv) grid.assign(Grid.wrap(grid_dat).export()) pv.execute() grid.execute() self.json_dict = pv.Outputs.export() # print(self.json_dict.keys()) self.df_output = pd.DataFrame() self.df_output[self.year] = self.json_dict['gen'] for col in self.df_output.columns: self.df_output[col] = preprocessing.minmax_scale( self.df_output[col].values.reshape(1, -1), feature_range=(0, 1), axis=1, copy=True).T if self.df_all is None: self.df_all = self.df_output.copy() else: self.df_all = pd.concat([self.df_all, self.df_output], axis=1)
def calculate_power(solar_data, pv_dict): """Use PVWatts to translate weather data into power. :param dict solar_data: weather data as returned by :meth:`Psm3Data.to_dict`. :param dict pv_dict: solar plant attributes. :return: (*numpy.array*) hourly power output. """ pv_dat = pssc.dict_to_ssc_table(pv_dict, "pvwattsv7") pv = PVWatts.wrap(pv_dat) pv.SolarResource.assign({"solar_resource_data": solar_data}) pv.execute() return np.array(pv.Outputs.gen)
Created on Wed Mar 4 13:47:58 2020 Most recently tested against PySAM 2.2.3 @author: frohro """ import json import PySAM.GenericSystem as GenericSystem import PySAM.Grid as Grid import PySAM.Singleowner as Singleowner import PySAM.PySSC as pssc ssc = pssc.PySSC() with open("Examples/100mW_Generic.json") as f: dic = json.load(f) gs_dat = pssc.dict_to_ssc_table(dic, "generic_system") grid_dat = pssc.dict_to_ssc_table(dic, "grid") so_dat = pssc.dict_to_ssc_table(dic, "singleowner") gs = GenericSystem.wrap(gs_dat) grid = Grid.from_existing(gs) grid.assign(Grid.wrap(grid_dat).export()) # to create GenericSystem and Singleowner combined simulation, sharing the same data so = Singleowner.from_existing(gs) so.assign(Singleowner.wrap(so_dat).export()) gs.execute() grid.execute() so.execute() print('Made it past execute.')
def retrieve_data(solar_plant, email, api_key, year="2016", rate_limit=0.5): """Retrieves irradiance data from NSRDB and calculate the power output using the System Adviser Model (SAM). :param pandas.DataFrame solar_plant: plant data frame. :param str email: email used to`sign up <https://developer.nrel.gov/signup/>`_. :param str api_key: API key. :param str year: year. :param int/float rate_limit: minimum seconds to wait between requests to NREL :return: (*pandas.DataFrame*) -- data frame with *'Pout'*, *'plant_id'*, *'ts'* and *'ts_id'* as columns. Values are power output for a 1MW generator. """ # SAM only takes 365 days. try: leap_day = (pd.Timestamp("%s-02-29-00" % year).dayofyear - 1) * 24 is_leap_year = True dates = pd.date_range(start="%s-01-01-00" % 2015, freq="H", periods=365 * 24) dates = dates.map(lambda t: t.replace(year=int(year))) except ValueError: leap_day = None is_leap_year = False dates = pd.date_range(start="%s-01-01-00" % year, freq="H", periods=365 * 24) # Identify unique location coord = get_plant_id_unique_location(solar_plant) data = pd.DataFrame({"Pout": [], "plant_id": [], "ts": [], "ts_id": []}) # PV tracking ratios # By state and by interconnect when EIA data do not have any solar PV in # the state pv_info = get_pv_tracking_data() zone_id = solar_plant.zone_id.unique() frac = {} for i in zone_id: state = id2abv[i] frac[i] = get_pv_tracking_ratio_state(pv_info, [state]) if frac[i] is None: frac[i] = get_pv_tracking_ratio_state( pv_info, list(interconnect2abv[abv2interconnect[state]])) # Inverter Loading Ratio ilr = 1.25 api = NrelApi(email, api_key, rate_limit) for key in tqdm(coord.keys(), total=len(coord)): lat, lon = key[1], key[0] solar_data = api.get_psm3_at( lat, lon, attributes="dhi,dni,wind_speed,air_temperature", year=year, leap_day=False, dates=dates, ).to_dict() for i in coord[key]: data_site = pd.DataFrame({ "ts": pd.date_range(start="%s-01-01-00" % year, end="%s-12-31-23" % year, freq="H") }) data_site["ts_id"] = range(1, len(data_site) + 1) data_site["plant_id"] = i power = 0 for j, axis in enumerate([0, 2, 4]): pv_dict = { "system_capacity": ilr, "dc_ac_ratio": ilr, "tilt": 30, "azimuth": 180, "inv_eff": 94, "losses": 14, "array_type": axis, "gcr": 0.4, "adjust:constant": 0, } pv_dat = pssc.dict_to_ssc_table(pv_dict, "pvwattsv7") pv = PVWatts.wrap(pv_dat) pv.SolarResource.assign({"solar_resource_data": solar_data}) pv.execute() ratio = frac[solar_plant.loc[i].zone_id][j] power += ratio * np.array(pv.Outputs.gen) if is_leap_year is True: data_site["Pout"] = np.insert(power, leap_day, power[leap_day - 24:leap_day]) else: data_site["Pout"] = power data = data.append(data_site, ignore_index=True, sort=False) data["plant_id"] = data["plant_id"].astype(np.int32) data["ts_id"] = data["ts_id"].astype(np.int32) data.sort_values(by=["ts_id", "plant_id"], inplace=True) data.reset_index(inplace=True, drop=True) return data
verbose = True # Make False if you don't want all the debugging info. # Get the SAM json file, make the simulations we need for the commercial # PVWatts simulation. # The json file is generated from SAM using the "Generate Code" menu item # in the added simulation case. Choose "JSON for inputs" and a .json file # with the title of your simulation case will be created where you select with # the "Open" button on the file dialog. json_file_path = 'Examples/100kW_PVWatts.json' # Change this file name to yours! with open(json_file_path) as f: dic = json.load(f) # The next seven lines are needed to load the PySAM data structures with the # inputs from the json file. pv_dat = pssc.dict_to_ssc_table(dic, "pvwattsv7") grid_dat = pssc.dict_to_ssc_table(dic, "grid") ur_dat = pssc.dict_to_ssc_table(dic, "utilityrate5") cl_dat = pssc.dict_to_ssc_table(dic, "cashloan") pv = PVWatts.wrap(pv_dat) grid = Grid.from_existing(pv) ur = UtilityRate.from_existing(pv) cl = Cashloan.from_existing(pv) grid.assign(Grid.wrap(grid_dat).export()) ur.assign(UtilityRate.wrap(ur_dat).export()) cl.assign(Cashloan.wrap(cl_dat).export()) # The models are executed in order. Note that the outputs from the first # simulation are automatically available for the next one, and so on. :-) pv.execute() grid.execute()