Last active
August 19, 2018 19:36
-
-
Save Yettimania/fb22156acff729009e49930d5cb4e912 to your computer and use it in GitHub Desktop.
Takes data from my Kesler D3 and generate a plot for the exported data.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create_weather_plot.sh hello | |
% cat create_weather_plot.sh | |
#!/bin/bash | |
sed -i '1,3d;5d' $1 | |
echo '' | |
echo 'CSV formated properly.' | |
echo '-----------------------------------------------' | |
echo 'Generating plots with weather_plot_rev5.py' | |
echo '-----------------------------------------------' | |
python ~/Documents/Backcountry_Reports/Weather_Graph_Plotter.py $1 | |
echo 'Plot has been generated!!' | |
echo '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' This will take a .csv file from the Kestrel Drop 3 and manipulate it into graphing all the pertinant weather data. | |
Graph 1: Temperature and Dew Point | |
Graph 2: Head Index and Humidity | |
Graph 3: Pressure | |
I have a script command create_weather_graph.sh which easily manipulated the .csv file to remove the unnecesssary lines. | |
''' | |
#Import python modules to be used. import sys is used to get an argument for the | |
#file names and starts at index 1. | |
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
import sys | |
title = input("Enter title for weather plot: ") | |
df = pd.read_csv(sys.argv[1]) | |
#I don't want the X-axis to show all the dates and times. I choose to plot 8 points and round | |
#them to the nearest integer. The last one needs to subtract one incase it rounds up. That is then | |
#appended to a list for the x lables in maplotlib | |
point_date = np.linspace(0,len(df['FORMATTED DATE_TIME']),8) | |
plot_date = np.rint(point_date) | |
plot_date[-1] = plot_date[-1]-1 | |
graph_data=[] | |
for x in range(0,len(plot_date)): | |
graph_data.append(df['FORMATTED DATE_TIME'][plot_date[x]]) | |
#Create the figure. | |
fig,axes = plt.subplots(nrows=3, ncols=1,figsize=(10,7.5)) | |
#Creation of graph 1. | |
#xticklabels are empty to remove those labels from the graph. | |
axes[0].plot(df['FORMATTED DATE_TIME'],df['Temperature']) | |
axes[0].plot(df['FORMATTED DATE_TIME'],df['Dew Point']) | |
axes[0].set_title(title,fontsize=18) | |
axes[0].set_ylabel('Temperature') | |
axes[0].set_xticks(plot_date) | |
axes[0].set_xticklabels([]) | |
axes[0].grid(True) | |
axes[0].legend(loc='best') | |
#Creation of graph 2 with a shared x axis. | |
ax2 = axes[1].twinx() | |
axes[1].plot(df['FORMATTED DATE_TIME'],df['Heat Stress Index'],color='g') | |
ax2.plot(df['FORMATTED DATE_TIME'],df['Relative Humidity'],color='r') | |
axes[1].set_ylabel('Heat Index',color='g') | |
ax2.set_ylabel('Humidity',color='r') | |
axes[1].set_xticklabels([]) | |
axes[1].set_xticks(plot_date) | |
axes[1].grid(True) | |
#Creation of graph 3, X ticks are which points to graph on the grid and the labels are | |
#created based on those same correspodning values. | |
axes[2].plot(df['FORMATTED DATE_TIME'],df['Station Pressure']) | |
axes[2].set_ylabel('Pressure') | |
axes[2].set_xticks(plot_date) | |
axes[2].set_xticklabels(graph_data,rotation=75) | |
axes[2].grid(True) | |
plt.tight_layout() | |
#df = pd.read_csv('weather.csv') | |
#print(df.head()) | |
plt.savefig('/home/kyle/Documents/Backcountry_Reports/'+ title + '_Weather.pdf') | |
#plt.savefig(title + '_Weather.pdf') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment