def calculate_model_zeta(self, station, start_time, end_time, figure=True, *args, **kwargs): wind_zeta_data = ReadData(self.wind_path, types='fvcom', variables=['time', 'zeta']) tide_zeta_data = ReadData(self.tide_path, types='fvcom', variables=['time', 'zeta']) index = wind_zeta_data.find_nearest_point('zeta', station) time_range = pd.date_range(start_time, end_time, freq='H') time_stamp = date2num(time_range) start_index = np.where(wind_zeta_data.data.time[:] == time_stamp[0]) end_index = np.where(wind_zeta_data.data.time[:] == time_stamp[-1]) zeta_wind = wind_zeta_data.data.zeta[start_index[0][0]: end_index[0][0]+1, index] - \ tide_zeta_data.data.zeta[start_index[0][0]:end_index[0][0]+1, index] if figure: zeta_fig = PlotFigure(cartesian=True) zeta_fig.plot_lines(time_stamp, zeta_wind, time_series=True, *args, **kwargs) return zeta_wind
ncep_slp_data = ReadData(select_ncep_slp_path, types='ncep', variables=['time', 'slp'], extents=[105, 135, 5, 45]) ncep_data = PassiveStore() setattr(ncep_data, 'lon', ncep_wind_data.data.lon) setattr(ncep_data, 'lat', ncep_wind_data.data.lat) setattr(ncep_data, 'time', ncep_wind_data.data.time) setattr(ncep_data, 'u10', ncep_wind_data.data.u10) setattr(ncep_data, 'v10', ncep_wind_data.data.v10) setattr(ncep_data, 'slp', ncep_slp_data.data.slp) ptime = pltdate.num2date(ncep_data.time, tz=None) ncep_wind_speed = np.sqrt(ncep_data.u10**2 + ncep_data.v10**2) # # 插值前ncep画图 X, Y = np.meshgrid(ncep_data.lon, ncep_data.lat) ncep_plot = PlotFigure(extents=[105, 135, 5, 45], title='ncep') ncep_plot.plot_surface(X, Y, ncep_wind_speed[0, :, :]) ncep_plot.show() # 网格数据路径 grid_path = r'H:\fvcom\fvcom_input_file\sms.2dm' # 表面强迫的插值 prep = FvcomPrep(grid_path) interped_data = prep.interp_surface_forcing(ncep_data) wind_speed = np.sqrt(interped_data.uwnd**2 + interped_data.vwnd**2) # 插值后ncep画图 fig_obj = PlotFigure(grid_path=grid_path, figsize=(12, 8), extents=[105, 135, 5, 45]) fig_obj.plot_surface(fig_obj.grid.lon, fig_obj.grid.lat, wind_speed[0, :]) fig_obj.show()
select_start_indx = np.where( gauge_data.data.time == select_time_stamp[0])[0][0] select_end_indx = np.where(gauge_data.data.time == select_time_stamp[-1])[0][0] select_gauge_zeta = gauge_zeta[select_start_indx:select_end_indx + 1] - gauge_mean_zeta # 选择时间范围的模式数据(减去平均) select_start_mindx = \ np.where(model_tide_data.data.time == select_time_stamp[0])[0][0] select_end_mindx = \ np.where(model_tide_data.data.time == select_time_stamp[-1])[0][0] select_model_zeta = specific_mzeta[select_start_mindx:select_end_mindx + 1] # %% 画图 plot_obj = PlotFigure(cartesian=True, y_label='Sea Level Anomalies(m)', legend_label=('Tide-Gauge', 'Model'), grid=True, time_interval=2) plot1 = plot_obj.plot_lines(select_time_stamp, select_gauge_zeta, time_series=True, color='b') plot2 = plot_obj.plot_lines(select_time_stamp, select_model_zeta, linestyle='--', color='r') plot_obj.set_legend(plot1, plot2) output = r'D:\2018_2019_research\china_sea_1993\images\final\before\kanmen_gmzeta.svg' plot_obj.save(output) # plot_obj.show()
from fvcom_tools_packages.read_data import ReadData from fvcom_tools_packages.fvcom_plot import PlotFigure import numpy as np # 准备数据 ncep_path = r'H:\ncep\uv\splanl.gdas.19930801-19930805.grb2.nc' ecmwf_path = r'E:\ecmwf\wind\1993\interim_uv1993_08.nc' extents = [105, 135, 5, 40] ncep_data = ReadData(ncep_path, types='ncep', variables=['lon', 'lat', 'time', 'wind'], extents=extents) ncep_wind_speed = np.sqrt(ncep_data.data.u10[:]**2 + ncep_data.data.v10[:]**2) ecmwf_data = ReadData(ecmwf_path, types='ecmwf', variables=['lon', 'lat', 'time', 'wind'], extents=extents) ecmwf_wind_speed = np.sqrt(ecmwf_data.data.u10[:]**2 + ecmwf_data.data.v10[:]**2) time_index = 0 # ncep画图 X, Y = np.meshgrid(ncep_data.data.lon, ncep_data.data.lat) ncep_plot = PlotFigure(extents=extents, title='ncep') ncep_plot.plot_surface(X, Y, ncep_wind_speed[0, :, :]) ncep_plot.show() # ecmwf画图 X, Y = np.meshgrid(ecmwf_data.data.lon, ecmwf_data.data.lat) ncep_plot = PlotFigure(extents=extents, title='ecmwf') ncep_plot.plot_surface(X, Y, ecmwf_wind_speed[0, :, :]) ncep_plot.show()
wind_spd = site_wind_data['wind_spd'].to_numpy() wind_dir = site_wind_data['wind_dir'].to_numpy() # 数据中的角度和quiver的角度不一样,需要加180度 wind_dir = wind_dir + 180 # 选择数据 start_time = date2num(datetime(1993, 9, 28, 2)) end_time = date2num(datetime(1993, 10, 12, 14)) start_index = np.where(start_time == time_stamp)[0][0] end_index = np.where(end_time == time_stamp)[0][0] select_wind_spd = wind_spd[start_index:end_index + 1] select_wind_dir = wind_dir[start_index:end_index + 1] select_wind_time = time_stamp[start_index:end_index + 1] # # 画风向时间序列图 # plot_obj = PlotFigure(figsize=(12, 6),cartesian=True, title='Da Chen') # plot_obj.plot_windDir_time(select_wind_time, select_wind_spd, select_wind_dir) # output_name = r'D:\2018_2019_research\china_sea_1993\images\papar_images\site_station\{}.pdf'.format(station) # # plot_obj.save(output_name) # plot_obj.show() # 画风速时间序列图 spd_plot = PlotFigure(cartesian=True, title='Yu Huan', grid=True, y_label='Wind Speed(m/s)') spd_plot.plot_lines(select_wind_time, select_wind_spd, time_series=True) output_name = r'D:\2018_2019_research\china_sea_1993\images\papar_images\site_station\{}_spd.pdf'.format( station) spd_plot.save(output_name) # spd_plot.show()
from fvcom_tools_packages.read_data import ReadData import numpy as np from matplotlib.dates import num2date """ 功能:绘制研究区域(包含台风路径、高度计路径以及验潮站) """ # %% 数据准备 altimeter_path = r'E:\altimeter_data\ctoh.sla.ref.TP.chinasea.088.nc' typhoon_path = r'E:\best_track\bwp1993\bwp261993.txt' alti_data = ReadData(altimeter_path, types='alti', alti_cycle=39) tp_data = ReadData(typhoon_path, types='bwp') # %% 画图 plot_obj = PlotFigure(figsize=(10, 8), extents=[115, 138, 15, 35], depth=True, tick_inc=[4, 4]) # 高度计轨迹 plot_obj.plot_lines(alti_data.data.alti_lon, alti_data.data.alti_lat, color='r', lw=4) # 台风轨迹 plot_obj.plot_lines(tp_data.data.tp_lon, tp_data.data.tp_lat, color='k', marker='o', mfc='r', mec='b', lw=4, ms=10)
start_time_stamp = date2num(start_time) end_time = datetime(1993, 10, 12, 14) end_time_stamp = date2num(end_time) start_time_indx = np.where(site_time == start_time_stamp)[0][0] end_time_indx = np.where(site_time == end_time_stamp)[0][0] select_site_time = site_time[start_time_indx:end_time_indx + 1] select_site_wind_spd = site_data.data.wind_spd[start_time_indx:end_time_indx + 1] select_site_wind_dir = site_data.data.wind_dir[start_time_indx:end_time_indx + 1] select_model_uwind = model_uwinded[start_time_indx:end_time_indx + 1] select_model_vwind = model_vwinded[start_time_indx:end_time_indx + 1] select_model_wind = model_winded[start_time_indx:end_time_indx + 1] # 只比较风速大小 spd_plot = PlotFigure(title='Sheng Si', cartesian=True, grid=True, y_label='Wind Speed(m/s)', legend_label=('site', 'model'), time_interval=2) plot1 = spd_plot.scatter(select_site_time, select_site_wind_spd, c='r') plot2 = spd_plot.plot_lines(select_site_time, select_model_wind, time_series=True) spd_plot.set_legend(plot1, plot2) output_name = r'D:\2018_2019_research\china_sea_1993\images\final\before\{}_MSwind_ncep.svg'.format( site_data.data.station) spd_plot.save(output_name) spd_plot.show()
prep_obj = FvcomPrep(grid_path) interped_zeta = prep_obj.interp_temp_spatial(model_wind_data.lon, model_wind_data.lat, model_wind_data.data.time, model_zeta, interp_alti_lon, interp_alti_lat, interp_alti_time, time_single=True, regular=False) # 计算出模式中对于高度计点的三个月平均值,并计算最后的模式zeta position_indx = np.ones(len(interp_alti_lat)) i = 0 for ilon, ilat in zip(interp_alti_lon, interp_alti_lat): position = (ilon, ilat) indx_tmp = prep_obj.find_nearest_point('zeta', position) position_indx[i] = indx_tmp.astype(int) i += 1 select_zeta = np.asarray([model_zeta[:, x.astype(int)] for x in position_indx]) mean_zeta = np.mean(select_zeta, axis=1) model_final_zeta = interped_zeta - np.mean(model_zeta) # %% 画图 plot_obj = PlotFigure(cartesian=True, x_label='Latitude(deg N)', y_label='Sea Surface Height Anomalies (m)', legend_label=('CTOH', 'Model')) plot_obj.plot_lines(interp_alti_lat, model_final_zeta) plot_obj.plot_lines(select_alti_lat, select_alti_sla_39) plot_obj.show()
#!/usr/bin/env python3 # -*- coding: UTF-8 -*- # __NAME__ = plot_sms_grid.py # __AUTHOR__ = 'QIU ZHOU' # __TIME__ = 2019/7/16 10:01 """ 功能:画sms网格图 """ from fvcom_tools_packages.fvcom_plot import PlotFigure #%% 数据准备 sms_path = r'E:\fvcom\fvcom_input_file\sms.2dm' #%% 画图 plot_obj = PlotFigure(grid_path=sms_path, extents=[105, 135, 6, 40], tick_inc=[5, 5]) plot_obj.plot_sms_grid(lw=0.1) output = r'D:\2018_2019_research\china_sea_1993\images\final\before\grid.svg' plot_obj.save(output, dpi=300) plot_obj.show()
start_time = date2num(datetime(1993, 9, 28, 2)) end_time = date2num(datetime(1993, 10, 12, 14)) start_index = np.where(start_time == time_stamp)[0][0] end_index = np.where(end_time == time_stamp)[0][0] select_temp = temp[start_index:end_index + 1] select_max_temp = max_temp[start_index:end_index + 1] select_min_temp = min_temp[start_index:end_index + 1] select_time = time_stamp[start_index:end_index + 1] select_press = press[start_index:end_index + 1] select_max_press = max_press[start_index:end_index + 1] select_min_press = min_press[start_index:end_index + 1] # Temp-Press画图 TP_plot = PlotFigure(cartesian=True, title='Yu Huan', y_label='Temperature(℃)', grid=True, legend_label=('Temperture', 'Pressure')) TP_plot.plot_lines(select_time, select_temp, time_series=True, double_yaxis=True, double_y=select_press, double_ylabel='Air Pressure(hPa)') output_name = r'D:\2018_2019_research\china_sea_1993\images\papar_images\site_station\{}_TP.pdf'.format( station) # TP_plot.save(output_name) TP_plot.show() # Max_temp画图 MT_plot = PlotFigure(cartesian=True,
freq='H') select_time_stamp = date2num(select_time) select_start_indx = np.where(gauge_data.data.time == select_time_stamp[0])[0][0] select_end_indx = np.where(gauge_data.data.time == select_time_stamp[-1])[0][0] select_gauge_zeta = gauge_zeta[select_start_indx:select_end_indx + 1] # %% 验潮站相对于高度计过境时间时的增水和前期最大增水) alti_pass_time = datetime(1993, 10, 8, 8, 32) alti_pass_date = alti_pass_time.strftime('%m-%dT%H:%M') alti_pass_stime = date2num(alti_pass_time) zeta_func = interp1d(select_time_stamp, select_gauge_zeta) gauge_zeta_alti = zeta_func(alti_pass_stime) point_first = 46 # 62手动选出厦门的第一个峰值的点,坎门的是46 # %% 画图 plot_obj = PlotFigure(cartesian=True, grid=True, y_label='Sea Level Anomalies(m)', time_interval=2, extents=[select_time_stamp[0],select_time_stamp[-1], -0.2, 0.8]) plot_obj.plot_lines(select_time_stamp, select_gauge_zeta, time_series=True, color='b') plot_obj.vline(alti_pass_stime) plot_obj.vline(select_time_stamp[point_first]) plot_obj.annotate(alti_pass_date, xy=(alti_pass_stime, gauge_zeta_alti), xytext=(alti_pass_stime + 1, gauge_zeta_alti + 0.1)) plot_obj.annotate(select_time[point_first].strftime('%m-%dT%H:%M'), xy=(select_time_stamp[point_first], select_gauge_zeta[point_first]), xytext=( select_time_stamp[point_first] + 1, select_gauge_zeta[point_first] + 0.1)) out_put = r'D:\2018_2019_research\china_sea_1993\images\final\before\gauge_xiamen.svg' plot_obj.save(out_put) plot_obj.show()
select_lat = depth_lat[lat_index_down:lat_index_up + 1] select_lon = depth_lon[lon_index_left:lon_index_right + 1] select_depth = depth[lat_index_down:lat_index_up + 1, lon_index_left:lon_index_right + 1] # 插值水深 interp_depth = [] func = interp2d(select_lon, select_lat, select_depth) for i in range(len(lat)): z = func(lon[i], lat[i]) interp_depth.append(z) # 计算距离 distance = [] for j in range(len(lat)): dis = distance_on_sphere(lon[0], lat[0], lon[j], lat[j]) / 1000 distance.append(dis) # 画图 plot_obj = PlotFigure(cartesian=True, x_label='Distance(km)', y_label='Depth(m)', extents=[0, 500, -2500, 0]) plot_obj.plot_lines(distance, interp_depth) plot_obj.plot_lines() plot_obj.ax.xaxis.set_ticks_position('top') plot_obj.ax.xaxis.set_label_position('top') plot_obj.ax.spines['bottom'].set_visible(False) plot_obj.ax.spines['right'].set_visible(False) output = r'D:\2018_2019_research\china_sea_1993\images\final\before\section2.svg' # plot_obj.save(output) plot_obj.show()
extents=[105, 135, 5, 40]) # 选择画图的时间范围 start_time = datetime(1993, 9, 25, 0) end_time = datetime(1993, 10, 12, 18) start_time_stamp = date2num(start_time) end_time_stamp = date2num(end_time) start_indx = np.where(start_time_stamp == temp_data.data.time)[0][0] end_indx = np.where(end_time_stamp == temp_data.data.time)[0][0] select_t2m = temp_data.data.t2m[start_indx:end_indx + 1, :, :] select_sst = temp_data.data.sst[start_indx:end_indx + 1, :, :] select_time = temp_data.data.time[start_indx:end_indx + 1] # 作图 for itime in range(len(select_time)): title = num2date(select_time[itime]).strftime('%Y-%m-%dT%H') temp_plot = PlotFigure(extents=[110, 135, 15, 40], tick_inc=[4, 5], title=title, cb_label='℃', cb_lim=[18, 36]) temp_plot.plot_surface(temp_data.data.lon, temp_data.data.lat, select_t2m[itime, :, :]) temp_plot.fill_region(city='Fujian', taiwan=True) out_dir = r'D:\2018_2019_research\china_sea_1993\images\papar_images\ecmwf_t2m' outname = 't2m' + num2date( select_time[itime]).strftime('%Y%m%dT%H') + '.png' out_path = os.path.join(out_dir, outname) temp_plot.save(out_path, dpi=300) # temp_plot.show()