Saturday, January 3, 2015

Scanner Unresponsive - What Next : ) ?

For the past 24 hours the scanner has not been functioning. Initially the top half of the image displayed the same repeating line of pixels, and a power cycle resulted in the device no longer appearing (lsusb) on the Pi

Both problems have separately occurred before. The former problem happened when the scanner was first buried. Dirt compacted too forcefully against the scanner meant the sensor was unable to complete a full pass, resulting in a similar image. The latter happened with the device reappearing after a day or two and several power cycles un/replugs, cause unknown.

So far the scanner has:
 - Spent ~6 months below ground
 - Captured ~17,000 images
 - Survived above-ground temps well below freezing

I'll wait a day or two more before going beyond power cycle and un/replugging the device : )

Meanwhile:
 - Automated uploading images to a remote server (Linode) and building daily videos.
 - - Next Step: Automate compilation of weekly and monthly videos, post online.

- Automated backup of the original images to Amazon S3 + file cleanup.
- - Next Step: Set it up to run regularly (right now I'm running the script instead of setting it up as a Cron job)

- Documentation / Build Guide.
- - Next step: Use the backup Canon Lide 20 to assemble the physical build guide
- - Next step: Review notes on existing process and create:
- - - Simple Pi guide (Just to view images as you like from the scanner)
- - - Timelapse Pi Guide (Include automation for creating timelapse video)

Beyond the above, there are two variations on this project that I would like to pursue:
1) Building a cylindrical scanner. Scrap the frame/body of an existing scanner, mount it to a glass cylinder and have it scan 360 degrees. I think it would be easier (physical constraints) to get it to scan from the outside in, but I think it might be more interesting to get it to scan from the inside out (buried in the ground). Similar to existing Mini-Rhizitrons, but with a 360 degree view.

2) Building a webcam version. Similar to existing Mini Rhizotrons, but significantly cheaper. This is how this project originally started. The image quality and viewing area will be reduced, but we'll have a significantly higher frame rate and nearly real time (ms delay) viewing. Taking an image once a day seems fine for tracking root growth, but tracking the path of certain bugs below ground seems like a 1 frame / minute frequency.

It would be wonderful to include additional data for both build options, ie:
 - Moisture
 - Humidity
 - Temperature

Monday, December 22, 2014

5 Months, Secondary Root Growth, and Things Moving Up

Compiled video for the last five months (see below). Brief notes of interest:

1. Secondary Root Growth. Around Sept. 21st there is a burst of root growth extending out from many of the existing roots. This lasts for about two weeks before settling down. Nearly all of the easily visible roots exhibit the same behavior at the same time. Neat! I'm assuming they are all coming from the same plant. What changed took place that enabled this process to happen? Temperature, sunlight change, moisture?

2. Underground Plant Growth. Plants generally start their life below ground, running their roots/radicles down, and their shoots/hypocotyl towards the sky. It's strange for me to see the upward growth below ground. At the 43s mark of this video you can see this happening. That behavior isn't abnormal, but it's growth I'm normally used to seeing only when a plant emerges above the earth. I mistakenly assume everything below ground is a root : )

43 seconds in the linked video puts us at late October with the growth continuing through November. With an average temperature of 34°F / 1°C, I have a hard time believing whatever sprouts above ground will survive long?

If this setup continues to survive, what other growth will we see as the temperature stays below freezing? It's about time I started measuring the soil temp!


~5 Months played back at ~10 seconds/month. 
See below for playback of 1 second/month.

~5 Months played back at ~1 second/month.  

Sunday, December 14, 2014

After These Messages

Spent the past two months out of the country. Automation was only partially functioning. In short, images from the scanner were not automatically offloading to a remote server, so I had to SSH in from Cambodia, Thailand, and New Zealand every few days to do this manually. A few days of data was lost, but beyond silly user error problems the setup has continued to function. The past week has seen an average temperature below freezing. Neat! Hoping to recompile some new timelapse videos over the next week. Will update soon.

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 : )