to get the file

advertisement
Further Investigations of Energy Balance
CENTER FOR EMBEDDED NETWORKED SENSING
1. Sap flow theory and sensors
1. Visit sap flow tree to see installation
2. Lucas downloads sap flow data wirelessly
2. Henry presents R Survey
3. More energy balance equations!
4. Modeling sub-surface soil temperatures:
1. Analytical model
2. Damping depth
3. Fourier Transforms for periodic data
Science Motivation
CENTER FOR EMBEDDED NETWORKED SENSING
Being able to model and predict sub-surface soil
temperatures will allow us to better understand the
interactions of temperature with the biological components
of the soil. For instance:
1. CO2 fluxes that are observed in forest soil environments
are spatially and temporally heterogeneous and are
difficult to predict, influencing estimates of total carbon
fluxes of forests (Davidson et al. 1998; Trumbore 2006).
2. Thermal environments in soils along costal areas
influence the composition of algae, plant, and animal
communities (Whitecraft and Levin 2007; Bortolus et al.,
2002)
Science Motivation
CENTER FOR EMBEDDED NETWORKED SENSING
Surface measurements are much more easy to conduct
than sub-surface measurements with buried probes.
Because the soil surface temperature depends on periodic
energy inputs, we should be able to measure a few
parameters, then calculate the soil temperatures at depth
using a Fourier series and an analytical model.
A Fourier series decomposes a periodic function or
periodic signal into a sum of simple sines and cosines.
“Fourier series were introduced by Joseph Fourier (1768–
1830) for the purpose of solving the heat equation in a
metal plate. It led to a revolution in mathematics…”
Soil Energy Balance
CENTER FOR EMBEDDED NETWORKED SENSING
Net radiation − Stored heat flux − Sensible heat flux = Latent heat flux
(solar)
(change in temp)
(air/water)
(evaporation)
(Rn)
(G)
(H)
(L)
Soil Temperature
CENTER FOR EMBEDDED NETWORKED SENSING
Soil temperatures decrease
in amplitude and shift in
time with depth.
Different locations with
different solar input (shading)
will have different water
content and soil
characteristics. These
differences will result in
different “damping depths”,
the parameter that describes
the attenuation and delay of
the daily temperature peak.
First Approximation – a sine wave
CENTER FOR EMBEDDED NETWORKED SENSING
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
Tz  T
surf
 T
surf
e
z / d
 2 t 2 tmax z 
cos 

 
p
d
 p
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
Tz  T
•
•
•
•
•
•
•
surf
 T
surf
e
z / d
 2 t 2 tmax z 
cos 

 
p
d
 p
z is the depth at which we want to model temperature.
T surf is the average temperature at the surface
T surf is the amplitude of the temperature fluctuation
d is the damping depth
t is the time
p is the period
tmax is the time at which the surface temperature wave
is at its maximum.
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
Tz  T
•
•
•
•
•
•
•
surf
 T
surf
e
z / d
 2 t 2 tmax z 
cos 

 
p
d
 p
z is the depth at which we want to model temperature.
T surf is the average temperature at the surface
T surf is the amplitude of the temperature fluctuation
d is the damping depth
t is the time
p is the period
tmax is the time at which the surface temperature wave
is at its maximum.
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
Calculating damping depth based on decrease in amplitude and phase shifts
JR soil
Avg. T
(°C)
T max
(°C)
Amplitude
(°C)
e-1 damp
(37%)
time for max
(d)
Surface
27.18
72.60
30.95
26.71
1.58428
8 cm depth
23.52
33.13
8.44
12.19
1.65270
T 8cm  T surf e  z / d
2t z

p
d
Decrease in amplitude (damping)
Phase shift (delay)
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
Calculating damping depth based on decrease in amplitude and phase shifts
JR soil
Avg. T
(°C)
T max
(°C)
Amplitude
(°C)
e-1 damp
(37%)
time for max
(d)
Surface
27.18
72.60
30.95
26.71
1.58428
8 cm depth
23.52
33.13
8.44
12.19
1.65270
-z
d
8
s
ln( T )  ln( T )
d  6.16 cm
p z
1 8
d

2 t 2 (1.6527  1.58428)
d  18.61cm
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
Damping depth can also be
calculated from soil physical
properties.
d
2
C

2

Example here is dry soil from
a temperate forest.
Damping depth is related to
frequency of the temperature
pulse ( = 2π/period) and:
 = thermal conductivity
C = volumetric heat capacity
 = thermal diffusivity
Thus, for a 86400 s period and damping depth of 15 cm,  = 8 × 10-7 m2 s-1.
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
Damping depth can also be
calculated from soil physical
properties.
Example here is dry soil from
a temperate forest.
Damping depth is related to
frequency of the temperature
pulse ( = 2π/period) and:
d
C

2

soil

C

Sand
1.11
2.41
4.61
Clay loam
0.57
2.61
2.18
1.77
3.19
5.54
Clarion soil
 = thermal conductivity
(W m-1 °C)
C = volumetric heat capacity
(MJ m-3 °C-1)
 = thermal diffusivity
(10-7 m2 s-1)
2
(fine-loamy)
Thus, for sand, d = 3.56 cm
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
Damping depth can also be
calculated from a finite
difference equation, provided
enough data:
T jn 1  T jn
 t

T jn1  2T jn  T jn1
( z )2
Example sine waves (time
interval is 0.5 minutes between
temperature readings). n is the
sequential measurement and j is
the depth of that measurement.
Use R to fit the data to the
model (we will fit data to a model
a little later).
Parameters: Estimate
 = 7.796e-06
d = 14.64 cm
Std. Error
t value
Pr(>|t|)
7.939e-09
982
<2e-16 ***
Fourier Transforms
CENTER FOR EMBEDDED NETWORKED SENSING
Fourier frequency
decomposition.
A Fourier transform will take
a signal and decompose it
into a series of superimposed
sine waves, each with a
shorter period (higher
frequency) and each with a
magnitude that determines
the sine wave’s influence on
the original signal.
Fourier Transforms
CENTER FOR EMBEDDED NETWORKED SENSING

f (t )  F0   (2an ) cos n0t  (2bn ) sin n0t
n 1
Fourier Transforms
CENTER FOR EMBEDDED NETWORKED SENSING

