3 Replies - 265 Views - Last Post: 05 August 2014 - 09:43 AM Rate Topic: -----

#1 beebeeking  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 25-June 14

Max/Min/Mean Per Day

Posted 05 August 2014 - 12:24 AM

Hi,

This is a snippet of my txt file (data.txt)

    TimeStamp,Irradiance,Ambient_Temperature
    21/7/2014 0:00,0.66,29.16
    21/7/2014 0:00,0.71,29.16
    21/7/2014 0:00,0.65,29.17
    21/7/2014 0:00,0.67,29.17
    21/7/2014 0:01,0.58,29.17
    .
    .
    . 
    .
    .
    22/7/2014 23:58,0.69,28.54
    22/7/2014 23:58,0.61,28.54
    22/7/2014 23:58,0.65,28.51
    22/7/2014 23:58,0.59,28.54
    22/7/2014 23:59,0.63,28.55
    22/7/2014 23:59,0.67,28.54
    22/7/2014 23:59,0.68,28.56
    22/7/2014 23:59,0.58,28.55



My Program will ask the user to enter from what time to what and will plot both the irradiance & ambient temperature

For now, i am able to display max/min/mean for over the days
but what i trying to achieve is:

1. Display the max/min per day (within each 24 hours period)
2. Display mean per day between 8:00a.m to 5:00p.m


This is a snippet of my code (for displaying max/min/mean):


 long_title = ('\n Max Irradiance value: {:.2f} at {}, Min Irradiance Value: {:.2f} at {}, Mean Irradiance Value: {:.2f} \n Max AMB_TEMP Value: {:.2f} at {} , Min AMB_TEMP Value: {:.2f} at {},Mean AMB_TEMP Value: {:.2f} at {} \n')
    fig.suptitle(short_title.format(startTime, endTime), fontsize=20, color='blue')  
    ax1.set_title(long_title.format(max(temp),t[np.argmax(temp)],   
    min(temp),t[np.argmin(temp)], np.average(y), max(temp),t[np.argmax(temp)],   
    min(temp),t[np.argmin(temp)], np.average(y), fontsize=16, color='green', ha='bottom')))


Is This A Good Question/Topic? 0
  • +

Replies To: Max/Min/Mean Per Day

#2 DK3250  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 105
  • Joined: 27-December 13

Re: Max/Min/Mean Per Day

Posted 05 August 2014 - 07:48 AM

What is your question ? The code snippet provided doesn't make sense to me.., maybe if I see more of the code.

Apparently you know the max and min functions.
I guess you also know list slicing (to get the values you want).
Average can be calculated as sum(<list>)/len(<list>)

This post has been edited by DK3250: 05 August 2014 - 07:52 AM

Was This Post Helpful? 0
  • +
  • -

#3 beebeeking  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 25-June 14

Re: Max/Min/Mean Per Day

Posted 05 August 2014 - 08:53 AM

Hi, Thanks for replying!
from datetime import datetime
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import numpy as np # support large, multi-dimen arrays n matrices
from scipy.stats import mode # stats like finding mode
import re # regular expression (process text)

linematchregex = re.compile('(\d+/\d+/\d+ \d+:\d+),(\d+\.\d+),(\d+\.\d+)' # find multiple pairs on the same line


startTime = datetime.strptime(raw_input('please enter start time in format like 21/7/2014 0:00 :'), '%d/%m/%Y %H:%M')
endTime   = datetime.strptime(raw_input('please enter end time in format like 22/7/2014 23:57 :') , '%d/%m/%Y %H:%M')


with open(r'fyp1.txt', 'r') as strm:
strm.next() #skip first line
t,y,temp = zip(*[p for line in strm for p in linematchregex.findall(line)])
t = [datetime.strptime(x, '%d/%m/%Y %H:%M') for x in t ]
y = [float(x) for i,x in enumerate(y) if startTime<=t[i]<=endTime]
temp = [float(x) for i,x in enumerate(temp) if startTime<=t[i]<=endTime]

t = [datetime.strptime(x, '%d/%m/%Y %H:%M') for x in t ]
temp = [float(x) for i,x in enumerate(temp) if startTime<=t[i]<=endTime]

t = [x for x in t if startTime<=x<=endTime]
fig = plt.figure()
ax1 = fig.add_subplot(1, 1, 1, axisbg='white')
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))
ax1.set_ylim(15,40)
ax1.plot(t, temp, 'c', linewidth=3.3)

short_title = ('Irradiance & Ambient Temperature vs. Time Graph \n From {} To {} \n ')
long_title = ('\n Max Irradiance value: {:.2f} at {}, Min Irradiance value: {:.2f} at {}, Mean Irradiance Value: {:.2f}, Max AMB_TEMP Value: {:.2f} at {} , Min AMB_TEMP Value: {:.2f} at {}, Mean AMB_TEMP Value: {:.2f} at {}\n')
fig.suptitle(short_title.format(startTime, endTime), fontsize=20, color='blue')
for k, v in temp_by_day.items():
ax1.set_title(long_title.format(max(y),t[np.argmax(y)], min(y),t[np.argmin(y)], np.average(y) max(temp),t[np.argmaxt(temp)], min(temp),t[np.argmin(temp)], np.average(temp) fontsize=16, color='green'))
plt.ylabel(u'Ambient Temperature(\u2103) & Irradiance', fontsize=16, color='blue')
plt.xlabel('Time ($H:M$)', fontsize=16, color='blue')
fig.tight_layout()
plt.show()


hi i forgot to delete line 35
Was This Post Helpful? 0
  • +
  • -

#4 DK3250  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 105
  • Joined: 27-December 13

Re: Max/Min/Mean Per Day

Posted 05 August 2014 - 09:43 AM

I'm still new to numpy and matplotlib - I need to hand the batoon to someone else on this question.
Sorry, - but good luck here on DIC.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1