Ejemplo n.º 1
0
def ReadForecastFile_fix(satID, ymd):
    '''
    解析卫星和固定点的预报文件
    '''
    timeList = []
    # 获取配置信息
    sat = inCfg['ORDER'][satID]['SELF_SAT']
    target_fix_group = inCfg['ORDER'][satID]['TARGET_FIX']
    target_fix_group_sec = inCfg['ORDER'][satID]['TARGET_FIX_SEC']
    target_fix_group_time = inCfg['ORDER'][satID]['TARGET_FIX_TIME']
    dict_fix_group_sec = {}
    dict_fix_group_time = {}

    # 固定点名和固定点的秒数对应放到字典中
    for i in xrange(len(target_fix_group)):
        dict_fix_group_sec[target_fix_group[i]] = target_fix_group_sec[i]
        dict_fix_group_time[target_fix_group[i]] = target_fix_group_time[i]
    # 拼接固定点预报文件
    Filedir = sat + '_' + 'FIX'
    FileName = sat + '_' + 'FIX' + '_' + ymd + '.txt'
    ForecastFile = os.path.join(CROSS_DIR, Filedir, FileName)
    # 预报文件存在,则读取。
    if os.path.isfile(ForecastFile):
        fp = open(ForecastFile, 'r')
        Lines = fp.readlines()
        fp.close()
        for fix_group in target_fix_group:  # 遍历固定点的组
            fixList = inCfg['FIX_LIST'][fix_group]
            for fix in fixList:  # 遍历组内的固定点
                for Line in Lines[10:]:
                    # 选择要订购的固定点
                    if fix in Line and ymd in Line:
                        # 进行时间处理,交叉时间点变为时间段
                        s_hms = Line.split()[1].strip()
                        lat = float(Line.split()[3].strip())
                        lon = float(Line.split()[4].strip())
                        cross_time = datetime.strptime('%s %s' % (ymd, s_hms),
                                                       '%Y%m%d %H:%M:%S')
                        secs = int(dict_fix_group_sec[fix_group])
                        # 时间过滤类型
                        dayNight = dict_fix_group_time[fix_group]
                        #                         print 'time filtering flag: %s' % dayNight
                        s_cross_time = cross_time - relativedelta(seconds=secs)
                        e_cross_time = cross_time + relativedelta(seconds=secs)
                        if s_cross_time.strftime('%Y%m%d') != ymd:
                            continue
                        if e_cross_time.strftime('%Y%m%d') != ymd:
                            continue
                        sunZ = pb_sat.getasol6s(ymd, s_hms.replace(':', ''),
                                                lon, lat)

                        if dayNight == 'ALL':
                            timeList.append([s_cross_time, e_cross_time])
                        elif dayNight == 'NIGHT' and sunZ > 100:
                            timeList.append([s_cross_time, e_cross_time])
                        elif dayNight == 'DAY' and sunZ <= 100:
                            timeList.append([s_cross_time, e_cross_time])
    return timeList
Ejemplo n.º 2
0
def ReadForecastFile_area(satID, ymd):
    '''
    解析卫星和区域的预报文件
    '''
    timeList = []
    sat = inCfg['ORDER'][satID]['SELF_SAT']
    target_area = inCfg['ORDER'][satID]['TARGET_AREA']
    target_fix_area_time = inCfg['ORDER'][satID]['TARGET_AREA_TIME']
    dict_fix_area_time = {}

    for i in xrange(len(target_area)):
        dict_fix_area_time[target_area[i]] = target_fix_area_time[i]

    # 遍历区域
    for area in target_area:
        Filedir = sat + '_' + area
        FileName = sat + '_' + area + '_' + ymd + '.txt'
        ForecastFile = os.path.join(CROSS_DIR, Filedir, FileName)
        # 预报文件存在则读取
        if os.path.isfile(ForecastFile):
            fp = open(ForecastFile, 'r')
            Lines = fp.readlines()
            fp.close()
            # 解析进出时间
            for Line in Lines[10:]:
                if ymd in Line:
                    s_hms = Line.split()[1].strip()
                    e_hms = Line.split()[2].strip()
                    lat = float(Line.split()[3].strip())
                    lon = float(Line.split()[4].strip())
                    s_cross_time = datetime.strptime('%s %s' % (ymd, s_hms),
                                                     '%Y%m%d %H:%M:%S')
                    e_cross_time = datetime.strptime('%s %s' % (ymd, e_hms),
                                                     '%Y%m%d %H:%M:%S')
                    sunZ = pb_sat.getasol6s(ymd, s_hms.replace(':', ''), lon,
                                            lat)
                    dayNight = dict_fix_area_time[area]
                    if dayNight == 'ALL':
                        timeList.append([s_cross_time, e_cross_time])
                    elif dayNight == 'NIGHT' and sunZ > 100:
                        timeList.append([s_cross_time, e_cross_time])
                    elif dayNight == 'DAY' and sunZ <= 100:
                        timeList.append([s_cross_time, e_cross_time])

    return timeList