f (t )  F0   (2an ) cos n0t  (2bn ) sin n0t
n 1
Fourier Transforms
CENTER FOR EMBEDDED NETWORKED SENSING
PASI Soil Temperature Exercise #1
CENTER FOR EMBEDDED NETWORKED SENSING
Practice with one year of soil temperature data from Puerto
Cuatreros, provided by Cintia.
• Look at some built-in R time series functions.
• Explore some visualizations in R.
• Fourier Transform the data near the surface and reconstruct
the temperature signal for a check of the method.
• Estimate damping depth using a few methods.
• Apply the analytical equation with damping depth to a Fourier
series to predict sub-surface temperatures.
• Calculate the heat stored and lost in a daily and annual cycle.
Exercise: Explore the data that Cintia provided on Tuesday,
estimating damping depths and calculating heat lost and stored
and soil heat flux.
R – an Integrated Statistical Package
CENTER FOR EMBEDDED NETWORKED SENSING
R is a free software
environment for
statistical computing
and graphics. It
compiles and runs on
a wide variety of UNIX
platforms, Windows
and MacOS.
www.r-project.org
Program installation
should be on the
server for both Mac
OS X and for
Windows
R – Install and change working directory
CENTER FOR EMBEDDED NETWORKED SENSING
After R is installed,
copy the files
included in the
subdirectory “R” on
the CD to your hard
drive.
Next, start R and
then change the
working directory to
the subdirectory
you just copied onto
your hard drive.
We are now ready
to start playing in R!
R-sig-ecology list serve:
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Puerto Cuatreros Soil Temperature Data
Commands
CENTER FOR
inEMBEDDED NETWORKED SENSING
black
Comments in
green
Output in blue
R Cursor in red
Puerto Cuatreros Soil Temperature Data
CENTER FOR EMBEDDED NETWORKED SENSING
> temps = read.table(file=file.choose(), header=TRUE, sep=",")
## navigate to the file, composite_data_set_interpolated.csv and click OK
> temps[1:10,] ## display first 10 rows; data in the array are [rows, columns]
Fecha, Hora, running_time, T_sed_25cm, T_sed_5cm , T_sed_15cm, T_aire_agua_5cm
1 37622.00 37622.00
2 37622.01 37622.01
3 37622.01 37622.01
4 37622.02 37622.02
5 37622.03 37622.03
6 37622.03 37622.03
7 37622.04 37622.04
8 37622.05 37622.05
9 37622.06 37622.06
10 37622.06 37622.06
1.000000
1.006944
1.013889
1.020833
1.027778
1.034722
1.041667
1.048611
1.055556
1.062500
21.26
21.26
21.26
21.28
21.26
21.26
21.26
21.26
21.26
21.26
21.22
21.10
21.00
20.92
20.82
20.78
20.70
20.64
20.56
20.48
21.76
21.74
21.70
21.68
21.66
21.64
21.64
21.62
21.56
21.56
17.94
17.86
17.94
17.86
17.90
17.92
17.62
17.64
17.74
17.48
Puerto Cuatreros Soil Temperature Data
CENTER FOR EMBEDDED NETWORKED SENSING
> attach(temps)
## “attach” the data so we can use column names
> summary(temps) ## get summary statistics for each column
Fecha
Min. :37622
1st Qu.:37713
Median :37804
Mean :37804
3rd Qu.:37896
Max. :37987
Hora
Min. :37622
1st Qu.:37713
Median :37804
Mean :37804
3rd Qu.:37896
Max. :37987
running_time
Min. : 1.00
1st Qu.: 92.25
Median :183.50
Mean :183.50
3rd Qu.:274.74
Max. :365.99
T_sed_25cm
Min. : 4.86
1st Qu.: 9.70
Median : 15.54
Mean : 14.66
3rd Qu.: 19.60
Max. :1081.83
T_sed_5cm…
Min. :-0.800
1st Qu.: 9.168
Median :15.020
Mean :14.432
3rd Qu.:19.610
Max. :31.920
> T_aire_agua_5cm[1:10] ## use column names to explore the data
> plot(running_time, T_sed_5cm)
## plot the first column (day) vs. surface temperature
Puerto Cuatreros Soil Temperature Data
CENTER FOR EMBEDDED NETWORKED SENSING
Puerto Cuatreros Soil Temperature Data
CENTER FOR EMBEDDED NETWORKED SENSING
> plot(running_time, T_sed_5cm,”l”)
Puerto Cuatreros Soil Temperature Data
CENTER FOR EMBEDDED NETWORKED SENSING
> lines(running_time, T_sed_15cm, col="red")
Puerto Cuatreros Soil Temperature Data
CENTER FOR EMBEDDED NETWORKED SENSING
> plot(running_time, T_sed_5cm, xlim=c(190,197), ylim=c(-2,10),"l")
Puerto Cuatreros Soil Temperature Data
CENTER FOR EMBEDDED NETWORKED SENSING
> lines(running_time, T_sed_15cm, xlim=c(190,197), ylim=c(-2,10),"l",col="red")
Time-series Data in R - decomposition
CENTER FOR EMBEDDED NETWORKED SENSING
“Traditional” Seasonal-Trend Decomposition (STL)
Seasonal effects tend to obscure the trends and short term variation present
in a time series. A time series can be considered to comprise three
components: a trend component T (m), a seasonal component S(m) and a
remainder R(m), sometimes referred to as the irregular component:
Y (m) = T (m) + S(m) + R(m)
Where Y (m) is the time series of interest. This is often used in predicting
trends in stock markets or housing prices.
The locally weighted regression smoothing technique (Loess) developed by
Cleveland (1979) has been widely used in data analysis. The STL method
consists of a series of applications of a Loess smoother with different moving
window widths chosen to extract different frequencies within a time series.
Cleveland, W. S.: Robust Locally Weighted Regression And Smoothing Scatterplots, Journal
Of The American Statistical Association, 74(368), 829–836, 1979.
Time-series Data in R - decomposition
CENTER FOR EMBEDDED NETWORKED SENSING
Measurements were recorded once every 10 min, so we will consider
these data on a daily-cycle.
Turn a week of data into an R time series object:
> data_week = ts(T_sed_5cm[which(running_time ==190):
+ which(running_time == 197)], freq=144) ## “seasonal” window of 1 day
> data_year = ts(T_sed_5cm,freq=144) ## turn a year of data into a time series
> plot(stl(data_week, s.window=144))
> x11()
> plot(stl(data_year, s.window=144))
Time-series Data in R - decomposition
CENTER FOR EMBEDDED NETWORKED SENSING
Decomposition of a week of data
Decomposition of a year of data
Fourier Transform of the Data
CENTER FOR EMBEDDED NETWORKED SENSING
> fft_5cm = fft(T_sed_5cm)
> fft_5cm[1:9]
## Fast Fourier transform of the 5 cm depth
## temperature data, show first 9 values
[1] 758571.610 +0.000i 197561.578 -35009.833i -30579.716 +13401.850i
[4] -11910.682 -4921.751i -2239.368 -6697.865i 18918.054 +7773.016i
[7] -3051.685 +6746.495i -18117.349 +5790.106i -2304.731 -8429.100i
Complex numbers representing magnitudes of frequency components of
the FFT.
Real + Imaginary in the form of x + yi
-2304.731
Real
- 8429.100i
Imaginary
Fourier Transforms – R
CENTER FOR EMBEDDED NETWORKED SENSING
## Mod() Returns the absolute value (modulus) of a complex number of x + yi:
> val_fft_5cm = Mod(fft_5cm) ## then divide by total number to get back values
> val_fft_5cm = val_fft_5cm / length(val_fft_5cm)
> val_fft_5cm[1:9]
[1] 14.4324888 3.8173448 0.6352274
[4] 0.2451962 0.1343666 0.3891303
[7] 0.1408788 0.3618738 0.1662577
> barplot(val_fft_5cm, xlim = c(1,20))
## bar plot with only first 20 rows
First term is the Constant, the
second is the 365-day period, the
third is the 182.5-day period, the
fourth is 365/3, the fifth is…?
Fourier Transforms – R
CENTER FOR EMBEDDED NETWORKED SENSING
Note: Results of the transform are symmetric…
> barplot(val_fft_5cm[2:length(val_fft_5cm)])
Also note: how to save graphical images to disk:
> png(file="wholebar.png", width=600, height=600)
> barplot(val_fft_5cm)
> dev.off()
Fourier Transforms – R
CENTER FOR EMBEDDED NETWORKED SENSING
To get the period values:
## divide number of days by a series: 1, 2, 3, 4…
> period = 365 / seq(0,length(val_fft_5cm))
> period [1:10]
[1] Inf 365.00000 182.50000 121.66667
[5] 91.25000 73.00000 60.83333
[8] 52.14286 45.62500 40.55556
The first period (Infinity) is really just the
constant offset (14.4 °C)
The second period is 365 days and is the
largest component visible, which means
it is contributing to the overall signal the
most.
Fourier Transforms – R
CENTER FOR EMBEDDED NETWORKED SENSING
How many components do we really need?
> which(val_fft_5cm >0.5)
[1]
1
> which(val_fft_5cm >0.1)
[1]
[11]
[20]
[29]
[38]
[46]
1
11
25
40
341
392
## which() identifies the index
of a value – its location in the
matrix.
2
?
3 366 52196 52559 52560...
2 3 4 5 6 7 8 9 10
14 15 16 17 19 20 23 24
26 27 28 29 30 33 35 37
41 42 45 50 62 63 84 340
359 364 365 366 367 368 381
731 1071 51491 51831 52170...
So, what are these points – what do they correspond to?
> period[1]
> period[2]
> period[3]
> period[366]
[1]
[1]
[1]
[1]
Inf
365
182.5
1
Fourier Transforms – R
CENTER FOR EMBEDDED NETWORKED SENSING
> barplot(val_fft_5cm[1:400])
Fourier Transforms – R
CENTER FOR EMBEDDED NETWORKED SENSING
> x11()
> barplot(val_fft_5cm[360:370])
## x11() opens up a new
graphical window
Fourier Transforms – R
CENTER FOR EMBEDDED NETWORKED SENSING
Reconstruction, to take some of the components and estimate the signal

f (t )  F0   (2an ) cos n0t  (2bn ) sin n0t
n 1
Real
0 = π / period
Imaginary
> omega = 2*pi / 365
## easier notation
> t = running_time
> F0 = Re(fft_5cm[1]) / length(fft_5cm)
## Constant offset is the first Real component divided by length
## 365 day sine wave reconstruction
> transform_365d = ((2 * Re(fft_5cm[2]) * cos(omega * 1 * t)) - (2 *
+ Im(fft_5cm[2]) * sin(omega * 1 * t)))/length(fft_5cm)
Fourier Transforms – R
CENTER FOR EMBEDDED NETWORKED SENSING
> transform_182d = ((2 * Re(fft_5cm[3]) * cos(omega * 2 * t)) - (2 *
+ Im(fft_5cm[3]) * sin(omega * 2 * t)))/length(fft_5cm)
## half-year sine wave reconstruction, above
> transform_1d = ((2 * Re(fft_5cm[366]) * cos(omega * 365 * t)) - (2 *
+ Im(fft_5cm[366]) * sin(omega * 365 * t)))/length(fft_5cm)
## one day sine wave reconstruction, above
> summation = F0 + transform_365d + transform_182d + transform_1d
## add them up and plot original plus new estimate
> plot(running_time,T_sed_5cm, ylim = c(0,30),'l')
> lines(running_time,summation,col="red")
Fourier Transforms – R
CENTER FOR EMBEDDED NETWORKED SENSING
Fourier Transforms – R
CENTER FOR EMBEDDED NETWORKED SENSING
> plot(running_time,T_sed_5cm, xlim=c(190,197), ylim=c(-2,10),'l')
> lines(running_time,summation, col="red")
Fourier Transforms – R
CENTER FOR EMBEDDED NETWORKED SENSING
Use more components, using a For loop:
> F0 = Re(fft_5cm[1]) / length(fft_5cm) ## the constant term
> summation = F0
> for(n in 1:366) {
## a loop that repeats 366 times, using n as a counter
+
+
transform = ((2 * Re(fft_5cm[n+1]) * cos(omega * n * t)) - (2 *
Im(fft_5cm[n+1]) * sin(omega * n * t))) / length(fft_5cm)
+
summation = summation + transform
+
}
## sum each new estimation into
one variable
> plot(running_time,T_sed_5cm, ylim = c(0,30),'l')
> lines(running_time,summation,col="red")
Fourier Transforms – R
CENTER FOR EMBEDDED NETWORKED SENSING
Fourier Transforms – R
CENTER FOR EMBEDDED NETWORKED SENSING
Look at a smaller section and the major components:
> t1 = which(running_time == 190)
> t2 = which(running_time == 197)
> T_5_7d = T_sed_5cm[t1:t2]
> week_time = running_time[t1:t2]
> week_time = week_time - 190 ## start from zero
> T_5_7d_fft = fft(T_5_7d)
> val_ T_5_7d_fft = Mod(T_5_7d_fft ) /
+ length(T_5_7d_fft )
> barplot(val_T_5_7d_fft , xlim = c(1,50))
> period = 7 / seq(0,length(val_T_5_7d_fft ))
> period[1:15]
[1] Inf 7.00 3.50 2.33 1.75
[6] 1.40 1.17 1.00 0.88 0.78
[11] 0.70 0.64 0.58 0.54
[15] 0.500
Fourier Transforms – R
CENTER FOR EMBEDDED NETWORKED SENSING
Sum the first 25 elements (up to a ¼ day cycle):
> F0 = Re(T_5_7d_fft[1]) / length(T_5_7d_fft)
> omega = 2*pi / 7
> summation = F0
> for(n in 1:25) {
+
+
+
transform = ((2 * Re(T_5_7d_fft[n+1]) * cos(omega * n * week_time)) –
(2 * Im(T_5_7d_fft[n+1]) * sin(omega * n * week_time))) /
length(T_5_7d_fft)
+
summation = summation + transform
+
}
> plot(week_time, T_5_7d ,"l")
> lines(week_time,summation,col="red")
Fourier Transforms – R
CENTER FOR EMBEDDED NETWORKED SENSING
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
Tz  T
•
•
•
•
•
•
•
surf
 T
