Backward trajectories vs python

Topics about the HYSPLIT trajectory model.
Post Reply
krzybart
Posts: 3
Joined: May 16th, 2019, 7:36 am
Registered HYSPLIT User: No

Backward trajectories vs python

Post by krzybart »

I would like to draw trajectories on a map in python using Hysplit. I have a script:

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()
Unfortunately, Hysplit does not create the 'traj_output.txt' file. Directory paths are correct, Hysplit works fine. The meteo data I have is in *.gbl format, for example RP199911.gbl (I have all file from 1948 to 2022).
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
However, the 'traj_output.txt' file is not created.. Is there some error in the script or in the relationship between python and Hysplit?
Hysplit v. 5.2.1 installed on Win10, Python 3.9.16.
alicec
Posts: 419
Joined: February 8th, 2016, 12:56 pm
Registered HYSPLIT User: Yes

Re: Backward trajectories vs python

Post by alicec »

I don't see an obvious problem.
Is a MESSAGE file created? How do you know HYSPLIT ran fine?
Post Reply

Return to “Trajectory Model”