Esempio n. 1
0
def make_disk_projlut_1km(out_file=None):
    res_degree = 0.01
    lats = FY4ASSI.get_latitude_1km()
    lons = FY4ASSI.get_longitude_1km()
    print(lats.shape)
    print(lats.min(), lats.max())
    print(lats)
    print(lons.shape)
    print(lons.min(), lons.max())
    print(lons)
    projstr = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
    proj = ProjCore(projstr,
                    res_degree,
                    unit="deg",
                    pt_tl=(69.995, 54.995),
                    pt_br=(139.995, 9.995))  # 角点也要放在格点中心位置
    result = proj.create_lut(lats=lats, lons=lons)
    proj.grid_lonslats()
    result['Longitude'] = proj.lons
    result['Latitude'] = proj.lats
    result['row_col'] = np.array([proj.row, proj.col], dtype=np.int32)
    print(result['row_col'])
    print(result['prj_i'])
    print(result['prj_j'])
    _write_out_file(out_file, result)
    print('生成FY4投影之后的查找表:{}'.format(out_file))
Esempio n. 2
0
def area(in_file,
         out_file,
         left_up_lon=None,
         left_up_lat=None,
         right_down_lon=None,
         right_down_lat=None,
         resolution_type=None,
         resultid=None):
    print('area <<< :{}'.format(in_file))
    if not os.path.isfile(in_file):
        print('数据不存在:{}'.format(in_file))
        return

    out_path = os.path.dirname(out_file)
    if not os.path.isdir(out_path):
        os.makedirs(out_path)

    if 'fy4a' in resultid.lower() and '4km' in resolution_type.lower():
        loader = FY4ASSI
        lons = FY4ASSI.get_longitude_4km()
        lats = FY4ASSI.get_latitude_4km()
    elif 'fy4a' in resultid.lower() and '1km' in resolution_type.lower():
        loader = FY4ASSI
        lons = FY4ASSI.get_longitude_1km()
        lats = FY4ASSI.get_latitude_1km()
    elif 'fy3d' in resultid.lower() and '1km' in resolution_type.lower():
        loader = FY3DSSI
        lons = FY3DSSI.get_longitude_1km()
        lats = FY3DSSI.get_latitude_1km()
    else:
        raise ValueError('不支持此分辨率: {}'.format(resolution_type))

    data_all = {
        'SSI': None,
        'DirSSI': None,
        'DifSSI': None,
        'G0': None,
        'Gt': None,
        'DNI': None,
        'Latitude': None,
        'Longitude': None,
    }

    try:
        datas = loader(in_file)
        data_get = {
            'SSI': datas.get_ssi,
            'DirSSI': datas.get_ib,
            'DifSSI': datas.get_id,
            'G0': datas.get_g0,
            'Gt': datas.get_gt,
            'DNI': datas.get_dni,
            'Latitude': lats,
            'Longitude': lons,
        }
        (row_min,
         row_max), (col_min,
                    col_max) = get_area_index(lons=lons,
                                              lats=lats,
                                              left_up_lon=left_up_lon,
                                              left_up_lat=left_up_lat,
                                              right_down_lon=right_down_lon,
                                              right_down_lat=right_down_lat)
        for dataname in data_all:
            if callable(data_get[dataname]):
                data = data_get[dataname]()
            else:
                data = data_get[dataname]
            data_all[dataname] = get_data_by_index(data=data,
                                                   row_min=row_min,
                                                   row_max=row_max,
                                                   col_min=col_min,
                                                   col_max=col_max)
    except Exception as why:
        print(why)
        print('选取数据过程出错,文件为:{}'.format(in_file))
        return

    try:
        _write_out_file(out_file, data_all)
    except Exception as why:
        print(why)
        print('输出结果文件错误')
        return
    return out_file
