Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
aschn committed Mar 31, 2015
2 parents f2750e8 + 8e1223e commit 1c428d6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
10 changes: 9 additions & 1 deletion pyiso/caiso.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,14 @@ def get_trade(self, latest=False,
# return all data
return parsed_data

def get_lmp(self, node_id, latest=True, start_at=False, end_at=False,
def get_lmp(self, node_id, **kwargs):
df = self.get_lmp_as_dataframe(node_id, **kwargs)
lmp_dict = {}
for i, row in df.iterrows():
lmp_dict[i.to_pydatetime()] = row['LMP_PRC']
return lmp_dict

def get_lmp_as_dataframe(self, node_id, latest=True, start_at=False, end_at=False,
market_run_id='RTM', **kwargs):
"""Returns a pandas DataFrame, not a list of dicts"""
# set args
Expand All @@ -188,6 +195,7 @@ def get_lmp(self, node_id, latest=True, start_at=False, end_at=False,

# strip congestion and loss prices
df = df.query('LMP_TYPE == "LMP"')
df.rename(columns={'MW': 'LMP_PRC'}, inplace=True)

# Get all data indexed on 'INTERVALSTARTTIME_GMT' as panda datetime
if df.index.name != 'INTERVALSTARTTIME_GMT':
Expand Down
41 changes: 34 additions & 7 deletions tests/test_caiso.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,10 +585,10 @@ def test_parse_oasis_renewables_dam(self):
'gen_MW': 580.83}
self.assertEqual(expected, parsed_data[0])

def test_get_lmp_latest(self):
def test_get_lmp_dataframe_latest(self):
c = self.create_client('CAISO')
ts = pytz.utc.localize(datetime.utcnow())
lmp = c.get_lmp('SLAP_PGP2-APND')
lmp = c.get_lmp_as_dataframe('SLAP_PGP2-APND')
self.assertEqual(len(lmp), 1)

self.assertGreaterEqual(lmp.iloc[0]['LMP_PRC'], -300)
Expand All @@ -598,16 +598,43 @@ def test_get_lmp_latest(self):
self.assertGreater(lmp.iloc[0].name, ts - timedelta(minutes=5))
self.assertLess(lmp.iloc[0].name, ts + timedelta(minutes=5))

def test_get_lmp_hist(self):
def test_get_lmp_dataframe_hist(self):
c = self.create_client('CAISO')
ts = pytz.utc.localize(datetime(2015, 3, 1, 12))
start = ts - timedelta(hours=2)
lmps = c.get_lmp('SLAP_PGP2-APND', latest=False, start_at=start, end_at=ts)
lmps = c.get_lmp_as_dataframe('SLAP_PGP2-APND', latest=False, start_at=start, end_at=ts)
self.assertEqual(len(lmps), 24)

self.assertGreaterEqual(lmps['MW'].max(), 0)
self.assertLess(lmps['MW'].max(), 30)
self.assertGreaterEqual(lmps['MW'].min(), 20)
self.assertGreaterEqual(lmps['LMP_PRC'].max(), 0)
self.assertLess(lmps['LMP_PRC'].max(), 1500)
self.assertGreaterEqual(lmps['LMP_PRC'].min(), -300)

self.assertGreaterEqual(lmps.index.to_pydatetime().min(), start)
self.assertLessEqual(lmps.index.to_pydatetime().max(), ts)

def test_get_lmp_latest(self):
c = self.create_client('CAISO')
ts = pytz.utc.localize(datetime.utcnow())
lmp = c.get_lmp('SLAP_PGP2-APND')
self.assertEqual(len(lmp), 1)

self.assertGreaterEqual(min(lmp.keys()), ts - timedelta(minutes=5))
self.assertLessEqual(max(lmp.keys()), ts + timedelta(minutes=5))

self.assertGreaterEqual(min(lmp.values()), -300)
self.assertLess(max(lmp.values()), 1500)

def test_get_lmp_hist(self):
c = self.create_client('CAISO')
ts = pytz.utc.localize(datetime(2015, 3, 1, 11, 0, 0))
start = ts - timedelta(hours=2)
lmp = c.get_lmp('SLAP_PGP2-APND', latest=False, start_at=start, end_at=ts)
self.assertEqual(len(lmp), 24)

self.assertGreaterEqual(min(lmp.keys()), start)
self.assertLessEqual(max(lmp.keys()), ts)

self.assertGreaterEqual(min(lmp.values()), -300)
self.assertLess(max(lmp.values()), 1500)


0 comments on commit 1c428d6

Please sign in to comment.