Esempio n. 1
0
def main(argv):
	# Read instance folder
	if len(argv) < 2 :
		displayHelp()
		sys.exit(2)
	folderPath=argv[0] if argv[0].endswith(("/","\\")) else argv[0]+"/"

	# Provide slack bus external ID as second argument
	slackBusId = int(argv[1])
	period = int(argv[2]) # Period in the scenario

	# Provide period of the scenario as third argument
	if not 0<period<96:
		raise Exception('Invalid period %s'%period)

	if not os.path.exists(folderPath):
		raise Exception('Folder \"%s\" does not exists.' % folderPath)

	# Read network data (all but power information)
	graph=networkMaker.makeNetwork(folderPath)

	# Read power information, select time horizon, day number, and scenario type.
	scenariosReader.readScenarios(folderPath,2020,1,graph,'H')

	# Output
	makePyflowCSV('caseYlpic.py', graph, 'ylpic', slackBusId, period)
Esempio n. 2
0
def main(argv):
    # Parse arguments
    if len(argv) < 4:
        displayHelp()
        sys.exit(2)
    inputPath = argv[0] if argv[0].endswith(("/", "\\")) else argv[0] + "/"
    if not os.path.exists(inputPath):
        raise Exception('Folder \"%s\" does not exists.' % inputPath)
    outputPath = argv[1] if argv[1].endswith(("/", "\\")) else argv[1] + "/"
    year = int(argv[2])
    scenario = argv[3]

    # Static mode?
    static = len(argv) == 5 and argv[4] == "--static"
    if static:
        print("STATIC MODE")
        for k in flexU.keys():
            flexU[k] = 0
        for k in flexD.keys():
            flexD[k] = 0

    #days=range(1,366)
    days = {26, 35, 51, 65, 106, 138, 142, 175, 263, 305, 344, 360}

    # Create output folder
    if not os.path.exists(outputPath):
        os.makedirs(outputPath)
    for d in days:
        dayDirectory = '%s/%s' % (outputPath, d)
        if not os.path.exists(dayDirectory):
            os.makedirs(dayDirectory)

    # Read graph
    graph = networkMaker.makeNetwork(inputPath)
    addRootBus(graph, 8001)

    # Read prices data
    pricesData = readPricesData('%sprices.xlsx' % inputPath)

    # Read day by day
    networkGenerated = False
    for d in days:
        print("\t%s" % d)
        g = copy.deepcopy(graph)
        scenariosReader.readScenarios(inputPath, year, d, g, scenario)

        if not networkGenerated:
            makeNetworkDot(g)
            networkGenerated = True

        makeNetworkCSV("%s/%s/network.csv" % (outputPath, d), g)
        makeProducers("%s/%s/producers" % (outputPath, d), g)
        makeRetailers("%s/%s/retailers" % (outputPath, d), g)
        makeQualificationIndicators("%s/%s" % (outputPath, d), g)
        makeTSO("%s/%s" % (outputPath, d))
        makePrices("%s/%s/prices.csv" % (outputPath, d), pricesData, year, d)
Esempio n. 3
0
def main(argv):
    # Parse arguments
    if len(argv) < 4 :
        displayHelp()
        sys.exit(2)
    inputPath=argv[0] if argv[0].endswith(("/","\\")) else argv[0]+"/"
    if not os.path.exists(inputPath):
        raise Exception('Folder \"%s\" does not exists.' % inputPath)
    outputPath=argv[1] if argv[1].endswith(("/","\\")) else argv[1]+"/"
    year=int(argv[2])
    scenario=argv[3]

    # Static mode?
    static=len(argv) == 5 and argv[4] == "--static"
    if static:
        print("STATIC MODE")
        for k in flexU.keys():
            flexU[k]=0
        for k in flexD.keys():
            flexD[k]=0

    #days=range(1,366)
    days={26,35,51,65,106,138,142,175,263,305,344,360}

    # Create output folder
    if not os.path.exists(outputPath):
        os.makedirs(outputPath)
    for d in days:
        dayDirectory='%s/%s'%(outputPath,d)
        if not os.path.exists(dayDirectory):
            os.makedirs(dayDirectory)

    # Read graph
    graph=networkMaker.makeNetwork(inputPath)
    addRootBus(graph,8001)

    # Read prices data
    pricesData = readPricesData('%sprices.xlsx' % inputPath)

    # Read day by day
    networkGenerated=False
    for d in days:
        print("\t%s" % d)
        g = copy.deepcopy(graph)
        scenariosReader.readScenarios(inputPath,year,d,g,scenario)

        if not networkGenerated:
            makeNetworkDot(g)
            networkGenerated=True

        makeNetworkCSV("%s/%s/network.csv" % (outputPath,d), g)
        makeProducers("%s/%s/producers"%(outputPath,d), g)
        makeRetailers("%s/%s/retailers"%(outputPath,d), g)
        makeQualificationIndicators("%s/%s"%(outputPath,d),g)
        makeTSO("%s/%s"%(outputPath,d))
        makePrices("%s/%s/prices.csv" % (outputPath,d), pricesData, year, d)
