def run(self,cont=False): water_lvl = 0 first = True success = True for data in self.sit: if first : first = False water_lvl = data.water_lvl out = self.alg( day=data.date.day, month=data.date.month, water_lvl=water_lvl, water_in=data.water_in, req = self.dam) water_lvl += data.water_in - out print util.date2td(data.date), data.water_in, out, water_lvl status = 'OK' self.dec.append(data.date,out,water_lvl,data.water_in,status) try: self.dam.run_check(water_lvl,self.dec) except AssertionError as e: status=str(e) #replace the status self.dec.pop() self.dec.append(data.date,out,water_lvl,data.water_in,status) success = False print util.date2td(data.date),e if not cont and status != 'OK': break return self.dec.dec
sys.path.append(dirname(__file__)+'../../natee/') import reader import util fname = 'bb.csv' data = reader.read(dirname(__file__)+'../data/'+fname) data = [(x.date,x.water_lvl,x.water_in*50) for x in data] date,lvl,influx = zip(*data) period = 365 ur = [sin(2*pi*x/365)*262+13379 for x in range(len(lvl))]#luckily the shift is 0 for bb dam lr = [(sin(2*pi*x/365)*2.5+237.5)*13462./260. for x in range(len(lvl))] fig = plt.figure() ax = fig.add_subplot(111) ax.plot(range(len(influx)),influx,label = 'incoming water per day scaled up by 50',alpha=0.7,color ='green') ax.plot(range(len(lvl)),lvl,label = 'water level',lw=2,alpha=0.7,color='red') ax.plot(range(len(ur)),ur,color='blue',label="upper/lower rule") ax.plot(range(len(lr)),lr,color='blue') xticks = range(0,7500,365) ax.set_xticks(xticks) xticklabels = [ util.date2td(date[i]) if i < len(date) else '' for i in xticks ] ax.set_xticklabels(xticklabels,rotation = 45) locs = ax.get_xticks() ax.set_title('Water Level in Bhumibol Dam') ax.set_ylabel('million m^3') ax.legend(loc=2) print locs ax.grid(True) plt.show()