<jupyter_start><jupyter_text>Read in the SWE data from the netCDF fileAll of these files can be accessed at https://rda.ucar.edu/datasets/ds612.0/In this example, one file is converted to 3-hr sums.<jupyter_code>import xarray as xr

ds = xr.open_dataset("../example_data/wrf2d_d01_CTRL_SNOW_ACC_NC_201301-201303.nc")

ds.SNOW_ACC_NC<jupyter_output><empty_output><jupyter_text>Examine the Time dimensionWe see the data are from every hour.<jupyter_code>ds.Time<jupyter_output><empty_output><jupyter_text>Plot the data on a simple map<jupyter_code>import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
%matplotlib inline

plt.rcParams['figure.figsize'] = 10, 10

ax = plt.axes(projection=ccrs.PlateCarree())
ax.set_extent([-128, -65, 25, 48])

ax.add_feature(cfeature.STATES.with_scale('10m'))

example = ds.sel(Time='2013-01-28 12:00:00')

mmp = ax.pcolormesh(example.XLONG, example.XLAT, example.SNOW_ACC_NC, vmax=2, cmap='Blues')

plt.colorbar(mmp, ax=ax, shrink=0.3, pad=0.01, extend='max')

plt.title("SWE Accumulation (mm) valid 2013-01-28 12:00:00")<jupyter_output><empty_output><jupyter_text>To improve continuity in the tracking, we can combine multiple hours into 3-hr chunksAn example using three hours on 2013-01-28 from 12:00 UTC to 14:00 UTC<jupyter_code>example1 = ds.sel(Time='2013-01-28 12:00:00')
example2 = ds.sel(Time='2013-01-28 13:00:00')
example3 = ds.sel(Time='2013-01-28 14:00:00')

total = example1.SNOW_ACC_NC + example2.SNOW_ACC_NC + example3.SNOW_ACC_NC

ax = plt.axes(projection=ccrs.PlateCarree())
ax.set_extent([-128, -65, 25, 48])

ax.add_feature(cfeature.STATES.with_scale('10m'))

example = ds.sel(Time='2013-01-28 12:00:00')

mmp = ax.pcolormesh(example.XLONG, example.XLAT, total.data, vmax=5, cmap='Blues')

plt.colorbar(mmp, ax=ax, shrink=0.3, pad=0.01, extend='max')

plt.title("SWE Accumulation (mm) valid 2013-01-28 12 - 14 UTC")<jupyter_output><empty_output><jupyter_text>Or, more simply..<jupyter_code>example_slice = ds.sel(Time=slice('2013-01-28 12:00:00', '2013-01-28 14:00:00'))

example_sum = example_slice.resample(Time='3H').sum('Time')

ax = plt.axes(projection=ccrs.PlateCarree())
ax.set_extent([-128, -65, 25, 48])

ax.add_feature(cfeature.STATES.with_scale('10m'))

mmp = ax.pcolormesh(example_slice.XLONG.values, example_slice.XLAT.values, example_sum.SNOW_ACC_NC.values[0], vmax=5, cmap='Blues')

plt.colorbar(mmp, ax=ax, shrink=0.3, pad=0.01, extend='max')

plt.title("SWE Accumulation (mm) valid 2013-01-28 12 - 14 UTC")<jupyter_output><empty_output><jupyter_text>Sanity check...Check the total difference between the 3H resample and the manual 3H summation<jupyter_code>import numpy as np

np.sum(total - example_sum.SNOW_ACC_NC.values[0])<jupyter_output><empty_output><jupyter_text>Read in the 3H transformed dataset and compare<jupyter_code>ds_3h = xr.open_dataset("../example_data/3H_sum_SNOW_ACC_CTRL_2012-2013.nc")

ds_3h_ex = ds_3h.sel(Time="2013-01-28 12:00:00")

ax = plt.axes(projection=ccrs.PlateCarree())
ax.set_extent([-128, -65, 25, 48])

ax.add_feature(cfeature.STATES.with_scale('10m'))

mmp = ax.pcolormesh(ds_3h_ex.XLONG.values, ds_3h_ex.XLAT.values, ds_3h_ex.SNOW_ACC_NC.values, vmax=5, cmap='Blues')

plt.colorbar(mmp, ax=ax, shrink=0.3, pad=0.01, extend='max')<jupyter_output><empty_output><jupyter_text>Find the difference between these data and the manual examples above<jupyter_code>np.sum(ds_3h_ex.SNOW_ACC_NC.values - example_sum.SNOW_ACC_NC.values[0])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1477888730385164, 'fraction_numerical': 0.08216833095577745, 'mean_word_length': 6.655021834061135, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 1, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '639207', 'license': 'MIT', 'n_tokens_mistral': 1649, 'n_tokens_neox': 1439, 'n_words': 249, 'path': 'future_snow/notebooks/Convert_to_3H.ipynb', 'repo_name': 'ahaberlie/Future_Snow', 'size': '3505'}