Esempio n. 4
0
def main(argv):
    # Provide slack bus external ID as second argument
    if len(argv) == 3:
        folderPath = argv[0] if argv[0].endswith(
            ("/", "\\")) else argv[0] + "/"
        slackBusId = int(argv[1])
        period = int(argv[2])  # Period in the scenario

        # Provide period of the scenario as third argument
        if not 0 < period <= 96:
            raise Exception('Invalid period %s' % period)

        if not os.path.exists(folderPath):
            raise Exception('Folder \"%s\" does not exists.' % folderPath)

        # Read network data (all but power information)
        graph = networkMaker.makeNetwork(folderPath)

        # Read power information, select time horizon, day number, and scenario type.
        scenariosReader.readScenarios(folderPath, 2020, 1, graph, 'H')

        # Output
        makePyflowFile('caseYlpic.py', graph, 'ylpic', slackBusId, period)

    elif len(argv) == 4 or len(argv) == 5:
        folderPath = argv[0] if argv[0].endswith(
            ("/", "\\")) else argv[0] + "/"
        slackBusId = int(argv[1])
        year = int(argv[2])
        scenario = argv[3]
        outputPath = ""
        if len(argv) == 5:
            outputPath = argv[4] + "/"

        # Read network data (all but power information)
        graph = networkMaker.makeNetwork(folderPath)

        days = range(1, 366)
        for d in days:
            print("\t%s" % d)
            g = copy.deepcopy(graph)
            scenariosReader.readScenarios(folderPath, year, d, g, scenario)

            for period in range(1, 97):
                makePyflowFile(
                    '%sylpic_y%ss%sd%sp%s.py' %
                    (outputPath, year, scenario, d, period), g,
                    'ylpic_y%ss%sd%sp%s' % (year, scenario, d, period),
                    slackBusId, period - 1)
    else:
        displayHelp()
        sys.exit(2)
def main(argv):
    # Provide slack bus external ID as second argument
    if len(argv) == 3:
        folderPath = argv[0] if argv[0].endswith(("/", "\\")) else argv[0] + "/"
        slackBusId = int(argv[1])
        period = int(argv[2])  # Period in the scenario

        # Provide period of the scenario as third argument
        if not 0 < period <= 96:
            raise Exception("Invalid period %s" % period)

        if not os.path.exists(folderPath):
            raise Exception('Folder "%s" does not exists.' % folderPath)

            # Read network data (all but power information)
        graph = networkMaker.makeNetwork(folderPath)

        # Read power information, select time horizon, day number, and scenario type.
        scenariosReader.readScenarios(folderPath, 2020, 1, graph, "H")

        # Output
        makeMatpowerFile("caseYlpic.m", graph, "ylpic", slackBusId, period)

    elif len(argv) == 4 or len(argv) == 5:
        folderPath = argv[0] if argv[0].endswith(("/", "\\")) else argv[0] + "/"
        slackBusId = int(argv[1])
        year = int(argv[2])
        scenario = argv[3]
        outputPath = ""
        if len(argv) == 5:
            outputPath = argv[4] + "/"

            # Read network data (all but power information)
        graph = networkMaker.makeNetwork(folderPath)

        days = range(1, 366)
        for d in days:
            print("\t%s" % d)
            g = copy.deepcopy(graph)
            scenariosReader.readScenarios(folderPath, year, d, g, scenario)

            for period in range(1, 97):
                makeMatpowerFile(
                    "%sylpic_y%ss%sd%sp%s.m" % (outputPath, year, scenario, d, period),
                    g,
                    "ylpic_y%ss%sd%sp%s" % (year, scenario, d, period),
                    slackBusId,
                    period - 1,
                )
    else:
        displayHelp()
        sys.exit(2)
