3-11-散点图-统计照片拍摄的频率

22 Jul 2018

在照片所在的文件夹下,运行下面的脚本,可以自动统计该文件夹里所有照片的拍摄日期以及数量,并绘制出结果。

photo_num.png

系统:win10下的linux子系统 or linux系统
软件:主要是GMT5.4.3以及其他一些linux中常用的小工具。
该脚本的优势是:可以自动化运行,统计和绘图一键生成。

#!/bin/bash


INFO_FILE=photo_information.txt
DATE_FILE=num_time.txt
# get initial time of photo files
ls -lR --full-time|grep '...[WGg]'|awk '{print $6}'|sed  '/^$/d'  > $INFO_FILE
# get number of same date of file
sort photo_information.txt | uniq -c > $DATE_FILE

## gmt plot 
f=photo_num
PS=$f.ps
PDF=$f.pdf
PNG=$f.png
# time range
tStart=`gawk '{system("date +%s -d"$2)}' $DATE_FILE | sort | head -n 1`
tStart=$[$tStart-172800]
tStart=`date +%Y-%m-%dT%H:%M:%S -d "1970-01-01 UTC $tStart seconds"`
tEnd=`gawk '{system("date +%s -d"$2)}' $DATE_FILE | sort | tail -n 1`
tEnd=$[$tEnd+172800]
tEnd=`date +%Y-%m-%dT%H:%M:%S -d "1970-01-01 UTC $tEnd seconds"`
# number range
MAX_NUM=`gawk '{print $1}' $DATE_FILE|gawk 'NR==1{max=$1;next}{max=max>$1?max:$1}END{print max}'`

gmt set FORMAT_DATE_MAP=o
gmt set FORMAT_DATE_IN=yyyy-mm-dd 
gmt set FONT=12p,0,black
gmt set FONT_ANNOT=12p,0,black
gmt set FONT_TITLE=12p,1,black
gmt set MAP_TITLE_OFFSET=4p
gmt set MAP_FRAME_WIDTH=0.5p

nSites=`cat $DATE_FILE | wc -l`
TOTAL_PHOTO=`gawk 'BEGIN{total=0}{total+=$1}END{print total}' $DATE_FILE`
barWidth=0.92 # the offset of bars is 1-$barWidth.
barColor=darkcyan
fac=0.5
pBarWidth=`echo $fac*$barWidth | bc`
JJ=JX25c/15c
RR=R${tStart}T/${tEnd}T/0/$[$MAX_NUM+30]

gmt psxy -$JJ -$RR -T -K  > $PS
gmt psbasemap -$JJ -$RR  -Bwsne -Bpxa4of1o -Bya100 --MAP_TICK_LENGTH=0p -K -O >> $PS
gawk '{print $2,$1}' $DATE_FILE | gmt psxy -$JJ -$RR -Bsxa1Yg1Y+l"date" -Bpxa4Of1o -Bya100+l"number of photos" -BSW -Sc0.003c -W${pBarWidth}c,$barColor   -K -O >> $PS
echo "Time spent=$nSites days;" |gmt pstext  -$RR -$JJ -F+cRT+f12p,1,black -D-0.5c/-0.2c -K -O >> $PS
echo "Total number of photos=$TOTAL_PHOTO" |gmt pstext  -$RR -$JJ -F+cRT+f12p,1,black -D-0.5c/-1.2c -K -O >> $PS
gmt psxy -$JJ -$RR -T -O >> $PS
#
#  export PDF, PNG.
#
gmt psconvert $PS -Tf -A -F$PDF
gmt psconvert $PS -Tg -A -F$PNG