Esempio n. 1
0
 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数据的路径
ncep_wind_dir = r'H:\ncep\uv\1993'
ncep_wind_files = os.listdir(ncep_wind_dir)
select_ncep_wind_path = [
    os.path.join(ncep_wind_dir, x) for x in ncep_wind_files[:]
]

ncep_slp_dir = r'H:\ncep\pressure\1993'
ncep_slp_files = os.listdir(ncep_slp_dir)
select_ncep_slp_path = [
    os.path.join(ncep_slp_dir, x) for x in ncep_slp_files[:]
]

# 读取数据
ncep_wind_data = ReadData(select_ncep_wind_path,
                          types='ncep',
                          variables=['lon', 'lat', 'time', 'wind'],
                          extents=[105, 135, 5, 45])
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画图
import ttide
from datetime import datetime
from matplotlib.dates import num2date, date2num
"""
    功能:比较模式和验潮站的增水情况
"""

# %% 数据准备
gauge_path = r'E:\gauge_data\h632a93.dat'  # 376表示厦门,632表示坎门
model_wind_path = r'E:\fvcom\fvcom_output_file\windNCEP_0001.nc'
model_tide_path = r'E:\fvcom\fvcom_output_file\AtideIB_0001.nc'
position_site = (121.169, 28.053
                 )  # 厦门地理坐标(118.04, 24.27),坎门的为(121.169, 28.053)

# %% 模式数据处理
model_tide_data = ReadData(model_tide_path, types='fvcom', variables=['zeta'])
model_wind_data = ReadData(model_wind_path, types='fvcom', variables=['zeta'])
model_zeta = model_wind_data.data.zeta - model_tide_data.data.zeta
model_start_time = model_tide_data.data.time[0]
model_end_time = model_tide_data.data.time[-1]
gauge_indx = model_tide_data.find_nearest_point('zeta', position_site)
# 减去模式的平均值(减去的平均值是模式结果的整体平均,非个点)
specific_mzeta = model_zeta[:, gauge_indx] - model_zeta.mean()

# %% 验潮站数据处理
gauge_data = ReadData(gauge_path, types='gauge')
# 做调和分析
elev_anomaly = gauge_data.data.elev / 1000 - 3.87  # 3.281表示厦门的海平参考面,坎门的为3.87
xout = ttide.t_tide(elev_anomaly,
                    stime=gauge_data.data.time[0],
                    lat=position_site[1])
Esempio n. 4
0
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
# __NAME__   = compare_ecmwf_ncep_wind.py
# __AUTHOR__ = 'QIU ZHOU'
# __TIME__   = 2019/6/24 14:42

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画图
Esempio n. 5
0
# 列出需要读取ecmwf数据的路径
ecmwf_wind_dir = r'E:\ecmwf\wind\1993'
ecmwf_wind_files = os.listdir(ecmwf_wind_dir)
select_ecmwf_wind_path = [
    os.path.join(ecmwf_wind_dir, x) for x in ecmwf_wind_files[7:10]
]

ecmwf_slp_dir = r'E:\ecmwf\press\1993'
ecmwf_slp_files = os.listdir(ecmwf_slp_dir)
select_ecmwf_slp_path = [
    os.path.join(ecmwf_slp_dir, x) for x in ecmwf_slp_files[7:10]
]

# 读取数据
ecmwf_wind_data = ReadData(select_ecmwf_wind_path,
                           types='ecmwf',
                           variables=['lon', 'lat', 'time', 'wind'],
                           extents=[105, 135, 5, 45])
ecmwf_slp_data = ReadData(select_ecmwf_slp_path,
                          types='ecmwf',
                          variables=['time', 'slp'],
                          extents=[105, 135, 5, 45])
