Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hysplitdev #140

Merged
merged 4 commits into from
Oct 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 43 additions & 8 deletions monetio/models/hytraj.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,48 @@ def get_traj(tdump):
varibs = varibs.split(",")
variables = varibs[1:]
# Read the traj arrays into pandas dataframe
heads = [
heads = (
[
"traj_num",
"met_grid",
"forecast_hour",
"traj_age",
"latitude",
"longitude",
"altitude",
]
+ variables
+ ["time"]
)

def dateparse(row):
slist = [row[2], row[3], row[4], row[5], row[6]]
tstr = " ".join(slist)
tstr = time_str_fixer(tstr)
tdate = pd.to_datetime(tstr, format="%y %m %d %H %M")
return tdate

dhash = {
0: int,
1: int,
2: str,
3: str,
4: str,
5: str,
6: str,
7: float,
8: float,
9: float,
10: float,
11: float,
}
traj = pd.read_csv(tdump, header=None, sep=r"\s+", dtype=dhash)
traj["time"] = traj.apply(lambda row: dateparse(row), axis=1)
traj = traj.drop([2, 3, 4, 5, 6], axis=1)
# Adds headers to dataframe
traj.columns = heads
# Makes all headers lowercase
zmoon marked this conversation as resolved.
Show resolved Hide resolved
neworder = [
"time",
"traj_num",
"met_grid",
Expand All @@ -232,12 +273,6 @@ def get_traj(tdump):
"longitude",
"altitude",
] + variables
traj = pd.read_csv(tdump, header=None, sep=r"\s+", parse_dates={"time": [2, 3, 4, 5, 6]})
# Adds headers to dataframe
traj.columns = heads
# Makes all headers lowercase
traj = traj[neworder]
traj.columns = map(str.lower, traj.columns)
# Puts time datetime object
traj["time"] = traj.apply(lambda row: time_str_fixer(row["time"]), axis=1)
traj["time"] = pd.to_datetime(traj["time"], format="%y %m %d %H %M")
return traj