Code: Select all
import os
import subprocess
import datetime as dt
import pandas as pd
import xarray as xr
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
latitude = 50.0
longitude = 20.0
start_datetime = dt.datetime(1999, 11, 1, 0) # Format: RRRR, MM, DD, hh
runtime = -72
hysplit_dir = r'C:\hysplit'
meteo_folder = r'R:\Dane\noaa'
output_file = os.path.join(hysplit_dir, 'working', 'traj_output.txt')
control_file = os.path.join(hysplit_dir, 'working', 'CONTROL')
with open(control_file, 'w') as f:
f.write(f"{start_datetime.year} {start_datetime.month} {start_datetime.day} {start_datetime.hour}\n")
f.write(f"1\n")
f.write(f"{latitude} {longitude} 10.0\n")
f.write(f"{runtime}\n")
f.write(f"0\n")
f.write(f"10000.0\n")
f.write(f"1\n")
f.write(f"{meteo_folder}\\RP{start_datetime.year}{start_datetime.month:02d}.gbl\n")
f.write(f"{output_file}\n")
with open(control_file, 'r') as f:
print(f.read())
process = subprocess.Popen([os.path.join(hysplit_dir, 'exec', 'hyts_std.exe')], cwd=os.path.join(hysplit_dir, 'working'))
return_code = process.wait()
traj_df = pd.read_csv(output_file, delim_whitespace=True, skiprows=9,
names=['yr', 'mon', 'day', 'hour', 'min', 'trajectory', 'pressure', 'lat', 'lon', 'height'])
ax = plt.axes(projection=ccrs.PlateCarree())
ax.stock_img()
ax.coastlines(resolution='110m')
ax.plot(traj_df['lon'], traj_df['lat'], 'r-', transform=ccrs.PlateCarree())
plt.show()
The CONTROL file that is created contains the following information:
Code: Select all
1999 11 1 0
1
50.0 20.0 10.0
-72
0
10000.0
1
R:\Dane\noaa\RP199911.gbl
C:\hysplit\working\traj_output.txt
Hysplit v. 5.2.1 installed on Win10, Python 3.9.16.