ecmwf_data = PassiveStore()
setattr(ecmwf_data, 'lon', ecmwf_wind_data.data.lon)
setattr(ecmwf_data, 'lat', ecmwf_wind_data.data.lat)
setattr(ecmwf_data, 'time', ecmwf_wind_data.data.time)
setattr(ecmwf_data, 'u10', ecmwf_wind_data.data.u10)
setattr(ecmwf_data, 'v10', ecmwf_wind_data.data.v10)
setattr(ecmwf_data, 'slp', ecmwf_slp_data.data.slp)
ptime = pltdate.num2date(ecmwf_data.time, tz=None)
ecmwf_wind_speed = np.sqrt(ecmwf_data.u10**2 + ecmwf_data.v10**2)
# # 插值前ecmwf画图
Esempio n. 6
0
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
# __NAME__   = OBC_inverse_barometric_adjuested.py
# __AUTHOR__ = 'QIU ZHOU'
# __TIME__   = 2019/6/21 14:21

from fvcom_tools_packages.fvcom_prep import FvcomPrep
from fvcom_tools_packages.read_data import ReadData
import numpy as np
from scipy.interpolate import interp1d
from matplotlib.dates import num2date

# 重构气压场数据准备
recon_press_path = r'H:\fvcom\fvcom_input_file\ecmwf_08_10_rec1.nc'
recon_press_data = ReadData(recon_press_path, types='fvcom', variables=['slp'])

# obc文件
obc_nc_path = r'H:\fvcom\fvcom_input_file\julian_obc_all.nc'
obc_data = ReadData(obc_nc_path, types='obc', variables=['obc', 'elev'])
obc_num = len(obc_data.data.obc)

# obc的经纬度
obc_lat = recon_press_data.data.lat[0:obc_num]
obc_lon = recon_press_data.data.lon[0:obc_num]
obc_press = recon_press_data.data.slp[:, 0:obc_num]

# 气压时间方向插值
pressure_obc = np.ones([len(obc_data.data.time), obc_num])
for iobc in range(obc_num):
    func = interp1d(recon_press_data.data.time, obc_press[:, iobc])
    pressure_obc_tmp = func(obc_data.data.time)
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
# __NAME__   = compare_tidal_constituents.py
# __AUTHOR__ = 'QIU ZHOU'
# __TIME__   = 2019/7/16 20:44
"""
    比较模式和验潮站的调和常数
"""
from fvcom_tools_packages.read_data import ReadData
from ttide import t_tide

# %% 数据准备
gauge_path = r'E:\gauge_data\h376a93.dat'  # 376表示厦门,632表示坎门
gauge_data = ReadData(gauge_path, types='gauge')
gauge_position = (118.04, 24.27)  # 厦门地理坐标(118.04, 24.27),坎门的为(121.169, 28.053)
model_path = r'E:\fvcom\fvcom_output_file\AtideIB_0001.nc'
model_data = ReadData(model_path, types='fvcom', variables=['zeta'])
indx = model_data.find_nearest_point('zeta', gauge_position)
# %% 调和分析
# 验潮站
elev_anomaly = gauge_data.data.elev / 1000 - 3.281  # 3.281表示厦门的海平参考面,坎门的为3.87
gauge_xout = t_tide(elev_anomaly,
                    stime=gauge_data.data.time[0],
                    lat=gauge_position[1])
# 模式
xiamen_model_elev = model_data.data.zeta[:, indx].flatten()
fvcom_xout = t_tide(xiamen_model_elev,
                    stime=model_data.data.time[0],
                    lat=gauge_position[1])
Esempio n. 8
0
# __NAME__   = plot_research_region.py
# __AUTHOR__ = 'QIU ZHOU'
# __TIME__   = 2019/7/11 10:14

from fvcom_tools_packages.fvcom_plot import PlotFigure
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,
Esempio n. 9
0
# -*- coding: UTF-8 -*-
# __NAME__   = match_model_site_wind.py
# __AUTHOR__ = 'QIU ZHOU'
# __TIME__   = 2019/7/2 9:21

