Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Session 7, soil moisture track: water in the top metre of soil at Turnbull

📍 In-situ sensor · 💧 Land water · 💧 Hydrology & land-surface modeling

Updated 14 October, afternoon: more cells where you write the analysis yourself. If you already finished the earlier version, submit it as is.

Wednesday 14 October 2026, self-guided. Each question has a self-check and a collapsed worked solution; open it after you have tried.

Learning outcomes. After this session you can:

  • tell whether a station file was modified or corrupted;

  • state what a soil moisture probe samples and what processing lies between it and a daily value;

  • read a daily station table: rows, units, missing-value codes, limits, a real extreme against an error;

  • find and clean sensor and processing problems, and measure how each biases the soil’s response to rain;

  • separate a shared seasonal cycle from day-to-day coupling in a correlation;

  • write the chain from a raw file to a learning problem without leaks;

  • write rules and instructions that let another person, or an AI tool, rerun your chain from the ten NCEI yearly files to the response to rain at 5 cm, and check whether it did.

Objectives for today. You will:

  • download ten years of daily soil moisture at five depths from NCEI and check your copy;

  • read the 5 cm series and the depth-by-time field, and date a wetting front;

  • hunt six problems planted in a synthetic twin and compute the response to rain three ways;

  • correlate precipitation, temperature and soil moisture with and without the seasonal cycle;

  • frame a dry-spell problem for machine learning;

  • start the two agent skill files you submit on Friday.

How to work. Work in a copy, lab_s07_soil_moisture_UWNETID.ipynb, here, opened with pixi run jupyter lab; do not commit, push or stash in the book clone. Edit NETID in the first code cell: it places the problems in your twin. Replace each ... or "" and run the self-check below it. In a Your turn cell you write the analysis, 2 to 5 lines: replace each None with your code and run the cell; its self-check says whether the result is right, and a collapsed worked solution follows. If you leave a None, the next cells continue with a reference result and say so. The times are rough estimates of how long each part takes, not a schedule. Parts 4 and 8, Your turn 6b, Your turn 7b with Question 7.3, and the hunt in Part 5 beyond three findings are for when you have time; skip them if you want more time for the rest.

Submit by Friday 16 October, 9:00, to the Canvas assignment “Session 7: explore your system’s data”: this notebook (.ipynb; HTML optional), the three files of Part 8 and a short comment. Completion only: the work does not count toward your grade, but a missing submission costs 10 points.

Not using git pull? Download this track as one zip, lab_s07_soil_moisture.zip, unzip it and open the notebook from the unzipped folder; the start page explains how.

NetID: (empty: you get the class twin, the one the worked solutions use)   offline mode: True   course copy: snapshots/uscrn_WA_Spokane_17_SSW_2015-2024.txt

Part 0. The system and the question (about 3 min)

The top metre of soil is a small reservoir: rain and snowmelt fill it; evaporation, root uptake and drainage empty it. How full it is decides whether a storm soaks in or runs off, how long plants grow into the dry season, and how much water recharges the aquifer. Drought monitors and weather and climate models track it for these reasons.

