Exemple #1
0
def shutdown() :
  global addToQueue, queueIsEmpty, clearQueue
  msg("SMDS Shutting down.")
  Engine.shutdown()
  Dispatch.shutdown()
  if theCache : theCache.close()
  addToQueue = notInit
  queueIsEmpty = notInit
  clearQueue = notInit
Exemple #2
0
def main():
    #Read in data
    data.set_input(*inputs_data())

    #Lists to store outputs
    PVPowerOut =[]
    IPowerOut =[]
    BatteryPower =[]
    GridPowerNet =[]
    BatteryCurrentCapacity =[]
    BatterySOC =[]

    #List to store inputs
    Day = []
    Hour = []
    DNI = []
    Load = []
    for hour in range(len(data.input.LocalTime)):
        #Simulate dispatch

        dispatch_result = Dispatch.Dispatch(*data.prep_for_dispatch(hour))
        data.set_dispatch_results(*dispatch_result)

        print (data.output.PVPowerOut, data.output.IPowerOut, data.output.BatteryPower, data.output.GridPowerNet,
                   data.input.BatteryCurrentCapacity, data.output.BatterySOC)

        # Changing from float to string
        data.to_string(hour)

        # Recording each timestep in list
        Day.append(data.input.DayOfYear[hour])
        Hour.append(data.input.LocalTime[hour])
        DNI.append(data.input.DNI[hour])
        Load.append(data.input.LoadUncontrollablePower[hour])
        PVPowerOut.append(data.output.PVPowerOut)
        IPowerOut.append(data.output.IPowerOut)
        BatteryPower.append(data.output.BatteryPower)
        GridPowerNet.append(data.output.GridPowerNet)
        BatteryCurrentCapacity.append(data.output.BatteryCurrentCapacity)
        BatterySOC.append(data.output.BatterySOC)

    # Writing to csv file
    f = open('HEMSOutputWeek1.csv', 'w')
    for z in range(len(data.input.LocalTime)):
        f.write(Day[z] + ',')
        f.write(Hour[z] + ',')
        f.write(DNI[z] + ',')
        f.write(Load[z] + ',')
        f.write(PVPowerOut[z] + ',')
        f.write(IPowerOut[z] + ',')
        f.write(BatteryPower[z] + ',')
        f.write(GridPowerNet[z] + ',')
        f.write(BatteryCurrentCapacity[z] + ',')
        f.write(BatterySOC[z])
        f.write('\n')
    f.close()
Exemple #3
0
def initialize(dispatch = True, seed = None, cache = None, autoClean = True) :
  """initialize(dispatch = True, seed = None, cache = None, autoClean = True)
Initialize the Single-Molecule Diffusion Simulator.
  If dispatch is True, SMDS will attempt to contact the local Foundry to
  operate in distributed mode.  If this contact fails or if dispatch is
  False, SMDS will operate in single-processor mode.  An optional seed for
  the random number generator may be provided, otherwise the generator is
  initialized with the current time.\n"""
  global initialized, addToQueue, queueIsEmpty, clearQueue, theCache
  if initialized : return
  if dispatch and Dispatch.initialize() :
    addToQueue = Dispatch.addToQueue
    queueIsEmpty = Dispatch.queueIsEmpty
    clearQueue = Dispatch.clearQueue
    msg("SMDS Initialized in Dispatch mode.")
  else :
    Engine.initialize()
    addToQueue = Engine.addToQueue
    queueIsEmpty = Engine.queueIsEmpty
    clearQueue = Engine.clearQueue
    msg("SMDS Initialized in Single-processor mode.")
  if seed : Cores.c2D.sRnd(int(seed))
  else    : Cores.c2D.sRnd()
  initialized = True
  if cache : theCache = Cache(cache, autoClean)
  # Ensure proper shutdown()
  from atexit import register
  from sys import exit
  from signal import signal, SIGTERM
  register(shutdown)
  signal(SIGTERM, lambda x,y : exit())
  try :
    from signal import SIGBREAK
    signal(SIGBREAK, lambda x,y : exit())
  except :
    pass
