<jupyter_start><jupyter_text>Exercise 1                                               <NAME>                                        Argonne National Laboratory<jupyter_code>#Plotting and reading in tabular data with Python.
#Import modules
import pyart
import matplotlib
from matplotlib import pyplot as plt
import numpy as np
import scipy
%matplotlib inline
from datetime import datetime, timedelta
from io import StringIO
from pytz import timezone
from jdcal import gcal2jd, jd2gcal
import matplotlib.dates as mdates
import datetime as dt
print("pyart.__version__")


#Testing in pyart is running correctly.
if pyart.__version__ == "1.6.0":
    if hasattr(pyart.graph, 'RadarMapDisplay'):
        print ("Ready to go")
    else:
        print ("ISSUES\n\nMissing\Broken Basemap\n")
        pyart._debug_info()
else:
    print ("ISSUES\n\nWrong Py-ART version\n")
    pyart._debug_info()
#Import data via urllib.request.
import urllib.request
radar = urllib.request.Request('http://www.atmos.anl.gov/ANLMET/anltower.48')
data = urllib.request.urlopen(radar) 
my_data = np.recfromtxt(data, skip_header = 2)
#Defining columns used for plotting.
#Placing data into an array and coverting to float.
Tdp_10m = np.array(my_data[0:192,9])
Tdp_10m = Tdp_10m.astype(np.float64)
Tdp_10m_max = np.amax(Tdp_10m)
Tdp_10m_min = np.amin(Tdp_10m)
TaC_10m = np.array(my_data[0:192,10])
TaC_10m = TaC_10m.astype(np.float)
TaC_10m_max = np.amax(TaC_10m)
TaC_10m_min = np.amin(TaC_10m)
julian_date = np.array(my_data[0:192,0])
julian_date = julian_date.astype(np.float)

time = np.array(my_data[0:192,1])



#Column stacking time and julian date in order to convert to datetime.
jda_time = np.column_stack((julian_date,time))
jda_time

#Creating a datetime object using a for loop.
jda_time = (jda_time)
base = datetime(2016, 1, 1, 0, 0, 0, 0)
transformed = [base + timedelta(days=int(float(x)-1), hours=int(y[0:2]), 
                                minutes=int(y[3:5])) for x, y in jda_time]
datetime_array = np.array(transformed)
datetime_array
#Plot dew-point and dry-bulb over cell number.
fig, ax1 = plt.subplots()
fig.suptitle('Dew-point and Dry-bulb Over Cell Number', fontsize=10, fontweight='bold')
y1 = Tdp_10m
ax1.plot(y1, 'b-')
ax1.set_xlabel('Cell Number')
# Make the y-axis label and tick labels match the line color.
ax1.set_ylabel('Dew-point Temperature °C', color='b')
for tl in ax1.get_yticklabels():
    tl.set_color('b')
plt.ylim((-0,35))
x = np.arange(0, 192)

ax2 = ax1.twinx()
y2 = TaC_10m
ax2.plot(y2, 'r-')
ax2.set_ylabel('Dry-bulb Temperature °C', color='r')
for tl in ax2.get_yticklabels():
    tl.set_color('r')
plt.ylim((-20, 30))
plt.show()
#Displaying maximum and minimum dewpoint and drybulb temperatures.
print('Maximum dew-point temperature = %f'%(Tdp_10m_max))
print('Minimum dew-point temperature = %f'%(Tdp_10m_min))
print('Maximum dry-bulb temperature = %f'%(TaC_10m_max))
print('Minimum dry-bulb temperature = %f'%(TaC_10m_min))
#Plot dew-point and dry-bulb over datetime.

fig, ax1 = plt.subplots()
fig.suptitle('Dew-point and Dry-bulb Over Datetime', fontsize=10, fontweight='bold')
x = np.array(datetime_array)
y1 = Tdp_10m
y2 = TaC_10m
ax1.set_xlabel('Datetime')
ax1.plot(x, y1, 'b-')
ax1.set_ylabel('Dew-point Temperature °C', color='b')
for tl in ax1.get_yticklabels():
    tl.set_color('b')
plt.ylim((-8,35))

ax2 = ax1.twinx()

ax2.plot(x, y2, 'r-')
ax2.set_ylabel('Dry-bulb Temperature °C', color='r')
for tl in ax2.get_yticklabels():
    tl.set_color('r')
plt.ylim((-8,35))


x_lims = (datetime_array)

# Converting datetime.datetime objects to the correct format for matplotlib to work with.
date_format = mdates.DateFormatter('%Y/%m/%d %H:%M:%S')
x_lims = mdates.date2num(x_lims)
ax1.xaxis_date()

# Using DateFormatter to choose how datetime string will appear.


ax1.xaxis.set_major_formatter(date_format)
fig.autofmt_xdate()  

ax1.annotate('local max', xy=(3, 1), xycoords='data',
                xytext=(0.8, 0.95), textcoords='axes fraction',
                arrowprops=dict(facecolor='black', shrink=0.05),
                horizontalalignment='right', verticalalignment='top')
                

plt.fill_between(x, y1, y2, color='green', alpha='0.5')

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1370834318128102, 'fraction_numerical': 0.03734341763176554, 'mean_word_length': 4.218249075215783, 'pattern_counts': {'":': 1, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '285482', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 1747, 'n_tokens_neox': 1624, 'n_words': 374, 'path': 'notebooks/exercise_1.ipynb', 'repo_name': 'zssherman/training_exercises', 'size': '4237'}