Monday, April 27, 2015

Documentation

Slowly documenting things! I'm aiming for minimal documentation that communicates as much as possible. This is proving to be difficult : ) This also meant burying another scanner : )


I currently plan on breaking documentation into three sections:
1. Setting up the Raspberry Pi to automate scans
 - Process documented, needs testing and significant clean up before starting rough draft

2. Preparing a scanner for burial
 - Photos taken and rough draft done, needs review

3. Burying the scanner
 - Photos taken and rough draft done, needs review

The last two sections are pretty straightforward. The first section needs a couple dedicated afternoons cleaning up the existing documentation, testing from scratch, and finding a balance of what+how much to communicate. I would love to see if the entire project could be done by a group of young students, and that brings up a number of questions.

What and how much to communicate really depends on the goal of whoever's perusing it. It's somewhat amusing that the easiest way to document is to document everything in excruciating detail. Which is probably a buzz kill for most...  Trying to take into account things like:
 - Would it help to include automated publishing of images + videos.
 - - Do we cover rsync, backing up, ssh, etc.? Or discuss GoogleCL?
 - Is local access to images and videos preferred, and then they can decide what to do with it?
 - - Do we discuss methods on Windows & Apple to process images and video?
 - What's a good price point to assume? Minimal: ~$100. Ideal: ~$150.
 - - This changes how much data can be recorded and methods of storage.
 - Do we keep it to the command line environment?
 - - Aside from viewing videos it's all been SSH. This can be a huge barrier for some.
 - Do we discuss open source software, hardware?
 - - This whole project would likely not have happened without it.

Mmmmm, food for thought! Sounds like I need to spend some time communicating with people who might want to use it, and what their goals and desires might be.

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.