Esempio n. 6
0
def main(argv):
    # Read instance folder
    if len(argv) < 1 :
        displayHelp()
        sys.exit(2)
    folderPath=argv[-1] if argv[-1].endswith(("/","\\")) else argv[-1]+"/"
    if not os.path.exists(folderPath):
        raise Exception('Folder \"%s\" does not exists.' % folderPath)

    # Read data
    graph=networkMaker.makeNetwork(folderPath)
    scenariosReader.readScenarios(folderPath,2020,1,graph,'H')

    # Create simple graph and draw
    makeNetworkDot(graph)
Esempio n. 7
0
def main(argv):
    # Read instance folder
    if len(argv) < 1:
        displayHelp()
        sys.exit(2)
    folderPath = argv[-1] if argv[-1].endswith(("/", "\\")) else argv[-1] + "/"
    if not os.path.exists(folderPath):
        raise Exception('Folder \"%s\" does not exists.' % folderPath)

    # Read data
    graph = networkMaker.makeNetwork(folderPath)
    scenariosReader.readScenarios(folderPath, 2020, 1, graph, 'H')

    # Create simple graph and draw
    makeNetworkDot(graph)
def main(argv):
	globalTic=time.time()

	# Default parameters
	year = 2020
	scenario = 'H'
	T = 96

	# Read instance folder
	if len(argv) < 1 :
		displayHelp()
		sys.exit(2)

	if len(argv) > 1:
		year=int(argv[0])
	if len(argv) > 2:
		scenario=argv[1]

	folderPath = argv[-1] if argv[-1].endswith(("/","\\")) else argv[-1]+"/"

	print("Compute time series %s %s" % (year, scenario))

	# Create work sheet
	wb = xlwt.Workbook()
	sheet = wb.add_sheet('timeseries')
	dateStyle = xlwt.easyxf(num_format_str='DD/MM/YYYY')

	# Header
	sheet.write(0,0,'Day')
	sheet.write(0,1,'Quarter')

	sheet.write(0,2,'Active production')
	sheet.write(1,2,'MW')

	sheet.write(0,3,'Active consumption')
	sheet.write(1,3,'MW')

	sheet.write(0,4,'Net active injection')
	sheet.write(1,4,'MW')

	sheet.write(0,5,'Reactive Production')
	sheet.write(1,5,'MVar')

	sheet.write(0,6,'Reactive Consumption')
	sheet.write(1,6,'MVar')

	sheet.write(0,7,'Net reactive injection')
	sheet.write(1,7,'MVar')

	# Read graph
	initGraph = networkMaker.makeNetwork(folderPath)

	# Read network data (all but power information)
	firstDay = datetime.date(year, 1, 1).toordinal()
	day = datetime.date(year, 1, 1)
	for d in range(0,365):
		tic = time.time()
		graph = copy.deepcopy(initGraph)

		# Obtain the corresponding date-time
		day=day.fromordinal(firstDay+d)

		# Read daily data
		scenariosReader.readScenarios(folderPath,year,d+1,graph,scenario)

		for t in range(0, T):
			l=2+d*T+t # Excel line

			# Write day and quarter
			sheet.write(l, 0, day, dateStyle)
			sheet.write(l, 1, t+1)

			# Find production & consumption
			activeProduction=0.0
			activeConsumption=0.0
			reactiveProduction=0.0
			reactiveConsumption=0.0

			for n, ndata in graph.nodes(data=True):
				Pd = 0 # MW
				Qd = 0 # MVar
				try:
					loadData = ndata['load']
					if loadData is not None:
						for label, baseline in loadData.activeProfiles.items():
							if len(baseline) < T:
								raise Exception("Error with label \"%s\" in node %s, baseline has %s periods in day %s." % (label, n, len(baseline),d+1))

						for baseline in loadData.activeProfiles.values():
							Pd += baseline[t]/1e3 # Convert from W to MW
						for baseline in loadData.reactiveProfiles.values():
							Qd += baseline[t]/1e3 # Convert from VAr to MVAr
				except KeyError:
					pass

				if Pd > 0:
					activeProduction+=Pd
					reactiveProduction+=Qd
				else:
					activeConsumption+=Pd
					reactiveConsumption+=Qd

			# Write
			sheet.write(l, 2, activeProduction)
			sheet.write(l, 3, activeConsumption)
			sheet.write(l, 4, activeProduction+activeConsumption)
			sheet.write(l, 5, reactiveProduction)
			sheet.write(l, 6, reactiveConsumption)
			sheet.write(l, 7, reactiveProduction+reactiveConsumption)

		print("\t day %s: %.3fs" % (d+1, time.time()-tic))

	# Save
	outputPath='timeseries-%s%s.xls' % (year,scenario)
	wb.save(outputPath)
	print('"%s" saved after %.2fs' % (outputPath, time.time()-globalTic))
