From 213034edfda5e62db044e7b6699775ad94933c07 Mon Sep 17 00:00:00 2001 From: HappyZ Date: Wed, 5 Jun 2019 14:15:50 -0500 Subject: [PATCH] add a batch processing bash --- .gitignore | 2 +- batch_parse.sh | 113 ++++++++++++++++++++++++++++++++++++++++++++ libs/parser_post.py | 1 - 3 files changed, 114 insertions(+), 2 deletions(-) create mode 100755 batch_parse.sh diff --git a/.gitignore b/.gitignore index 6c277ba..8ba22ce 100644 --- a/.gitignore +++ b/.gitignore @@ -55,4 +55,4 @@ CATKIN_IGNORE .setup.sh config.json data -example/20190505_170223_sig/* +example_orient_0/20190505_170223_sig/* diff --git a/batch_parse.sh b/batch_parse.sh new file mode 100755 index 0000000..15cb1b4 --- /dev/null +++ b/batch_parse.sh @@ -0,0 +1,113 @@ +#!/bin/sh + +LOG_FILE=batch_parse.log +PYTHON=python +VERSION=$(${PYTHON} -c 'import platform; major, minor, patch = platform.python_version_tuple(); print(major);') + +if [ VERSION == 2 ]; then + PYTHON=python3 + VERSION=$(${PYTHON} -c 'import platform; major, minor, patch = platform.python_version_tuple(); print(major);') +fi + +if [ VERSION == 3 ]; then + echo "cannot find the right python version 3" + exit +fi + +echo "python to be used: ${PYTHON} at $(which ${PYTHON})" + +if [ "$#" -lt 2 ]; then + echo "usage: $0 " + exit +fi + +if [ ! -d "$1" ]; then + echo "cannot find directory: '${1}'" + exit +fi + +SAMPLING_NUM=50 +if [ "$#" -eq 3 ]; then + SAMPLING_NUM=$3 +fi + +echo "working on folder '$1'" + +mkdir -p ${2}_all +mkdir -p ${2}_horiz +mkdir -p ${2}_verti +mkdir -p ${2}_subsampled +mkdir -p ${2}_direction_0 +mkdir -p ${2}_direction_1 +mkdir -p ${2}_direction_2 +mkdir -p ${2}_direction_3 + +for folder in ${1%/}/*; do + if [ ! -d "$folder" ]; then + continue + fi + # prepare + ORIENT=$(echo ${folder} | awk -F "_" '{print $NF}') + if [ $ORIENT = "0" ]; then + MOVE_TO_FOLDER=${2}_horiz + elif [ $ORIENT = "2" ]; then + MOVE_TO_FOLDER=${2}_horiz + elif [ $ORIENT = "1" ]; then + MOVE_TO_FOLDER=${2}_verti + elif [ $ORIENT = "3" ]; then + MOVE_TO_FOLDER=${2}_verti + else + continue + fi + + echo "processing folder: ${folder}.." >> $LOG_FILE 2>&1 + + echo "########################################" + echo " processing folder: ${folder}.." + echo "########################################" + + ${PYTHON} preprocessor.py "${folder}" --pickle -vd >> $LOG_FILE 2>&1 + if [ ! $? -eq 0 ]; then + echo "missing required files.." + continue + fi + echo "########################################" + echo " default" + echo "########################################" + for file in $(find ${folder} -name "*.png" -o -name "*.pickle"); do + cp ${file} ${2}_all/ + mv ${file} $MOVE_TO_FOLDER/ + done + + echo "########################################" + echo " subsampling" + echo "########################################" + # ${PYTHON} preprocessor.py "${folder}" --pickle -vd --sampling --sampling-num ${SAMPLING_NUM} > $LOG_FILE 2>&1 + # for file in $(find ${folder} -name "*.png" -o -name "*.pickle"); do + # mv ${file} ${2}_subsampled/ + # done + + echo "########################################" + echo " extract based on moving direction" + echo "########################################" + if [ $MOVE_TO_FOLDER = "${2}_horiz" ]; then + ${PYTHON} preprocessor.py "${folder}" --pickle -vd --filters 0 >> $LOG_FILE 2>&1 + for file in $(find ${folder} -name "*.png" -o -name "*.pickle"); do + mv ${file} ${2}_direction_0/ + done + ${PYTHON} preprocessor.py "${folder}" --pickle -vd --filters 2 >> $LOG_FILE 2>&1 + for file in $(find ${folder} -name "*.png" -o -name "*.pickle"); do + mv ${file} ${2}_direction_2/ + done + elif [ $MOVE_TO_FOLDER = "${2}_verti" ]; then + ${PYTHON} preprocessor.py "${folder}" --pickle -vd --filters 1 >> $LOG_FILE 2>&1 + for file in $(find ${folder} -name "*.png" -o -name "*.pickle"); do + mv ${file} ${2}_direction_1/ + done + ${PYTHON} preprocessor.py "${folder}" --pickle -vd --filters 3 >> $LOG_FILE 2>&1 + for file in $(find ${folder} -name "*.png" -o -name "*.pickle"); do + mv ${file} ${2}_direction_3/ + done + fi +done +# python3 ../xiaomi_vacuum_as_data_collector/preprocessor.py "$1/$i" --map \ No newline at end of file diff --git a/libs/parser_post.py b/libs/parser_post.py index c0bc8f0..af64711 100644 --- a/libs/parser_post.py +++ b/libs/parser_post.py @@ -97,7 +97,6 @@ def blocking_display_rss_map(rss_map: np.ndarray, visualize: bool = False, outpu if q == 'q': sys.exit() plt.close() - print() def convert_to_pickle_rss(