from fvcom_tools_packages.read_data import ReadData
from fvcom_tools_packages.fvcom_plot import PlotFigure
import pandas as pd
from scipy.interpolate import interp1d
import numpy as np
from datetime import datetime
from matplotlib.dates import date2num

# %% 数据准备
site_path = r'E:\site_data\yjs_sql\shengsi.xlsx'
site_data = ReadData(site_path, variables=['wind'], types='site_excel')
model_wind_path = r'E:\fvcom\fvcom_input_file\ncep_08_10_wnd.nc'
model_wind_data = ReadData(model_wind_path, variables=['wind'], types='fvcom')

# %% model数据匹配site数据
# 站点经纬度
station_ll = (122.27, 30.44)  # shengsi
# station_ll = (121.57, 29.12)  # shipu
# station_ll = (121.54, 28.27)  # dachen
# station_ll = (121.16, 28.05)  # yuhuan
index_station = model_wind_data.find_nearest_point('u', station_ll)

# 时间插值
model_time = model_wind_data.data.time[:]
site_time = site_data.data.time[:]
func_u = interp1d(model_time, model_wind_data.data.uwnd[:, index_station])
    功能:该代码主要用于比较模式和高度计的增水
"""
from fvcom_tools_packages.read_data import ReadData
from fvcom_tools_packages.fvcom_plot import PlotFigure
from fvcom_tools_packages.fvcom_prep import FvcomPrep
import numpy as np
from datetime import datetime
from matplotlib.dates import date2num, num2date

# %% 数据准备
alti_path = r'E:\altimeter_data\ctoh.sla.ref.TP.chinasea.088.nc'
model_wind_path = r'E:\fvcom\fvcom_output_file\windNCEP_0001.nc'
model_tide_path = r'E:\fvcom\fvcom_output_file\AtideIB_0001.nc'

# %% 处理高度计数据(主要是减去三个月的平均值,更好的与模式比较)
alti_data = ReadData(alti_path, types='alti')
# 找出全部错误的pass
indx = np.where(alti_data.data.alti_time.max(axis=0) > 711957.9999)[0]
alti_time = alti_data.data.alti_time[:, indx]
alti_sla = alti_data.data.alti_sla[:, indx]
alti_cycle = alti_data.data.alti_cycle[indx]
# 所有pass的海面高度平均
all_pass_mean = np.mean(alti_sla, axis=1).shape
alti_sla = alti_sla[:, 1] - all_pass_mean
# 选取8,9,10三个月的cycle,算出平均值
start_time = datetime(1993, 8, 1)
end_time = datetime(1993, 10, 31)
start_time_stamp = date2num(start_time)
end_time_stamp = date2num(end_time)
start_indx = np.where(alti_time.max(axis=0) >= start_time_stamp)[0][0]
end_indx = np.where(alti_time.max(axis=0) <= end_time_stamp)[0][-1]
Esempio n. 11
0
from fvcom_tools_packages.fvcom_prep import FvcomPrep
from fvcom_tools_packages.read_data import ReadData
from fvcom_tools_packages.fvcom_grid import Grid
import numpy as np
from scipy.interpolate import interp1d, griddata
import os
from matplotlib.dates import num2date
# ecmwf数据准备
ecmwf_slp_dir = r'E:\ecmwf\press\1993'
ecmwf_slp_files = os.listdir(ecmwf_slp_dir)
select_ecmwf_slp_path = [
    os.path.join(ecmwf_slp_dir, x) for x in ecmwf_slp_files[7:10]
]
ecmwf_slp_data = ReadData(select_ecmwf_slp_path,
                          types='ecmwf',
                          variables=['lon', 'lat', 'time', 'slp'],
                          extents=[105, 135, 5, 40])
# obc文件
obc_nc_path = r'H:\fvcom\fvcom_input_file\julian_obc_all.nc'
obc_data = ReadData(obc_nc_path, types='obc', variables=['obc', 'elev'])
obc_num = len(obc_data.data.obc)
# 网格文件
sms_path = r'H:\fvcom\fvcom_input_file\sms.2dm'
sms_data = Grid(sms_path)
# obc的经纬度
obc_lat = sms_data.lat[0:obc_num]
obc_lon = sms_data.lon[0:obc_num]

# 气压空间方向插值
LON, LAT = np.meshgrid(ecmwf_slp_data.data.lon, ecmwf_slp_data.data.lat)
pressure_time_obc = np.ones([len(ecmwf_slp_data.data.time), obc_num],
from matplotlib.dates import num2date
import numpy as np

"""
    方法:气压场采用Fujita公式,然后计算梯度风,叠加ueno的移动风场来重构风场
          重构部分的风场替换掉之前生成的表明风场驱动(气压场同样操作)
          为了做敏感性实验,重构风场和气压场以后都设为0
