Skip to content

Commit 2d9eed3

Browse files
authored
Merge pull request dClimate#34 from dClimate/hotfix/simulated-storm-col
add sim column to simulated trop storms
2 parents 212f2ac + ada4870 commit 2d9eed3

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

dweather_client/storms_datasets.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,19 @@ def get_data(self, basin, **kwargs):
8585

8686
if basin not in {'EP', 'NA', 'NI', 'SI', 'SP', 'WP'}:
8787
raise ValueError("Invalid basin ID")
88-
metadata = self.get_metadata(self.head)
89-
90-
files = [self.get_file_object(f"{self.head}/{f}") for f in metadata['files'] if basin in f]
91-
dfs = [pd.read_csv(f, header=None, compression="gzip")[range(10)] for f in files]
9288

93-
df = pd.concat(dfs).reset_index(drop=True)
94-
columns = ['year', 'month', 'tc_num', 'time_step', 'basin', 'lat', 'lon', 'min_press', 'max_wind', 'rmw']
95-
df.columns = columns
96-
df.loc[df.lon > 180, 'lon'] = df.lon - 360
97-
98-
return process_df(df, **kwargs)
89+
metadata = self.get_metadata(self.head)
90+
dfs = []
91+
for f in metadata["files"]:
92+
if basin in f:
93+
file_obj = self.get_file_object(f"{self.head}/{f}")
94+
df = pd.read_csv(file_obj, header=None, compression="gzip")[range(10)]
95+
columns = ['year', 'month', 'tc_num', 'time_step', 'basin', 'lat', 'lon', 'min_press', 'max_wind', 'rmw']
96+
df.columns = columns
97+
df["sim"] = f[-8]
98+
dfs.append(df)
99+
100+
big_df = pd.concat(dfs).reset_index(drop=True)
101+
big_df.loc[big_df.lon > 180, 'lon'] = big_df.lon - 360
102+
103+
return process_df(big_df, **kwargs)

dweather_client/tests/test_client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from dweather_client.client import get_station_history, get_gridcell_history, get_tropical_storms,\
33
get_yield_history, get_power_history, get_gas_history, get_alberta_power_history, GRIDDED_DATASETS
44
from dweather_client.aliases_and_units import snotel_to_ghcnd
5-
import numpy as np
65
import pandas as pd
76
from io import StringIO
87
import datetime
@@ -90,7 +89,7 @@ def test_simulated_storms():
9089
df_subset_circle_ni = get_tropical_storms('simulated', 'NI', radius=500, lat=21, lon=65, ipfs_timeout=IPFS_TIMEOUT)
9190
df_subset_box_ni = get_tropical_storms('simulated', 'NI', min_lat=21, max_lat=22, min_lon=65, max_lon=66, ipfs_timeout=IPFS_TIMEOUT)
9291

93-
assert len(df_all_ni.columns) == len(df_subset_circle_ni.columns) == len(df_subset_box_ni.columns) == 10
92+
assert len(df_all_ni.columns) == len(df_subset_circle_ni.columns) == len(df_subset_box_ni.columns) == 11
9493
assert len(df_subset_circle_ni) < len(df_all_ni)
9594
assert len(df_subset_box_ni) < len(df_all_ni)
9695

0 commit comments

Comments
 (0)