-
Notifications
You must be signed in to change notification settings - Fork 11
Closed
Labels
Description
# Get data
data = et.data.get_data("colorado-flood")
os.chdir(os.path.join(et.io.HOME, 'earth-analytics'))
import matplotcheck.notebook as nb
import matplotcheck.timeseries as ts
import matplotcheck.raster as ra
# BEGIN SOLUTION
import os
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from matplotlib.dates import DateFormatter
import seaborn as sns
import numpy as np
import pandas as pd
import earthpy as et
import hydrofunctions as hf
import urllib
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()
# prettier plotting with seaborn
sns.set(font_scale=1.5)
sns.set_style("whitegrid")
# import file
f = "data/colorado-flood/discharge/06730200-discharge-daily-1986-2013.txt"
discharge = pd.read_csv(f,
skiprows=23,
header=[1, 2],
sep='\t',
parse_dates=[2])
# drop one level of index
discharge.columns = discharge.columns.droplevel(1)
# set the date column as the index
discharge = discharge.set_index(["datetime"])
monthly_max_all = discharge.resample("M").max()
monthly_max = monthly_max_all['1990':'2014']
fig, ax = plt.subplots(figsize=(10, 8))
ax.scatter(x=monthly_max.index,
y=monthly_max["17663_00060_00003"],
color="purple")
ax.set_title(
"HW Plot 1: Stream Discharge - Monthly Max Value\n be sure to add x and y labels (not shown here)")
ax.set(xlabel="Date")
# END SOLUTION
### DO NOT REMOVE LINE BELOW ###
plot_1_ts = nb.convert_axes(plt, which_axes="current")
mpc_plot_1_ts = mts.TimeSeriesTester(plot_1_ts)
results = []
TEST
mts.TimeSeriesTester(plot_1_ts)
mpc_plot_1_ts.assert_xydata(xy_expected = precip.reset_index(),
xtime=True,
xcol="DATE",
ycol="HPCP")
Output error: i suspect this has something to do with NAN values but i am not sure
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-38-1b4d8c2d48dc> in <module>
4 xtime=True,
5 xcol="DATE",
----> 6 ycol="HPCP")
7
8 #precip
~/Documents/github/0-python/matplotcheck/matplotcheck/base.py in assert_xydata(self, xy_expected, xcol, ycol, points_only, xtime, xlabels, tolerence, message)
938 try:
939 np.testing.assert_array_max_ulp(
--> 940 np.array(xy_data["x"]), np.array(xy_expected[xcol])
941 )
942 except AssertionError:
~/miniconda3/envs/earth-analytics-python/lib/python3.7/site-packages/numpy/testing/_private/utils.py in assert_array_max_ulp(a, b, maxulp, dtype)
1617 __tracebackhide__ = True # Hide traceback for py.test
1618 import numpy as np
-> 1619 ret = nulp_diff(a, b, dtype)
1620 if not np.all(ret <= maxulp):
1621 raise AssertionError("Arrays are not almost equal up to %g ULP" %
~/miniconda3/envs/earth-analytics-python/lib/python3.7/site-packages/numpy/testing/_private/utils.py in nulp_diff(x, y, dtype)
1658 y = np.array(y)
1659
-> 1660 t = np.common_type(x, y)
1661 if np.iscomplexobj(x) or np.iscomplexobj(y):
1662 raise NotImplementedError("_nulp not implemented for complex array")
<__array_function__ internals> in common_type(*args, **kwargs)
~/miniconda3/envs/earth-analytics-python/lib/python3.7/site-packages/numpy/lib/type_check.py in common_type(*arrays)
719 p = array_precision.get(t, None)
720 if p is None:
--> 721 raise TypeError("can't get common type for non-numeric array")
722 precision = max(precision, p)
723 if is_complex:
TypeError: can't get common type for non-numeric array
- i suspect this has to do with NA values. we need to clear those out
Reactions are currently unavailable