Sunday, September 21, 2014

10 Weeks in 10 Seconds

The project has been running for approximately ten weeks. Geologists probably know this better than almost anyone: Ten weeks is a terribly short period. I think if this project lasts a year I will find myself only partially satisfied. Seeing things change (roots grow, leaves decompose, roots get eaten, water saturating the soil in a storm, etc.) is fascinating, but I still have no idea what the changes in seasons or significant temperature change will have on the appearance of the soil. Things to look forward to : )

Wednesday, September 17, 2014

Video / Automation Fun

The latest work on this project has been focused on automation and the last few posts have been a result of that. The next few days should see two posts each day of two slightly different views. Eventually that should change to two or three posts a week showing a compiled video of the past 7 days of footage. In the long run I would love to include some basic automated analysis: level of activity/change in images, brightness, changes in color, temperature & moisture. So far all of this is being done on a Raspberry Pi.

For the moment the automated steps are:
  1. Take the scan (scanimage)
  2. Modify images as needed (cropping, resizing, timestamping via imagemagick)
  3. Consolidate the original images (tar)
  4. Compile the current day's images into a video (mp4 via avconv)
  5. Combine the current day of video with all previous days of video (avconv)
  6. Upload the resulting video to youtube and make a blog post (googlecl)
So far I've written 7 or 8 short bash scripts that I compile into two separate scripts. If you've stumbled across this, please don't use any of this with any expectation that it's "the right way". Suggestions/advice are very, very welcome : )

The first three steps from above run every 15 minutes
#!/bin/bash
#start a 300 dpi scan, convert it to a jpg and flip it vertically
#start scan
sudo /usr/bin/scanimage -l 0mm -t 0mm -x 215mm -y 297mm --format tiff --resolution 300 | sudo /usr/bin/convert - -flip /var/www/tmp/sc_$(date -d "today" +"%Y%m%dT%H%M%S").jpg 
#put files in /var/www/tmp
cd /var/www/tmp/ 
#loop through jpgs in directory
for file in *.jpg; do 
#save cropped version
convert -crop 1920x1080+310+285 $file zleaf_$file; 
#grab date and time from file name
ndate="${file:3:4}\/${file:7:2}\/${file:9:2}"
ntime="${file:12:2}:${file:14:2}:${file:16:2}"
tdate="${file:3:4}_${file:7:2}_${file:9:2}" 
#set appropriate width
width=$(identify -format %W zleaf_${file})
width=$((${width} * 2 / 10 )) 
#apply time stamp to image
convert                  \
     -background '#0008'    \
     -gravity center        \
     -fill white            \
     -size ${width}x50     \
      caption:"${ndate} ${ntime}"      \
      zleaf_"${file}"              \
     +swap                  \
     -gravity south         \
     -composite             \
        "b${file}"
done 
#cleanup / move files to appropriate directories.
mv b$file /var/www/testcaption
if [ -f /var/www/300/300_$tdate.tar ]
then
tar -rvf /var/www/300/300_$tdate.tar $file
        else
tar -cvf /var/www/300/300_$tdate.tar $file
fi
if [ -f /var/www/300Zoom/300Zoom_$tdate.tar ]
        then
                tar -rvf /var/www/300Zoom/300Zoom_$tdate.tar zleaf_$file
        else
                tar -cvf /var/www/300Zoom/300Zoom_$tdate.tar zleaf_$file
fi
sudo rm *.jpg
The last three steps run a few minutes after midnight
#!/bin/bash
testdir=/var/www/testcaption/
prev=$(date -d "yesterday" +"%Y%m%d")
version="0.1"
echo $version >> $testdir/$prev.txt  
echo "begin rename $(date)" >> $testdir/$prev.txt
x=1; for i in b*.jpg; do counter=$(printf %04d $x); mv "$i" ${prev}-"$counter".jpg; x=$(($x+1)); done
echo "end rename: $(date)" >> $testdir/$prev.txt

echo "begin encode $(date)" >> $testdir/$prev.txt
ffmpeg -r 30 -i ${prev}-%04d.jpg -r 30  -vcodec libx264 -crf 20 -g 15 $prev.mp4
echo "end encode $(date)" >> $testdir/$prev.txt

#twodago=$(date -d "2 days ago" +"%Y%m%d")
ongoing=current
onedago=$(date -d "yesterday" +"%Y%m%d")
echo "begin combine $(date)" >> $testdir/$onedago.txt
avconv -y -i $ongoing.mp4 -f mpegts -c copy -bsf:v h264_mp4toannexb $ongoing.mpeg.ts
avconv -y -i $onedago.mp4 -f mpegts -c copy -bsf:v h264_mp4toannexb $onedago.mpeg.ts
avconv -y -isync -i "concat:"$ongoing".mpeg.ts|"$onedago".mpeg.ts" -c copy $ongoing.mp4
echo "end combine $(date)" >> $testdir/$onedago.txt

echo "begin youtube upload $(date)" >> $testdir/$prev.txt
google youtube post --category Tech current.mp4 &> upload.txt
movie=$(grep -o -P '(?<==).*(?=&)' upload.txt)
google blogger post --title "Video Upload: $prev" --src "<iframe width=\"560\" height=\"315\" src=\"//www.youtube.com/embed/$movie\" frameborder=\"0\" allowfullscreen></iframe>"
echo "end youtube upload $(date)" >> $testdir/$prev.txt 
echo "begin cleanup $(date)" >> $testdir/$prev.txt
sudo rm *.jpg
mv ${prev}*.* $testdir/prevdata/
echo "end cleanup $(date)" >> $testdir/prevdata/$prev.txt 
echo "begin notify $(date)" >> $testdir/prevdata/$prev.txt
cat $testdir/prevdata/$prev.txt | mail -s "Video upload "$prev"" joshdont@gmail.com
echo "end notify $(date)" >> $testdir/prevdata/$prev.txt

Monday, September 8, 2014

Tech Summary


I think I have all the basic software and hardware components in place and functioning. The process is not as streamlined as I would like it to be and there's a million more things to resolve. That being said enough is in place that I can call this a functional setup : )

Hardware
A Raspberry Pi with a Powered Plugable USB Hub connected to a WiFi Dongle and a USB Extension cable all sit above ground and inside.

The USB Extension cable runs outside through a small hole in a wall and connects to a buried Canon Lide 20 Scanner. Both data & power run over USB. This is convenient and less scary (to me) than connecting a 120v higher amperage scanner to the outside world. Also, not all scanners work when oriented vertically!

The scanner has been waterproofed (so far) via an application of neutral curing acid-free silicone and a thick plastic bag. The scanner sits vertically with the top a couple cm below the earth's surface and the bottom approx. 30cm below.

Software
a) The Pi runs Raspbian, a linux distro based off of Debian.

b) SANE controls the Scanner.

c) ImageMagick is used to flip and convert the scanned image to a JPG.

d) ImageMagick is later used to overlay a timestamp onto the bottom of the JPG.

e) FFMPEG is used to convert a series of sequentially numbered JPGs into a h264 encoded video.

A few bash scripts automate most of this process.

Cheating
I currently offload all of the images from the Pi onto a somewhat beefier Apple Laptop that process steps d & e. This could be done on the Pi, but would take almost forever.

Short Term Tech Future
1) Backup images to a separate local storage location.

2) Upload images to a separate online storage location.

3) Use online storage location to process and upload compiled videos to youtube.

4) Build new enclosure for webcam version

5) Bury webcam version below the frost line (42" in Michigan)

6) Build complete documentation for the Scanner version

7) Build complete documentation for the Camera version.

Long Term Tech Future
1) Utilize additional sensors to gather more data

2) Figure out more things that can be analyzed from the image feed along

3) Discover new methods of analyzing image feed.


Thursday, September 4, 2014

Worm sightings, books and more!



When I first started this project the first thing I thought I would see (aside from soil) were worms. It's been approximately 7 weeks since this scanner was buried and above is the first decent sighting of a worm! Update: Soil Flatworm! 

Perhaps the scanner isn't in soil conditions worms prefer, maybe the scanner emits something worms don't like. It could be that we're looking at such a small sliver of soil that the the chances of seeing a large portion of any worm is slim (we're only seeing a few millimeters deep). Towards the end of the video you see the worm burrow out of view, and a realization sets in of just how three dimensional soil is that the plant and animal life traverse! Also, more awesome videos showing 3D soil reconstructions.

I finished reading "What a Plant Knows" by Daniel Chamovitz and have just started "Know Soil Know Life" by David Lindbo, Deb Kozlowski, and Clay Robinson. What a Plant Knows has been a wonderful snapshot of our current scientific understanding on the various sensing abilities of plants. Without little to no background in plant biology I found this to be an easy and engaging read. It's fascinating that to a certain extent plants can sense light, smells, touch, and retain and pass on memories.

So far I've only had time to skim through Know Soil Know Life. It contains beautiful color photos, drawings, and graphs in abundance. A welcome change from the previous books I've been reading, and I'm looking forward to actually read it!

Books are such wonderful resources, but I'm curious to know what digital (and not just videos or recreations of books) options there are for teaching something many might consider a fairly mundane subject... ? : )

People generally react to the timelapse videos of soil with a mixture of confused enthusiasm. There's a lot going on below the earth that is difficult to ascertain with a few minutes of reading. And while digging through the soil is highly recommended, it's very difficult to grasp things that often happen in non-human sizes and timescales. I'm fascinated by the reconstructions of soil by Prof. John Crawford, A/Prof. Margaret Barbour, and Prof. Mark Adams, and wonder how they can be used to further engage an earlier interest in something like soil : )

Wednesday, September 3, 2014

Following the Roots

Taking footage that's already been recorded, but focusing on the growth of roots. This view is zoomed in, and we're exceeding the resolution the images were captured, hence the blur.

If the purpose is to track root growth, I could have set the scanning resolution to be significantly higher to enable much clearer and closer looking footage. The downside would be that faster moving (nematodes, arthropods, etc.) would appear blurry as the scanning head moved across them.

Future options:
 - Running two scans at different resolutions would resolve that issue.
 - Find a scanner that can scan quicker at a higher resolution
 - - How fast does it need to run to keep most things in focus?
 - - How often does one need to take a picture to more intuitively pick up the path of a nematode?
 - - One minute image captures on a buried webcam seemed adequate.
 - - Six minute image captures on the scanner is inadequate.

Why are the roots growing into the earth? Mmmmmm gravitropism ftw! Why do the roots stop growing? The Radish roots (at top) I believe had their tops devoured by an animal, as no radishes were every found when checked ~3 weeks in. I'm not sure what the roots are coming from in the bottom video.

I learned of the software RootFly, but haven't tried using it yet as it's windows based. I'm currently doing most of this on a Raspberry Pi (Linux) and Mac (OSX).