"""

# 台风最佳路径数据
# # 1997年WINNIE
# tp_track_path = r'H:\best_track\CH\CH1997BST.txt'
# tp_track_data = ReadData(tp_track_path, str_before='WINNIE', str_after='WINNIE(-)1', types='ch')
# 1993年Flo
tp_track_path = r'H:\best_track\CH\CH1993BST.txt'
tp_track_data = ReadData(tp_track_path, str_before='Flo', str_after='Gene', types='ch')

# ecmwf 生成的表明风场和气压驱动
old_file_path = r'H:\fvcom\fvcom_input_file\ecmwf_08_10.nc'
fvcom_data = ReadData(old_file_path, variables=['wind', 'slp'])
fvcom_data.read_fvcom_nc()
fvcom_data.data.slp[:] = 101325
fvcom_data.data.uwnd[:] = 0
fvcom_data.data.vwnd[:] = 0



# 重构风场
# 所求风场点的经纬度
lon = fvcom_data.data.lonc
lat = fvcom_data.data.latc
from fvcom_tools_packages.read_data import ReadData
from fvcom_tools_packages.fvcom_plot import PlotFigure
import pandas as pd
from matplotlib.dates import date2num
from datetime import datetime
import numpy as np
from ttide import t_tide
from scipy.interpolate import interp1d

"""
    功能:处理验潮站数据,并画图
"""

# %% 数据准备
gauge_path = r'E:\gauge_data\h632a93.dat'  # 376表示厦门,632表示坎门
gauge_data = ReadData(gauge_path, types='gauge')
gauge_position = (121.169, 28.053)  # 厦门地理坐标(118.04, 24.27),坎门的为(121.169, 28.053)
# %% 调和分析
elev_anomaly = gauge_data.data.elev / 1000 - 3.87  # 3.281表示厦门的海平参考面,坎门的为3.87
xout = t_tide(elev_anomaly, stime=gauge_data.data.time[0],
              lat=gauge_position[1])
gauge_zeta = elev_anomaly - xout(gauge_data.data.time)
# %% 筛选数据
select_time = pd.date_range('1993-09-28 00:00:00',
                            '1993-10-12 00:00:00',
                            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]
# %% 验潮站相对于高度计过境时间时的增水和前期最大增水)
Esempio n. 14
0
# __AUTHOR__ = 'QIU ZHOU'
# __TIME__   = 2019/7/3 9:23

from fvcom_tools_packages.read_data import ReadData
from fvcom_tools_packages.fvcom_plot import PlotFigure
import os
from datetime import datetime
from matplotlib.dates import date2num, num2date
import numpy as np

# 数据准备(采用的是ECMWF的2m气温)
temp_path_dir = r'E:\ecmwf\temp\1993'
temp_filename = os.listdir(temp_path_dir)
temp_path = [os.path.join(temp_path_dir, x) for x in temp_filename[7:10]]
temp_data = ReadData(temp_path,
                     types='ecmwf',
                     variables=['lon', 'lat', 'time', 't2m', 'sst'],
                     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)):