surf
e
z / d
 2 t 2 tmax z 
cos 

 
p
d
 p
z is the depth at which we want to model temperature.
T surf is the average temperature at the surface
T surf is the amplitude of the temperature fluctuation
d is the damping depth for a specific period
t is the time
p is the Fourier period
tmax is the time at which the surface temperature wave
is at its maximum.
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
What is the damping depth?
Example here is tidal flat soil
(Beigt et al. 2003) with  of about
3.78 × 10-7.
Damping depth is related to
frequency of the temperature
pulse ( = 2π/period) and:
 = thermal conductivity
C = volumetric heat capacity
 = thermal diffusivity
d
2λ
Cω

2κ
ω
> w = 2 * pi / 86400
> sqrt(2 * 3.78e-7 / w)
[1] 0.1019595
Thus, for a period of 86400 s, a damping depth for tidal flat soil is 10.2 cm.
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
Damping depth can also be
calculated from thermal
diffusivity using a finite
difference equation.
T jn 1  T jn
 t

T jn1  2T jn  T jn1
( z )2
Let’s use the week’s worth of data for calculating the , using the 5, 15, and
25 cm data. Tj is the temperature at 15 cm:
> T_15_7d = T_sed_15cm[t1:t2] ## subset the 15 cm data
> T_25_7d = T_sed_25cm[t1:t2]
> dT = diff(T_15_7d) ## takes difference between rows (n is now n-1)
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
Create a model and fit the
data to the model using
Nonlinear Least Squares
(nls).
T jn 1  T jn
 t

T jn1  2T jn  T jn1
( z )2
dT
bigT

 t ( z ) 2
