コード例 #1
0
ファイル: aid_lonlat_projlut.py プロジェクト: NingAnMe/GFSSI
def make_disk_projlut_4km(out_file=None):
    res_int = 4000
    lats = FY4ASSI.get_latitude_4km()
    lons = FY4ASSI.get_longitude_4km()
    res_degree = meter2degree(res_int)
    projstr = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
    proj = ProjCore(projstr,
                    res_degree,
                    unit="deg",
                    pt_tl=(23, 81),
                    pt_br=(179.5, -81))  # 角点也要放在格点中心位置
    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'])
    _write_out_file(out_file, result)
    print('生成FY4投影之后的查找表:{}'.format(out_file))
コード例 #2
0
ファイル: gfssi_e03_ssi_area.py プロジェクト: NingAnMe/GFSSI
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
コード例 #3
0
ファイル: gfssi_b01_ssi_itcal.py プロジェクト: NingAnMe/GFSSI
def itcal(in_file,
          out_file,
          resultid=None,
          planid=None,
          datatime=None,
          resolution_type=None):
    # 如果原来的整点数据不存在,直接使用G0进行补充
    # 如果原来的整点数据存在,使用G0进行校正
    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,
                            element=None)
        return
    print('<<< itcal: {}'.format(in_file))

    beta = 35.0  # 常量

    try:
        datas = FY4ASSI(in_file)
    except Exception as why:
        print(why)
        print('初始化FY4A SSI读取类错误')
        return
    date_time = FY4ASSI.get_date_time_orbit(in_file)
    y, m, d, hr, minus = assignTime(date_time)
    e = assignE(y, m, d)
    doy = calDoy(y, m, d)
    delta = calDelta(doy)
    print(delta)
    try:
        lons = FY4ASSI.get_longitude_4km()
        lats = FY4ASSI.get_latitude_4km()
    except Exception as why:
        print(why)
        print('读取lons和lats错误')
        return

    DQF = np.ones_like(lons, dtype=np.int8)  # 标识数据集

    Omega = calOmega(hr, minus, lons, e)
    cos_the_taz = calCosThetaz(lats, delta, Omega)
    G0 = calG0(doy, cos_the_taz)
    print('G0')
    print(np.nanmin(G0), np.nanmax(G0))
    print((G0 > 0).sum())
    index_invalid_g0 = np.logical_or(
        G0 >= 1500, G0 <= 0)  # ########################## G0的无效值赋值为nan
    G0[index_invalid_g0] = np.nan
    if np.isnan(G0).all():
        print('Warning::::::::没有有效的G0数据,不生产数据')
        return

    # G0无效
    DQF[index_invalid_g0] = 0

    # 校正总直散数据
    if os.path.isfile(in_file):

        try:
            Itol = datas.get_ssi()
            Ib = datas.get_dirssi()
            Id = datas.get_difssi()
        except Exception as why:
            print(why)
            print('读取ssi,dirssi和difssi错误')
            return

        # 将G0 >= 1400, G0 <= 0的值置为nan
        Itol[index_invalid_g0] = np.nan
        Ib[index_invalid_g0] = np.nan
        Id[index_invalid_g0] = np.nan

        # Itol 有效
        index_valid_itol = np.logical_and(np.isfinite(Itol), Itol < G0)
        DQF[index_valid_itol] = 1

        # 校正G0有效,但是Itol无效的数据
        index_invalid_itol = np.logical_or(
            Itol > G0, np.logical_and(np.isnan(Itol), np.isfinite(G0)))
        Itol[index_invalid_itol] = G0_Correct * G0[index_invalid_itol]
        Ib[index_invalid_itol] = 0.3 * Itol[index_invalid_itol]
        Id[index_invalid_itol] = 0.7 * Itol[index_invalid_itol]
        DQF[index_invalid_itol] = 2
    else:
        Itol = G0_Correct * G0
        Ib = 0.3 * Itol
        Id = 0.7 * Itol

    # 计算Gt和DNI
    Rb = calRb(lats, beta, delta, Omega, cos_the_taz)
    Ai = Ib / G0
    Gt = calGt(Ib, Id, Ai, Rb, beta, Itol)
    DNI = Ib / cos_the_taz

    # 校正Gt
    index_invalid_gt = np.logical_and(Gt < 0, np.isfinite(G0))
    Gt[index_invalid_gt] = 0.75 * G0[index_invalid_gt]
    DQF[index_invalid_gt] = 3
    Gt[lats < 0] = np.nan  # 20191121 AnNing 根据用户需求,Gt的数据只生产北半球

    # 输出数据
    result = {
        'G0': G0,
        'Gt': Gt,
        'DNI': DNI,
        'SSI': Itol,
        'DirSSI': Ib,
        'DifSSI': Id,
        'DQF': DQF
    }

    try:
        _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,
                            element=None)
    except Exception as why:
        print(why)
        print('输出结果文件错误')
        return
コード例 #4
0
ファイル: gfssi_b02_ssi_1km.py プロジェクト: NingAnMe/GFSSI
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)
コード例 #5
0
ファイル: install.py プロジェクト: NingAnMe/GFSSI
from lib.lib_get_index_by_lonlat import make_point_index_lut

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

if not os.path.isfile(BASEMAP_FY4_4KM):
    print('生成FY4 4KM背景图')
    make_basemap_fy4a(res='4km', out_file=BASEMAP_FY4_4KM)
    print(BASEMAP_FY4_4KM)

if not os.path.isfile(KDTREE_LUT_FY4_4KM):
    print('生成FY4 4KM查找表')
    lats = FY4ASSI.get_latitude_4km()
    lons = FY4ASSI.get_longitude_4km()
    make_point_index_lut(lons, lats, out_file=KDTREE_LUT_FY4_4KM)
    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查找表')