福衛七號:大氣斜溫圖
(使用Python)

首先,安裝 netCDF4、matplotlib和metpy函式庫。你可以在VS Code的終端中使用以下命令安裝:


pip install netCDF4 matplotlib metpy 


import netCDF4 as nc

import matplotlib.pyplot as plt

from metpy.plots import SkewT

from metpy.units import units

from metpy.calc import dewpoint_from_relative_humidity

import numpy as np

import pandas as pd


# 讀取NetCDF檔案

file_path = 'C:/fs7data/fs7_2024065/wetPf2_C2E1.2024.065.05.16.G10_0001.0001_nc'

ds = nc.Dataset(file_path)


# 提取數據

alt = ds.variables['MSL_alt'][:]

temp = ds.variables['Temp'][:].data * units.degC

pres = ds.variables['Pres'][:].data * units.hPa

rh = ds.variables['rh'][:].data / 100.0  # 轉換為比例


# 確保相對濕度是單位為"dimensionless"的Quantity

rh = units.Quantity(rh, '')


# 計算露點溫度

dewpoint = dewpoint_from_relative_humidity(temp, rh)


# 檢查提取數據的形狀

print(temp.shape)

print(pres.shape)

print(dewpoint.shape)


# 如果數據是一維的,直接使用

temp_profile = temp[:]

pres_profile = pres[:]

dewpoint_profile = dewpoint[:]

alt_profile = alt[:]  # 高度數據


# 創建數據框以儲存數據

data = {

    'Height_MSL': alt_profile,  # 高度數據

    'Temperature_C': temp_profile.magnitude,

    'Pressure_hPa': pres_profile.magnitude,

    'Dew_Point_C': dewpoint_profile.magnitude

}


df = pd.DataFrame(data)

csv_file_path = 'C:/fs7data/1.csv'

df.to_csv(csv_file_path, index=False)


print(f"Data saved to {csv_file_path}")


# 創建Skew-T圖

fig = plt.figure(figsize=(10, 10))

skew = SkewT(fig)


# 繪製溫度剖面 (藍色實線)

skew.plot(pres_profile, temp_profile, 'b-', label='Temperature')

# 繪製露點溫度剖面 (紅色虛線)

skew.plot(pres_profile, dewpoint_profile, 'r--', label='Dew Point')


# 繪製乾絕熱線

skew.plot_dry_adiabats()


# 繪製濕絕熱線

skew.plot_moist_adiabats()


# 繪製等混合比線

skew.plot_mixing_lines()


# 設定圖表範圍

skew.ax.set_ylim(1000, 100)

skew.ax.set_xlim(-50, 50)


# 添加網格和標籤

skew.ax.grid(True)

skew.ax.set_xlabel('Temperature (°C)')

skew.ax.set_ylabel('Pressure (hPa)')

skew.ax.legend()


# 顯示圖表

plt.title('Skew-T Log-P Diagram')

plt.show()


wetPf2_C2E1.2024.065.05.16.G10_0001.0001_nc

wetPf2_C2E3.2024.065.21.34.G21_0001.0001_nc