def __init__( self, weather_dataframe, # weather data from NSRDB (pd.DataFrame) weather_meta_data, # meta data for the weather data file above (pd.DataFrame) system_capacity_dc=1, # DC system capacity (kW or MW) dc_ac_ratio=1.1, # Set DC/AC ratio (or inverter loading ratio). See https://sam.nrel.gov/sites/default/files/content/virtual_conf_july_2013/07-sam-virtual-conference-2013-woodcock.pdf tilt=0, # tilt of system in degrees (0 = horizontal) azimuth=180, # azimuth angle (in degrees) from north (180 = south facing) inv_eff=96, # inverter efficiency in percent losses=14.0757, # system losses in percent (soiling, shading, wiring, etc.) array_type=0, # specify fixed tilt system (0=Fixed, 1=Fixed Roof, 2=1 Axis Tracker, 3=Backtracted, 4=2 Axis Tracker) gcr=0.4, # ground coverage ratio adjust_constant=0 # constant loss adjustment ): # Set up Software Simulation Core (SSC) Object ssc = sscapi.PySSC() # Set Up Data Containers dat = ssc.data_create() # container for all input data wfd = ssc.data_create() # weather file data container # Fill wfd container with weather data ssc.data_set_number(wfd, 'lat', weather_meta_data['Latitude']) ssc.data_set_number(wfd, 'lon', weather_meta_data['Longitude']) ssc.data_set_number(wfd, 'tz', weather_meta_data['Local Time Zone']) ssc.data_set_number(wfd, 'elev', weather_meta_data['Elevation']) ssc.data_set_array(wfd, 'year', weather_dataframe.index.year) ssc.data_set_array(wfd, 'month', weather_dataframe.index.month) ssc.data_set_array(wfd, 'day', weather_dataframe.index.day) ssc.data_set_array(wfd, 'hour', weather_dataframe.index.hour) ssc.data_set_array(wfd, 'minute', weather_dataframe.index.minute) ssc.data_set_array(wfd, 'dn', weather_dataframe['DNI']) ssc.data_set_array(wfd, 'df', weather_dataframe['DHI']) ssc.data_set_array(wfd, 'wspd', weather_dataframe['Wind Speed']) ssc.data_set_array(wfd, 'tdry', weather_dataframe['Temperature']) # Add wfd container to dat container ssc.data_set_table(dat, 'solar_resource_data', wfd) ssc.data_free(wfd) # Specify the system Configuration ssc.data_set_number(dat, 'system_capacity', system_capacity_dc) ssc.data_set_number(dat, 'dc_ac_ratio', dc_ac_ratio) ssc.data_set_number(dat, 'tilt', tilt) ssc.data_set_number(dat, 'azimuth', azimuth) ssc.data_set_number(dat, 'inv_eff', inv_eff) ssc.data_set_number(dat, 'losses', losses) ssc.data_set_number(dat, 'array_type', array_type) ssc.data_set_number(dat, 'gcr', gcr) ssc.data_set_number(dat, 'adjust:constant', adjust_constant) # Add the software simulation core object and the input data object as attributes to the PVSystem object self.ssc = ssc self.dat = dat
def sam_simulation(meteo_data, verbose=False, **kwargs): """ SAM performance simulation Perform a PVWATTS simulation using the SAM python implementation. Args: meteo_data (pd.DataFrame): Solar radiation dataframe kwargs (dictionary): Dictionary containing simulation parameters Returns: CP (float): Capacity factor Generation (float): Generation over the year of simulation meto_data (pd.DataFrame): Dataframe with hourly generation """ params = { 'lat': kwargs['lat'], 'lon': kwargs['lng'], 'timezone': kwargs['timezone'], 'elevation': kwargs['elevation'], 'sys_capacity': kwargs['system_capacity'], 'dc_ac_ratio': kwargs['dc_ac_ratio'], 'inv_eff': kwargs['inv_eff'], 'losses': kwargs['losses'], 'configuration': kwargs['configuration'], 'tilt': kwargs['tilt'], } if verbose: print({key: type(value) for key, value in params.items()}) ssc = sscapi.PySSC() wfd = ssc.data_create() ssc.data_set_number(wfd, 'lat', params['lat']) ssc.data_set_number(wfd, 'lon', params['lon']) ssc.data_set_number(wfd, 'tz', params['timezone']) ssc.data_set_number(wfd, 'elev', params['elevation']) ssc.data_set_array(wfd, 'year', meteo_data.index.year) ssc.data_set_array(wfd, 'month', meteo_data.index.month) ssc.data_set_array(wfd, 'day', meteo_data.index.day) ssc.data_set_array(wfd, 'hour', meteo_data.index.hour) ssc.data_set_array(wfd, 'minute', meteo_data.index.minute) ssc.data_set_array(wfd, 'dn', meteo_data['DNI']) ssc.data_set_array(wfd, 'df', meteo_data['DHI']) ssc.data_set_array(wfd, 'wspd', meteo_data['Wind Speed']) ssc.data_set_array(wfd, 'tdry', meteo_data['Temperature']) # Create SAM compliant object dat = ssc.data_create() ssc.data_set_table(dat, 'solar_resource_data', wfd) ssc.data_free(wfd) # Set system capacity in MW ssc.data_set_number(dat, 'system_capacity', params['sys_capacity']) # Set DC/AC ratio (or power ratio). See https://sam.nrel.gov/sites/default/files/content/virtual_conf_july_2013/07-sam-virtual-conference-2013-woodcock.pdf ssc.data_set_number(dat, 'dc_ac_ratio', params['dc_ac_ratio']) # Set tilt of system in degrees ssc.data_set_number(dat, 'tilt', params['tilt']) # Set azimuth angle (in degrees) from north (0 degrees) ssc.data_set_number(dat, 'azimuth', 180) # Set the inverter efficency ssc.data_set_number(dat, 'inv_eff', params['inv_eff']) # Set the system losses, in percent ssc.data_set_number(dat, 'losses', params['losses']) # Set ground coverage ratio ssc.data_set_number(dat, 'gcr', 0.4) # Set constant loss adjustment ssc.data_set_number(dat, 'adjust:constant', 0) system_capacity = params['sys_capacity'] value = params['configuration'] if isinstance(params['configuration'], dict): d = {} for key, val in value.iteritems(): ssc.data_set_number(dat, 'array_type', val) # execute and put generation results back into dataframe mod = ssc.module_create('pvwattsv5') ssc.module_exec(mod, dat) meteo_data['generation'] = np.array(ssc.data_get_array(dat, 'gen')) CP = meteo_data['generation'].sum() / (525600 / int('60') * system_capacity) generation = meteo_data['generation'].sum() d[key] = CP d['gen_' + key] = generation ssc.data_free(dat) ssc.module_free(mod) return (d) else: ssc.data_set_number(dat, 'array_type', value) # execute and put generation results back into dataframe mod = ssc.module_create('pvwattsv5') ssc.module_exec(mod, dat) meteo_data['generation'] = np.array(ssc.data_get_array(dat, 'gen')) meteo_data['cf'] = meteo_data['generation'] / system_capacity CP = meteo_data['generation'].sum() / (525600 / int('60') * system_capacity) generation = meteo_data['generation'].sum() click.secho('Output data from SAM.', fg='green') click.secho(f'Capacity Factor: {CP}', fg='blue') click.secho(f'Annual Generation: {generation}', fg='blue') ssc.data_free(dat) ssc.module_free(mod) meteo_data.to_csv(output_path / 'test.csv') return (meteo_data, (CP, generation)) return (True)
# -*- coding: utf-8 -*- """ Created on Thu Feb 11 17:50:06 2016 @author: Koats """ import sscapi ssc = sscapi.PySSC() dat = ssc.data_create() def simparam(): def subaltset(): def subarray(angle): def loss():
def get_csvs_simulations (mesh, path, year, interval, kw, tiltc): mesh = pd.read_csv(mesh, header = -1, encoding = "ISO-8859-1")[1:] for i, val in tqdm (enumerate(mesh[1]), desc = "Counties in Mexico completed for this day/dataframe"): info = pd.read_csv(str(path + '/' + str(year) + 'meta/' + mesh[1].iloc[i] + '.csv'), nrows = 1) timezone = info['Local Time Zone'] elevation = info['Elevation'] df = pd.read_csv(str(path + '/' + str(year) + '/' + mesh[1].iloc[i] + '.csv')) latitude = float(mesh[2].iloc[i]) longitude = float(mesh[3].iloc[i]) kw = int(kw) year = df['Year'][i] month = df['Month'][i] day = df['Day'][i] hour = df['Hour'][i] minute = df['Minute'][i] df = df.set_index(pd.date_range('1/1/{yr} 00:00'.format(yr = year), freq = interval + 'Min', periods = 525600 / int(interval))) ssc = sscapi.PySSC() wfd = ssc.data_create() ssc.data_set_number(wfd, 'lat'.encode('utf-8'), latitude) ssc.data_set_number(wfd, 'lon'.encode('utf-8'), longitude) ssc.data_set_number(wfd, 'tz'.encode('utf-8'), timezone) ssc.data_set_number(wfd, 'elev'.encode('utf-8'), elevation) ssc.data_set_array(wfd, 'year'.encode('utf-8'), df.index.year) ssc.data_set_array(wfd, 'month'.encode('utf-8'), df.index.month) ssc.data_set_array(wfd, 'day'.encode('utf-8'), df.index.day) ssc.data_set_array(wfd, 'hour'.encode('utf-8'), df.index.hour) ssc.data_set_array(wfd, 'minute'.encode('utf-8'), df.index.minute) ssc.data_set_array(wfd, 'dn'.encode('utf-8'), df['DNI']) ssc.data_set_array(wfd, 'df'.encode('utf-8'), df['DHI']) ssc.data_set_array(wfd, 'wspd'.encode('utf-8'), df['Wind Speed']) ssc.data_set_array(wfd, 'tdry'.encode('utf-8'), df['Temperature']) dat = ssc.data_create() ssc.data_set_table(dat, 'solar_resource_data'.encode('utf-8'), wfd) ssc.data_free(wfd) # System Capacity in KW system_capacity = kw ssc.data_set_number(dat, 'system_capacity'.encode('utf-8'), system_capacity) # Set DC/AC ratio (or power ratio). See https://sam.nrel.gov/sites/default/files/content/virtual_conf_july_2013/07-sam-virtual-conference-2013-woodcock.pdf dc_ac_ratio = 1.1 ssc.data_set_number(dat, 'dc_ac_ratio'.encode('utf-8'), dc_ac_ratio) # Set tilt of system in degrees (default: 25) # Optimum: (latitude * .76) + 3.1 tilt = (float(mesh[2].iloc[i])) if tiltc == "Normal" else ((float(mesh[2].iloc[1])*.76) + 3.1) ssc.data_set_number(dat, 'tilt'.encode('utf-8'), tilt) # Set azimuth angle (in degrees) from north (0 degrees) azimuth = 180 ssc.data_set_number(dat, 'azimuth'.encode('utf-8'), azimuth) # Set the inverter efficiency inv_eff = 96 ssc.data_set_number(dat, 'inv_eff'.encode('utf-8'), inv_eff) # Set the system losses, in percent losses = 14.0757 ssc.data_set_number(dat, 'losses'.encode('utf-8'), losses) # Specify fixed tilt system (1=true, 0=false) array_type = 1 ssc.data_set_number(dat, 'array_type'.encode('utf-8'), array_type) # Set ground coverage ratio gcr = 0.4 ssc.data_set_number(dat, 'gcr'.encode('utf-8'), gcr) # Set constant loss adjustment loss_adjustment = 0 ssc.data_set_number(dat, 'adjust:constant'.encode('utf-8'), loss_adjustment) # Execute and put generation results back into dataframe mod = ssc.module_create('pvwattsv5'.encode('utf-8')) ssc.module_exec(mod, dat) df['generation'] = np.array(ssc.data_get_array(dat, 'gen'.encode('utf-8'))) # Free the memory ssc.data_free(dat) ssc.module_free(mod) # Divide sum of generation by the number of periods times the system size df['generation'].sum() / (525600/int(interval) * system_capacity) # Total Energy: df['generation'].sum() df['latitude'] = latitude df['longitude'] = longitude df['timezone'] = np.array(timezone)[0] df['elevation'] = np.array(elevation)[0] systemconfig_id = 'sc' + str(system_capacity) + 'dcac' + str(dc_ac_ratio) +\ 'tilt' + str(tilt) + 'az' + str(azimuth) + 'eff' + str(inv_eff) +\ 'loss' + str(losses) + 'gc' + str(gcr) +\ ('adj' + str(loss_adjustment) if loss_adjustment != 0 else '') +\ ('fixed' if array_type == 1 else '') df['ID_scenario'] = systemconfig_id df.to_csv (str(path + '/' + str(year) + 'SAMgen_' + str(interval) + 'mins_' + str(float(kw)/1000.0) + 'MW_' + tiltc + '/' + mesh[1].iloc[i] + '.csv'), index = False)