Exemple #4
0
def ESS_calc(
        file, lat, lon, n, rates
):  # inputs: a load profile, lat/lon coordinates, name of location
    I = 1  # Incrementation. 1 = hour .25= quarter hourly
    # create 5 lists to keep track of data.
    # 1) the date, aka 8760 values "YYYY-MM-DD hour:min:sec"
    # 2) consumption vals, aka the load profile. How much electricity used per hour
    # 3) bill before solar (electricity only) per hour
    # 4) solar - Output of PVWatts.py. Solar generation for 8760
    # 5) net load = load - solar
    output = LoadProfile.run(file, rates)
    consumption = output[1]
    before_solar = output[2]
    import_rates = output[3]
    export_rates = output[4]
    solar = PVWatts.run(lat, lon)

    net_load = []
    for i in range(len(consumption)):
        net_load += [consumption[i] - solar[i]]

    after_solar = []
    for i in range(len(net_load)):
        if net_load[i] >= 0:
            after_solar += [net_load[i] * import_rates[i] * I]
        else:
            after_solar += [net_load[i] * export_rates[i] * I]

    # writes all calculations to a csv file
    name = "Outputs/" + n + ".csv"
    with open(name, 'w') as output_file:
        headers = [
            "Date/Time", "Load", "Bill Before Solar", "Solar",
            "Net Load Solar Only", "Bill Solar Only", "Import Rate",
            "Export Rate"
        ]
        writer = csv.DictWriter(output_file, headers)

        writer.writeheader()
        for i in range(len(consumption)):
            writer.writerow({
                "Date/Time": i,
                "Load": consumption[i],
                "Bill Before Solar": before_solar[i],
                "Solar": solar[i],
                "Net Load Solar Only": net_load[i],
                "Bill Solar Only": after_solar[i],
                "Import Rate": import_rates[i],
                "Export Rate": export_rates[i]
            })

    # perform dispatch analysis through Dispatch.py. Gets basic storage and soc.
    # calculate bill of solar and storage
    # calculates the difference between bill pre-solar and bill solar/storage to get ESS savings
    d = pd.read_csv(name)
    d = Dispatch.full_savings_dispatch(d, I)
    d['Net Load (Solar and Storage)'] = d["Load"] - d["basic storage"] - d[
        "Solar"]
    d["Bill PV + ESS"] = np.where(
        d["Net Load (Solar and Storage)"] >= 0,
        d['Net Load (Solar and Storage)'] * d['Import Rate'] * I,
        d['Net Load (Solar and Storage)'] * d['Export Rate'] * I)
    d["ESS Savings"] = d["Bill Solar Only"] - d["Bill PV + ESS"]
    d["yearly ESS savings"] = d["ESS Savings"].sum()
    val = d.at[0, "yearly ESS savings"]
    bill_pre_solar = d["Bill Before Solar"].sum()
    bill_solar_only = d["Bill Solar Only"].sum()
    bill_solar_storage = d["Bill PV + ESS"].sum()
    d = d.to_csv(name)
    return (val, bill_pre_solar, bill_solar_only, bill_solar_storage)
                state = str(location) + '-' + str(step)
                '''Construct the match pool: Request_arr and Driver_arr '''

                Request_arr = list(Request_data.loc[
                    (Request_data['Pickup_step'] == step) &
                    (Request_data['Pickup_Location'] == location), 'Order_id'])

                Driver_arr = list(
                    Driver_data.loc[(Driver_data['step'] == step) &
                                    (Driver_data['Order_id'] == -1) &
                                    (Driver_data['Location_id'] == location),
                                    'Driver_id'])

                if len(Driver_arr) != 0:

                    dispatch = Dispatch(Request_arr, Driver_arr)
                    '''Generate the matched results'''

                    Matched_driver, Matched_order = dispatch.random_dispatch()
                    '''Update the Request info'''

                    for order_id, driver_id in Matched_order.items():

                        if driver_id != -1:
                            '''Update the matched driver info into the Request info'''

                            Request_data.loc[
                                (Request_data['Pickup_step'] == step) &
                                (Request_data['Pickup_Location'] == location) &
                                (Request_data['Order_id'] == order_id),
                                'Driver_id'] = driver_id
Exemple #6
0
    BatterySOC =[]

    #List to store inputs
    Day = []
    Hour = []
    DNI = []
    Load = []
    for hour in range(len(data.input.LocalTime)):
        #Simulate dispatch
<<<<<<< HEAD
        data.output.IPowerIn, data.output.IPowerOut, data.output.BatteryPower, data.output.GridPowerNet,\
        data.output.BatteryCapacityAsEnergy, data.output.BatterySOC, data.input.BatteryCurrentCapacity, data.output.PVPowerOut = Dispatch.Dispatch(data.input.EnergySystemType,
                                data.input.LoadControllablePower[hour], data.input.LoadCurtailPercent,
                                data.input.LoadUncontrollablePower[hour], data.input.DayOfYear[hour], data.input.LocalTime[hour],
                                data.input.TimeZone, data.input.Longitude, data.input.Latitude, data.input.PVSlope,
                                data.input.GlobalHorizontalRadiation[hour], data.input.ClearnessIndex[hour], data.input.DNI[hour],
                                data.input.TimeStepHourlyFraction, data.input.DFI[hour], data.input.GroundReflectance,
                                data.input.Inverterefficeincy, data.input.PVcapacity, data.input.Invertercapacity,
                                data.input.StartTOU, data.input.StopTOU, data.input.BatteryCurrentCapacity,
                                data.input.BatteryNominalCapacity, data.input.BatteryMinCapacityAsFraction,
                                data.input.BatteryChargeEff, data.input.BatteryDischargeEff, data.input.BatteryMaxCRate, data.input.BatteryVoltageNominal)
=======
>>>>>>> 6951d82161b1ed5e6351388f22aa29f3abe0b383

        dispatch_result = Dispatch.Dispatch(*data.prep_for_dispatch(hour))
        data.set_dispatch_results(*dispatch_result)

        print (data.input.DNI[hour], data.output.PVPowerOut, data.output.IPowerOut, data.output.BatteryPower, data.output.GridPowerNet,
                   data.output.BatteryCapacityAsEnergy, data.output.BatterySOC, data.input.BatteryCurrentCapacity)

        # Changing from float to string
<<<<<<< HEAD
Exemple #7
0
def speak(str):
    form win32com.client import Dispatch
    speak=Dispatch("SAPI.Spvoice")
    speak.Speak(str)