Esempio n. 9
0
def main(argv):
    globalTic = time.time()

    # Default parameters
    year = 2020
    scenario = 'H'
    T = 96

    # Read instance folder
    if len(argv) < 1:
        displayHelp()
        sys.exit(2)

    if len(argv) > 1:
        year = int(argv[0])
    if len(argv) > 2:
        scenario = argv[1]

    folderPath = argv[-1] if argv[-1].endswith(("/", "\\")) else argv[-1] + "/"

    print("Compute time series %s %s" % (year, scenario))

    # Create work sheet
    wb = xlwt.Workbook()
    sheet = wb.add_sheet('timeseries')
    dateStyle = xlwt.easyxf(num_format_str='DD/MM/YYYY')

    # Header
    sheet.write(0, 0, 'Day')
    sheet.write(0, 1, 'Quarter')

    sheet.write(0, 2, 'Active production')
    sheet.write(1, 2, 'MW')

    sheet.write(0, 3, 'Active consumption')
    sheet.write(1, 3, 'MW')

    sheet.write(0, 4, 'Net active injection')
    sheet.write(1, 4, 'MW')

    sheet.write(0, 5, 'Reactive Production')
    sheet.write(1, 5, 'MVar')

    sheet.write(0, 6, 'Reactive Consumption')
    sheet.write(1, 6, 'MVar')

    sheet.write(0, 7, 'Net reactive injection')
    sheet.write(1, 7, 'MVar')

    # Read graph
    initGraph = networkMaker.makeNetwork(folderPath)

    # Read network data (all but power information)
    firstDay = datetime.date(year, 1, 1).toordinal()
    day = datetime.date(year, 1, 1)
    for d in range(0, 365):
        tic = time.time()
        graph = copy.deepcopy(initGraph)

        # Obtain the corresponding date-time
        day = day.fromordinal(firstDay + d)

        # Read daily data
        scenariosReader.readScenarios(folderPath, year, d + 1, graph, scenario)

        for t in range(0, T):
            l = 2 + d * T + t  # Excel line

            # Write day and quarter
            sheet.write(l, 0, day, dateStyle)
            sheet.write(l, 1, t + 1)

            # Find production & consumption
            activeProduction = 0.0
            activeConsumption = 0.0
            reactiveProduction = 0.0
            reactiveConsumption = 0.0

            for n, ndata in graph.nodes(data=True):
                Pd = 0  # MW
                Qd = 0  # MVar
                try:
                    loadData = ndata['load']
                    if loadData is not None:
                        for label, baseline in loadData.activeProfiles.items():
                            if len(baseline) < T:
                                raise Exception(
                                    "Error with label \"%s\" in node %s, baseline has %s periods in day %s."
                                    % (label, n, len(baseline), d + 1))

                        for baseline in loadData.activeProfiles.values():
                            Pd += baseline[t] / 1e3  # Convert from W to MW
                        for baseline in loadData.reactiveProfiles.values():
                            Qd += baseline[t] / 1e3  # Convert from VAr to MVAr
                except KeyError:
                    pass

                if Pd > 0:
                    activeProduction += Pd
                    reactiveProduction += Qd
                else:
                    activeConsumption += Pd
                    reactiveConsumption += Qd

            # Write
            sheet.write(l, 2, activeProduction)
            sheet.write(l, 3, activeConsumption)
            sheet.write(l, 4, activeProduction + activeConsumption)
            sheet.write(l, 5, reactiveProduction)
            sheet.write(l, 6, reactiveConsumption)
            sheet.write(l, 7, reactiveProduction + reactiveConsumption)

        print("\t day %s: %.3fs" % (d + 1, time.time() - tic))

    # Save
    outputPath = 'timeseries-%s%s.xls' % (year, scenario)
    wb.save(outputPath)
    print('"%s" saved after %.2fs' % (outputPath, time.time() - globalTic))