WA Spokane 17 SSW is a station of the U.S. Climate Reference Network (USCRN), run by the National Oceanic and Atmospheric Administration (NOAA) and distributed by its National Centers for Environmental Information (NCEI). It sits in Turnbull National Wildlife Refuge, on the channeled scablands south of Spokane, where Ice Age floods scoured the basalt. Summers are dry, winters wet and cold. Soil probes were added in 2009 to 2011 for drought monitoring, with the National Integrated Drought Information System (https://www.ncei.noaa.gov/access/crn/why.html); Bell et al. (2013, doi:10.1175/JHM-D-12-0146.1) describe the network.

Guiding question: When it rains at Turnbull, how much water does the top of the soil take up, how does it move down the profile, and how does this change through the year?

<Figure size 700x460 with 1 Axes>
NCEI station list: US Fish & Wildlife Service, Turnbull NWR (Headquarters Site), 47.41 N, 117.52 W, commissioned 2007-09-28, status Commissioned

Question 0.1. Predict the month (1 to 12) in which the soil at 5 cm is wettest on average, and the driest. Part 3 checks it.

not answered yet

Part 1. Download the raw data and know what you have (about 15 min)

NCEI serves one file per station and year at https://www.ncei.noaa.gov/pub/data/uscrn/products/daily01/. The next cell downloads the ten files of 2015 to 2024 (0.8 MB) and joins them in year order, as snapshots/make_uscrn_WA_Spokane_17_SSW_2015-2024.py built the course copy. Without a network, it uses the course copy.

Offline mode: no download. You will work from the course copy in snapshots/.

Has the file been modified or corrupted?

Four checks, cheapest first:

  1. Size in bytes. A transfer that stopped early gives a smaller file.

  2. Number of rows. One per calendar day.

  3. First and last records. Does the file start and end where it should?

  4. Fingerprint. SHA-256 (Secure Hash Algorithm, 256-bit) turns every byte into a 64-character code; one changed byte changes the code completely. NCEI publishes none for these files, so the course recorded one per file (served in the provenance file).

A different fingerprint does not by itself mean damage: NCEI revises its data. README section 2 lists three reprocessings of precipitation (2015, 2016, 2017), and NCEI’s notice of 20 October 2022 says every soil moisture value was rerun “for all stations and the period of record” after dry readings had been set to zero instead of flagged. Find which years changed, then compare values.

course copy fingerprint matches the one recorded when it was built: True
Loading...

The next cell writes two damaged copies to s07_my_files/: one digit changed (0.266 becomes 0.267 in the first row), and 100 bytes cut from the end. The edited copy passes every check but the fingerprint; the short copy keeps its row count, but its size and last record give it away.

Loading...

Question 1.1. How many rows must the file have if no day is missing or repeated, 1 January 2015 to 31 December 2024? Count by hand.

Question 1.2. Is your download byte for byte the course copy (True or False)? Skip it if you could not download.

not answered yet
No download to compare (offline or skipped). You are working from the course copy, which is fine.
Notebook Cell
days in the calendar: 3653   rows in the course copy: 3653
correct. One line per day, no day missing and none repeated. A file that ends early or repeats a day fails here.

Native resolution: what the probe measures and what the file gives you

The provider’s words (copies under sensor_documentation in the provenance file):

  • NCEI, What is measured (https://www.ncei.noaa.gov/access/crn/measurements.html): “15 [...] Hydra Probe II (SDI-12) units are placed in the ground in three plots at five depths [...]. These probes use reflected electromagnetic radio waves at 50 MHz to determine the dielectric permittivity of the soil [...], which can be converted to volumetric soil moisture [...] by use of a calibration equation. [...] All 15 probes are interrogated every two minutes and their measurements averaged over 5-minute periods”.

  • NCEI notice of 20 October 2022: the conversion is one equation for every station, from Seyfried et al. (2005, doi:10.2136/vzj2004.0148) “with slightly updated coefficients”: Volumetric = (0.109 × SQRT(Dielectric)) − 0.179.

  • Daily README, note J: “The soil values reported in this dataset are an average of the day’s hourly soil measurements which are calculated from the multiple independent measurements.” Note E: “When the raw data are flagged as erroneous, these derived values are not calculated, and are instead reported as missing.”

  • Technical Memorandum USCRN-19-001 (2019), p. 16: “The Hydra probe lacks the ability to measure water content in frozen soils”.

  • Sensing volume: a cylinder 5.7 cm long and 3.0 cm across (manufacturer, https://stevenswater.com/products/hydraprobe/).

The dataset record (doi:10.7289/V5MS3QR9) keeps 5-minute values only at 5 cm, hourly values at all depths, and at one test station each hourly value was a single reading until 27 March 2018 (USCRN-19-001, p. 33). The number of readings behind a daily value at 50 cm is not documented, so give a range.

Your turn 1. How much soil and how many readings lie behind one daily value? Compute v_probe, the soil volume one probe senses in cm³ (a float; the sensing volume is a cylinder), and two integers for one depth and one day: n_readings_max if each of the 3 probes is read every 2 minutes, and n_readings_min if each probe gives one reading per hour.

Hint: the volume of a cylinder is np.pi * r**2 * length, with r half the diameter.

not answered yet
Notebook Cell
correct. One probe senses about 40 cm3, the three together about 121 cm3, a handful of soil, and one daily value rests on somewhere between 72 and 2160 readings.

Three documented ways the probe misleads, and what each does to a derived number:

  1. One calibration for every soil. In clay-rich soil (Selma, Alabama) the Hydra Probe read 10 to 15% higher than an Acclima probe, because of “the relatively high electrical conductivity of the clay” (USCRN-19-001, p. 8). A near-constant bias shifts every absolute value and threshold, such as “the driest tenth of days”; the response to rain changes only as much as the bias scales with water content.

  2. Air gaps. Cracks can give “a 0.000 volumetric observation in soil that was moist” (NCEI notice, October 2022), which pulls the layer mean down.

  3. Dry readings flagged, not zeroed, since 2022. In the driest weeks a layer mean may rest on the one or two wettest probes, which lifts the dry tail.

Question 1.3. From the quotes, fill in the native resolution, and say whether the daily file is raw (what the sensor recorded) or derived (computed from it).

Question 1.4. In one or two sentences, name the processing steps between the radio-wave reading in the soil and the number in your file.

not answered yet
not answered yet
Notebook Cell
correct. Each daily value is an average over three probes and many readings, converted from a dielectric measurement by a general equation: a derived product.
correct. You named: conversion from dielectric, averaging, quality control, combining probes.

Part 2. A table: what one row records (about 15 min)

One row is one station-day: station 04136 by its Weather Bureau Army Navy (WBAN) number, and a Local Standard Time (LST) day, midnight to midnight without daylight saving. The file has no header line: names and units are in snapshots/uscrn_daily01_HEADERS.txt, definitions in snapshots/uscrn_daily01_readme.txt, and fields are separated by spaces (README note A).

28 field names, the first six: ['WBANNO', 'LST_DATE', 'CRX_VN', 'LONGITUDE', 'LATITUDE', 'T_DAILY_MAX']

Your turn 2a. Read the course copy COURSE_FILE into raw: a pandas DataFrame with one row per line of the file and the 28 names in names as columns, indexed by date (a DatetimeIndex made from the LST_DATE column, which also stays a column). The file has no header line, and runs of spaces separate the fields.

Hint: pd.read_csv with sep=r"\s+", header=None and names=; then assign pd.to_datetime(..., format="%Y%m%d") to raw.index.

not answered yet
Notebook Cell
correct. 3653 days and 28 fields, indexed by the local date.
`raw` is blank or not the expected shape. Using the reference result so you can continue; compare with yours.
(3653, 28)
Loading...
Loading...

Question 2.1. In one sentence: what does one row record, where, and over what span of time? (README section 5, fields 1 and 2, note D.)

Question 2.2. What are the units of SOIL_MOISTURE_5_DAILY, and which provider file states them?

Question 2.3. Which number marks a missing value in the soil moisture fields, and which in the air temperature fields (README note C)?

not answered yet
not answered yet
not answered yet
Notebook Cell
correct. One row is one Local Standard Time day at one station.
correct. A volume of water per volume of soil, a fraction between 0 and the soil's pore space.
correct. README note C: the lowest number the field's width can hold. Read as a number, it is an error.
         T_DAILY_MAX  T_DAILY_MIN  T_DAILY_MEAN  T_DAILY_AVG  P_DAILY_CALC  SOLARAD_DAILY  SUR_TEMP_DAILY_MAX  SUR_TEMP_DAILY_MIN  SUR_TEMP_DAILY_AVG  RH_DAILY_MAX  RH_DAILY_MIN  RH_DAILY_AVG  SOIL_MOISTURE_5_DAILY  SOIL_MOISTURE_10_DAILY  SOIL_MOISTURE_20_DAILY  SOIL_MOISTURE_50_DAILY  SOIL_MOISTURE_100_DAILY  SOIL_TEMP_5_DAILY  SOIL_TEMP_10_DAILY  SOIL_TEMP_20_DAILY  SOIL_TEMP_50_DAILY  SOIL_TEMP_100_DAILY
-99.000            0            0             0            0             0              0                   0                   0                   0             0             0             0                    611                     180                     112                     222                       58                  0                   0                   0                   0                    0
-9999.0           15           15            15           15             2            224                   9                   9                   9             9             9             9                      0                       0                       0                       0                        0                 56                  60                  74                  79                   61

Your turn 2b. Make df, a copy of raw in which both missing-value codes of Question 2.3 are blank (NaN), and n_blank, a pandas Series with the number of blank values in each column of df, zeros included. Then show the columns that have at least one blank, without changing n_blank.

Hint: raw.replace([code_1, code_2], np.nan), then .isna().sum(); select with n_blank[n_blank > 0].

not answered yet
Notebook Cell
correct. The 5 cm soil moisture is blank far more often than the 5 cm soil temperature: Part 3 asks why.
T_DAILY_MAX 15 T_DAILY_MIN 15 T_DAILY_MEAN 15 T_DAILY_AVG 15 P_DAILY_CALC 2 SOLARAD_DAILY 224 SUR_TEMP_DAILY_MAX 9 SUR_TEMP_DAILY_MIN 9 SUR_TEMP_DAILY_AVG 9 RH_DAILY_MAX 9 RH_DAILY_MIN 9 RH_DAILY_AVG 9 SOIL_MOISTURE_5_DAILY 611 SOIL_MOISTURE_10_DAILY 180 SOIL_MOISTURE_20_DAILY 112 SOIL_MOISTURE_50_DAILY 222 SOIL_MOISTURE_100_DAILY 58 SOIL_TEMP_5_DAILY 56 SOIL_TEMP_10_DAILY 60 SOIL_TEMP_20_DAILY 74 SOIL_TEMP_50_DAILY 79 SOIL_TEMP_100_DAILY 61 dtype: int64

Question 2.4. Before looking at the values, write the lowest and highest values you would accept at this site for 5 cm soil moisture, daily precipitation and daily maximum air temperature. The next cell counts values outside your limits, as read and after the missing codes become blanks.

not answered yet
`df` is blank or not the expected shape. Using the reference result so you can continue; compare with yours.
not answered yet: fill in your limits first

Question 2.5. One real extreme and one error. Is the hottest day real (three days shown on each side)? Is the lowest 5 cm soil moisture as read real? Late June 2021 is the Pacific Northwest heat wave (Philip et al., 2022, doi:10.5194/esd-13-1689-2022).

Loading...
lowest SOIL_MOISTURE_5_DAILY as read: -99.0   after the codes become blanks: 0.011
not answered yet
Notebook Cell
correct. The hottest day sits in a run of hot days during a documented heat wave; -99.000 is the missing-value code.

Part 3. A 1D array: the 5 cm time series (about 15 min)

Near-surface soil moisture rises in steps when rain soaks in, then decays as the surface dries and water drains, on top of the seasonal cycle of evaporation.

Your turn 3a. Make sm5, the 5 cm soil moisture column of df (a pandas Series); miss, a Series that is True on the days sm5 is blank; and steps, a Series counting how often each time step between consecutive dates occurs.

Hint: .isna() for the blanks; for the steps, .diff() on df.index.to_series(), then .value_counts().

not answered yet
Notebook Cell
correct. Now find when the blank days fall.
`sm5` is blank or not the expected shape. Using the reference result so you can continue; compare with yours.
`miss` is blank or not the expected shape. Using the reference result so you can continue; compare with yours.
`steps` is blank or not the expected shape. Using the reference result so you can continue; compare with yours.
time steps between consecutive rows: {'1 day': 3652}
blank days at 5 cm: 611 of 3653
Loading...
<Figure size 1100x550 with 2 Axes>

Your turn 3b. Make monthly, the mean 5 cm soil moisture of each calendar month (a Series of 12 values, index 1 to 12), and days_with_value, the number of days with a value behind each of those means. Then make sm5_monthly, one mean per month of the record (a Series of 120 values), and plot it.

Hint: sm5.groupby(sm5.index.month) followed by .mean() or .count(); sm5.resample("MS").mean(), then .plot().

not answered yet
Notebook Cell
correct. 4 months of the record have no 5 cm value at all and stay blank in sm5_monthly. Compare days_with_value in winter and in summer: frozen days are blank.
<Figure size 640x480 with 1 Axes>
`monthly` is blank or not the expected shape. Using the reference result so you can continue; compare with yours.
mean 5 cm soil moisture by month (m3/m3): {1: 0.311, 2: 0.31, 3: 0.305, 4: 0.284, 5: 0.214, 6: 0.127, 7: 0.052, 8: 0.034, 9: 0.047, 10: 0.111, 11: 0.218, 12: 0.276}
days with a 5 cm value / calendar days, by month: {1: '143/310', 2: '120/283', 3: '253/310', 4: '300/300', 5: '310/310', 6: '300/300', 7: '310/310', 8: '310/310', 9: '299/300', 10: '301/310', 11: '241/300', 12: '155/310'}
mean precipitation by month (mm/day, rain and melted snow): {1: 1.98, 2: 1.65, 3: 1.22, 4: 1.06, 5: 1.27, 6: 0.76, 7: 0.17, 8: 0.24, 9: 0.54, 10: 1.5, 11: 2.11, 12: 2.52}
CRX_VN (datalogger program version) around late 2023:
date
2023-11-01    2.622
2023-11-12    2.424
2023-12-20    2.622

Question 3.1. What is the sampling interval, in days?

Question 3.2. How many days have no 5 cm soil moisture, and how long is the longest run of blank days?

Question 3.3. Most blanks fall in winter: why? What happened from 11 November to 20 December 2023, when every soil depth is blank but precipitation and air temperature are not? Use the gap table, the lower panel and CRX_VN (README field 3).

Question 3.4. Compare your Part 0 prediction with the monthly means: how close are the top months, and on how many days does each winter mean rest, since frozen days are blank? One sentence in prediction_note.

not answered yet
not answered yet
not answered yet
not answered yet
Notebook Cell
correct. Every row is one day after the previous one; gaps are blank values, not missing rows.
correct. Now ask when the gaps happen.
91% of blank 5 cm days have a 5 cm soil temperature at or below 1 C
correct. Two causes, two different fixes: a frozen probe is a limit of the method; an outage is lost data.
date
2015-01-01    2.422
2018-09-23    2.622
2023-11-12    2.424
2023-12-20    2.622
correct. Your Part 0 prediction matches the monthly means. Months [1, 2, 3] all lie within 0.01 m3/m3 of the wettest: a late-winter plateau, not one wettest month. And those winter means rest only on the unfrozen days, because frozen days are blank.

Part 4. A 2D array: soil moisture by depth and time (about 12 min, if you have time)

The five probe columns form a 2D array, depth by time. Physics predicts its structure: rain wets the top first and moves down over days to weeks, deeper probes respond later and smoother, and summer root uptake dries even the deepest probe.

<xarray.DataArray 'soil_moisture' (depth_cm: 5, time: 3653)> Size: 146kB
array([[  nan,   nan,   nan, ..., 0.311, 0.308, 0.299],
       [  nan,   nan,   nan, ..., 0.36 , 0.36 , 0.353],
       [0.266, 0.259, 0.254, ..., 0.321, 0.321, 0.315],
       [0.233, 0.227, 0.223, ..., 0.291, 0.292, 0.285],
       [0.204, 0.198, 0.193, ..., 0.242, 0.244, 0.237]], shape=(5, 3653))
Coordinates:
  * depth_cm  (depth_cm) int64 40B 5 10 20 50 100
  * time      (time) datetime64[us] 29kB 2015-01-01 2015-01-02 ... 2024-12-31
Attributes:
    units:    m3/m3
    source:   USCRN daily01, WA Spokane 17 SSW

Your turn 4a. Make one_year, the part of sm from 1 August 2021 to 31 July 2022 (a DataArray, depth by time), and profile_mean, its mean over time at each depth (a DataArray with one value per depth). Plot profile_mean against depth, surface at the top.

Hint: sm.sel(time=slice(first_day, last_day)) with dates as "YYYY-MM-DD", then .mean("time"); .plot(y="depth_cm", yincrease=False).

not answered yet
Notebook Cell
correct. Each depth averages only the days it has a value: blank (frozen) days near the surface leave part of the winter out of the shallow means.
<Figure size 640x480 with 1 Axes>
`one_year` is blank or not the expected shape. Using the reference result so you can continue; compare with yours.
<Figure size 1000x360 with 2 Axes>
autumn 2021 arrival of the wetting front (first day 0.05 m3/m3 above the late-summer minimum):
5      2021-09-20
10     2021-09-29
20     2021-10-02
50     2021-10-29
100    2021-11-02

Your turn 4b. Make change_by_depth, the mean absolute day-to-day change of soil moisture at each depth over the whole record (a DataArray with one value per depth, in m³/m³). Show it.

Hint: sm.diff("time"), then abs(), then .mean("time").

not answered yet
Notebook Cell
correct. Compare the five values from top to bottom for Question 4.3.
depth_cm 5 0.0049 10 0.0041 20 0.0035 50 0.0034 100 0.0031 Name: soil_moisture, dtype: float64

Question 4.1. Is the depth axis evenly spaced? What is the time step?

Question 4.2. In autumn 2021, how many days did the wetting front take from 5 cm to 100 cm?

Question 4.3. Does the day-to-day change get smaller with every step down in depth?

Further: in 2018, 2019 and 2020 the 100 cm probe wets before the 50 cm one (check.arrival_dates(2018)). Give one physical and one instrumental explanation.

not answered yet
not answered yet
not answered yet
Notebook Cell
correct. Five probes at 5, 10, 20, 50 and 100 cm: an image drawn with equal rows would stretch the top.
correct. In 2021 the front took weeks to reach 1 m. Other autumns differ: 2016 took 8 days, and in 2017 (32 days from 5 cm) the 20, 50 and 100 cm probes wetted on the same day, during one storm. Run arrival_dates(2016) and arrival_dates(2017).
correct. Soil above a probe smooths the rain signal it receives.
{2016: 8, 2017: 32, 2021: 43} days from 5 to 100 cm, by autumn

Part 5. A synthetic twin with planted problems (about 30 min)

(a) List possible problems. (b) Hunt for them. (c) Compute the response to rain three ways. (d) Write how each problem biased it. When you stop hunting, a clean that fixes only what you found is complete, and what you missed goes in (d). Two sentences are enough for (d).

lab_s07_soil_synthetic.py builds a twin of the Turnbull record: weather drawn from the real file’s monthly statistics, soil from a five-layer water balance, and a known truth. The generator adds noise and plants six problems of ten kinds, placed by your NetID. Unlike the station, the twin blanks a depth when its daily mean soil temperature is below 0 °C, and its 50 and 100 cm layers sometimes wet in one step, which is not a planted spike. Compare the twin only with its own truth, and leave twin.truth closed until your findings are recorded.

(a) Before you look at your twin, list the problems a soil probe, a precipitation gauge, a datalogger or a person converting the files could put in a daily table like this. Think through a year in the life of the station.

not answered yet
Notebook Cell
You named 10 of the ten kinds this generator can plant.
correct. Now hunt for them in your twin.
seed 629; 6 problems planted; file for Part 8: s07_my_files/soil_twin_class.csv
names to use in your findings:
  spike                  isolated one-day jumps in a soil moisture column
  drift                  a slow, steady change in one probe that is not in the soil
  stuck                  a probe that repeats the same value day after day
  frozen_read_as_dry     frozen-soil days reported as very dry instead of left blank
  missing_code_left_in   a missing-value code written as a number
  gauge_outage_as_zero   days when the precipitation gauge failed, written as 0 mm
  rain_one_day_late      precipitation written one day after it fell
  probes_swapped         two probe depths exchanged after a maintenance visit
  duplicated_days        days that appear twice in the table
  units_percent          soil moisture written in percent instead of m3/m3
Loading...
<Figure size 1100x700 with 3 Axes>
<Figure size 1100x700 with 3 Axes>

(b) Hunt. A finding gives the kind (a name from the list), the column, the first and last dates, and why the values are physically implausible. Find at least three, then go on to (c); hunt for the rest if you have time. Your turn 5a and the checks after it find some problems for you; the rest need physics. Zoom with plot_twin(obs, "2019-03-01", "2019-11-30") and ask:

  • What should the 5 cm probe report when the soil at 5 cm is below 0 °C?

  • Which probe should follow air temperature more closely, 10 cm or 20 cm? Every year?

  • Should the late-summer minimum at a depth climb year after year?

  • When the soil wets up, did rain fall that day? In which year does it wet up the day before the rain?

Your turn 5a. Two checks that need no physics. Make n_duplicated_dates, the number of rows of obs whose date already appeared on an earlier row (an integer), and out_of_range, a Series with, for each soil moisture column in sm_cols, the number of values below 0 or above 1 m³/m³. Show out_of_range.

Hint: .duplicated() on obs["date"], then .sum(); join the two comparisons with |, each one in parentheses: (obs[sm_cols] < 0) | (...), then .sum().

not answered yet
Notebook Cell
correct. These checks need no physics. Each count above zero is a finding to record, with its dates.
sm_5cm 34 sm_10cm 33 sm_20cm 87 sm_50cm 87 sm_100cm 87 dtype: int64
rows: 3653   calendar days: 3653
largest one-day rises at 5 cm (values between 0 and 1 only), with that day's rain:
             rise  rain_mm  next day
date                                
2024-01-18  0.274      0.0     0.003
2024-02-28  0.272      0.6    -0.001
2023-12-08  0.269      0.0     0.003
2017-12-22  0.266      0.0     0.003
2023-11-30  0.262      0.9    -0.002
2018-02-08  0.261      0.0     0.005
longest run of identical consecutive values, by column (days): {'sm_5cm': 6, 'sm_10cm': 5, 'sm_20cm': 5, 'sm_50cm': 5, 'sm_100cm': 4}
not answered yet: add at least one finding to the list

When you have hunted for a while, set show_missed=True above and rerun to see which kinds you have not found (not where).

(c) The derived quantity. The response to rain is the rise in water content per amount of rain. rain_response(table) fits the day-to-day change at 5 cm against the day’s precipitation (days with at least 2 mm, unfrozen soil) and returns the slope in m³/m³ per 10 mm. On cold days the gauge also catches snow that does not reach the soil that day, which lowers the response. Compute it on the truth, the table as delivered, and your cleaned table. First, three cleaning steps that need no dates and so fit every twin.

Your turn 5b. Make basic, the twin table obs with (1) each date kept once, (2) negative soil moisture blank in every sm_cols column, (3) sm_5cm blank on the days st_5cm is below 0 °C; then r_basic, the response to rain on basic (a float).

Hint: .drop_duplicates("date"); .where(... >= 0) on basic[sm_cols] only, assigned back to basic[sm_cols]; basic.loc[condition, "sm_5cm"] = np.nan; rain_response(basic)[0].

not answered yet
Notebook Cell
correct. Response to rain as delivered 0.0209, after these three steps 0.0209 m3/m3 per 10 mm. The steps need no dates, so they fit every twin; clean() below adds the steps that need your findings.
In your twin these steps do not move the response; the problems that do need dates.

Now the steps that need your findings. clean returns one row per day with the same columns, each line with its physical reason; you can start from your three lines above. The commented lines show patterns, not where your problems are.

not answered yet

(d) Reflect. For each problem you found: did it bias the response, in which direction, and why (which column and which days does the response use)? Which problems did cleaning undo, and which can no cleaning undo? Use the names above.

not answered yet
Notebook Cell
                 problem     column       start         end
0          units_percent     sm_5cm  2016-12-13  2017-03-06
1          units_percent    sm_10cm  2016-12-13  2017-03-06
2          units_percent    sm_20cm  2016-12-10  2017-03-06
3          units_percent    sm_50cm  2016-12-10  2017-03-06
4          units_percent   sm_100cm  2016-12-10  2017-03-06
5     frozen_read_as_dry     sm_5cm  2017-11-23  2018-03-24
6     frozen_read_as_dry     sm_5cm  2022-12-09  2023-01-31
7     frozen_read_as_dry     sm_5cm  2023-11-19  2024-02-27
8     frozen_read_as_dry    sm_10cm  2017-12-11  2018-03-24
9                  spike    sm_10cm  2015-06-15  2015-06-15
10                 spike    sm_10cm  2016-08-14  2016-08-14
11                 spike    sm_10cm  2016-10-04  2016-10-04
12                 spike    sm_10cm  2019-10-02  2019-10-02
13        probes_swapped    sm_10cm  2020-09-18  2024-12-31
14  gauge_outage_as_zero  precip_mm  2016-04-24  2016-05-26
15     rain_one_day_late  precip_mm  2022-01-01  2022-12-31

You recorded 16 findings. They match 6 of the 6 planted problems.
{'truth': 0.016, 'as delivered': 0.0209, 'after cleaning': 0.0165} m3/m3 per 10 mm
correct. Off from the truth: as delivered 30%, cleaned 3%.
median drydown time at 5 cm (days), truth / delivered / cleaned: [28.5, 27.4, 27.4]

The worked solution also computes the median e-folding time of drying after warm-season storms (soil.drydown_timescale). It hardly moves: a median over some forty drydowns ignores the few a stuck probe or a spike corrupts, which still carry the problem.

Part 6. Correlations on the real data (about 10 min, plus 6 if you have time)

Question 6.1. Before computing: what sign ("+" or "-") do you expect for the correlation of a day’s precipitation with that day’s change in 5 cm soil moisture? For daily mean air temperature with 5 cm soil moisture?

not answered yet
Loading...
lag 0 uses 2989 unfrozen days; 73% of them had no precipitation
<Figure size 1000x360 with 2 Axes>

Question 6.2. At which lag is Pearson largest, and which is second? Why is the second non-zero for means over an LST day? Why is Spearman lower than Pearson: how does a rank correlation treat the many tied zeros (days without precipitation), and what do the few large storms do to Pearson?

not answered yet
Notebook Cell
correct. Recorded. Compare it with the correlations below.
correct. Rain that falls late in a Local Standard Time day shows up in the next day's average.

The trap: a shared seasonal cycle. Warm months are dry months at Turnbull, so temperature and soil moisture correlate across the year even if a warm day does nothing to the soil that day. Remove the mean seasonal cycle from both (anomaly: each day minus the smoothed ten-year mean of that calendar day) and correlate again. Daily anomalies persist, so for lag-1 autocorrelations r1 and r2 the effective number of independent pairs is n_eff = n (1 − r1 r2) / (1 + r1 r2) (Bretherton et al., 1999, doi:10.1175/1520-0442(1999)012<1990:TENOSD>2.0.CO;2).

Your turn 6a (Question 6.3). Make Ta and Sa, the anomalies of T and S from anomaly(), and two Pearson correlations as floats: r_raw between T and S, and r_anomaly between Ta and Sa.

Hint: T.corr(S) gives Pearson r and skips the days on which either value is blank.

not answered yet
Notebook Cell
correct. Most of the raw correlation is the shared seasonal cycle, not day-to-day coupling.
`Ta` is blank or not the expected shape. Using the reference result so you can continue; compare with yours.
`Sa` is blank or not the expected shape. Using the reference result so you can continue; compare with yours.
`r_anomaly` is blank or not the expected shape. Using the reference result so you can continue; compare with yours.
<Figure size 1000x340 with 3 Axes>

Your turn 6b (Question 6.4, if you have time). Does the anomaly correlation differ from zero? Make n_both, the number of days on which both anomalies have a value (an integer); r1 and r2, the lag-1 autocorrelations of Ta and Sa; n_eff from the formula above; and anomaly_r_differs_from_zero, True when |r_anomaly| (that is, abs(Ta.corr(Sa))) is above 2/√n_eff (about the 95% level).

Hint: (Ta.notna() & Sa.notna()).sum(), Ta.autocorr(1), abs() and np.sqrt().

not answered yet
not answered yet
Notebook Cell
correct. Thousands of days, but only a few hundred independent pieces of information.
correct. |r| = 0.05 against 2/sqrt(n_eff) = 0.09: once the season is removed, a warm day says nothing about that day's soil moisture.

Part 7. From data to a learning problem (about 12 min, plus 6 if you have time)

Question 7.1. Write the chain from the raw file to a table a model could learn from, in order, each step with its reason: rows, depths and periods kept; what you remove and what you keep as a real extreme; frozen days; resampling; anomalies or not; a training, validation and test split with no leak; where balancing goes.

not answered yet

Question 7.2. Which machine learning (ML) task fits the guiding question, and what exactly is the target? For example:

  • regression: tomorrow’s change in 5 cm soil moisture, from today’s soil moisture and the precipitation observed up to today (add tomorrow’s precipitation only as a forecast, and say so);

  • classification of dry spells: whether the soil at 20 cm is in the driest tenth of the training years’ days.

not answered yet
days per split: {'train': 2192, 'test': 731, 'validation': 730}

Your turn 7a. The dry-spell target. Make s20, the 20 cm soil moisture column of df; threshold, its 10th percentile over the training days only (a float); dry, a Series that is 1.0 on days below the threshold, 0.0 on other days and blank where s20 is blank; and dry_share, the share of dry days in each split (a Series indexed by split name).

Hint: .quantile(0.10) on s20[split == "train"]; .astype(float) then .where(s20.notna()); .groupby(split).mean().

not answered yet
Notebook Cell
correct. The dry share is not the same in the three splits. Question 7.3 asks for the training one.

Your turn 7b (if you have time). The regression target. Make y_reg, tomorrow’s 5 cm soil moisture minus today’s, on today’s row (a Series with one value per day), and print how many days rise by 0.02 m³/m³ or more and the skewness of y_reg.

Hint: .shift(-1) moves tomorrow’s value onto today’s row; .skew().

not answered yet
Notebook Cell
days rising by 0.02 m3/m3 or more: 94   skewness: 3.8
correct. Most days barely change and a few storms make large rises: skewness 3.8.
`threshold` is blank or not the expected shape. Using the reference result so you can continue; compare with yours.
`dry` is blank or not the expected shape. Using the reference result so you can continue; compare with yours.
`dry_share` is blank or not the expected shape. Using the reference result so you can continue; compare with yours.
`y_reg` is blank or not the expected shape. Using the reference result so you can continue; compare with yours.
dry class: 20 cm soil moisture below 0.052 m3/m3 (10th percentile of 2015 to 2020)
Loading...
dry-class share by month (all years): {1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0, 5: 0.0, 6: 0.0, 7: 0.02, 8: 0.33, 9: 0.71, 10: 0.51, 11: 0.04, 12: 0.0}
days with a 20 cm value, by year: {2015: 361, 2016: 365, 2017: 345, 2018: 359, 2019: 362, 2020: 366, 2021: 364, 2022: 353, 2023: 322, 2024: 344}
dry days, by year: {2015: 31, 2016: 0, 2017: 42, 2018: 71, 2019: 0, 2020: 49, 2021: 65, 2022: 57, 2023: 93, 2024: 79}
response when yesterday's 5 cm moisture is 0 to 0.1 m3/m3: 0.025 m3/m3 per 10 mm (80 days)
response when yesterday's 5 cm moisture is 0.1 to 0.2 m3/m3: 0.017 m3/m3 per 10 mm (80 days)
response when yesterday's 5 cm moisture is 0.2 to 0.28 m3/m3: 0.019 m3/m3 per 10 mm (114 days)
response when yesterday's 5 cm moisture is 0.28 to 1 m3/m3: 0.015 m3/m3 per 10 mm (176 days)
<Figure size 1000x320 with 2 Axes>
training days: 2158, dry: 193; weight for a dry day: 10.2, wet day: 1
base rate seen by the model: 0.089 unweighted, 0.500 weighted
regression target, training days per bin: [1, 2, 5, 49, 385, 1049, 174, 61, 29, 16, 9, 10, 8, 6, 7, 5, 3, 1, 2, 1]
weight of a typical day: 1; mean weight of the 1% largest rises: 331; share of all training weight on those 19 days: 30%

The dry class is mostly the season: nearly every dry day falls in August to October, so day of year alone predicts much of it. Drought monitors rank soil moisture against the same time of year; a fairer target is the driest tenth for that calendar week of the training years. The dry share rises in the test years because 2023 and 2024 were dry and the 2023 outage removed wet-season days. The response to precipitation falls as the soil gets wetter, so today’s soil moisture belongs among the regression inputs.

Weighting the dry class up tells the model dry days are as common as wet ones, so its probabilities must be read against the real base rate. Split first, then balance only the training data, and judge a rare class by recall and precision, not accuracy. For the skewed regression target, cap inverse-frequency weights (for example at 10), or the handful of storms printed above carries the fit, and report errors per quantile of the target.

Question 7.3 (if you have time, with Your turn 7b). Your choices, and the training share of the dry class as a fraction: your dry_share["train"] from Your turn 7a.

not answered yet
Notebook Cell
correct. Every step has a place; check that each also has a reason.
correct. Several tasks fit this question; the target you named decides which.
correct. And the base rate differs between the splits: a model trained on wetter years meets drier ones, and the 2023 outage removed wet-season days from the test years.

Part 8. Instructions for an AI tool (about 7 min, if you have time)

In class. Give an AI tool your twin file and these instructions, and compare its findings with yours. The twin test stays in this notebook (ai_findings, ai_comparison); item (d) is a separate conversation on the real data with your two files. UW Purple cannot run code or read binary files: upload the CSV. Claude or GitHub Copilot in VS Code can run the computation.

The attached CSV is a daily record from one station in eastern Washington, 2015 to 2024: air
temperature (C), precipitation (mm/day), volumetric soil moisture (m3/m3) and soil temperature (C)
at 5, 10, 20, 50 and 100 cm. Blank cells are missing; a depth is blank when its soil is frozen.
1. List every problem a sensor, the datalogger, the processing or a person put in this table:
   kind, column, first and last date, physical reason. Do not change the file.
2. Compute the least-squares slope of the daily change in sm_5cm against precip_mm (m3/m3 per
   10 mm), on days with at least 2 mm and st_5cm above 0 C that day and the day before, as given
   and after removing the problems you found. Show your code.

By Friday. From the templates in lab_s07_templates/, write and submit:

  • reproducibility_rules.md: rules an AI tool must follow on your project data, built on the six AGENTS.md headings of HW1 (1.9, Step 7) and the class rubric, each checkable yes or no;

  • pipeline_instructions.md: how an AI tool goes from the ten NCEI files to the response to rain on the real 5 cm series, with the checks, the cleaning reasons (flag, remove, or keep a real extreme such as 29 June 2021) and what it could not do;

  • ai_conversation.md (the transcript may be a PDF beside it): your record of trying both files on the real data with UW Purple (with the course copy as text, or the CSV printed below), Claude or GitHub Copilot, and what you checked and corrected;

  • a two- or three-sentence Canvas comment on it.

twin file for the test:       s07_my_files/soil_twin_class.csv
real data as CSV for Purple:  s07_my_files/uscrn_WA_Spokane_17_SSW_2015-2024.csv
real data, file as read, codes left in as numbers: 2.0196 m3/m3 per 10 mm on 522 days
real data, codes as blanks (all cleaning): 0.0179 m3/m3 per 10 mm on 450 days
not answered yet

Question 8.1. What did the tool miss or invent, and did it treat a real extreme as an error? Compare its cleaned response with your r_cleaned and r_truth.

not answered yet

Wrap-up (about 5 min)

Three answers, two to four sentences each, each with one number or date from today’s work:

  1. What is one daily soil moisture value, physically: what volume of soil, how many readings, which conversions and removals stand between probe and number?

  2. Which planted problem moved your derived quantity most, and why could cleaning not fully undo it?

  3. For your project data: one sensor or processing problem you will check first, and the physical test.

not answered yet

Sources

  • Data: Palecki, M.A., et al. (2015): United States Climate Reference Network (USCRN) Processed Data from the Version 2 USCRN Database. daily01, WA_Spokane_17_SSW, 2015 to 2024. NOAA NCEI, doi:10.7289/V5MS3QR9. Public domain (NCEI Open Data Policy).

  • NCEI: Why the USCRN is needed, https://www.ncei.noaa.gov/access/crn/why.html.

  • Bell, J.E., et al. (2013): U.S. Climate Reference Network soil moisture and temperature observations. Journal of Hydrometeorology, 14, 977 to 988, doi:10.1175/JHM-D-12-0146.1.

  • NCEI (2022): Correction to process converting Stevens HydraProbe real dielectric to volumetric soil moisture, https://www.ncei.noaa.gov/pub/data/uscrn/publications/events/Correction to Volumetric Soil Moisture 10202022.pdf.

  • Diamond, H., et al. (2019): An evaluation of the use of the Acclima soil moisture/temperature probe for the USCRN as a replacement for the existing Hydra soil probe. USCRN Technical Memorandum USCRN-19-001, https://www.ncei.noaa.gov/pub/data/uscrn/documentation/research/NOAA-Tech-Memo-Soil-FINAL-AUGUST 2019.pdf.

  • Seyfried, M.S., et al. (2005): Dielectric loss and calibration of the Hydra Probe soil water sensor. Vadose Zone Journal, 4, 1070 to 1079, doi:10.2136/vzj2004.0148.

  • Philip, S.Y., et al. (2022): Rapid attribution analysis of the extraordinary heat wave on the Pacific coast of the US and Canada in June 2021. Earth System Dynamics, 13, 1689 to 1713, doi:10.5194/esd-13-1689-2022.

  • Bretherton, C.S., et al. (1999): The effective number of spatial degrees of freedom of a time-varying field. Journal of Climate, 12, 1990 to 2009, doi:10.1175/1520-0442(1999)012<1990:TENOSD>2.0.CO;2.

  • Hargreaves, G.H., and Z.A. Samani (1985): Reference crop evapotranspiration from temperature. Applied Engineering in Agriculture, 1, 96 to 99, doi:10.13031/2013.26773 (the twin’s evaporation).

  • Map: Natural Earth 1:50m coastline and borders, public domain.

Summary

Run this cell last, save, and upload the notebook with the Part 8 files.

==== SESSION 7 SUMMARY ====
track: soil
netid: not answered
parts answered: P0 0/1 | P1 0/4 | P2 0/7 | P3 0/6 | P4 0/5 | P5 0/6 | P6 0/4 | P7 0/5 | P8 0/2
self-checks passed: 0 of 37
planted problems found: not answered (seed 629)
derived quantity (truth / as given / after cleaning): not answered / not answered / not answered m3/m3 per 10 mm
reflection 1: not answered
reflection 2: not answered
reflection 3: not answered
==== END SUMMARY ====