We know t and z, so we rearrange the equation and
provide a starting ‘guess’
for the value of .
> bigT = T_25_7d - 2 * T_15_7d + T_5_7d
> bigT = bigT[1:length(bigT)-1] ## make the same length as dT
> model <- nls(dT ~ I(k * bigT / (0.15)^2 * 600), start=list(k=0.000001))
> summary(model)
k
Estimate
1.253e-06
Std. Error
2.476e-08
t value
50.61
Pr(>|t|)
<2e-16 ***
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
Damping depth from the
finite difference model and
the relationship between
damping depth and thermal
diffusivity (and thermal
conductivity and
volumetric heat capacity):
d
2
C
> k = as.numeric(coef(model))
> sqrt(2 * k / (2 * pi / 86400))
[1] 0.1856545
Which equals 18.5 cm for a 24 h damping depth

2

Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
Tz  T
surf
 T
surf
e
z / d
 2 t 2 tmax z 
cos 

 
p
d
 p
Damping depth can also be calculated using a period of the
Fourier decomposition for two different depths. Let’s use the
week’s worth of data from before:
> T_5_7d_fft = fft(T_5_7d) ## get the Fourier transform for the 5 cm depth
> T_15_7d_fft = fft(T_15_7d)
## get the single day component
>n=8
> T_5_7d_trans = ((2 * Re(T_5_7d_fft[n+1]) * cos(omega * n * week_time)) + (2 * Im(T_5_7d_fft[n+1]) * sin(omega * n * week_time))) / length(T_5_7d_fft)
> T_15_7d_trans = ((2 * Re(T_15_7d_fft[n+1]) * cos(omega * n * week_time)) + (2 * Im(T_15_7d_fft[n+1]) * sin(omega * n * week_time))) / length(T_15_7d_fft)
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
Tz  T
surf
 T
surf
e
z / d
 2 t 2 tmax z 
cos 

 
p
d
 p
> plot(week_time,T_5_7d_trans,"l")
> lines(week_time,T_15_7d_trans,col="red")
Each Fourier transform starts
at time = 0, so if there is a
delay or shift in time between
different Fourier transforms,
then we need to add that back
in.
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
Tz  T
surf
 T
surf
e
z / d
 2 t 2 tmax z 
cos 

 
p
d
 p
> which(T_5_7d == max(T_5_7d))
[1] 954
> which(T_15_7d == max(T_15_7d))
[1] 962 963
> time_shift = week_time[962] - week_time[954]
> time_shift
[1] 0.0555555
> time_shifted = week_time - time_shift
We want the deeper layer to be delayed, so time for the transform should
“appear” earlier relative to the shallower layer
> T_15_7d_trans = ((2 * Re(T_15_7d_fft[n+1]) * cos(omega * n * time_shifted)) + (2 * Im(T_15_7d_fft[n+1]) * sin(omega * n * time_shifted))) / length(T_15_7d_fft)
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
Tz  T
surf
 T
surf
e
z / d
 2 t 2 tmax z 
cos 

 
p
d
 p
So, since we have nice , clean, “artificial” data, a nls will not
work. We need to solve for d using plain old algebra:
Damping:
> z = 10 ## centimeters
> dT = max(T_5_7d_trans)
> Tz = max(T_15_7d_trans)
log(Tz) = log(dT * e-z/d) = log(dT) + log(e-z/d)
> d = -z / (log(Tz) - log(dT))
>d
[1] 6.19422
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
Tz  T
surf
 T
surf
e
z / d
 2 t 2 tmax z 
cos 

 
p
d
 p
Delay: z / d = (2 * pi * time shift) / p
> d = z / (2*pi*time_shift )
>d
[1] 28.64792
Lots of different estimates of damping depth… which one to use??
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
d
2
C

2

Let’s start with the soil properties-based estimate:
## estimated soil thermal diffusivity
> k = 1.253e-06
## create sequence from 1 to 25
> damping=seq(1:25)
> damping=sqrt(2 * k / (2 * pi / (86400 * 7 / damping)))
> damping
[1] 0.49114134 0.34728937 0.28356058 0.24557067 0.21964508
[6] 0.20050761 0.18563398
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
Let’s use two day’s worth of data at 5 cm to estimate the temperature at
15 cm depth:
> t1 = which(running_time == 194)
> t2 = which(running_time == 196)
> T_5_2d = T_sed_5cm[t1:t2]
> T_5_2d_fft = fft(T_5_2d)
> val_T_5_2d_fft = Mod(T_5_2d_fft ) /
+ length(T_5_2d_fft )
> barplot(val_T_5_2d_fft , xlim = c(1,50))
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
> period = 2 / seq(0,length(val_T_5_2d_fft ))
> period [1:10]
[1] Inf 2.0000000 1.0000000 0.6666667
[5] 0.5000000 0.4000000 0.3333333
[8] 0.2857143 0.2500000 0.2222222
> d2_time = running_time[t1:t2]
> d2_time = d2_time - 194
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
d
2
C

2

Let’s start with the soil properties-based estimate of damping depth and
estimate the different damping depths for the two-day sequence:
## estimated soil thermal diffusivity
> k = 1.253e-06
## create sequence from 1 to 10
> damping=seq(1:10)
> damping=sqrt(2 * k / (2 * pi / (86400 * 2 / damping)))
> damping
[1] 0.26252609 0.18563398 0.15156951 0.13126304 0.11740524
[6] 0.10717583 0.09922553 0.09281699 0.08750870 0.08301804
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
This is how we did it last time:
> F0 = Re(T_5_2d_fft[1]) / length(T_5_2d_fft)
> omega = 2*pi / 2
> summation = F0
> for(n in 1:10) {
+
+
+
transform = ((2 * Re(T_5_2d_fft[n+1]) * cos(omega * n * d2_time)) –
(2 * Im(T_5_2d_fft[n+1]) * sin(omega * n * d2_time))) /
length(T_5_2d_fft)
+
summation = summation + transform
+
}
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
Tz  T
surf
 T
surf  z / d
e
 2 t 2 tmax z 
cos 

 
p
d
 p
> for(n in 1:10) {
+
+
transform = ((2 * Re(T_5_2d_fft[n+1]) * cos(omega * n * d2_time)) - (2 *
Im(T_5_2d_fft[n+1]) * sin(omega * n * d2_time))) / length(T_5_2d_fft)
+
+
+
+
dT = max(transform)
exponent = exp(-.10/damping[n])
tmax=d2_time[which(transform==
max(transform[1:(length(transform)/(n+1))]))]
+ depth_estimate = dT * exponent * cos(omega * n * d2_time +
2*pi*tmax[1]-z/damping[n])
+
+ summation = depth_estimate + summation
+ }
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
> T_15_2d = T_sed_15cm[t1:t2]
> plot(d2_time,T_15_2d,ylim=c(3,8))
> lines(d2_time,summation,col="red")
We used d = 18.56 cm, which is
too big. Plus an absolute value shift.
Use d = 12 as a next guess,
(k = 0.5e-6), and move up by 1°C
because of multi-day trends that are
not represented:
> summation = summation + 1
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
CENTER FOR EMBEDDED NETWORKED SENSING
Exercise: Explore the data that Cintia provided on Tuesday,
estimating damping depths and calculating heat lost and stored
and soil heat flux. Data has been put into one file and missing
data have been interpolated: St_all_data.csv
Let’s determine:
1. Damping depth using…?
2. Model sub-surface temperatures from surface measurements (using
5 cm estimate 15 cm and using 25 cm estimate 50 cm).
1. Fourier transform the shallow depth.
2. Apply the analytical model for the first n frequencies.
3. Plot against the actual values.
3. Calculate heat stored in the soil down to 25 cm and 50 cm.
4. Calculate the heat flux at 5 cm using 50 cm estimated temperatures.
Gsurface  K
soil
T
T
 CpZ
z
t
K
soil
 W m 1 C 1

Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
We modeled the 5 cm
depth using Fourier
transformed data and
then reconstructed (in
the red).
We will now take each
component sine wave
of the reconstruction
and apply the subsurface prediction
model to it. Then we
will sum them up and
see how well the
model did at
predicting
temperature at 15 cm.
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
This is how we reconstructed it last time:
Sum the first 25 elements (up to a ¼ day cycle):
> F0 = Re(T_sed_5cm_7d_fft[1]) / length(T_sed_5cm_7d_fft)
> omega = 2*pi / 7
> summation = F0
> for(n in 1:25) {
+
+
+
transform = ((2 * Re(T_5_7d_fft[n+1]) * cos(omega * n * week_time)) –
(2 * Im(T_5_7d_fft[n+1]) * sin(omega * n * week_time))) /
length(T_5_7d_fft)
+
summation = summation + transform
+
}
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
Tz  T
> for(n in 1:25) {
surf
 T
surf  z / d
e
 2 t 2 tmax z 
cos 

 
p
d
 p
+
+
transform = ((2 * Re(T_5_7d_fft[n+1]) * cos(omega * n * week_time)) - (2 *
Im(T_5_7d_fft[n+1]) * sin(omega * n * week_time))) / length(T_5_7d_fft)
+
+
+
+
dT = max(transform)
exponent = exp(-.10/damping[n])
tmax=week_time[which(transform==
max(transform[1:(length(transform)/(n+1))]))]
+ depth_estimate = dT * exponent * cos(omega * n * week_time+
2*pi*tmax[1]-z/damping[n])
+
+ summation = depth_estimate + summation
+ }
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
> plot(week_time, T_15_7d, ylim = c(-1,11) ,"l")
> lines(week_time, summation, col="red")
The estimated temperature
and the actual sub-sufrace
temperature have similar
magnitudes (good) but the
predicted values are
delayed too much (bad).
Also, multi-day patterns
influence the signals and
the structure is not as
matched as desirable.
What else is causing
temperature fluctuations on
the mud flats?
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
d
2
C

