def draw_fine_global_map(title, ofile, lons, lats, value, vmin, vmax, fmt='%d', flag=0): opath = os.path.dirname(ofile) if not os.path.isdir(opath): os.makedirs(opath) fig = plt.figure(figsize=(6, 4)) # 图像大小 pos1 = [0.1, 0.3, 0.8, 0.6] ax1 = add_ax(fig, *pos1) p = dv_map(fig, ax=ax1) p.colormap = 'jet' p.delat = 30 p.delon = 30 # p.colorbar_fmt = "%0.2f" p.show_countries = True # p.show_china = True # p.show_china_province = True p.show_line_of_latlon = True p.show_colorbar = False p.easyplot( lats, lons, value, vmin=vmin, vmax=vmax, markersize=1.5, marker='.') p.draw() # 直方图 pos2 = [0.1, 0.15, 0.8, 0.1] ax2 = add_ax(fig, *pos2) p2 = dv_hist(fig, ax=ax2) p2.easyplot( value.reshape((-1,)), bins=512, cmap="jet", range=(vmin, vmax)) p2.xlim_min = vmin p2.xlim_max = vmax p2.simple_axis(mode=0) p2.draw() # ColorBar pos3 = [0.1, 0.115, 0.8, 0.03] ax3 = add_ax(fig, *pos3) add_colorbar_horizontal(ax3, vmin, vmax, cmap="jet", fmt=fmt) # colorbar上打点 if flag == 1: value = np.ma.masked_where(np.abs(value) > 3 * vmax, value) mean = np.ma.mean(value) print 'b', mean else: mean = np.ma.mean(value) precent = (mean - vmin) / (vmax - vmin) ax3.plot(precent, 0.5, 'ko', ms=5, zorder=5) font_mono = get_DV_Font() strlist = ["mean = %0.2f" % mean] add_annotate(ax2, strlist, 'left_top', font_mono) # 总标题 fig.suptitle(title, fontproperties=p.font, size=14) p.savefig(ofile)
def plot_bias_map(lat=None, lon=None, data=None, out_file=None, title=None, vmin=None, vmax=None): if title: title = title else: title = "Map" # 绘制偏差的全球分布图,保持0值永远在bar的中心 if vmin is not None and vmax is not None: vmin = vmin vmax = vmax else: datamax = np.max(data) if datamax >= 0: vmin = -1.0 * datamax vmax = datamax else: vmin = datamax vmax = -1.0 * datamax p = dv_map.dv_map() p.colorbar_fmt = '%0.3f' color_list = [ '#000081', '#0000C8', '#1414FF', '#A3A3FF', '#FFA3A3', '#FF1414', '#C70000', '#810000' ] cmap = colors.ListedColormap(color_list, 'indexed') p.easyplot(lat, lon, data, vmin=vmin, vmax=vmax, ptype=None, markersize=0.05, marker='s', colormap=cmap) p.title = title make_sure_path_exists(os.path.dirname(out_file)) p.savefig(out_file) print '>>> {}'.format(out_file)
def plot_map_project(latitude, longitude, count, out_file, title=None, ptype=None, vmin=None, vmax=None, marker=None, markersize=None): if title is not None: title = title else: title = "Map" if vmin is not None: vmin = vmin if vmax is not None: vmax = vmax if marker is not None: marker = marker else: marker = 's' if markersize is not None: markersize = markersize else: markersize = 1 p = dv_map.dv_map() p.easyplot(latitude, longitude, count, vmin=vmin, vmax=vmax, ptype=ptype, markersize=markersize, marker=marker) p.title = title p.add_landmark(lonlatlocation) p.savefig(out_file) print '>>> {}'.format(out_file)
def plot_map_project( latitude, longitude, value, out_file, box=None, title=None, ptype=None, vmin=None, vmax=None, marker=None, markersize=None): if box is not None: box = box # nlat, slat, wlon, elon:北(小),南(大),东(大),西(小) if title is not None: title = title else: title = "Map" if vmin is not None: vmin = vmin if vmax is not None: vmax = vmax if marker is not None: marker = marker else: marker = 's' if markersize is not None: markersize = markersize else: markersize = 5 p = dv_map() p.easyplot(latitude, longitude, value, vmin=vmin, vmax=vmax, box=box, ptype=ptype, markersize=markersize, marker=marker) p.title = title p.savefig(out_file) print('>>> {}'.format(out_file))
def plot_shanghai(latitude, longitude, value, out_file, box=None, title=None, ptype=None, vmin=None, vmax=None, marker=None, markersize=None, AREA=None): if box is not None: box = box # nlat, slat, wlon, elon:北(小),南(大),东(大),西(小) if title is not None: title = title else: title = "Map" if vmin is not None: vmin = vmin if vmax is not None: vmax = vmax if marker is not None: marker = marker else: marker = 's' if markersize is not None: markersize = markersize else: markersize = 5 # 开始画图----------------------- fig = plt.figure(figsize=(9., 8.)) # 图像大小 p = dv_map(fig=fig) subplots_adjust(left=0.07, right=0.98, top=0.90, bottom=0.15) p.show_colorbar = False p.show_countries = False p.show_coastlines = False # p.show_line_of_latlon = False # p.show_china = True p.show_china_province = True p.show_inside_china = True p.show_inside_china_mini = False p.delat = 2 # 纬度刻度线分辨率 p.delon = 2 # 经度刻度线分辨率 p.color_coast = "#3a3a3a" # 海岸线颜色 p.color_contry = "#3a3a3a" # 国家颜色 p.fontsize_tick = 15 # set color map p.valmin = vmin p.valmax = vmax p.colormap = plt.get_cmap('jet') # mpl.cm.rainbow, summer # p.colorbar_extend = "max" # plot p.easyplot(latitude, longitude, value, box=box, markersize=markersize, ptype="pcolormesh") if AREA: print('设置地区 :{}'.format(AREA)) if AREA == 'YRD': citys = ["江苏省", "安徽省", "浙江省", "上海市"] elif AREA == 'BTH': citys = ["北京市", "天津市", "河北省"] elif AREA == 'FWP': citys = ["陕西省", "山西省", "河南省"] elif AREA == 'FWP': citys = ["广东省"] else: citys = [] for city in citys: p.city_boundary(city, linewidth=1.2, shape_name='中国省级行政区') # 色标 --------------------------- cb_loc = [0.12, 0.07, 0.76, 0.03] # unit = r"$\mathregular{(10^{15}\/\/molec/cm^2)}$" fontsize = 16 # p.add_custom_colorbar(cb_loc, p.valmin, p.valmax, # fmt="%d", # unit="(1E16 molec/cm^2)", # fontsize=fontsize) c_ax = fig.add_axes(cb_loc) cbar = fig.colorbar(p.cs, cax=c_ax, orientation='horizontal') for l in c_ax.xaxis.get_ticklabels(): l.set_fontproperties(p.font_mid) l.set_fontsize(fontsize) l.set_color(p.color_ticker) # cbar写单位 # cbar.ax.set_title(unit, x=1.0382, y=0, color=p.color_ticker, # ha='left', va='center', # fontproperties=p.font_mid, fontsize=fontsize) # 标题 --------------------------- p.w_title = p.suptitle(title, fontsize=14, y=0.97) # save p.savefig(out_file, dpi=300) print(">>> {}".format(out_file)) p.clean()
def proj_dcc(self): # 初始化投影参数 rowMax=None, colMax=None lookup_table = prj_gll(resLat=self.resLat, resLon=self.resLon) newLats, newLons = lookup_table.generateLatsLons() proj_data_num = np.full_like(newLats, 0) row = proj_data_num.shape[0] col = proj_data_num.shape[1] if self.is_monthly: # 如果是月的,需要查找当前自然月所有数据 PERIOD = calendar.monthrange(int(self.ymd[:4]), int(self.ymd[4:6]))[1] # 当前月份天数 _ymd = self.ymd[:6] + '%02d' % PERIOD # 当月最后一天 else: PERIOD = 1 _ymd = self.ymd file_list = [] for daydelta in xrange(PERIOD): cur_ymd = pb_time.ymd_plus(_ymd, -daydelta) # 判断文件是否存在 file_name = '%s_DCC_SLT_%s.H5' % (self.sat_sensor, cur_ymd) ym = self.ymd[:6] HDF_file = os.path.join(self.ifile, ym, file_name) if not os.path.isfile(HDF_file): print("file no exist : %s" % HDF_file) else: file_list.append(HDF_file) if len(file_list) == 0: return # 开始进行投影 for HDF_file in file_list: h5File = h5py.File(HDF_file, 'r') lons = h5File.get('Longitude')[:] lats = h5File.get('Latitude')[:] h5File.close() lons = lons / 100. lats = lats / 100. ii, jj = lookup_table.lonslats2ij(lons, lats) for i in xrange(row): for j in xrange(col): condition = np.logical_and(ii[:] == i, jj[:] == j) idx = np.where(condition) proj_data_num[i][j] = proj_data_num[i][j] + len(idx[0]) proj_data_num = np.ma.masked_where(proj_data_num == 0, proj_data_num) if self.is_monthly: print("plot: %s" % self.ymd[0:6]) p = dv_map.dv_map() p.easyplot(newLats, newLons, proj_data_num, vmin=0, vmax=10000, ptype=None, markersize=20, marker='s') title_name = '%s_dcc_projection_' % self.sat_sensor + str( self.ymd[0:6]) p.title = u'dcc: ' + str(title_name) + u' (分辨率1度)' opath_fig = os.path.join(self.ofile, 'Monthly', '%s' % self.ymd[:6]) if not os.path.exists(opath_fig): os.makedirs(opath_fig) fig_name = os.path.join( opath_fig, '%s_%s_dcc_monthly.png' % (self.sat_sensor, self.ymd[:6])) p.savefig(fig_name) opath_hdf = os.path.join(self.ofile, 'Monthly', '%s' % self.ymd[:6]) if not os.path.exists(opath_hdf): os.mkdir(opath_hdf) opath_hdf = os.path.join( opath_hdf, '%s_%s_dcc_monthly.hdf' % (self.sat_sensor, self.ymd[0:6])) h5file_W = h5py.File(opath_hdf, 'w') h5file_W.create_dataset('proj_data_nums', dtype='i2', data=proj_data_num, compression='gzip', compression_opts=5, shuffle=True) h5file_W.close() ########################################### # read hdf file and cont values print("write txt: %s" % self.ymd[0:6]) if not os.path.exists(self.ofile_txt): os.mkdir(self.ofile_txt) opath_txt = os.path.join( self.ofile_txt, '%s_dcc_monthly_count.txt' % self.sat_sensor) if self.ifile and len(self.ymd) == 8: hdf = h5py.File(opath_hdf, 'r') data_mat = hdf.get("proj_data_nums")[:] hdf.close() count_value = np.sum(data_mat) self.data_count = '%8s\t%8s\n' % (self.ymd[0:6], count_value) lock.acquire() self.write_txt(opath_txt) lock.release() else: print("plot: %s" % self.ymd) p = dv_map.dv_map() p.easyplot(newLats, newLons, proj_data_num, vmin=0, vmax=10000, ptype=None, markersize=20, marker='s') title_name = '%s_dcc_projection_' % self.sat_sensor + str(self.ymd) p.title = u'dcc: ' + str(title_name) + u' (分辨率1度)' opath_fig = os.path.join(self.ofile, 'Daily', '%s' % self.ymd) if not os.path.exists(opath_fig): os.makedirs(opath_fig) fig_name = os.path.join( opath_fig, '%s_%s_dcc_daily.png' % (self.sat_sensor, self.ymd)) p.savefig(fig_name) opath_hdf = os.path.join(self.ofile, 'Daily', '%s' % self.ymd) if not os.path.exists(opath_hdf): os.mkdir(opath_hdf) opath_hdf = os.path.join( opath_hdf, '%s_%s_dcc_daily.hdf' % (self.sat_sensor, self.ymd)) h5file_W = h5py.File(opath_hdf, 'w') h5file_W.create_dataset('proj_data_nums', dtype='i2', data=proj_data_num, compression='gzip', compression_opts=5, shuffle=True) h5file_W.close() ########################################### # read hdf file and cont values print("write txt: %s" % self.ymd) if not os.path.exists(self.ofile_txt): os.mkdir(self.ofile_txt) opath_txt = os.path.join( self.ofile_txt, '%s_dcc_daily_count.txt' % self.sat_sensor) if self.ifile and len(self.ymd) == 8: hdf = h5py.File(opath_hdf, 'r') data_mat = hdf.get("proj_data_nums")[:] count_value = np.sum(data_mat) self.data_count = '%8s\t%8s\n' % (self.ymd, count_value) lock.acquire() self.write_txt(opath_txt) lock.release()
fy4_lon_lat_lut = 'FY4X_LON_LAT_LUT.H5' with h5py.File(fy4_lon_lat_lut, 'r') as hdf5_file: lats = hdf5_file.get('/Latitude')[:] lons = hdf5_file.get('/Longitude')[:] lat_0 = 28.550000 lon_0 = 23.390000 lat_max = lat_0 + 3 lat_min = lat_0 - 3 lon_max = lon_0 + 3 lon_min = lon_0 - 3 box = [lat_max, lat_min, lon_min, lon_max] # box = [60, 10, 70, 150] p = dv_map() p.easyplot(lats, lons, lats, vmin=None, vmax=None, ptype=None, markersize=0.1, marker='o', box=None) lonlatlocation = [(123.0, -74.5, u"Dome_C"), (23.39, 28.55, u"Libya4")] p.add_landmark(lonlatlocation) out_picture = 'map_test.png' p.savefig(out_picture) print '>>> {}'.format(out_picture)
def main(): pickle_file = 'fy3d_mersi_global.pickle' if not os.path.isfile(pickle_file): dir_path = "/home/gsics/nas03/CMA_GSICS/SourceData/FENGYUN-3D/MERSI/L1/ORBIT/2018/20180630" times = [ '0800', '0805', '0810', '0815', '0820', '0825', '0830', '0835', '0840', '0845', '0850', '0855', '0900', '0905', '0910', '0915', '0920', '0925', '0930', '0935', '0940', '0945', '0950', '0955', '1000', '1005', '1010', '1015', '1020', '1025', '1030', '1035', '1040', '1045', '1050', '1055', '1100', '1110', '1115', '1120', '1125', '1130', ] file_name = 'FY3D_MERSI_GBAL_L1_20180630_{}_1000M_MS.HDF' lon_all = list() lat_all = list() tbb_all = list() for i in times: in_file = os.path.join(dir_path, file_name.format(i)) print in_file read_mersi_l1 = ReadMersiL1(in_file) lon = read_mersi_l1.get_longitude() lat = read_mersi_l1.get_latitude() tbb = read_mersi_l1.get_tbb()['CH_24'] for d in [lat, lon, tbb]: index = np.isfinite(d) lat = lat[index] lon = lon[index] tbb = tbb[index] lon_all = np.append(lon_all, lon) lat_all = np.append(lat_all, lat) tbb_all = np.append(tbb_all, tbb) print(lon_all.shape, lat_all.shape, tbb_all.shape) data = { 'lon': lon_all, 'lat': lat_all, 'tbb': tbb_all, } with open(pickle_file, 'wb') as f: pickle.dump(data, f) else: with open(pickle_file, 'rb') as f: data = pickle.load(f) lat = data['lat'] lon = data['lon'] tbb = data['tbb'] print(lat.shape, lon.shape, tbb.shape) out_file = 'FY3D+MERSI_TBB_GLOBAL_DISTRIBUTION.png' title = 'FY3D+MERSI TBB GLOBAL DISTRIBUTION CH_24 20180630' vmin = int(np.nanmin(tbb)) vmax = int(np.nanmax(tbb)) p = dv_map.dv_map() p.easyplot(lat, lon, tbb, markersize=1, marker='s', vmin=vmin, vmax=vmax) p.title = title p.savefig(out_file) print '>>> {}'.format(out_file)
def run(satPair, ymd): # 解析配置文件 shortsat1 = (satPair.split('_')[0]).split('+')[0] sensor1 = (satPair.split('_')[0]).split('+')[1] shortsat2 = (satPair.split('_')[1]).split('+')[0] sensor2 = (satPair.split('_')[1]).split('+')[1] #ipath = os.path.join(MATCH_DIR, satPair, ymd[:6]) ipath = os.path.join(MATCH_DIR, satPair, ymd[:4], ymd) # 获取输入文件列表 pat = '[_,\-\+\w]+_%s\d{6}.hdf5' % ymd FileLst = pb_io.FindFile(ipath, pat) dictLon1 = {} dictLat1 = {} dictTbb1 = {} dictLon2 = {} dictLat2 = {} dictTbb2 = {} i = 0 if FileLst != []: for iFile in FileLst: try: h5File_R = h5py.File(iFile, 'r') obritType = h5File_R.attrs.get('obrit Direction1')[0] Lon1 = h5File_R.get('S1_Lon')[:] Lat1 = h5File_R.get('S1_Lat')[:] Lon2 = h5File_R.get('S2_Lon')[:] Lat2 = h5File_R.get('S2_Lat')[:] if len(obritType) == 0: print iFile continue if obritType not in dictLon1.keys(): dictLon1[obritType] = Lon1 dictLat1[obritType] = Lat1 dictLon2[obritType] = Lon2 dictLat2[obritType] = Lat2 dictTbb1[obritType] = {} dictTbb2[obritType] = {} for band in BandLst: tbb1 = h5File_R.get('/%s/S1_FovTbbMean' % band)[:] tbb2 = h5File_R.get('/%s/S2_FovTbbMean' % band)[:] if band not in dictTbb1[obritType].keys(): dictTbb1[obritType][band] = tbb1 dictTbb2[obritType][band] = tbb2 else: dictLon1[obritType] = np.concatenate( (dictLon1[obritType], Lon1)) dictLat1[obritType] = np.concatenate( (dictLat1[obritType], Lat1)) dictLon2[obritType] = np.concatenate( (dictLon2[obritType], Lon2)) dictLat2[obritType] = np.concatenate( (dictLat2[obritType], Lat2)) for band in BandLst: tbb1 = h5File_R.get('/%s/S1_FovTbbMean' % band)[:] tbb2 = h5File_R.get('/%s/S2_FovTbbMean' % band)[:] dictTbb1[obritType][band] = np.concatenate( (dictTbb1[obritType][band], tbb1)) dictTbb2[obritType][band] = np.concatenate( (dictTbb2[obritType][band], tbb2)) h5File_R.close() except Exception as e: print str(e) # 按照升降轨道 和 不同通道分别出图,暂时出tbb即可 for adType in dictLat1.keys(): for band in dictTbb1[adType].keys(): print adType, band Tbb1 = dictTbb1[adType][band] Tbb2 = dictTbb2[adType][band] Tbb1 = np.ma.masked_where(Tbb1 <= 0, Tbb1) Tbb2 = np.ma.masked_where(Tbb1 <= 0, Tbb2) outName = '%s+%s_GBAL_MAP_%s_%s_%s.png' % (shortsat1, sensor1, adType, ymd, band) #opath = os.path.join(MATCH_DIR, satPair, outName) opath = os.path.join(MATCH_DIR, satPair, ymd[:4], outName) p = dv_map.dv_map(figsize=(6, 5)) p.title = '%s %s BT collocated with %s at %s %s (%s)' % ( shortsat1, sensor1, sensor2, band, ymd, adType) # p.colorbar_fmt = '%0.2f' vmin = 180 vmax = 300 p.delat = 30 p.delon = 30 p.easyplot(dictLat1[adType], dictLon1[adType], Tbb1, vmin=vmin, vmax=vmax, markersize=1, marker='.') p.savefig(opath, dpi=300) outName = '%s+%s_GBAL_MAP_%s_%s_%s.png' % (shortsat2, sensor2, adType, ymd, band) #opath = os.path.join(MATCH_DIR, satPair, outName) opath = os.path.join(MATCH_DIR, satPair, ymd[:4], outName) p = dv_map.dv_map(figsize=(6, 5)) p.title = '%s %s BT convoluted at %s at %s %s (%s)' % ( shortsat2, sensor2, sensor1, band, ymd, adType) # p.colorbar_fmt = '%0.2f' vmin = 180 vmax = 300 p.delat = 30 p.delon = 30 p.easyplot(dictLat2[adType], dictLon2[adType], Tbb2, vmin=vmin, vmax=vmax, markersize=1, marker='.') p.savefig(opath, dpi=300) outName = '%s+%s_%s+%s_GBAL_MAP_%s_%s_%s.png' % ( shortsat1, sensor1, shortsat2, sensor2, adType, ymd, band) #opath = os.path.join(MATCH_DIR, satPair, outName) opath = os.path.join(MATCH_DIR, satPair, ymd[:4], outName) p = dv_map.dv_map(figsize=(6, 5)) p.title = '%s %s BT at %s %s (%s)' % (sensor1, sensor2, band, ymd, adType) # p.colorbar_fmt = '%0.2f' vmin = -2 vmax = 2 p.delat = 30 p.delon = 30 diffTbb = Tbb1 - Tbb2 diffTbb = np.ma.masked_where(Tbb1 <= 0, diffTbb) p.easyplot(dictLat1[adType], dictLon1[adType], diffTbb, vmin=vmin, vmax=vmax, markersize=1, marker='.') p.savefig(opath, dpi=300)
def proj_fy2_dcc(self): print self.ymd # print 'start project %s %s' % (self.sat, self.sensor) # 初始化投影参数 rowMax=None, colMax=None lookup_table = prj_gll(nlat=self.nlat, slat=self.slat, wlon=self.wlon, elon=self.elon, resLat=self.resLat, resLon=self.resLon) newLats, newLons = lookup_table.generateLatsLons() proj_data_num = np.full_like(newLats, 0) row = proj_data_num.shape[0] col = proj_data_num.shape[1] for L1File in self.ifile: # # print L1File h5File = h5py.File(L1File, 'r') lons = h5File.get('Longitude')[:] lats = h5File.get('Latitude')[:] lons = lons / 100. lats = lats / 100. h5File.close() ii, jj = lookup_table.lonslats2ij(lons, lats) for i in xrange(row): for j in xrange(col): condition = np.logical_and(ii[:, 0] == i, jj[:, 0] == j) idx = np.where(condition) # if len(idx[0]) > 0: # print len(idx[0]) proj_data_num[i][j] = proj_data_num[i][j] + len(idx[0]) proj_data_num = np.ma.masked_where(proj_data_num == 0, proj_data_num) p = dv_map.dv_map() p.easyplot(newLats, newLons, proj_data_num, vmin=0, vmax=10000, box=[30., -30., 60., 120.], ptype=None, markersize=20, marker='s') title_name = '%s_dcc_projection_' % self.sat + str(self.ymd) p.title = u'dcc: ' + str(title_name) + u' (分辨率1度)' fig_name = self.ofile + '/%s' % self.ymd[:6] if not os.path.exists(fig_name): os.mkdir(fig_name) fig_name = fig_name + '/%s_%s_dcc.png' % (self.sat, self.ymd) p.savefig(fig_name) opath_hdf = self.ofile + '/%s' % self.ymd[:6] if not os.path.exists(opath_hdf): os.mkdir(opath_hdf) opath_hdf = opath_hdf + '/%s_%s_dcc.hdf' % (self.sat, self.ymd) h5file_W = h5py.File(opath_hdf, 'w') h5file_W.create_dataset('proj_data_nums', dtype='i2', data=proj_data_num, compression='gzip', compression_opts=5, shuffle=True) h5file_W.close() ########################################### # read hdf file and cont values opath_txt = self.ofile_txt + '/%s_dcc_daily_count.txt' % self.sat if len(self.ifile) == 1 and len(self.ymd) == 8: daily_hdf = h5py.File(opath_hdf) data_mat = daily_hdf.get("proj_data_nums", 'r') count_value = np.sum(data_mat) self.FileSave = '%8s\t%8s\n' % (self.ymd, count_value) self.Write(opath_txt)
def draw(self, in_file, proj_file, dataset_name, vmin=None, vmax=None): if self.error: return # 加载 Proj 数据 if os.path.isfile(proj_file): try: with h5py.File(proj_file, 'r') as h5: lut_ii = h5.get("lut_ii")[:] lut_jj = h5.get("lut_jj")[:] data_ii = h5.get("data_ii")[:] data_jj = h5.get("data_jj")[:] except Exception as why: print why print "Can't open file: {}".format(proj_file) return else: print "File does not exist: {}".format(proj_file) return with time_block("Draw load", switch=TIME_TEST): # 加载产品数据 if os.path.isfile(in_file): try: with h5py.File(in_file, 'r') as h5: proj_value = h5.get(dataset_name)[:][data_ii, data_jj] except Exception as why: print why print "Can't open file: {}".format(in_file) return else: print "File does not exist: {}".format(in_file) return if vmin is not None: vmin = vmin if vmax is not None: vmax = vmax p = dv_map.dv_map() p.title = "{} {}".format(dataset_name, self.ymd) # 增加省边界 # p1.show_china_province = True p.delat = 30 p.delon = 30 p.show_line_of_latlon = False # p.colormap = 'gist_rainbow' # p.colormap = 'viridis' # p.colormap = 'brg' # 创建查找表 lookup_table = prj_core( self.cmd, self.res, unit="deg", row=self.row, col=self.col) lookup_table.grid_lonslats() lons = lookup_table.lons lats = lookup_table.lats # 创建完整的数据投影 value = np.full((self.row, self.col), self.fill_value, dtype='f4') value[lut_ii, lut_jj] = proj_value value = np.ma.masked_less_equal(value, 0) # 掩掉 <=0 的数据 # 乘数据的系数,水色产品为 0.001 slope = 0.001 value = value * slope p.easyplot(lats, lons, value, ptype=None, vmin=vmin, vmax=vmax, markersize=0.1, marker='o') out_png_path = os.path.dirname(in_file) out_png = os.path.join(out_png_path, '{}.png'.format(dataset_name)) pb_io.make_sure_path_exists(os.path.dirname(out_png)) p.savefig(out_png, dpi=300)
def plot_map_picture(value, longitude, latitude, title='', vmin=-np.inf, vmax=np.inf, areas=None, box=None, ticks=None, file_out=None, ptype='pcolormesh', mksize=5, nanhai=False): if file_out is None: print('没有指定输出文件:file_out is None') return # 开始画图----------------------- fig = plt.figure(figsize=(9, 8)) # 图像大小 p = dv_map(fig=fig) subplots_adjust(left=0.07, right=0.98, top=0.90, bottom=0.15) p.show_colorbar = False p.show_countries = False p.show_coastlines = False # p.show_line_of_latlon = False # p.show_china = True if nanhai: p.nanhai_loc = [0.83, 0.25, 0.15, 0.17] p.nanhai_minimap() p.show_china_province = True p.show_inside_china = True p.show_inside_china_mini = True if box: if abs(box[1] - box[0]) < 10: p.delat = 2 else: p.delat = 5 if abs(box[2] - box[3]) < 10: p.delon = 2 elif abs(box[2] - box[3]) < 40: p.delon = 5 else: p.delon = 10 # else: # p.delat = 2 # 纬度刻度线分辨率 # p.delon = 2 # 经度刻度线分辨率 p.color_coast = "#3a3a3a" # 海岸线颜色 p.color_contry = "#3a3a3a" # 国家颜色 p.fontsize_tick = 15 # set color map p.valmin = vmin p.valmax = vmax p.colormap = plt.get_cmap('jet') # mpl.cm.rainbow, summer, jet, bwr # p.colorbar_extend = "max" # plot p.easyplot(latitude, longitude, value, vmin=vmin, vmax=vmax, box=box, markersize=mksize, ptype=ptype) if areas is not None and len(areas) > 0: print('设置地区 :{}'.format(areas)) # aeres = ["江苏省", "安徽省", "浙江省", "上海市"] for aere in areas: p.city_boundary(aere, linewidth=1.2, shape_name='中国省级行政区') # 色标 --------------------------- cb_loc = [0.12, 0.07, 0.76, 0.03] # unit = r"$\mathregular{(10^{15}\/\/molec/cm^2)}$" fontsize = 16 # p.add_custom_colorbar(cb_loc, p.valmin, p.valmax, # fmt="%d", # unit="(1E16 molec/cm^2)", # fontsize=fontsize) c_ax = fig.add_axes(cb_loc) # cbar = fig.colorbar(p.cs, cax=c_ax, ticks=np.arange(0, 1.6, 0.3), orientation='horizontal') fig.colorbar(p.cs, cax=c_ax, ticks=ticks, orientation='horizontal') for l in c_ax.xaxis.get_ticklabels(): l.set_fontproperties(p.font_mid) l.set_fontsize(fontsize) l.set_color(p.color_ticker) # cbar写单位 # cbar.ax.set_title(unit, x=1.0382, y=0, color=p.color_ticker, # ha='left', va='center', # fontproperties=p.font_mid, fontsize=fontsize) # 标题 --------------------------- p.w_title = p.suptitle(title, fontsize=14, y=0.97) # save p.savefig(file_out, dpi=200) print(">>> {}".format(file_out)) p.clean()
# wavenums, response = cris.get_spectral_response() # # wavenums, response = cris.get_spectral_response_low() # print_data_status(wavenums) # print_data_status(response) # print 'get_spectral_response1111:' # wavenums1, response1 = cris.get_spectral_response_high() # print_data_status(wavenums1) # print_data_status(response1) print 'longitude:' t_data1 = cris.get_longitude() print 'latitude:' t_data2 = cris.get_latitude() value = np.full_like(t_data2, 100.) tbbs = tbb['CH_21'] p = dv_map.dv_map(figsize=(6, 5)) p.easyplot(t_data2, t_data1, tbbs, vmin=180, vmax=320, markersize=1.5, marker='.') p.savefig('D:/data/CRIS/test1.png') pass # # # print 'sensor_azimuth:' # t_data = cris.get_sensor_azimuth() # print_data_status(t_data) # print 'sensor_zenith:' # t_data = cris.get_sensor_zenith()