In [1]:
import mechanize
import json
import pandas as pd
import datetime

In [2]:
# systems I have access to as rsignell@usgs.gov
d={}
d['signell']='15610'
d['buesseler']='13942'
d['lindell']='14479'
d['mcgillicuddy']='16327'

# my micro inverter ids
micro={}
micro['southeast']= ['395311', '395314', '395315', '395313', '395320', '395309', '395310']
micro['southwest']= ['395321', '395312', '395318', '395319', '395317', '395316']

In [3]:
login_url='https://enlighten.enphaseenergy.com/login'
username='rsignell@usgs.gov'
password='4U10PXWU55'

In [4]:
# read the login form
response = mechanize.urlopen(login_url)
forms = mechanize.ParseResponse(response, backwards_compat=False)
form = forms[0]
print form


<POST https://enlighten.enphaseenergy.com/login/login application/x-www-form-urlencoded
  <HiddenControl(utf8=&#x2713;) (readonly)>
  <HiddenControl(authenticity_token=ACCW+PkLwulr6rPUmQjBNSS1OdaMVd4eeprkGAHhjek=) (readonly)>
  <TextControl(user[email]=)>
  <PasswordControl(user[password]=)>
  <SubmitControl(commit=Sign In) (readonly)>>

In [5]:
# fill in the login form
br=mechanize.Browser()
br.open(login_url)
br.select_form(nr=0)
br.set_all_readonly(False)
br['user[email]']=username
br['user[password]']=password
br['authenticity_token']=form['authenticity_token']
br['commit']=form['commit']
br['utf8']=form['utf8']
br.submit();

In [6]:
# retrieve the JSON data and return as Pandas Series
def get_micro_data(system='15610', micro_inverters=['395315']):
    
    def get_data(system,inverter):
        url='https://enlighten.enphaseenergy.com/systems/%s/devices/%s/graph_widget.json?timeframe=recent' % (system, inverter)
        tmp_file = br.retrieve(url)[0]
        json_data=open(tmp_file)
        data = json.load(json_data)
        u=array(data['data_sets'][0]['data'])
        return u
    
    first = True
    for inverter in micro_inverters:
        if first:
            u = get_data(system, inverter)
            dn=[datetime.datetime.fromtimestamp(time) for time in u[:,0]]
            df=pd.DataFrame(u[:,1],index=dn, columns=[inverter])
            first = False
        else:
            u = get_data(system, inverter)
            df[inverter]=u[:,1]
    return df

In [7]:
df_east = get_micro_data(system=d['signell'],micro_inverters=micro['southeast'])

In [8]:
df_east.plot(figsize=(16,4),grid=True,title='Southeast Panels');



In [9]:
df_west = get_micro_data(system=d['signell'],micro_inverters=micro['southwest'])

In [10]:
df_west.plot(figsize=(16,4),grid=True,title='Southwest Panels');



In [11]:
dfwm=df_west.median(axis=1)

In [12]:
dfem=df_east.median(axis=1)

In [13]:
dfcomp=pd.concat([dfem, dfwm],axis=1)

In [14]:
dfcomp.plot(figsize=(16,4),grid=True,title='Southeast/Southwest Panel comparison');


In the plot above, you can see that the southeast panels produce more power earlier in the day, and southwest panels produce more power later in the day, as you would expect.


In [15]:
df_diff = dfcomp[0]-dfcomp[1]
df_diff.plot(figsize=(16,4),grid=True,title='Southeast - Southwest Panels');



In [16]:
df_diff = (dfcomp[0]-dfcomp[1])/(dfcomp[0]+dfcomp[1])
df_diff.plot(figsize=(16,4),grid=True,title='fraction difference (SE-SW)/(SW+SE)');



In [ ]: