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))
def plot_fy4_image_map(data, out_file='test.jpg', resolution_type='4km', vmin=0, vmax=1000, interp=3, **kwargs): if '4km' in resolution_type.lower(): projlut = FY4ASSI.get_lonlat_projlut_4km() mask = None elif '1kmcorrect' in resolution_type.lower(): projlut = FY4ASSI.get_lonlat_projlut_1km() interp = 1 mask = get_china_mask_projlut_fy4_1km() elif '1km' in resolution_type.lower(): projlut = FY4ASSI.get_lonlat_projlut_1km() mask = get_china_mask_projlut_fy4_1km() else: raise ValueError('plot_image_map 不支持此分辨率: {}'.format(resolution_type)) row, col = projlut['row_col'] image_data = np.full((row, col), np.nan, dtype=np.float32) proj_i = projlut['prj_i'] proj_j = projlut['prj_j'] pre_i = projlut['pre_i'] pre_j = projlut['pre_j'] # 投影方格以外的数据过滤掉 valid_index = np.logical_and.reduce( (proj_i >= 0, proj_i < row, proj_j >= 0, proj_j < col)) proj_i = proj_i[valid_index] proj_j = proj_j[valid_index] pre_i = pre_i[valid_index] pre_j = pre_j[valid_index] image_data[proj_i, proj_j] = data[pre_i, pre_j] fig = plt.figure(figsize=(col / 100, row / 100), dpi=100) for i in range(interp): fill_points_2d_nan(image_data) # 对1KM数据使用china的shape掩码 if mask is not None: image_data[~mask] = np.nan fig.figimage(image_data, vmin=vmin, vmax=vmax, cmap='jet') fig.patch.set_alpha(0) plt.savefig(out_file, transparent=True) fig.clear() plt.close() print("监测到数据的最小值和最大值:{}, {}".format(np.nanmin(data), np.nanmax(data))) print('>>> :{}'.format(out_file))
def _get_multi_point_data(full_file, indexs, get_datetime, resultid, dates, values, thread_lock, **kwargs): indexs = np.array(indexs, dtype=np.int) datas_tmp = {} length = len(indexs) loader = FY4ASSI(full_file) data_geter = { 'Itol': loader.get_ssi, 'Ib': loader.get_ib, 'Id': loader.get_id, 'G0': loader.get_g0, 'Gt': loader.get_gt, 'DNI': loader.get_dni, } elements = data_geter.keys() for element_ in elements: try: data_tmp = data_geter[element_]()[indexs[:, 0], indexs[:, 1]] except Exception: data_tmp = [np.nan for i in range(length)] datas_tmp[element_] = data_tmp date = get_datetime(full_file) if 'Orbit' in resultid: date += relativedelta(hours=8) date = date.strftime('%Y%m%d%H%M%S') with thread_lock: dates.append(date) values.append(datas_tmp)
def product_fy4a_1km_disk_full_data_orbit(date_start=None, date_end=None, thread=THREAD, **kwargs): """ 绘制原始4KM数据的图像 3个产品,每个产品2张图像,共6张图像 :param date_start: 开始日期 datetime :param date_end: 结束日期 datetime :param thread: :return: """ resultid_in = 'FY4A_AGRI_L2_SSI_Orbit' resultid_out = 'FY4A_AGRI_L2_SSI_Orbit' frequency = 'Orbit' resolution_type_in = '4KMCorrect' resolution_type = '1KM' out_dir = os.path.join( DATA_ROOT_DIR, 'SSIData/FY4A/SSI_{resolution_type}/Full/{frequency}') out_dir = out_dir.format(resolution_type=resolution_type, frequency=frequency) planid = 1 results = find_result_data(resultid=resultid_in, datatime_start=date_start, datatime_end=date_end, resolution_type=resolution_type_in) in_files = [row.address for row in results] in_files.sort() in_files_length = len(in_files) print('找到的文件总数:{}'.format(in_files_length)) print('开始生产') p = Pool(thread) for in_file in in_files[:]: in_file_name = os.path.basename(in_file) datatime = FY4ASSI.get_date_time_orbit(in_file) if datatime.minute != 0: continue date_time = datatime.strftime('%Y%m%d%H%M%S') out_file_name = in_file_name.replace(resolution_type_in, resolution_type) out_file = os.path.join(out_dir, date_time[:8], out_file_name) if DEBUG or thread == 1: fy4a_ssi_4km_to_1km(in_file, out_file, resultid_out, planid, datatime, resolution_type) else: p.apply_async(fy4a_ssi_4km_to_1km, args=(in_file, out_file, resultid_out, planid, datatime, resolution_type)) p.close() p.join() print('完成全部的任务:{}'.format(sys._getframe().f_code.co_name))
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))
def _get_point_data(full_file, element, index, get_datetime, resultid, dates, datas, values, thread_lock, **kwargs): datas_tmp = {} loader = FY4ASSI(full_file) data_geter = { 'Itol': loader.get_ssi, 'Ib': loader.get_ib, 'Id': loader.get_id, 'G0': loader.get_g0, 'Gt': loader.get_gt, 'DNI': loader.get_dni, } elements = data_geter.keys() for element_ in elements: try: data_tmp = data_geter[element_]()[index] print(data_tmp) if np.isnan(data_tmp): datas_tmp[element_] = 0 else: datas_tmp[element_] = data_tmp except Exception as why: if DEBUG: print(why) datas_tmp[element_] = 0 date = get_datetime(full_file) if 'Orbit' in resultid: date += relativedelta(hours=8) date = date.strftime('%Y%m%d%H%M%S') print(datas_tmp) data_format = {'date': date} for element_ in datas_tmp: data_ = datas_tmp[element_] if data_ != 0: data_format[element_] = data_ else: data_format[element_] = np.nan data_str = '{date}\t{Itol:0.4f}\t{Ib:0.4f}\t{Id:0.4f}\t{G0:0.4f}\t{Gt:0.4f}\t{DNI:0.4f}\n'.format( **data_format) with thread_lock: dates.append(date) datas.append(data_str) if datas_tmp.get(element) is not None: values.append(datas_tmp)
def plot_map_full(in_file, resultid='', planid='', datatime='', resolution_type=None): print('plot_map_orbit <<<:{}'.format(in_file)) if not os.path.isfile(in_file): print('数据不存在:{}'.format(in_file)) return if 'fy4a' in resultid.lower(): rgb = FY4ASSI(in_file).get_rgb_ref() else: print('不支持的卫星:{}'.format(resultid)) return element = "Cloud" area_type = "Full" out_file1 = in_file + ".PNG" try: if not os.path.isfile(out_file1): plot_fy4a_cloud_disk(rgb, out_file=out_file1, resolution_type=resolution_type) else: print('文件已经存在,跳过:{}'.format(out_file1)) # 入库 if os.path.isfile(out_file1) and not exist_result_data( resultid=resultid, datatime=datatime, resolution_type=resolution_type, element=element, area_type=area_type): add_result_data(resultid=resultid, planid=planid, address=out_file1, datatime=datatime, resolution_type=resolution_type, area_type=area_type, element=element) except Exception as why: print(why) print('绘制{}图像错误:{}'.format(area_type, out_file1))
def georaster(in_file): datas = FY4ASSI(in_file) ssi = datas.get_ssi() index_valid = np.isfinite(ssi) if not index_valid.any(): print('ERROR:没有有效数据') return lons = datas.get_longitude_1km() lats = datas.get_latitude_1km() lons = lons[index_valid] lats = lats[index_valid] # 计算对应的经度范围 lons_min = np.nanmin(lons) lons_max = np.nanmax(lons) lon_arange = np.arange(LatLonRange[2], LatLonRange[3], LatLonRange[4]) if np.searchsorted(lon_arange, lons_max) <= np.searchsorted(lon_arange, lons_min) + 10: print('ERROR:经度范围不足') return data_index = np.searchsorted(lon_arange, lons_min) - 1 min_lon = LatLonRange[2] + data_index * LatLonRange[4] num_lon = np.searchsorted(lon_arange, lons_max) - data_index # 计算对应的纬度范围 lats_min = np.nanmin(lats) lats_max = np.nanmax(lats) lat_arange = np.arange(LatLonRange[0], LatLonRange[1], LatLonRange[4]) if np.searchsorted(lat_arange, lats_max) <= np.searchsorted(lat_arange, lats_min) + 10: print('ERROR:纬度范围不足') return data_index = np.searchsorted(lat_arange, lats_min) - 1 min_lat = LatLonRange[0] + data_index * LatLonRange[4] num_lat = np.searchsorted(lat_arange, lats_max) - data_index return min_lon, num_lon, min_lat, num_lat
def nc2txt(in_file, out_file): """ 列变为行,行变为列 :param in_file: :param out_file: :return: """ datas = FY4ASSI(in_file) ssi = datas.get_ssi() ssi[np.isnan(ssi)] = 0 ssi[np.logical_or(ssi < 0, ssi > 1500)] = 0 if not os.path.isfile(out_file): with open(out_file, 'w') as file_out: i, j = ssi.shape i = list(range(i)) j = list(range(j)) for jj in j: for ii in i: mid = ssi[ii, jj] file_out.write("%15.7f" % mid) file_out.write("\n") file_out.close()
def plot_map_full(in_file, vmin=0, vmax=1000, resultid='', planid='', datatime='', resolution_type=None): print('plot_map_orbit <<<:{}'.format(in_file)) if not os.path.isfile(in_file): print('数据不存在:{}'.format(in_file)) return dir_ = os.path.dirname(in_file) in_filename = os.path.basename(in_file) if 'fy4a' in resultid.lower(): datas = FY4ASSI(in_file) elif 'fy3d' in resultid.lower(): datas = FY3DSSI(in_file) else: print('不支持的卫星:{}'.format(resultid)) return datas_ = { 'Itol': datas.get_ssi, 'Ib': datas.get_ib, 'Id': datas.get_id, 'G0': datas.get_g0, 'Gt': datas.get_gt, 'DNI': datas.get_dni, } for element in datas_.keys(): try: data = datas_[element]() except Exception as why: print(why) print('读取数据错误:{}'.format(element)) data = None if data is not None: # 快视图绘制 area_type = 'Full_DISK' out_filename1 = in_filename + '_{}_{}.PNG'.format( area_type, element) out_file1 = os.path.join(dir_, out_filename1) try: if not os.path.isfile(out_file1): plot_image_disk(data, out_file=out_file1, resultid=resultid, resolution_type=resolution_type, vmin=vmin, vmax=vmax) else: print('文件已经存在,跳过:{}'.format(out_file1)) # 入库 if os.path.isfile(out_file1) and not exist_result_data( resultid=resultid, datatime=datatime, resolution_type=resolution_type, element=element, area_type=area_type): add_result_data(resultid=resultid, planid=planid, address=out_file1, datatime=datatime, resolution_type=resolution_type, area_type=area_type, element=element) except Exception as why: print(why) print('绘制{}图像错误:{}'.format(area_type, out_file1)) # 等经纬图绘制 area_type = 'Full_LATLON' out_filename2 = in_filename + '_{}_{}.PNG'.format( area_type, element) out_file2 = os.path.join(dir_, out_filename2) # try: if not os.path.isfile(out_file2): plot_image_map(data, out_file=out_file2, resultid=resultid, resolution_type=resolution_type, vmin=vmin, vmax=vmax) else: print('文件已经存在,跳过:{}'.format(out_file2)) # 入库 if os.path.isfile(out_file2) and not exist_result_data( resultid=resultid, datatime=datatime, resolution_type=resolution_type, element=element, area_type=area_type): add_result_data(resultid=resultid, planid=planid, address=out_file2, datatime=datatime, resolution_type=resolution_type, area_type=area_type, element=element)
def combine_area(in_files, out_file, day=False): """ :param in_files: :param out_file: :param day: 是否日合成,因为日合成的时候,要改变数据的单位为KW/m2 :return: """ out_path = os.path.dirname(out_file) if not os.path.isdir(out_path): os.makedirs(out_path) if os.path.isfile(out_file): print('文件已经存在,跳过:{}'.format(out_file)) return data_all = { 'SSI': None, 'DirSSI': None, 'DifSSI': None, 'G0': None, 'Gt': None, 'DNI': None, 'Latitude': None, 'Longitude': None, } for in_file in in_files: print('combine <<< :{}'.format(in_file)) try: 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, 'Latitude': datas.get_latitude_area, 'Longitude': datas.get_longitude_area, } for dataname in data_all: data_all[dataname] = add_data(data_all[dataname], data_get[dataname]()) except Exception as why: print(why) print('合成数据过程出错,文件为:{}'.format(in_file)) continue # 从时次产品转为日产品的时候,单位变为kw/m2 try: if day: print('从时次产品转为日产品的时候,单位变为kw/m2') for dataname in data_all: data = data_all[dataname] if data is not None: data_all[dataname] = data * 0.001 except Exception as why: print(why) print('转换单位出错') try: _write_out_file(out_file, data_all) except Exception as why: print(why) print('输出结果文件错误') return
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)
def fy4a_save_4km_orbit_data_in_database(date_start=None, date_end=None, **kwargs): print(date_start) print(date_end) # source_dir = os.path.join('/FY4/FY4A/AGRI/L2/SSI/DISK/NOM') source_dir = os.path.join( '/home/gfssi/GFData/SourceData/FY4A/SSI_4KM/Full/Orbit') ssi_dir = os.path.join(DATA_ROOT_DIR, 'SSIData', 'FY4A', 'SSI_4KM', 'Full', 'Orbit') ext = '.NC' resultid = 'FY4A_AGRI_L2_SSI_Orbit' planid = 1 results = find_result_data(resultid=resultid, datatime_start=date_start, datatime_end=date_end, resolution_type='4KM') results_files = [row.address for row in results] results_files = set(results_files) session = Session() count = 0 for root, dirs, files in os.walk(source_dir): for file_name in files: if ext is not None: if '.' not in ext: ext = '.' + ext if os.path.splitext(file_name)[1].lower() != ext.lower(): continue try: src_file = os.path.join(root, file_name) datatime = FY4ASSI.get_date_time_orbit(src_file) if date_start is not None and date_end is not None: if not date_start <= datatime <= date_end: continue yyyymmdd = datatime.strftime("%Y%m%d") dst_file = os.path.join(ssi_dir, yyyymmdd, file_name) dst_file = dst_file.replace('4000M', '4KM') if not os.path.isfile(dst_file): dst_dir = os.path.dirname(dst_file) if not os.path.isdir(dst_dir): os.makedirs(dst_dir) os.symlink(src_file, dst_file) if dst_file in results_files: continue result_data = ResultData() result_data.resultid = resultid result_data.planid = planid result_data.address = dst_file result_data.datatime = datatime result_data.createtime = datetime.now() result_data.resolution_type = '4KM' result_data.area_type = 'Full_DISK' result_data.element = None session.add(result_data) count += 1 print('{} -----> {}'.format(src_file, dst_file)) if count >= 500: session.commit() count = 0 except Exception as why: print(why) os.remove(dst_file) session.commit() session.close()
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
def combine_full(in_files, out_file, day=False, resultid=None, planid=None, datatime=None, resolution_type=None): """ :param in_files: :param out_file: :param day: 是否日合成,因为日合成的时候,要改变数据的单位为KW/m2 :param resultid: :param planid: :param datatime: :param resolution_type: :return: """ out_path = os.path.dirname(out_file) if not os.path.isdir(out_path): os.makedirs(out_path) 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): print('开始入库') add_result_data(resultid=resultid, planid=planid, address=out_file, datatime=datatime, resolution_type=resolution_type, area_type=area_type) return data_all = { 'SSI': None, 'DirSSI': None, 'DifSSI': None, 'G0': None, 'Gt': None, 'DNI': None, } for in_file in in_files: print('combine <<< :{}'.format(in_file)) try: datas = FY4ASSI(in_file) # 日合成的时候,只使用整点数据 if day: date_time = FY4ASSI.get_date_time_orbit(in_file) if date_time.minute != 0: continue 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, } for dataname in data_all: data_all[dataname] = add_data(data_all[dataname], data_get[dataname]()) except Exception as why: print(why) print('合成数据过程出错,文件为:{}'.format(in_file)) continue # 从时次产品转为日产品的时候,单位变为kw/m2 try: if day: print('从时次产品转为日产品的时候,单位变为kw/m2') for dataname in data_all: data = data_all[dataname] if data is not None: data_all[dataname] = data * 0.001 except Exception as why: print(why) print('转换单位出错') try: _write_out_file(out_file, data_all) if os.path.isfile(out_file) and not exist_result_data(resultid=resultid, datatime=datatime, resolution_type=resolution_type, area_type=area_type): print('开始入库') add_result_data(resultid=resultid, planid=planid, address=out_file, datatime=datatime, resolution_type=resolution_type, area_type=area_type) except Exception as why: print(why) print('输出结果文件错误') return
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
from lib.lib_read_ssi import FY4ASSI, FY3DSSIENVI 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):