2

Let’s use a different delay depth of 28.64 cm, as calculated before:
> k = 1.041668e-05
> delay=seq(1:25)
> delay=sqrt(2 * k / (2 * pi / (86400 * 7 / delay)))
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
Re-write the loop with delay in place for the second damping depth
> for(n in 1:25) {
+
+
transform = ((2 * Re(T_5_7d_fft[n+1]) * cos(omega * n * week_time)) - (2 *
Im(T_5_7d_fft[n+1]) * sin(omega * n * week_time))) / length(T_5_7d_fft)
+
+
+
+
dT = max(transform)
exponent = exp(-.10/damping[n])
tmax=week_time[which(transform==
max(transform[1:(length(transform)/(n+1))]))]
+ depth_estimate = dT * exponent * cos(omega * n * week_time+
2*pi*tmax[1]-z/delay[n])
+
+ summation = depth_estimate + summation
+ }
Modeling Sub-surface Temperatures
CENTER FOR EMBEDDED NETWORKED SENSING
> plot(week_time, T_15_7d, ylim = c(-1,11) ,"l")
> lines(week_time, summation, col="red")
Now the estimated
temperature and the actual
sub-sufrace temperature
have similar magnitudes
(good) and the predicted
values are delayed at a
more reasonable value.
For such a short time
period, multi-day patterns
influence the signals and
the structure is not as
matched as desirable... but
it’s not horrible….
Light (PAR) sensing
CENTER FOR EMBEDDED NETWORKED SENSING
Light (PAR) sensing
CENTER FOR EMBEDDED NETWORKED SENSING
$15
$320
$6000
Soil Temperature Sensing
CENTER FOR EMBEDDED NETWORKED SENSING
Soil surface energy example
CENTER FOR EMBEDDED NETWORKED SENSING
Soil surface energy example
CENTER FOR EMBEDDED NETWORKED SENSING
Data for 24 h on July 16,
2007 along a 10.75 m
transect in a temperate
forest:
(A) measured soil surface
temperatures every 0.25
m.
(B) measured (indicated with
arrows) and calculated
soil temperatures at 8 cm
depth using the soil
model and Fourier
transforms.
(C) calculated soil heat flux
at the surface.
(D) calculated heat storage
between the surface and
8 cm depth.
Soil surface energy example
CENTER FOR EMBEDDED NETWORKED SENSING
Data for 24 h on March 3,
2008 along the same
10.75 m transect:
(A) measured soil surface
temperatures every 0.25
m.
(B) measured (indicated with
arrows) and calculated
soil temperatures at 8 cm
depth using the soil
model and Fourier
transforms.
(C) calculated soil heat flux
at the surface.
(D) calculated heat storage
between the surface and
8 cm depth.
Temperature sensing
CENTER FOR EMBEDDED NETWORKED SENSING
Thermistors:
• Accurate over a wide temperature range.
• Good stability over a long life.
• Excellent price/performance ratio (they’re cheap).
• Low heat conductivity through small diameter leads
(depends on application).
Calibration:
• Steinhart-Hart equation
• Polynomial
Temperature sensing
CENTER FOR EMBEDDED NETWORKED SENSING
Vout
Vin
Vout
Rthermistor
 Vin
Rthermistor  R fixed
Temperature sensing
CENTER FOR EMBEDDED NETWORKED SENSING
Temperature sensing
CENTER FOR EMBEDDED NETWORKED SENSING
Temperature sensing
CENTER FOR EMBEDDED NETWORKED SENSING
Soil Heat Flux
CENTER FOR EMBEDDED NETWORKED SENSING
Soil heat flux at the surface can be based upon:
• The heat flux at some depth (measured with a heat flux plate)
and the volumetric heat capacity of soil, or
• A temperature difference in the soil and the thermal
conductivity and volumetric heat capacity of the soil.
T
Gsurface  Gz  C p Z
t
Gsurface  K
soil
C
p
T
T
 CpZ
z
t
 MJ m 3 C 1
K
soil

 W m 1 C 1

SensorKit and Prep for Data Collection
CENTER FOR EMBEDDED NETWORKED SENSING
SensorKit and Prep for Data Collection
Download