Esempio n. 3
0
def fy4a_ssi_4km_to_1km(in_file,
                        out_file,
                        resultid=None,
                        planid=None,
                        datatime=None,
                        resolution_type=None):
    print('<<< itcal: {}'.format(in_file))

    area_type = 'Full_DISK'
    if os.path.isfile(out_file):
        print('数据已经存在: {}'.format(out_file))
        if not exist_result_data(resultid=resultid,
                                 datatime=datatime,
                                 resolution_type=resolution_type,
                                 area_type=area_type):
            add_result_data(resultid=resultid,
                            planid=planid,
                            address=out_file,
                            datatime=datatime,
                            resolution_type=resolution_type,
                            area_type=area_type)
        return

    datas = FY4ASSI(in_file)
    data_get = {
        'SSI': datas.get_ssi,
        'DirSSI': datas.get_ib,
        'DifSSI': datas.get_id,
        'G0': datas.get_g0,
        'Gt': datas.get_gt,
        'DNI': datas.get_dni,
    }
    result = {}
    elements = data_get.keys()

    lats_4km = FY4ASSI.get_latitude_4km()
    lons_4km = FY4ASSI.get_longitude_4km()

    lats_1km = FY4ASSI.get_latitude_1km()
    lons_1km = FY4ASSI.get_longitude_1km()
    ddem = FY4ASSI.get_ddem_1km()

    lats_min = np.nanmin(lats_1km) - 5
    lats_max = np.nanmax(lats_1km) + 5
    lons_min = np.nanmin(lons_1km) - 5
    lons_max = np.nanmax(lons_1km) + 5

    print(lats_min, lats_max, lons_min, lons_max)

    index1 = np.logical_and.reduce((
        lons_4km <= lons_max,
        lons_4km >= lons_min,
        lats_4km <= lats_max,
        lats_4km >= lats_min,
    ))

    for element in elements:
        print(element)
        values = data_get.get(element)()
        index2 = np.isfinite(values)
        index = np.logical_and(index1, index2)
        valid_count = index.sum()
        print(index1.sum())
        print(index2.sum())
        print('有效点数量:{}'.format(valid_count))
        if valid_count <= 0:
            data = np.full_like(lons_1km, np.nan)
        else:
            lats_ = lats_4km[index].reshape(-1, 1)
            lons_ = lons_4km[index].reshape(-1, 1)
            points = np.concatenate((lons_, lats_), axis=1)
            values = values[index]
            data = griddata(points,
                            values, (lons_1km, lats_1km),
                            method='linear')
            data = topoCorrection(data, ddem)
        result[element] = data

    _write_out_file(out_file, result)
    if os.path.isfile(out_file) and not exist_result_data(
            resultid=resultid,
            datatime=datatime,
            resolution_type=resolution_type,
            area_type=area_type):
        add_result_data(resultid=resultid,
                        planid=planid,
                        address=out_file,
                        datatime=datatime,
                        resolution_type=resolution_type,
                        area_type=area_type)
Esempio n. 4
0
    print(KDTREE_LUT_FY4_4KM)

if not os.path.isfile(LON_LAT_LUT_FY4_1KM):
    print('生成FY4 1KM经纬度文件')
    make_lonlat_lut_1km(D_DEM_1KM, out_file=LON_LAT_LUT_FY4_1KM)
    print(LON_LAT_LUT_FY4_1KM)

if not os.path.isfile(PROJ_LUT_FY4_1KM):
    print('生成FY4 1KM投影经纬度文件')
    make_disk_projlut_1km(out_file=PROJ_LUT_FY4_1KM)
    print(PROJ_LUT_FY4_1KM)

if not os.path.isfile(KDTREE_LUT_FY4_1KM):
    print('生成FY4 1KM查找表')
    lons = FY4ASSI.get_longitude_1km()
    lats = FY4ASSI.get_latitude_1km()
    make_point_index_lut(lons, lats, out_file=KDTREE_LUT_FY4_1KM)
    print(KDTREE_LUT_FY4_1KM)

if not os.path.isfile(D_DEM_1KM):
    print('解压D_DEM.txt')
    dir_path = get_aid_path()
    with tarfile.open('Aid/ddem.tar', 'r') as tar:
        tar.extract('D_DEM.txt', dir_path)
    print(D_DEM_1KM)

if not os.path.isfile(LON_LAT_LUT_FY3_1KM):
    print('生成FY3 1KM经纬度文件')
    fy3d_envi = os.path.join(get_aid_path(), 'Sz_20190531.dat')
    make_lonlat_lut_fy3d_1km(fy3d_envi, out_file=LON_LAT_LUT_FY3_1KM)
    print(LON_LAT_LUT_FY3_1KM)