<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Collect Data
Goal is to collect data from SenseHat.
Step1:  Get data
Read data from the SenseHat in an interactive way.
Step2:  Write measurements to disk
Write measurements to disk every 1 minute.
Use CSV file format.
Timestamp with ISO8601 format of YYYY-hh-mmTHH
<ASSISTANT_TASK:>
Python Code:
import csv
import os
import sys
import time
from datetime import datetime
from sense_hat import SenseHat
sense = SenseHat()
sense.clear()
Explanation: Collect Data
Goal is to collect data from SenseHat.
End of explanation
sense.get_temperature()
sense.get_humidity()
sense.get_compass()
sense.get_temperature_from_humidity()
sense.get_temperature_from_pressure()
sense.get_pressure()
sense.get_humidity()
while True:
    pressure = sense.get_pressure()
    pressure = round(pressure, 3)
    
    humidity = sense.get_humidity()
    humidity = round(humidity, 3)
    
    print 'Pressure: {0}\t Humidty: {1}'.format(pressure, humidity)
    
Explanation: Get data
Read data from the SenseHat in an interactive way.
End of explanation
# output directory
output_directory = r'/home/pi/Projects/pi_weather/data/'
def get_measurements():
    '''
    Return list of measurements
    
    Order of returned list is:
    * datetime, temp_humidity, temp_pressure, pressure and humidity
    
    Notes:
    * Numeric values rounded to 3 decimal places
    '''
    # clear previous data
    sense.clear()
    # generate iso8601 yyyy-mm-ddTHH:MM:SS timestamp string
    recorded_datetime = datetime.isoformat(datetime.now())
    # capture data from sensors
    temperature_from_humidity = round(sense.get_temperature_from_humidity(), 3)
    temperature_from_pressure = round(sense.get_temperature_from_pressure(), 3)
    pressure = round(sense.get_pressure(), 3)
    humidity = round(sense.get_humidity(), 3)
    
    return([recorded_datetime, temperature_from_humidity, temperature_from_pressure, pressure, humidity])
# ===== csv file
csv_file_name = 'raw.csv'
# full path to csv file
csv_path = os.path.join(output_directory, csv_file_name)
# csv column names
csv_headers = ['datetime', 'temperature_from_humidity', 'temperature_from_pressure', 'pressure', 'humidity']
# check if csv file exists
if os.path.exists(csv_path):
    pass
else:
    # create csv file on disk with headers
    with open(csv_path, 'w') as f:
        writer = csv.writer(f)
        writer.writerow(csv_headers)
# loop and read data every minute
while True:
    # get data
    data = get_measurements()
    
    # append data to csv
    print(data)
    
    with open(csv_path, 'a') as f:
        writer = csv.writer(f)
        writer.writerow(data)
    
    # wait 1 minute
    time.sleep(5)
Explanation: Write measurements to disk
Write measurements to disk every 1 minute.
Use CSV file format.
Timestamp with ISO8601 format of YYYY-hh-mmTHH:MM:SS.
End of explanation
<END_TASK>