<commit_before>#!/usr/bin/env python
# Copyright (C) 2013 <NAME>
#
# This program is free software. See terms in LICENSE file.
"""
Photovoltaic System Performance Monitoring

"""

import tmy3
import geo
import numpy as np
import inverters
import modules
import irradiation
import json
import math
import datetime
import forecast
import noaa
import pathfinder
from collections import Counter
from geopy import geocoders

class resultSet(object):
    def _init_(self):
        self.timeseries = None
        self.values = None
        self.dailyAve = 0
        self.annualOutput = 0
        self.clippingHours = 0

    def dump(self):
        return (self.timeseries, self.values)
    def dumps(self):
        return ([int((i - datetime.datetime(1970,1,1)).total_seconds()) \
                for i in self.timeseries],self.values)

    def plotd(self):
        import matplotlib.pyplot as plt
        import matplotlib.dates as mdates
        fig = plt.figure()
        ax = fig.add_subplot(111)
        months   = mdates.MonthLocator()
        mFormat = mdates.DateFormatter('%b')
        ax.xaxis.set_major_locator(months)
        ax.xaxis.set_major_formatter(mFormat)
        ax.plot(self.timeseries, self.values)
        return fig
        #plt.ion()
        #plt.show()

    def plot(self):
        import matplotlib.pyplot as plt
        total = self.hourlyValues
        a = []
        for i in range(0,len(self.hourlyValues),24):
            a.append(self.hourlyValues[i:i+23])
        data = np.array(a)
        data = np.rot90(data)
        fig = plt.figure()
        ax = fig.add_subplot(111)#plt.subplots()
        ax.set_xlim([0,365])
        ax.set_ylim([0,22])
        ax.set_ylabel('Hour of Day')
        ax.set_xlabel('Day of Year')
        heatmap = ax.imshow(data,aspect='auto',cmap=plt.cm.OrRd)
        txt =  "Year 1 Output: %s KWh" % round(sum(total)/1000,1)
        cbar = fig.colorbar(heatmap) 
        cbar.set_label('Output (Wh)')
        ax.annotate(txt, xy=(10,3))
        txt = "Year 1 Annual Output: %s kWh" % self.annualOutput
        ax.annotate(txt, xy=(10,2))
        plt.tight_layout()
        return fig

    def summary(self):
        print "Year 1 Annual Output: %s kWh" % self.annualOutput
        print "Year 1 Daily Average: %s kWh" % self.dailyAve
        print "Inverter hours clipping: %s" % self.clippingHours

def fileToSystem(filename):
    """Load a system from a json file"""
    try:
        return jsonToSystem(json.loads(open(filename).read()))

    except:
        print "Error: file corrupt or not found:"


def jsonToSystem(jsonDescription):
    """Load a system from a json description"""
    #todo: this is getting unweildy should probably be refactored<commit_msg>fix label<commit_after>#!/usr/bin/env python
# Copyright (C) 2013 <NAME>
#
# This program is free software. See terms in LICENSE file.
"""
Photovoltaic System Performance Monitoring

"""

import tmy3
import geo
import numpy as np
import inverters
import modules
import irradiation
import json
import math
import datetime
import forecast
import noaa
import pathfinder
from collections import Counter
from geopy import geocoders

class resultSet(object):
    def _init_(self):
        self.timeseries = None
        self.values = None
        self.dailyAve = 0
        self.annualOutput = 0
        self.clippingHours = 0

    def dump(self):
        return (self.timeseries, self.values)
    def dumps(self):
        return ([int((i - datetime.datetime(1970,1,1)).total_seconds()) \
                for i in self.timeseries],self.values)

    def plotd(self):
        import matplotlib.pyplot as plt
        import matplotlib.dates as mdates
        fig = plt.figure()
        ax = fig.add_subplot(111)
        months   = mdates.MonthLocator()
        mFormat = mdates.DateFormatter('%b')
        ax.xaxis.set_major_locator(months)
        ax.xaxis.set_major_formatter(mFormat)
        ax.plot(self.timeseries, self.values)
        return fig

    def plot(self):
        import matplotlib.pyplot as plt
        total = self.hourlyValues
        a = []
        for i in range(0,len(self.hourlyValues),24):
            a.append(self.hourlyValues[i:i+23])
        data = np.array(a)
        data = np.rot90(data)
        fig = plt.figure()
        ax = fig.add_subplot(111)#plt.subplots()
        ax.set_xlim([0,365])
        ax.set_ylim([0,22])
        ax.set_ylabel('Hour of Day')
        ax.set_xlabel('Day of Year')
        heatmap = ax.imshow(data,aspect='auto',cmap=plt.cm.OrRd)
        txt =  "Year 1 Output: %s KWh" % round(sum(total)/1000,1)
        cbar = fig.colorbar(heatmap) 
        cbar.set_label('Output (W)')
        ax.annotate(txt, xy=(10,3))
        plt.tight_layout()
        return fig

    def summary(self):
        print "Year 1 Annual Output: %s kWh" % self.annualOutput
        print "Year 1 Daily Average: %s kWh" % self.dailyAve
        print "Inverter hours clipping: %s" % self.clippingHours

def fileToSystem(filename):
    """Load a system from a json file"""
    try:
        return jsonToSystem(json.loads(open(filename).read()))

    except:
        print "Error: file corrupt or not found:"


def jsonToSystem(jsonDescription):
    """Load a system from a json description"""
    #todo: this is getting unweildy should probably be refactored
{'fraction_non_alphanumeric': 0.1097261567516525, 'fraction_numerical': 0.017752596789423983, 'mean_word_length': 2.5591397849462365, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3116773', 'n_tokens_mistral': 1781, 'n_tokens_neox': 1680, 'n_words': 444}