我有一个程序,根据它的时间对图像进行排序(它就在它的名字上)。我命令他们看看6点和18点是白天还是晚上(因为时间间隔为3小时,所以我不介意之前或之后的时间)。
我用个人标准来做这件事。我关注的是西班牙发生的事情。
如您所见,我从照片的名称中得到时间、日期或月份,因为名称类似于:IR39_MSG2-SEVI-MSG15-0100-NA-20080701151239
import os , time, shutil
directorio_origen = "D:/TR/Eumetsat_IR_photos/"
directorio_destino_dia = "D:/TR/IR_Photos/Daytime"
directorio_destino_noche = "D:/TR/IR_Photos/Nighttime"
def get_hour(file_name):
return file_name[37:39]
def get_day(file_name):
return file_name[35:37]
def get_month(file_name):
return file_name[33:35]
for root, dirs, files in os.walk(directorio_origen, topdown=False):
for fn in files:
path_to_file = os.path.join(root, fn)
hora = int(get_hour(fn))
dia = int(get_day(fn))
mes = int(get_month(fn))
if ((mes == 1 or mes == 2 or mes == 11 or mes == 12 and 6 < hora < 18) or
(mes == 3 and dia < 17 and 6 < hora < 18) or (mes == 3 and dia == 17 and 6 <= hora < 18) or(mes == 3 and dia > 17 and 6 <= hora <= 18) or
(4 <= mes <= 8 and 6 <= hora <= 18) or
(mes == 9 and dia <= 15 and 6 <= hora <= 18) or (mes == 9 and dia >= 16 and 6 <= hora < 18) or
(mes == 10 and dia <= 13 and 6 <= hora < 18) or (mes == 10 and dia >= 14 and 6 < hora < 18)):
new_directorio = directorio_destino_dia
else:
new_directorio = directorio_destino_noche
try:
if not os.path.exists(new_directorio):
os.mkdir(new_directorio)
shutil.copy(path_to_file, new_directorio)
except OSError:
print("El archivo no ha podido ser ordenado" % fn)
我想要解决的是,像IR39_MSG2-SEVI-MSG15-0100-NA-20100110**21**1241
、IR39_MSG2-SEVI-MSG15-0100-NA-20100111**00**1240
或IR39_MSG2-SEVI-MSG15-0100-NA-20100104**00**1241
这样的图像是按白天排序的,我不知道为什么(高时)。
问题是,像00,03或21这样的图片总是在晚上,09或12总是白天。
编辑的
所以你可以理解我为什么要使用这个标准,我会附上一张照片或数据,你可以看到6点18是白天还是晚上取决于太阳是升起还是没有升起:
看清楚这些数据并不重要,只是想让你知道我为什么会这样做。
PD:我不认为我的照片是在不同的分钟内拍摄的。
谢谢你的帮助。
发布于 2020-11-02 13:49:13
这个问题在第一个条件下似乎是(mes == 1 or mes == 2 or mes == 11 or mes == 12 and 6 < hora < 18)
。将其更改为(mes in (1, 2, 11, 12) and 6 < hora < 18)
,它应该可以工作:
def is_day_time(mes, dia, hora):
if (
(mes in (1, 2, 11, 12) and 6 < hora < 18) or
(mes == 3 and dia < 17 and 6 < hora < 18) or
(mes == 3 and dia == 17 and 6 <= hora < 18) or
(mes == 3 and dia > 17 and 6 <= hora <= 18) or
(4 <= mes <= 8 and 6 <= hora <= 18) or
(mes == 9 and dia <= 15 and 6 <= hora <= 18) or
(mes == 9 and dia >= 16 and 6 <= hora < 18) or
(mes == 10 and dia <= 13 and 6 <= hora < 18) or
(mes == 10 and dia >= 14 and 6 < hora < 18)
):
return True
return False
print( is_day_time(1, 10, 21) )
print( is_day_time(1, 11, 0) )
print( is_day_time(1, 4, 0) )
指纹:
False
False
False
https://stackoverflow.com/questions/64646656
复制相似问题