一、功能介绍
标题里的数据编号特指MODIS数据的命名方式,即将某一年的第n天转换为这一天对应的月和日。例如2014年的第193天是7月12日。利用这个脚本可以辅助分析MODIS数据的月变化。1-1
运行该脚本后的结果如下图所示:
1-2

二、脚本代码

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import sys
import arcpy

reload(sys)
sys.setdefaultencoding('utf-8')


class NumCvt:
    def __init__(self, time_res, year):
        """
        :param time_res:
        :param year:
        """
        self.year = year
        self.time_res = time_res
        self.list_num = []
        self.t_0 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
        self.t_1 = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

    def judge_year(self):
        if self.year % 4 == 0:
            return 1
        elif self.year % 4 != 0:
            return 0

    def cre_list_num(self):
        if self.judge_year():
            self.list_num = list(range(1, 366, self.time_res))
        else:
            self.list_num = list(range(1, 365, self.time_res))

    def cvt(self):
        list_day = []
        list_month = []
        if self.judge_year() == 0:
            t = self.t_0[:]
        else:
            t = self.t_1[:]
        for num in self.list_num:
            month = 1
            while True:
                if num - sum(t[:month]) <= 0:
                    list_day.append(num - sum(t[:month-1]))
                    list_month.append(month)
                    break
                else:
                    month += 1
                    continue
        return list_day, list_month


time_resolution = arcpy.GetParameterAsText(0)
year = arcpy.GetParameterAsText(1)


cvt1 = NumCvt(time_res=int(time_resolution), year=int(year))
cvt1.cre_list_num()
x_value = cvt1.list_num
y_value = cvt1.cvt()[1]
z_value = cvt1.cvt()[0]
arcpy.AddMessage("Year:" + year + " ; " + "Time_resolution: " + time_resolution)
for i in range(len(x_value)):
    arcpy.AddMessage("Num: " + str(x_value[i])+" ; " + "Month: " + str(y_value[i])+" ; " + "Day: " + str(z_value[i]))

三、工具参数
3-1
3-2

四、工具界面
4-1

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