動作環境
Xeon E5-2620 v4 (8コア) x 2
32GB RAM
CentOS 6.8 (64bit)
openmpi-1.8.x86_64 とその-devel
mpich.x86_64 3.1-5.el6とその-devel
gcc version 4.4.7 (とgfortran)
NCAR Command Language Version 6.3.0
WRF v3.7.1を使用。
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37)
Python 3.6.0 on virtualenv
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
関連
処理内容
- ファイル名
- 例: AAA_20170228_030000_BBB.png
- 画像に
2017/02/28 03:00
というラベルを追加する。
参考
code v0.1
label_image_171005.py
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import sys
import re
import sys
import subprocess as sb
# on Python 2.6.6
# ImageMagick 6.7.2-7
# coding rule: PEP8
# v0.1 Oct. 5, 2017
# - execute convert command to add label to the image
# - add get_datetime_label()
# - add debug_make_dummy()
def debug_make_dummy():
acmd = "convert -size 430x360 xc:white AAA_20170228_030000_BBB.png"
sb.call(acmd.split())
def get_datetime_label(filename):
# input(filename): e.g. AAA_20170228_030000_BBB.png
#
date_hhnn = re.sub(r'.*_(\d{4})(\d{2})(\d{2})_(\d{2})(\d{2})(\d{2})_.*',
r'\1/\2/\3 \4:\5',
filename)
return date_hhnn
# @spec
# convert -pointsize 20 -annotate +80+50 '2017/02/28 03:00'
# AAA_20170228_030000_BBB.png out_labeled.png
SEPARATOR = "=" # prevent separation by " " of the date_hhnn
IMG_CMD = "convert"
PARAM = "-pointsize 20 -annotate +80+50"
aparam = PARAM.replace(" ", SEPARATOR)
TEXT = "WHITE"
SRC = "AAA_20170228_030000_BBB.png"
DST = "out_labeled.png"
# debug
debug_make_dummy()
#
albl = get_datetime_label(SRC)
print(albl)
acmd = "=".join([IMG_CMD, aparam, albl, SRC, DST])
cmdlist = acmd.split(SEPARATOR) # prevent separation by " " of the date_time
print(cmdlist)
sb.call(cmdlist)
run
2017/02/28 03:00
['convert', '-pointsize', '20', '-annotate', '+80+50', '2017/02/28 03:00', 'AAA_20170228_030000_BBB.png', 'out_labeled.png']
out_labeled.pngが生成される。
生成画像
はまった点
sb.call(cmdlist)時にsplit()とすると「2017/02/28 03:00」文字列中の空白も分離対象となった。
"="をセパレータにすることで対処した。すっきりした方法ではない。
教えていただいた項目
@shiracamus さんのコメントですっきりした方法を教えていただきました。
情報感謝です。