Ejemplo n.º 3
0
def ReadForecastFile_GEO_LEO(sat1, sat2, sat2_secs, dayNight, ymd):
    timeList = []
    # match_time = ymd[0:4] + '.' + ymd[4:6] + '.' + ymd[6:8]
    # 拼接预报文件
    Filedir = sat1 + '_' + sat2
    FileName = sat1 + '_' + sat2 + '_' + ymd + '.txt'
    ForecastFile = os.path.join(CROSS_DIR, Filedir, FileName)
    if not os.path.isfile(ForecastFile):  # 不存在则调换卫星顺序
        Filedir = sat2 + '_' + sat1
        FileName = sat2 + '_' + sat1 + '_' + ymd + '.txt'
        ForecastFile = os.path.join(CROSS_DIR, Filedir, FileName)
        if not os.path.isfile(ForecastFile):  # 调换顺序后还不存在则跳过
            return timeList

    fp = open(ForecastFile, 'r')
    Lines = fp.readlines()
    fp.close()
    for Line in Lines[10:]:
        if ymd in Line:  # 订购日期所在行
            s_hms = Line.split()[1].strip()
            e_hms = Line.split()[2].strip()
            lat = float(Line.split()[3].strip())
            lon = float(Line.split()[4].strip())
            cross_time1 = datetime.strptime('%s %s' % (ymd, s_hms),
                                            '%Y%m%d %H:%M:%S')
            cross_time2 = datetime.strptime('%s %s' % (ymd, e_hms),
                                            '%Y%m%d %H:%M:%S')
            # 目标卫星阈值秒
            s_cross_time = cross_time1 - relativedelta(seconds=sat2_secs)
            e_cross_time = cross_time2 + relativedelta(seconds=sat2_secs)
            if s_cross_time.strftime('%Y%m%d') != ymd:
                continue
            if e_cross_time.strftime('%Y%m%d') != ymd:
                continue
            sunZ = pb_sat.getasol6s(ymd, s_hms.replace(':', ''), lon, lat)

            if dayNight == 'ALL':
                timeList.append([s_cross_time, e_cross_time])
            elif dayNight == 'NIGHT' and sunZ > 100:
                timeList.append([s_cross_time, e_cross_time])
            elif dayNight == 'DAY' and sunZ <= 100:
                timeList.append([s_cross_time, e_cross_time])
    return timeList
Ejemplo n.º 4
0
    def filter_time_type(self, time_type):
        """
        time
        """
        # 数据长度
        lens = self.data['lat1'].size
        idx_list = []
        for i in range(lens):
            ymd = self.data['ymdhms1'][i][0:8]
            hms = self.data['ymdhms1'][i][8:]
            lat = self.data['lat1'][i]
            lon = self.data['lon1'][i]
            sun_z = getasol6s(ymd, hms, lon, lat)
            # 所属时间类型 白天 夜间 全天 符合给定条件则进入
            if self.is_day_neight(time_type, sun_z):
                idx_list.append(i)

        if len(idx_list) > 0:
            idx = (np.array(idx_list))
            for key in list(self.data.keys()):
                self.data[key] = self.data[key][idx]
Ejemplo n.º 5
0
def jump_cross_point(crossFile, snoxFile, dayNight):
    '''
    description :增加跳点功能,并返回新的交叉内容
    crossFile: 交叉预报文件
    snoxFile: 近重合预报文件
    sat2_cross_num: 保留个数
    '''
    #     Lines = []
    Lines1 = []
    Lines2 = []
    save_cross_num = 8  # 订购保留8个

    if os.path.isfile(crossFile):

        fp = open(crossFile, 'r')
        bufs = fp.readlines()
        fp.close()
        # 获取长度不包含头信息
        bodyLines = bufs[10:]

        # 黑白过滤
        dayNightLines = []
        print u'黑白过滤前 交叉点数量 %d' % len(bodyLines)
        for Line in bodyLines:
            ymd = Line.split()[0].strip()
            hms = Line.split()[1].strip()
            lat = float(Line.split()[2].strip())
            lon = float(Line.split()[3].strip())
            sunZ = pb_sat.getasol6s(ymd, hms.replace(':', ''), lon, lat)

            if dayNight == 'ALL':
                dayNightLines.append(Line)
            elif dayNight == 'NIGHT' and sunZ > 100:
                dayNightLines.append(Line)
            elif dayNight == 'DAY' and sunZ <= 100:
                dayNightLines.append(Line)
            else:
                pass

        lens = len(dayNightLines)
        print u'黑白过滤后 交叉点数 %d' % lens

        half_cross_num = save_cross_num / 2
        if lens <= save_cross_num:
            Lines1 = dayNightLines
            print u'<= %d, 全部保留' % save_cross_num
        else:
            Lines1 = dayNightLines[:half_cross_num] + \
                dayNightLines[-half_cross_num:]
            print u'> %d, 保留前%d,后%d' % (save_cross_num, half_cross_num,
                                        half_cross_num)


#         if lens <= save_cross_num:
#             Lines1 = dayNightLines
#         else:
#             Rest = lens % save_cross_num
#             if save_cross_num - Rest == 1:  # 满足间隔取点步长增加条件
#                 step = int(lens / save_cross_num) + 1
#             else:
#                 step = int(lens / save_cross_num)
#             newBodyLines = dayNightLines[::step]
#             # 间隔取点后还有多余的丢弃
#             Lines1 = newBodyLines[:save_cross_num]
#         print '间隔取点后 交叉点数 %d' % len(Lines1)

# 近重合
    if os.path.isfile(snoxFile):
        fp = open(snoxFile, 'r')
        bufs = fp.readlines()
        fp.close()
        # 获取长度
        Lines2 = bufs[10:]
    return Lines1 + Lines2