示例#1
0
def test_reopt_sizing_pvsam(solar_resource):
    import PySAM.Utilityrate5 as ur
    sys = pvsam.default("FlatPlatePVCommercial")
    fin = ur.from_existing(sys, "FlatPlatePVCommercial")
    bt = stbt.from_existing(sys, "GenericBatteryCommercial")

    sys.SolarResource.solar_resource_file = solar_resource
    bt.Load.crit_load = [0] * 8760
    post = sys.Reopt_size_battery_post()

    assert('Scenario' in post['reopt_post'])
    assert(post['reopt_post']['Scenario']['Site']['latitude'] == pytest.approx(33.6, 0.1))
示例#2
0
def run_calculation(meter_id, year, month=None):
    hours = [0, 744, 1416, 2160, 2880, 3624, 4344, 5088, 5832, 6552, 7296, 8016]
    pysam_array_length = 8760
    if not month:
        from_datetime = datetime(year, 1, 1, 0, 0, 1)
        thru_datetime = datetime(year, 12, 31, 23, 59, 59)
    else:
        last_day = monthrange(year, month)[1]
        from_datetime = datetime(year, month, 1, 0, 0, 1)
        thru_datetime = datetime(year, month, last_day, 23, 59, 59)

    meter_history = MeterHistory.objects.filter(meter_id=meter_id, as_of_datetime__gte=from_datetime,
                                                as_of_datetime__lte=thru_datetime).order_by('as_of_datetime')

    load_data = [0 for i in range(pysam_array_length)]
    counter = 0
    if month:
        counter = hours[month-1]
    for row in meter_history:
        load_data[counter] = row.value
        counter += 1

    rate_plan_history = MeterRatePlanHistory.objects.filter(meter_id=meter_id).order_by("from_datetime")
    if not rate_plan_history:
        raise Exception("Cannot find MeterRatePlanHistory for meter {}".format(meter_id))

    rate_plan = rate_plan_history[0].rate_details

    model = utility.new()
    rates = URDBv7_to_ElectricityRates(rate_plan)
    model.ElectricityRates.assign(rates)

    lifetime_data = dict()
    lifetime_data['analysis_period'] = 1
    lifetime_data['system_use_lifetime_output'] = 1
    lifetime_data['inflation_rate'] = 99

    model.Lifetime.assign(lifetime_data)

    model.SystemOutput.degradation = [99]
    gen = [0 for i in range(pysam_array_length)]

    model.SystemOutput.gen = gen
    model.Load.load = load_data

    model.execute()

    if not month:
        return model.Outputs.year1_monthly_utility_bill_w_sys
    else:
        return (model.Outputs.year1_monthly_utility_bill_w_sys[month-1],)
示例#3
0
def test_reopt_sizing_pvwatts(solar_resource):
    round = 0

    tracker = SummaryTracker()
    while round < 25:   # multiple runs required to check for memory leaks
        round += 1

        sys = pv.default("PVWattsBatteryCommercial")
        sys.SolarResource.solar_resource_file = solar_resource
        batt = bt.from_existing(sys, "PVWattsBatteryCommercial")
        sys.SolarResource.solar_resource_data = dict({'lat': 3, 'lon': 3})
        batt.Battery.crit_load = [0] * 8760
        fin = ur.from_existing(sys, "PVWattsBatteryCommercial")

        post = sys.Reopt_size_battery_post()

    assert('Scenario' in post['reopt_post'])
    assert(post['reopt_post']['Scenario']['Site']['latitude'] == pytest.approx(3, 0.1))
    tracker_diff = tracker.diff()
    tracker.print_diff()
# 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()
ur.execute()
cl.execute()

if verbose:  # Print out some results.  The variable names can be found in
    # the model pages of the docs.
    print('Replicating SAM Results using PySAM')
示例#5
0
ssc = PySSC()

# I generated json files using "Generate Code" option in example.sam in pysam-examples and exporting as json.
# Battery data is captured through detailed PV model, but will be used with PVWatts here
with open(os.path.join('pysam_inputs', "pvwatts.json")) as f:
    dic = json.load(f)
    pvwatts_dat = dict_to_ssc_table(dic, "pvwattsv5")
    pv = pvwatts.wrap(pvwatts_dat)

with open(os.path.join('pysam_inputs', "pvsamv1.json")) as f:
    dic = json.load(f)
    batt_dat = dict_to_ssc_table(dic, "battery")
    batt = battery.wrap(batt_dat)
    utility_dat = dict_to_ssc_table(dic, "utilityrate5")
    utilityrate = utility.wrap(utility_dat)
    loan_dat = dict_to_ssc_table(dic, "cashloan")
    loan = cashloan.wrap(loan_dat)

# run PV model
pv.execute()
ac = pv.Outputs.ac  # W
gen = [i / 1000 for i in ac]

# run Battery model
batt.System.gen = gen

# because version of PySAM is a little behind the development version I exported json from
batt.Battery.batt_power_discharge_max = 5.06
batt.Battery.batt_power_charge_max = 5.06
示例#6
0
            ])
    if verbose:
        print(json_file_path)

except NameError:
    print('NameError: with the json file')
else:
    with open(json_file_path) as f:
        dic = json.load(f)
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 = PVWattsCommercial.wrap(pv_dat)
grid = Grid.from_existing(pv)
ur = UtilityRate.from_existing(pv, 'PVWattsCommercial')
cl = Cashloan.from_existing(pv, 'PVWattsCommercial')
grid.assign(Grid.wrap(grid_dat).export())
ur.assign(UtilityRate.wrap(ur_dat).export())
cl.assign(Cashloan.wrap(cl_dat).export())

degradation = cl.SystemOutput.degradation[0]
if verbose:
    print('degradation', degradation)
if testing:
    pv.execute()
    grid.execute()
    ur.execute()
    cl.execute()
    npv_single_stage = cl.Outputs.npv
    if verbose: