def buildValuesBackwards(self, startDate, endDate, location, tracking, storageMWh):
		#reverse the arrays containing price and solar data.
		print "Building Values Backwards"
		tz = SydneyTimezone()
		lat= location[0]
		lon = location[1]
		state= location[2]
		# locationName = location[3]
		startDate = startDate.astimezone(tz)
		endDate = endDate.astimezone(tz)

		controller = Controller(gui=False)
		data = controller.getTimeseriesNemDNICos(state=state, lat = lat, lon = lon, startDate = startDate, endDate = endDate)
		plant = Plant(namePlateMW = 1)
		storage = Storage(storageLevels = self.numStates, effectiveCapacityMWh = storageMWh, batteryType = self.batteryType)
		plant = Plant(1)

		values=np.zeros(shape=(data.shape[0] + 1, storage.getNumStorageLevels()+1))
		destinations = np.zeros(shape=( data.shape[0] + 1, storage.getNumStorageLevels()+1))
		
		totalArrayOutput = 0

		# if self.shaved:
		# 	data = self.shaveNemData(data)

		if tracking:
			COS_INDEX = self.TRACKING_COS_INDEX
		else:
			COS_INDEX = self.FIXED_COS_INDEX

		#iterate backwards through time.
		for timeIndex in np.arange(0, data.shape[0])[::-1]:
			# Get the timeperiod outputs
			cos = data[timeIndex][COS_INDEX]
			price = data[timeIndex][self.PRICE_INDEX]

			if self.capped:
				price = min(price, 300)

			dni = data[timeIndex][self.DNI_INDEX]
			ghi_factor = data[timeIndex][self.GHI_FACTOR_INDEX]
			ghi = np.multiply(ghi_factor, dni)			
			arrayOutput = plant.getPlantOutput(dni=dni, ghi=ghi, timePeriodHrs=0.5, cosine=cos)
			totalArrayOutput = totalArrayOutput + arrayOutput
			date = datetime.datetime(year=int(data[timeIndex][self.YEAR_INDEX]), month = int(data[timeIndex][self.MONTH_INDEX]), day = int(data[timeIndex][self.DAY_INDEX]), hour=int(data[timeIndex][self.HOUR_INDEX]), minute=int(data[timeIndex][self.MINUTE_INDEX]), tzinfo=SydneyTimezone())
			
			# iterate through the storagelevels
			for storageLevel in np.arange(storage.getNumStorageLevels()+1):
				# Find the optimal destination and its corresponding value
				valueAndDestination = self.getValueAndDestination(storage = storage, price=price, solarOutputMWh=arrayOutput, storageLevel=storageLevel,  nextTimePeriodValues = values[timeIndex + 1], date = date)
				values[ timeIndex, storageLevel] = valueAndDestination[0]
				destinations[timeIndex, storageLevel] = valueAndDestination[1]
		
		prices = np.transpose(data)[self.PRICE_INDEX]
		sun = np.transpose(data)[self.DNI_INDEX]
		
		return (values, destinations,prices, sun, totalArrayOutput)
Exemplo n.º 2
0
def getLCOEHighLow(tracking, location):
	

	print "Beginning LCOE Simulation"
	controller = Controller(gui=False)
	tz = SydneyTimezone()


	lat= location[0]
	lon = location[1]
	state= location[2]
	locationName = location[3]

	totalPSHIncident = 0
	timePeriodCouner = 0
	yearCounter = 0
	for year in np.arange(2005, 2012):
		yearCounter = yearCounter + 1
		print year
		startDate = datetime.datetime(year=year, month=1, day=1, hour=1, tzinfo = tz)
		endDate= datetime.datetime(year=year, month=12, day=31, hour=23, minute=30, tzinfo = tz)
		print "retrieving data"
		data = controller.getTimeseriesNemDNICos(state=state, lat = lat, lon = lon, startDate = startDate, endDate = endDate)
		print "data retrieved"
		plant = SolarPlant(namePlateMW = 1)

		# Iterate through the time series and perform calculations.
		for i in np.arange(data.shape[0]):
			timePeriodCouner = timePeriodCouner + 1

			dni = data[i][7]
			# date = datetime.datetime(year=int(data[i][0]), month = int(data[i][1]), day = int(data[i][2]), hour=int(data[i][3]), minute=int(data[i][4]), tzinfo=SydneyTimezone())
			if dni > 0:
				if tracking:
					cos = data[i][10]
				else:
					cos = data[i][9]
				ghi_factor = data[i][8]
				ghi = np.multiply(ghi_factor, dni)
				output = plant.getPlantOutput(dni=dni, ghi=ghi, timePeriodHrs=0.5, cosine=cos)
				totalPSHIncident = totalPSHIncident + ((dni * cos)/1000.0) 

	# Write to the averages data file.
	numDays = timePeriodCouner / 48.0
	averagePSHPerDay = totalPSHIncident / (numDays)
	if tracking:
		lcoeLow = getLCOELowTracking(averagePSHPerDay)
		lcoeHigh = getLCOEHighTracking(averagePSHPerDay)
	else:
		lcoeLow = getLCOELowFixed(averagePSHPerDay)
		lcoeHigh = getLCOEHighFixed(averagePSHPerDay)
	return (lcoeHigh, lcoeLow)
	def followPathBackThroughDataset(self, destinations, startDate, endDate, location, storageMWh, tracking):
		#reverse the arrays containing price and solar data.
		print "Following Path back through dataset."
		tz = SydneyTimezone()
		lat= location[0]
		lon = location[1]
		state= location[2]
		# locationName = location[3]
		startDate = startDate.astimezone(tz)
		endDate = endDate.astimezone(tz)

		controller = Controller(gui=False)
		data = controller.getTimeseriesNemDNICos(state=state, lat = lat, lon = lon, startDate = startDate, endDate = endDate)
		plant = Plant(namePlateMW = 1)
		storage = Storage(storageLevels = self.numStates, effectiveCapacityMWh = storageMWh, batteryType = self.batteryType)
		plant = Plant(1)

		#iterate backwards through time.
		totalRevenue = 0
		currentLevel = 0

		if tracking:
			COS_INDEX = self.TRACKING_COS_INDEX
		else:
			COS_INDEX = self.FIXED_COS_INDEX

		for timeIndex in np.arange(0, data.shape[0]):
			# Get the timeperiod outputs
			cos = COS_INDEX
			price = data[timeIndex][self.PRICE_INDEX]
			if self.capped and price > 300:
				price = 300
			dni = data[timeIndex][self.DNI_INDEX]
			ghi_factor = data[timeIndex][self.GHI_FACTOR_INDEX]
			ghi = np.multiply(ghi_factor, dni)			
			arrayOutput = plant.getPlantOutput(dni=dni, ghi=ghi, timePeriodHrs=0.5, cosine=cos)
			
			date = datetime.datetime(year=int(data[timeIndex][self.YEAR_INDEX]), month = int(data[timeIndex][self.MONTH_INDEX]), day = int(data[timeIndex][self.DAY_INDEX]), hour=int(data[timeIndex][self.HOUR_INDEX]), minute=int(data[timeIndex][self.MINUTE_INDEX]), tzinfo=SydneyTimezone())
			
			nextLevel = destinations[timeIndex][currentLevel]
			storageEnergy = storage.getEnergyOut(currentLevel, nextLevel)
			costOfMovement = storage.getCostOfMovement(currentLevel, nextLevel)
			outputMWh = arrayOutput + storageEnergy
			value = self.valueFunction(outputMWh, price, date) - costOfMovement
			totalRevenue = totalRevenue + value
			currentLevel = nextLevel
		
		return totalRevenue
def getStrikePrice(startDate, endDate, location):
	tz = SydneyTimezone()
	lat= location[0]
	lon = location[1]
	state= location[2]
	startDate = startDate.astimezone(tz)
	endDate = endDate.astimezone(tz)

	controller = Controller(gui=False)
	data = controller.getTimeseriesNemDNICos(state=state, lat = lat, lon = lon, startDate = startDate, endDate = endDate)
	counter = 0
	average = 0
	for i in np.arange(data.shape[0]):
		counter = counter + 1
		price = data[i][6]
		average = average + price

	average = np.divide(float(average), float(counter))
	return average
def getStrikePrice(startDate, endDate, location):
	tz = SydneyTimezone()
	lat= location[0]
	lon = location[1]
	state= location[2]
	startDate = startDate.astimezone(tz)
	endDate = endDate.astimezone(tz)

	controller = Controller(gui=False)
	data = controller.getTimeseriesNemDNICos(state=state, lat = lat, lon = lon, startDate = startDate, endDate = endDate)
	counter = 0
	average = 0
	for i in np.arange(data.shape[0]):
		date = datetime.datetime(year=int(data[i][0]), month = int(data[i][1]), day = int(data[i][2]), hour=int(data[i][3]), minute=int(data[i][4]), tzinfo=SydneyTimezone())
		if date.hour >= 7 and date.hour < 22 and date.weekday() < 5:
			counter = counter + 1
			price = data[i][6]
			average = average + price

	average = np.divide(float(average), float(counter))
	return average
def printTimeseries():
	print "Price and Solar Daily Trends"
	controller = Controller(gui=False)
	tz = SydneyTimezone()
	inflation = 1.027
	contractStartHour = 7
	contractEndHour = 16

	


	strikePrices = [100,150,200,250]

	for strikePrice in strikePrices:
		
		averagesPath = "/Users/lukemarshall/Documents/Workspace/Thesis/simulationResults/market/shapedCapRevenue/"+str(strikePrice)+".csv"
		
		averagesFile = open(averagesPath, 'w')
		averagesFile.write("Location, Revenue Fixed, Revenue Tracking\n")

		for location in locations.getLocations():
			lat= location[0]
			lon = location[1]
			state= location[2]
			locationName = location[3]


			if state == "nsw":
				capFactor = 0.280152271502
				capFactorTracking = 0.337531327017
			if state == "vic":
				capFactor = 0.259125863986
				capFactorTracking = 0.319551495158
			if state == "qld":
				capFactor = 0.28828551756
				capFactorTracking = 0.342014584626
			if state == "sa":
				capFactor = 0.317160237904
				capFactorTracking = 0.391816336203

			
			dayCounter = 0
			lastDays = 0
			counter = 0
			
			contractStartHour = 7
			contractEndHour = 16

			
			countAboveStrike = 0
			countFixedDemandMet = 0
			countTrackingDemandMet = 0

			countContractTimePeriods = averagePayoutFixed = averagePayoutTracking = 0
			spotRevenueFixed = spotRevenueTracking = 0
			totalFixedMWh = totalTrackingMWh = 0

			for year in np.arange(2005, 2012):
				print year
				startDate = datetime.datetime(year=year, month=1, day=1, hour=1, tzinfo = tz)
				date = datetime.datetime(year=year, month=1, day=1, hour=1, tzinfo = tz)
				endDate= datetime.datetime(year=year, month=12, day=31, hour=23, minute=30, tzinfo = tz)
				data = controller.getTimeseriesNemDNICos(state=state, lat = lat, lon = lon, startDate = startDate, endDate = endDate)
				plant = SolarPlant(namePlateMW = 1)
				timeDiff = endDate - startDate

				if timeDiff != lastDays:
					dayCounter = dayCounter + timeDiff.days
				lastDays = timeDiff.days
				for i in np.arange(data.shape[0]):
					counter = counter + 1
					price = data[i][6]
					dni = data[i][7]

					date = datetime.datetime(year=int(data[i][0]), month = int(data[i][1]), day = int(data[i][2]), hour=int(data[i][3]), minute=int(data[i][4]), tzinfo=SydneyTimezone())
					if dni > 0:
						trackingCos = data[i][10]
						cos = data[i][9]
						ghi_factor = data[i][8]
						ghi = np.multiply(ghi_factor, dni)
						fixedOutputMWh = plant.getPlantOutput(dni=dni, ghi=ghi, timePeriodHrs=0.5, cosine=cos)
						trackingOutputMWh = plant.getPlantOutput(dni=dni, ghi=ghi, timePeriodHrs=0.5, cosine=trackingCos)
					else:
						fixedOutputMWh = 0
						trackingOutputMWh = 0
					price = int(price)
					
					totalFixedMWh = totalFixedMWh + fixedOutputMWh
					totalTrackingMWh = totalTrackingMWh + trackingOutputMWh




					if price < 0:
						price = 0

					hour = date.hour + (float(date.minute)/60.0)
					timePeriodHrs = 0.5
					mwNameplate = 1
					if hour >= contractStartHour and hour <= contractEndHour: 
						spotRevenueFixed = spotRevenueFixed + fixedOutputMWh * min(price, strikePrice)
						spotRevenueTracking = spotRevenueTracking + trackingOutputMWh * min(price, strikePrice)

						countContractTimePeriods = countContractTimePeriods + 1
						if price > strikePrice:
							averagePayoutFixed = averagePayoutFixed + (capFactor * (price - strikePrice) * timePeriodHrs)
							averagePayoutTracking = averagePayoutTracking + (capFactorTracking * (price - strikePrice) * timePeriodHrs)
							countAboveStrike = countAboveStrike + 1
							if fixedOutputMWh > (capFactor * timePeriodHrs * mwNameplate):
								countFixedDemandMet = countFixedDemandMet + 1
							if trackingOutputMWh > (capFactorTracking * timePeriodHrs * mwNameplate):
								countTrackingDemandMet = countTrackingDemandMet + 1
					else:
						spotRevenueFixed = spotRevenueFixed + fixedOutputMWh * min(price, 300)
						spotRevenueTracking = spotRevenueTracking +  trackingOutputMWh * min(price, 300)

			averagePayoutFixed = float(averagePayoutFixed) / float(countAboveStrike)
			averagePayoutTracking = float(averagePayoutTracking) / float(countAboveStrike)

			probabilityFixedMet = float(countFixedDemandMet) / float(countAboveStrike)
			probabilityTrackingMet = float(countTrackingDemandMet) / float(countAboveStrike)

			probabilityAboveStrike = float(countAboveStrike) / float(countContractTimePeriods)

			trackingPrice = (averagePayoutTracking * probabilityAboveStrike / probabilityTrackingMet) * countContractTimePeriods
			fixedPrice = (averagePayoutFixed * probabilityAboveStrike / probabilityFixedMet) * countContractTimePeriods

			totalRevenueTracking = trackingPrice + spotRevenueTracking
			totalRevenueFixed = fixedPrice + spotRevenueFixed

			revenueTrackingPerMWh = float(totalRevenueTracking) / float(totalTrackingMWh)
			revenueFixedPerMWh = float(totalRevenueFixed) / float(totalFixedMWh)

			averageString = state+", "+str(revenueFixedPerMWh)+","+str(revenueTrackingPerMWh)+"\n"
			averagesFile.write(averageString)

			print "Averages written to file."
	
	print "Finished"
	averagesFile.close()
def printTimeseries():
	print "Price and Solar Daily Trends"
	controller = Controller(gui=False)
	tz = SydneyTimezone()
	inflation = 1.027
	contractStartHour = 7
	contractEndHour = 16

	


	strikePrices = [100,150,200,250]

	for strikePrice in strikePrices:
		averagesPath = "/Users/lukemarshall/Documents/Workspace/Thesis/simulationResults/market/maximumShapedCapValue/"+str(strikePrice)+".csv"
		averagesFile = open(averagesPath, 'w')
		averagesFile.write("Location, Maximum Value\n")

		for location in locations.getLocations():
			lat= location[0]
			lon = location[1]
			state= location[2]
			locationName = location[3]
			

			maxPrice = 300
			maxBucket = int(maxPrice / 10.0)
			priceFrequency = np.zeros(shape=(maxBucket,1))
			dayCounter = 0
			lastDays = 0
			counter = 0
			
			contractStartHour = 7
			contractEndHour = 16

			maxValue = 0
			for year in np.arange(2005, 2012):
				print year
				startDate = datetime.datetime(year=year, month=1, day=1, hour=1, tzinfo = tz)
				date = datetime.datetime(year=year, month=1, day=1, hour=1, tzinfo = tz)
				endDate= datetime.datetime(year=year, month=12, day=31, hour=23, minute=30, tzinfo = tz)
				data = controller.getTimeseriesNemDNICos(state=state, lat = lat, lon = lon, startDate = startDate, endDate = endDate)
				plant = SolarPlant(namePlateMW = 1)
				timeDiff = endDate - startDate

				if timeDiff != lastDays:
					dayCounter = dayCounter + timeDiff.days
				lastDays = timeDiff.days
				for i in np.arange(data.shape[0]):
					counter = counter + 1
					price = data[i][6]
					dni = data[i][7]
					demand = data[i][5]
					date = datetime.datetime(year=int(data[i][0]), month = int(data[i][1]), day = int(data[i][2]), hour=int(data[i][3]), minute=int(data[i][4]), tzinfo=SydneyTimezone())
					if dni > 0:
						trackingCos = data[i][10]
						cos = data[i][9]
						ghi_factor = data[i][8]
						ghi = np.multiply(ghi_factor, dni)
						output = plant.getPlantOutput(dni=dni, ghi=ghi, timePeriodHrs=0.5, cosine=cos)
						trackingOutput = plant.getPlantOutput(dni=dni, ghi=ghi, timePeriodHrs=0.5, cosine=trackingCos)
					else:
						output = 0
						trackingOutput = 0
					price = int(price)
					
					if price < 0:
						price = 0

					hour = date.hour + (float(date.minute)/60.0)
					timePeriodHrs = 0.5

					if hour >= contractStartHour and hour <= contractEndHour: 
						if price > strikePrice:
							# print "WOOOOO"
							maxValue = maxValue + (price - strikePrice) * timePeriodHrs
					
			maxValueMonthly = float(maxValue) / float(7 * 12)
			averageString = state+", "+str(float(maxValueMonthly))+"\n"
			averagesFile.write(averageString)

			print "Averages written to file."
	
	print "Finished"
	averagesFile.close()
def printTimeseries():
	print "Price and Solar Daily Trends"
	controller = Controller(gui=False)
	tz = SydneyTimezone()
	inflation = 1.027
	
	for location in locations.getLocations():
		lat= location[0]
		lon = location[1]
		state= location[2]
		locationName = location[3]
		
		averagesPath = "/Users/lukemarshall/Documents/Workspace/Thesis/simulationResults/market/cumulativeShapedPriceFrequency/"+state+".csv"
		
		averagesFile = open(averagesPath, 'w')
		averagesFile.write("Price, Count\n")

		print "==============="+locationName+"==============="

		maxPrice = 300
		maxBucket = int(maxPrice / 10.0)
		priceFrequency = np.zeros(shape=(maxBucket,1))
		dayCounter = 0
		lastDays = 0
		counter = 0
		
		contractStartHour = 7
		contractEndHour = 16
		
		for year in np.arange(2005, 2012):
			print year
			startDate = datetime.datetime(year=year, month=1, day=1, hour=1, tzinfo = tz)
			date = datetime.datetime(year=year, month=1, day=1, hour=1, tzinfo = tz)
			endDate= datetime.datetime(year=year, month=12, day=31, hour=23, minute=30, tzinfo = tz)
			data = controller.getTimeseriesNemDNICos(state=state, lat = lat, lon = lon, startDate = startDate, endDate = endDate)
			plant = SolarPlant(namePlateMW = 1)
			timeDiff = endDate - startDate

			if timeDiff != lastDays:
				dayCounter = dayCounter + timeDiff.days
			lastDays = timeDiff.days
			for i in np.arange(data.shape[0]):
				counter = counter + 1
				price = data[i][6]
				dni = data[i][7]
				date = datetime.datetime(year=int(data[i][0]), month = int(data[i][1]), day = int(data[i][2]), hour=int(data[i][3]), minute=int(data[i][4]), tzinfo=SydneyTimezone())
				if dni > 0:
					trackingCos = data[i][10]
					cos = data[i][9]
					ghi_factor = data[i][8]
					ghi = np.multiply(ghi_factor, dni)
					output = plant.getPlantOutput(dni=dni, ghi=ghi, timePeriodHrs=0.5, cosine=cos)
					trackingOutput = plant.getPlantOutput(dni=dni, ghi=ghi, timePeriodHrs=0.5, cosine=trackingCos)
				else:
					output = 0
					trackingOutput = 0
				price = int(price)
				
				if price < 0:
					price = 0

				hour = date.hour + (float(date.minute)/60.0)
				if date.hour >= contractStartHour and date.hour <= contractEndHour:
					index = int(price / 10.0)
					index = min(index, priceFrequency.shape[0] - 1)
					priceFrequency[index] = priceFrequency[index] + 1
				
		# Make cumulative
		for i in np.arange(priceFrequency.shape[0])[::-1]:
			if i < priceFrequency.shape[0] - 1:
				priceFrequency[i] = priceFrequency[i] + priceFrequency[i+1]
				

		for i in np.arange(priceFrequency.shape[0]):
			averageString = "> "+str(i*10)+", "+str(float(priceFrequency[i]))+"\n"
			averagesFile.write(averageString)

		print "Averages written to file."
	
	print "Finished"
	averagesFile.close()
def printTimeseries():
	print "Price and Solar Daily Trends"
	controller = Controller(gui=False)
	tz = SydneyTimezone()
	inflation = 1.027
	
	for location in locations.getLocations():
		lat= location[0]
		lon = location[1]
		state= location[2]
		locationName = location[3]
		
		averagesPath = "/Users/lukemarshall/Documents/Workspace/Thesis/simulationResults/market/dailyTrends/highPrices/"+state+".csv"
		
		averagesFile = open(averagesPath, 'w')
		averagesFile.write("Hour, Count, Price, Fixed Output, Tracking Output, DNI, Demand, Overall Probability, Average Fixed Output, Average Tracking Output\n")

		print "==============="+locationName+"==============="

		priceAndSolarTrends = np.zeros(shape=(48,9))
		eventCounter = 0
		lastDays = 0
		for year in np.arange(2005, 2012):
			print year
			startDate = datetime.datetime(year=year, month=1, day=1, hour=1, tzinfo = tz)
			date = datetime.datetime(year=year, month=1, day=1, hour=1, tzinfo = tz)
			endDate= datetime.datetime(year=year, month=12, day=31, hour=23, minute=30, tzinfo = tz)
			print "retrieving data"
			data = controller.getTimeseriesNemDNICos(state=state, lat = lat, lon = lon, startDate = startDate, endDate = endDate)
			print "data retrieved"
			plant = SolarPlant(namePlateMW = 1)
			timeDiff = endDate - startDate
			print str(data.shape[0])

			if timeDiff != lastDays:
				eventCounter = eventCounter + timeDiff.days
			lastDays = timeDiff.days
			print "=====================+++++++++++++++++"+str(data.shape[0])
			for i in np.arange(data.shape[0]):

				halfHourIndex = int(round(((date.hour * 60)+ date.minute) / 30))
				price = data[i][6]
				demand = data[i][5]
				dni = data[i][7]
				# date = datetime.datetime(year=int(data[i][0]), month = int(data[i][1]), day = int(data[i][2]), hour=int(data[i][3]), minute=int(data[i][4]), tzinfo=SydneyTimezone())
				if dni > 0:
					trackingCos = data[i][10]
					cos = data[i][9]
					ghi_factor = data[i][8]
					ghi = np.multiply(ghi_factor, dni)
					output = plant.getPlantOutput(dni=dni, ghi=ghi, timePeriodHrs=0.5, cosine=cos)
					trackingOutput = plant.getPlantOutput(dni=dni, ghi=ghi, timePeriodHrs=0.5, cosine=trackingCos)
				else:
					cos = 0
					ghi_factor = 0
					ghi = 0
					output = 0
					trackingOutput = 0

				if price > 300:
					priceAndSolarTrends[halfHourIndex][0] = price + priceAndSolarTrends[halfHourIndex][0]
					priceAndSolarTrends[halfHourIndex][1] = (2 *output) + priceAndSolarTrends[halfHourIndex][1]
					priceAndSolarTrends[halfHourIndex][2] = (2 *trackingOutput) + priceAndSolarTrends[halfHourIndex][2]
					priceAndSolarTrends[halfHourIndex][3] = dni + priceAndSolarTrends[halfHourIndex][3]
					priceAndSolarTrends[halfHourIndex][4] = demand + priceAndSolarTrends[halfHourIndex][4]
					priceAndSolarTrends[halfHourIndex][5] = priceAndSolarTrends[halfHourIndex][5] + 1
					priceAndSolarTrends[halfHourIndex][7] = priceAndSolarTrends[halfHourIndex][7] + (float(output) / 0.5)
					priceAndSolarTrends[halfHourIndex][8] = priceAndSolarTrends[halfHourIndex][8] + (float(trackingOutput) / 0.5)
				priceAndSolarTrends[halfHourIndex][6] = priceAndSolarTrends[halfHourIndex][6] + 1
				
				date = date + datetime.timedelta(seconds = (30 * 60))
				
		for i in np.arange(48):
			eventCounter = priceAndSolarTrends[i][5]
			if eventCounter > 0:
				priceAndSolarTrends[i][0] = float(priceAndSolarTrends[i][0]) / float(eventCounter)
				priceAndSolarTrends[i][1] = float(priceAndSolarTrends[i][1]) / float(eventCounter)
				priceAndSolarTrends[i][2] = float(priceAndSolarTrends[i][2]) / float(eventCounter)
				priceAndSolarTrends[i][3] = float(priceAndSolarTrends[i][3]) / float(eventCounter)
				priceAndSolarTrends[i][4] = float(priceAndSolarTrends[i][4]) / float(eventCounter)
				priceAndSolarTrends[i][7] = float(priceAndSolarTrends[i][7]) / float(eventCounter)
				priceAndSolarTrends[i][8] = float(priceAndSolarTrends[i][8]) / float(eventCounter)
				print str(priceAndSolarTrends[i][6])
				priceAndSolarTrends[i][6] = eventCounter / float(priceAndSolarTrends[i][6])

			else:
				priceAndSolarTrends[i][6] = 0

		for i in np.arange(48):

			averageString = str(round((i/2.0), 1))+", "+str(priceAndSolarTrends[i][5])+", "+str(priceAndSolarTrends[i][0])+", "+str(priceAndSolarTrends[i][1])+", "+str(priceAndSolarTrends[i][2])+", "+str(priceAndSolarTrends[i][3])+", "+str(priceAndSolarTrends[i][4])+", "+str(priceAndSolarTrends[i][6])+", "+str(priceAndSolarTrends[i][7])+", "+str(priceAndSolarTrends[i][8])+"\n"
			averagesFile.write(averageString)

		print "Averages written to file."
	
	print "Finished"
	averagesFile.close()
Exemplo n.º 10
0
def printTimeseries(tracking):
	if tracking:
		print "Tracking"
		lcoePath = "/Users/lukemarshall/Documents/Workspace/Thesis/simulationResults/lcoe/trackingAll.csv"
		stateAveragesPath = "/Users/lukemarshall/Documents/Workspace/Thesis/simulationResults/lcoe/tracking.csv"
	else:
		print "Non-Tracking"
		lcoePath = "/Users/lukemarshall/Documents/Workspace/Thesis/simulationResults/lcoe/fixedAll.csv"
		stateAveragesPath = "/Users/lukemarshall/Documents/Workspace/Thesis/simulationResults/lcoe/fixed.csv"
	

	lcoeFile = open(lcoePath, 'w')
	headingString = "Location, State, PSH, LCOE Low, LCOE High\n"
	lcoeFile.write(headingString)

	stateAveragesFile = open(stateAveragesPath, 'w')
	headingString = "Location, PSH, LCOE Low, LCOE High\n"
	stateAveragesFile.write(headingString)

	print "Beginning LCOE Simulation"
	controller = Controller(gui=False)
	tz = SydneyTimezone()
	stateAverages = [["nsw",0,0,0,0], ["qld",0,0,0,0], ["vic",0,0,0,0], ["sa",0,0,0,0]]

	for location in locations.getLocations():

		lat= location[0]
		lon = location[1]
		state= location[2]
		locationName = location[3]
		print "==============="+locationName+"==============="


		totalPSHIncident = 0
		timePeriodCouner = 0
		yearCounter = 0
		for year in np.arange(2005, 2012):
			yearCounter = yearCounter + 1
			print year
			startDate = datetime.datetime(year=year, month=1, day=1, hour=1, tzinfo = tz)
			endDate= datetime.datetime(year=year, month=12, day=31, hour=23, minute=30, tzinfo = tz)
			print "retrieving data"
			data = controller.getTimeseriesNemDNICos(state=state, lat = lat, lon = lon, startDate = startDate, endDate = endDate)
			print "data retrieved"
			plant = SolarPlant(namePlateMW = 1)

			# Iterate through the time series and perform calculations.
			for i in np.arange(data.shape[0]):
				timePeriodCouner = timePeriodCouner + 1
				price = data[i][6]
				dni = data[i][7]
				# date = datetime.datetime(year=int(data[i][0]), month = int(data[i][1]), day = int(data[i][2]), hour=int(data[i][3]), minute=int(data[i][4]), tzinfo=SydneyTimezone())
				if dni > 0:
					if tracking:
						cos = data[i][10]
					else:
						cos = data[i][9]
					ghi_factor = data[i][8]
					ghi = np.multiply(ghi_factor, dni)
					output = plant.getPlantOutput(dni=dni, ghi=ghi, timePeriodHrs=0.5, cosine=cos)
					totalPSHIncident = totalPSHIncident + ((dni * cos)/1000.0) 

		# Write to the averages data file.
		numDays = timePeriodCouner / 48.0
		averagePSHPerDay = totalPSHIncident / (numDays)
		if tracking:
			lcoeLow = getLCOELowTracking(averagePSHPerDay)
			lcoeHigh = getLCOEHighTracking(averagePSHPerDay)
		else:
			lcoeLow = getLCOELowFixed(averagePSHPerDay)
			lcoeHigh = getLCOEHighFixed(averagePSHPerDay)
		averageString = locationName +", "+state+", "+str(round(averagePSHPerDay, 2)) +", "+str(round(lcoeLow, 2))+", "+str(round(lcoeHigh, 2))+"\n"
		lcoeFile.write(averageString)
		print "Averages written to file."
		for stateAverage in stateAverages:
			if stateAverage[0] == state:
				stateAverage[1] = lcoeLow + stateAverage[1]
				stateAverage[2] = lcoeHigh + stateAverage[2]
				stateAverage[3] = stateAverage[3] + averagePSHPerDay
				stateAverage[4] = stateAverage[4] + 1
 
	
	for stateAverage in stateAverages:
		state = stateAverage[0]
		lcoeLow = float(stateAverage[1]) / float(stateAverage[4])
		lcoeHigh = float(stateAverage[2]) / float(stateAverage[4])
		averagePSHPerDay = float(stateAverage[3]) / float(stateAverage[4])
		averageString = state+", "+str(round(averagePSHPerDay, 2)) +", "+str(round(lcoeLow, 2))+", "+str(round(lcoeHigh, 2))+"\n"
		stateAveragesFile.write(averageString)

	print "Finished"
	lcoeFile.close()
	stateAveragesFile.close()
def printTimeseries(tracking):
	if tracking:
		print "Tracking"
		stateAveragesPath = "/Users/lukemarshall/Documents/Workspace/Thesis/simulationResults/market/capacityFactor/tracking.csv"

	else:
		print "Non-Tracking"
		stateAveragesPath = "/Users/lukemarshall/Documents/Workspace/Thesis/simulationResults/market/capacityFactor/fixed.csv"

	nameplateCapacityMW = 1
	stateAveragesFile = open(stateAveragesPath, 'w')

	stateAveragesFile.write("Location, Capacity Factor\n")

	print "Beginning Capacity Factor Simulation"
	controller = Controller(gui=False)
	tz = SydneyTimezone()
	inflation = 1.027

	stateAverages = [["nsw",0,0], ["qld",0,0], ["vic",0,0], ["sa",0,0]]


	for location in locations.getLocations():
		lat= location[0]
		lon = location[1]
		state= location[2]
		
		totalMWh = 0
		totalHours = 0
		for year in np.arange(2005, 2012):
			print year
			startDate = datetime.datetime(year=year, month=1, day=1, hour=1, tzinfo = tz)
			endDate= datetime.datetime(year=year, month=12, day=31, hour=23, minute=30, tzinfo = tz)
			data = controller.getTimeseriesNemDNICos(state=state, lat = lat, lon = lon, startDate = startDate, endDate = endDate)
			plant = SolarPlant(namePlateMW = 1)



			# Iterate through the time series and perform calculations.
			for i in np.arange(data.shape[0]):
				totalHours = totalHours + 0.5
				date = datetime.datetime(year=int(data[i][0]), month = int(data[i][1]), day = int(data[i][2]), hour=int(data[i][3]), minute=int(data[i][4]), tzinfo=SydneyTimezone())
				dni = data[i][7]
				if dni > 0:
					if tracking:
						cos = data[i][10]
					else:
						cos = data[i][9]
					ghi_factor = data[i][8]
					ghi = np.multiply(ghi_factor, dni)
					output = plant.getPlantOutput(dni=dni, ghi=ghi, timePeriodHrs=0.5, cosine=cos)
				else:
					cos = 0
					ghi_factor = 0
					ghi = 0
					output = 0
				totalMWh = totalMWh + output


		for stateAverage in stateAverages:
			if state == stateAverage[0]:
				stateAverage[1] = stateAverage[1] + totalMWh
				stateAverage[2] = stateAverage[2] + totalHours

	for stateAverage in stateAverages:
		state = stateAverage[0]
		capacityFactor = float(stateAverage[1]) / (float(stateAverage[2]) * float(nameplateCapacityMW))
		stateAveragesFile.write(str(state)+", "+str(capacityFactor)+"\n")
		

	print "Finished"
	stateAveragesFile.close()
def printTimeseries(tracking, fractionContracted):
	if tracking:
		print "Tracking"
		stateAveragesPath = "/Users/lukemarshall/Documents/Workspace/Thesis/simulationResults/market/shapedCap/tracking/average/"+str(fractionContracted)+"Contracted.csv"
		averagesPath = "/Users/lukemarshall/Documents/Workspace/Thesis/simulationResults/market/shapedCap/tracking/averagesAll/"+str(fractionContracted)+"Contracted.csv"
		yearlyPath = "/Users/lukemarshall/Documents/Workspace/Thesis/simulationResults/market/shapedCap/tracking/yearly/"+str(fractionContracted)+"Contracted.csv"

	else:
		print "Non-Tracking"
		stateAveragesPath = "/Users/lukemarshall/Documents/Workspace/Thesis/simulationResults/market/shapedCap/fixed/average/"+str(fractionContracted)+"Contracted.csv"
		averagesPath = "/Users/lukemarshall/Documents/Workspace/Thesis/simulationResults/market/shapedCap/fixed/averagesAll/"+str(fractionContracted)+"Contracted.csv"
		yearlyPath = "/Users/lukemarshall/Documents/Workspace/Thesis/simulationResults/market/shapedCap/fixed/yearly/"+str(fractionContracted)+"Contracted.csv"

	yearlyFile = open(yearlyPath, 'w')
	averagesFile = open(averagesPath, 'w')
	stateAveragesFile = open(stateAveragesPath, 'w')

	yearlyFile.write("Location, State, Year, Average Market Price, Average Revenue, Total Generation MWh, Average PSH/Day, Value of Call, Count Over 300 And Generation, Count Over 300 No Generation\n" ) 
	averagesFile.write("Location, State, Average Market Price, Average Revenue, Average Call Value, Average Count Over 300 And Generation, Average Count Over 300 No Generation\n")
	stateAveragesFile.write("Location, Average Market Price, Average Revenue, Average Call Value, Average Count Over 300 And Generation, Average Count Over 300 No Generation\n")

	stateAverages = [["nsw",0,0,0,0,0,0], ["qld",0,0,0,0,0,0], ["vic",0,0,0,0,0,0], ["sa",0,0,0,0,0,0]]

	print "Beginning Shaped $300 Cap Simulation"
	controller = Controller(gui=False)
	tz = SydneyTimezone()
	inflation = 1.027

	startHour = 7
	finishHour = 20

	for location in locations.getLocations():

		lat= location[0]
		lon = location[1]
		state= location[2]
		locationName = location[3]
		print "==============="+locationName+"==============="
		averageMarketPrice = averageRevenue  = averageCallValue = 0
		averageCountOver300Gen = averageCountOver300NoGen = 0

		startYear = 2005
		endYear = 2011
		for year in np.arange(startYear, endYear + 1):
			print year
			startDate = datetime.datetime(year=year, month=1, day=1, hour=1, tzinfo = tz)
			endDate= datetime.datetime(year=year, month=12, day=31, hour=23, minute=30, tzinfo = tz)
			print "retrieving data"
			data = controller.getTimeseriesNemDNICos(state=state, lat = lat, lon = lon, startDate = startDate, endDate = endDate)
			print "data retrieved"
			plant = SolarPlant(namePlateMW = 1)

			totalYearlyRevenue = totalYearlyMWh = totalYearlySpotPrice = totalYearlyPSH = callValue = yearlyCountOver300Gen = yearlyCountOver300NoGen = 0

			# Iterate through the time series and perform calculations.
			for i in np.arange(data.shape[0]):
				price = data[i][6]
				dni = data[i][7]
				date = datetime.datetime(year=int(data[i][0]), month = int(data[i][1]), day = int(data[i][2]), hour=int(data[i][3]), minute=int(data[i][4]), tzinfo=SydneyTimezone())
				
				if dni > 0:
					if tracking:
						cos = data[i][10]
					else:
						cos = data[i][9]
					ghi_factor = data[i][8]
					ghi = np.multiply(ghi_factor, dni)
					output = plant.getPlantOutput(dni=dni, ghi=ghi, timePeriodHrs=0.5, cosine=cos)
					totalYearlyPSH = totalYearlyPSH + (ghi/1000.0)
				else:
					cos = 0
					ghi_factor = 0
					ghi = 0
					output = 0

				# ######################################################################
				# Put options pricing stuff here.
				timePeriodHrs = 0.5
				if price > 300 and date.hour >= startHour and date.hour <= finishHour:
					payout = (timePeriodHrs * (price - 300) ) * fractionContracted 
					callValue = callValue + payout
					totalYearlyRevenue= totalYearlyRevenue + (output * price) -  payout
					if output > 0:
						yearlyCountOver300Gen = yearlyCountOver300Gen + 1
					else:
						yearlyCountOver300NoGen = yearlyCountOver300NoGen + 1	
				else:
					totalYearlyRevenue = totalYearlyRevenue + (output * price)
					

				totalYearlyMWh = totalYearlyMWh + output
				totalYearlySpotPrice = totalYearlySpotPrice + price
				# ######################################################################


			# Calculate Yearly Averages
			averageYearlyRevenue = np.divide(totalYearlyRevenue, totalYearlyMWh)
			averageYearlyMarketPrice = np.divide(totalYearlySpotPrice, data.shape[0])
			averagePshPerDay = (totalYearlyPSH / 365.0)

			# Write to the yearly data file.
			yearlyString =  locationName +", "+state+", "+ str(endDate.year) +", "+ str(np.round(averageYearlyMarketPrice, decimals = 2)) +", "+ str(np.round(averageYearlyRevenue, decimals = 2)) 
			yearlyString = yearlyString + ", "+ str(totalYearlyMWh) + ", "+ str(averagePshPerDay)+ ", "+str(callValue)+ ", "+str(yearlyCountOver300Gen)+ ", "+str(yearlyCountOver300NoGen)+"\n"
			yearlyFile.write(yearlyString)
			print "Yearly data written to file."

			# Add to cumulative totals for averaging.
			averageCallValue = averageCallValue + callValue
			averageCountOver300Gen = averageCountOver300Gen + yearlyCountOver300Gen
			averageCountOver300NoGen = averageCountOver300NoGen + yearlyCountOver300NoGen
			averageRevenue = averageRevenue +(averageYearlyRevenue  *  np.power(inflation, (2014 - year) ) )
			averageMarketPrice = averageMarketPrice + (averageYearlyMarketPrice * np.power(inflation, 2014 - year))

		# Write to the averages data file.
		numYears = float(endYear - startYear + 1)
		averageCountOver300Gen = averageCountOver300Gen / numYears
		averageCountOver300NoGen = averageCountOver300NoGen / numYears
		averageCallValue = averageCallValue / numYears
		averageRevenue = averageRevenue / numYears
		averageMarketPrice = averageMarketPrice / numYears

		# Write averages to data file.
		averageString = locationName +", "+state+", "+ str(np.round(averageMarketPrice, decimals = 2))+ ", "+ str(np.round(averageRevenue, decimals = 2))
		averageString = averageString +", "+ str(averageCallValue)+", "+str(averageCountOver300Gen)+", "+str(averageCountOver300NoGen)+"\n"
		averagesFile.write(averageString)
		print "Averages written to file."
		for stateAverage in stateAverages:
			if state == stateAverage[0]:
				stateAverage[1] = stateAverage[1] + averageMarketPrice
				stateAverage[2] = stateAverage[2] + averageRevenue
				stateAverage[3] = stateAverage[3] + averageCallValue
				stateAverage[4] = stateAverage[4] + averageCountOver300Gen
				stateAverage[5] = stateAverage[5] + averageCountOver300NoGen
				stateAverage[6] = stateAverage[6] + 1

	for stateAverage in stateAverages:
		state = stateAverage[0]
		count = float(stateAverage[6])

		averageMarketPrice = float(stateAverage[1]) / count
		averageRevenue = float(stateAverage[2]) / count
		averageCallValue = float(stateAverage[3]) / count
		averageCountOver300Gen = float(stateAverage[4]) / count
		averageCountOver300NoGen = float(stateAverage[5]) / count
		
		averageString = state+", "+ str(np.round(averageMarketPrice, decimals = 2))+ ", "+ str(np.round(averageRevenue, decimals = 2))
		averageString = averageString +", "+ str(averageCallValue)+", "+str(averageCountOver300Gen)+", "+str(averageCountOver300NoGen)+"\n"
		stateAveragesFile.write(averageString)
	
	print "Finished"
	averagesFile.close()
	yearlyFile.close()
def printTimeseries(tracking):
	if tracking:
		print "Tracking"
		stateAveragesPath = "/Users/lukemarshall/Documents/Workspace/Thesis/simulationResults/market/merchantModelCappedSpot/tracking/average.csv"
		averagesPath = "/Users/lukemarshall/Documents/Workspace/Thesis/simulationResults/market/merchantModelCappedSpot/tracking/averageAll.csv"
		yearlyPath = "/Users/lukemarshall/Documents/Workspace/Thesis/simulationResults/market/merchantModelCappedSpot/tracking/yearly.csv"

	else:
		print "Non-Tracking"
		stateAveragesPath = "/Users/lukemarshall/Documents/Workspace/Thesis/simulationResults/market/merchantModelCappedSpot/fixed/average.csv"
		averagesPath = "/Users/lukemarshall/Documents/Workspace/Thesis/simulationResults/market/merchantModelCappedSpot/fixed/averageAll.csv"
		yearlyPath = "/Users/lukemarshall/Documents/Workspace/Thesis/simulationResults/market/merchantModelCappedSpot/fixed/yearly.csv"

	yearlyFile = open(yearlyPath, 'w')
	averagesFile = open(averagesPath, 'w')
	stateAveragesFile = open(stateAveragesPath, 'w')

	yearlyFile.write("Location, State, Year, Average Market Price, Average Revenue, Total Generation MWh, Average PSH/Day\n" ) 
	averagesFile.write("Location, State, Average Market Price, Average Revenue\n")
	stateAveragesFile.write("Location, Average Market Price, Average Revenue\n")

	print "Beginning Merchant Model Simulation"
	controller = Controller(gui=False)
	tz = SydneyTimezone()
	inflation = 1.027

	stateAverages = [["nsw",0,0,0], ["qld",0,0,0], ["vic",0,0,0], ["sa",0,0,0]]
	for location in locations.getLocations():

		lat= location[0]
		lon = location[1]
		state= location[2]
		locationName = location[3]
		print "==============="+locationName+"==============="
		averageMarketPrice = averageRevenue = count = 0
		
		for year in np.arange(2005, 2012):
			print year
			startDate = datetime.datetime(year=year, month=1, day=1, hour=1, tzinfo = tz)
			endDate= datetime.datetime(year=year, month=12, day=31, hour=23, minute=30, tzinfo = tz)
			print "retrieving data"
			data = controller.getTimeseriesNemDNICos(state=state, lat = lat, lon = lon, startDate = startDate, endDate = endDate)
			print "data retrieved"
			plant = SolarPlant(namePlateMW = 1)

			totalYearlyRevenue = totalYearlyMWh = totalYearlySpotPrice = totalYearlyPSH = 0

			# Iterate through the time series and perform calculations.
			for i in np.arange(data.shape[0]):
				price = min(data[i][6], 300)
				dni = data[i][7]
				# date = datetime.datetime(year=int(data[i][0]), month = int(data[i][1]), day = int(data[i][2]), hour=int(data[i][3]), minute=int(data[i][4]), tzinfo=SydneyTimezone())
				if dni > 0:
					if tracking:
						cos = data[i][10]
					else:
						cos = data[i][9]
					ghi_factor = data[i][8]
					ghi = np.multiply(ghi_factor, dni)
					output = plant.getPlantOutput(dni=dni, ghi=ghi, timePeriodHrs=0.5, cosine=cos)
					totalYearlyPSH = totalYearlyPSH + (ghi/1000.0)
				else:
					cos = 0
					ghi_factor = 0
					ghi = 0
					output = 0

				totalYearlyRevenue = totalYearlyRevenue + (output * price)

				totalYearlyMWh = totalYearlyMWh + output
				totalYearlySpotPrice = totalYearlySpotPrice + price

			averageYearlyRevenue = np.divide(totalYearlyRevenue, totalYearlyMWh)
			averageYearlyMarketPrice = np.divide(totalYearlySpotPrice, data.shape[0])
			averagePshPerDay = (totalYearlyPSH / 365.0)


			# Write to the yearly data file.
			yearlyString =  locationName +", "+state+", "+ str(endDate.year) +", "+ str(np.round(averageYearlyMarketPrice, decimals = 2)) +", "+ str(np.round(averageYearlyRevenue, decimals = 2)) 
			yearlyString = yearlyString + ", "+ str(totalYearlyMWh) + ", "+ str(averagePshPerDay)+"\n"
			yearlyFile.write(yearlyString)
			print "Yearly data written to file."

			averageRevenue = averageRevenue +(averageYearlyRevenue  *  np.power(inflation, (2014 - year) ) )
			averageMarketPrice = averageMarketPrice + (averageYearlyMarketPrice * np.power(inflation, 2014 - year))
			count = count + 1

		# Write to the averages data file.
		averageRevenue = averageRevenue / float(count)
		averageMarketPrice = averageMarketPrice / float(count)

		averageString = locationName +", "+state+", "+ str(np.round(averageMarketPrice, decimals = 2))+ ", "+ str(np.round(averageRevenue, decimals = 2))+"\n"
		averagesFile.write(averageString)
		print "Averages written to file."
		for stateAverage in stateAverages:
			if state == stateAverage[0]:
				stateAverage[1] = stateAverage[1] + averageMarketPrice
				stateAverage[2] = stateAverage[2] + averageRevenue
				stateAverage[3] = stateAverage[3] + 1
	for stateAverage in stateAverages:
		state = stateAverage[0]
		averageMarketPrice = float(stateAverage[1]) / float(stateAverage[3])
		averageRevenue = float(stateAverage[2]) / float(stateAverage[3])
		stateAveragesFile.write(str(state)+", "+str(averageMarketPrice)+", "+str(averageRevenue)+"\n")
	
	print "Finished"
	stateAveragesFile.close()
	averagesFile.close()
	yearlyFile.close()
def printTimeseries():
	print "Price and Solar Daily Trends"
	controller = Controller(gui=False)
	tz = SydneyTimezone()
	inflation = 1.027
	
	for location in locations.getLocations():
		lat= location[0]
		lon = location[1]
		state= location[2]
		locationName = location[3]
		
		averagesPath = "/Users/lukemarshall/Documents/Workspace/Thesis/simulationResults/market/priceFrequency/"+state+".csv"
		
		averagesFile = open(averagesPath, 'w')
		averagesFile.write("Price, Count\n")

		print "==============="+locationName+"==============="

		maxPrice = 300
		maxBucket = int(maxPrice / 10.0)
		priceFrequency = np.zeros(shape=(maxBucket,1))
		dayCounter = 0
		lastDays = 0
		counter = 0
		for year in np.arange(2005, 2012):
			print year
			startDate = datetime.datetime(year=year, month=1, day=1, hour=1, tzinfo = tz)
			date = datetime.datetime(year=year, month=1, day=1, hour=1, tzinfo = tz)
			endDate= datetime.datetime(year=year, month=12, day=31, hour=23, minute=30, tzinfo = tz)
			data = controller.getTimeseriesNemDNICos(state=state, lat = lat, lon = lon, startDate = startDate, endDate = endDate)
			plant = SolarPlant(namePlateMW = 1)
			timeDiff = endDate - startDate

			if timeDiff != lastDays:
				dayCounter = dayCounter + timeDiff.days
			lastDays = timeDiff.days
			for i in np.arange(data.shape[0]):
				counter = counter + 1
				halfHourIndex = int(round(((date.hour * 60)+ date.minute) / 30))
				price = min(data[i][6], 300)
				demand = data[i][5]
				dni = data[i][7]
				# date = datetime.datetime(year=int(data[i][0]), month = int(data[i][1]), day = int(data[i][2]), hour=int(data[i][3]), minute=int(data[i][4]), tzinfo=SydneyTimezone())
				if dni > 0:
					trackingCos = data[i][10]
					cos = data[i][9]
					ghi_factor = data[i][8]
					ghi = np.multiply(ghi_factor, dni)
					output = plant.getPlantOutput(dni=dni, ghi=ghi, timePeriodHrs=0.5, cosine=cos)
					trackingOutput = plant.getPlantOutput(dni=dni, ghi=ghi, timePeriodHrs=0.5, cosine=trackingCos)
				else:
					cos = 0
					ghi_factor = 0
					ghi = 0
					output = 0
					trackingOutput = 0
				price = int(price)
				
				if price < 0:
					price = 0
				index = int(price / 10.0)
				index = min(index, priceFrequency.shape[0] - 1)
				priceFrequency[index] = priceFrequency[index] + 1

				# priceFrequency[halfHourIndex][0] = price + priceFrequency[halfHourIndex][0]
				# priceFrequency[halfHourIndex][1] = (2 *output) + priceFrequency[halfHourIndex][1]
				# priceFrequency[halfHourIndex][2] = (2 *trackingOutput) + priceFrequency[halfHourIndex][2]
				# priceFrequency[halfHourIndex][3] = dni + priceFrequency[halfHourIndex][3]
				# priceFrequency[halfHourIndex][4] = demand + priceFrequency[halfHourIndex][4]
				# priceFrequency[halfHourIndex][5] = priceFrequency[halfHourIndex][5] + 1
				
				date = date + datetime.timedelta(seconds = (30 * 60))

		for i in np.arange(priceFrequency.shape[0]):
			averageString = str(i*10)+"-"+str(i*10+10)+", "+str(float(priceFrequency[i]))+"\n"
			averagesFile.write(averageString)

		print "Averages written to file."
	
	print "Finished"
	averagesFile.close()
def printTimeseries(tracking):

	controller = Controller(gui=False)
	tz = SydneyTimezone()
	inflation = 1.027

	for location in locations.getLocations():

		lat= location[0]
		lon = location[1]
		state= location[2]
		locationName = location[3]
		
		lcoes = lcoe.getLCOEHighLow(tracking, location)
		lcoeHigh = lcoes[0]
		lcoeLow = lcoes[1]

		if tracking:
			path = "/Users/lukemarshall/Documents/Workspace/Thesis/simulationResults/market/solarMarketFactorCapped/tracking/"+locationName+".csv"
		else:
			path = "/Users/lukemarshall/Documents/Workspace/Thesis/simulationResults/market/solarMarketFactorCapped/fixed/"+locationName+".csv"
		
		outFile = open(path, 'w')
		outFile.write("Month, Solar-Market Factor High, Solar-Market Factor Low, Average Revenue, Average Market Price\n" ) 
		
		for month in np.arange(1,13):
			lastDayOfMonth = 31
			if month == 9 or month == 4 or month == 6 or month == 11:
				lastDayOfMonth = 30
			elif month == 2:
				lastDayOfMonth = 28

			counter = 0
			averageMonthlyRevenue = 0
			averageMonthlySpotPrice =0
			totalMonthlyMWh = 0
			totalMonthlyRevenue = 0
			totalMonthlyMWh = 0
			totalMonthlySpotPrice = 0
			totalMonthlyRevenue = totalMonthlyMWh = totalMonthlySpotPrice = totalYearlyPSH = 0
			for year in np.arange(2005, 2012):
				print year
				startDate = datetime.datetime(year=year, month=month, day=1, hour=1, tzinfo = tz)
				endDate= datetime.datetime(year=year, month=month, day=lastDayOfMonth, hour=23, minute=30, tzinfo = tz)
				print "retrieving data"
				data = controller.getTimeseriesNemDNICos(state=state, lat = lat, lon = lon, startDate = startDate, endDate = endDate)
				print "data retrieved"
				plant = SolarPlant(namePlateMW = 1)

				# Iterate through the time series and perform calculations.
				for i in np.arange(data.shape[0]):
					price = min(data[i][6], 300)
					dni = data[i][7]
					# date = datetime.datetime(year=int(data[i][0]), month = int(data[i][1]), day = int(data[i][2]), hour=int(data[i][3]), minute=int(data[i][4]), tzinfo=SydneyTimezone())
					if dni > 0:
						if tracking:
							cos = data[i][10]
						else:
							cos = data[i][9]
						ghi_factor = data[i][8]
						ghi = np.multiply(ghi_factor, dni)
						output = plant.getPlantOutput(dni=dni, ghi=ghi, timePeriodHrs=0.5, cosine=cos)
						totalYearlyPSH = totalYearlyPSH + (ghi/1000.0)
					else:
						cos = 0
						ghi_factor = 0
						ghi = 0
						output = 0

					totalMonthlyRevenue = totalMonthlyRevenue + (output * price)

					totalMonthlyMWh = totalMonthlyMWh + output
					totalMonthlySpotPrice = totalMonthlySpotPrice + price
					counter = counter + 1

			averageMonthlyRevenue = np.divide(totalMonthlyRevenue, totalMonthlyMWh)
			averageMonthlySpotPrice = np.divide(totalMonthlySpotPrice, float(counter))
			# averagePshPerDay = (totalYearlyPSH / 365.0)

			factorHigh = (averageMonthlyRevenue / max(lcoeHigh, averageMonthlySpotPrice)) - 1
			factorLow = (averageMonthlyRevenue / max(lcoeLow, averageMonthlySpotPrice)) - 1

			# Write to the yearly data file.
			outString =  str(int(round(month))) +", "+ str(np.round(factorHigh, decimals = 2)) +", "+ str(np.round(factorLow, decimals = 2))+ ", "+str(np.round(averageMonthlyRevenue, decimals = 2))+", "+ str(np.round(averageMonthlySpotPrice, decimals = 2)) +"\n"
			outFile.write(outString)
		

	print "Finished"
	outFile.close()