<jupyter_start><jupyter_text>Selecting a particular dateThe following is one example of how to select a particular date. When we load the dataset, Xarray decodes the time coordinate into an array of datetime objects. The nice thing about them is that they can be accessed in ways that allow the specification of parts of the date.In the following cell, we will use the `dt` accessor to get the indices that are in july (month value equal 7) and with a day (i.e. day of month) equal to 4. Note that `time.dt.month ==7` returns an array of True/False values that is True for all data identified as being in July. Then we use the `&` to combine that array with the True/False array that checks for the day of the month being 4.<jupyter_code>time = ds['time']
independence_day = sac_tmax[(time.dt.month == 7) & (time.dt.day == 4)]
time.dt.day[0:366]<jupyter_output><empty_output><jupyter_text>Quick look plotsXarray has some simple plotting functionality. We can use that here to get a quck look at the resulting series of 4 July Tmax values in Sacramento._NOTE:_ We really should not rely on Xarray's plots for very much because it becomes hard to customize them.<jupyter_code>%matplotlib inline
independence_day.plot()
np.histogram(independence_day)
independence_day.min().values
independence_day.load()
plt.hist(independence_day, bins=10)
plt.hist(independence_day, bins=40)<jupyter_output><empty_output><jupyter_text>Simple functionJust as a reminder, you can make reusable code by defining a function. Here is a function that is called `degC_to_degF` that takes temperature in Celsius and converts it to Fahrenheit. Then we use that function to really drive home the point that Sacramento is super hot.<jupyter_code>def degC_to_degF(C):
    return C * (9./5.) + 32.

in_f = degC_to_degF(independence_day)
in_f.plot()
def plot_hist_month(ts, month):
    month_data = ts[ts['time.month'] == month]
    h, edges = np.histogram(month_data, bins=np.arange(-10.5, 120.5, 0.5), density=True)
    bin_centers = edges[:-1:] + 0.5*np.diff(edges)  # take all but the last edge and add the half-width of the bin
    # to transform from "density" to hprime so that the sum of hprime = 1
    hprime = h / h.sum()  # has units of "fraction of data set" and sums to 1.0
    fig, ax = plt.subplots(constrained_layout=True)
    ax.bar(bin_centers, hprime)
    ax.set_ylabel("fraction")
    return fig, ax
# proving that the centers are correct
# fake_x = np.linspace(0, 1, 11)
# fake_y = np.random.random_sample(1000)
# fake_h, fake_edges = np.histogram(fake_x)
# print(fake_x)
# print(fake_edges)
# bin_centers = fake_edges[:-1] + 0.5*np.diff(fake_edges)
# print(bin_centers)
#np.histogram?
ax007.set_ylim(0, .5)
y = set([1979, 1980, 1981])
min(y)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09561752988047809, 'fraction_numerical': 0.022455632017385006, 'mean_word_length': 4.754166666666666, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '550707', 'license': 'MIT', 'n_tokens_mistral': 959, 'n_tokens_neox': 893, 'n_words': 339, 'path': 'notebooks/extract_location_and_date.ipynb', 'repo_name': 'brianpm/TemperatureExtremes', 'size': '2761'}