Skip to content

Commit 87bfeff

Browse files
authored
Merge pull request #7 from NGWPC/mdeshotel_NGWPC-9009
Mdeshotel ngwpc 9009
2 parents 4725a75 + b19d408 commit 87bfeff

99 files changed

Lines changed: 1664655 additions & 1664608 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

data_assimilation_engine/soil_moisture/SMAP_preprocessing/smap_gage.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import xarray as xr
1111
from dotenv import find_dotenv, load_dotenv
1212
from shapely import MultiPoint, Polygon, voronoi_polygons
13-
1413
from utils.utils import time_function, timing_block
1514

1615
load_dotenv(find_dotenv())
@@ -226,7 +225,6 @@ def process_yearly_data(self, output_directory: str):
226225
if not os.path.exists(output_directory):
227226
os.makedirs(output_directory)
228227
for col in df.columns:
229-
print(col)
230228
file = os.path.join(output_directory, f"gages-{col}_soil_moisture.csv")
231229
df["basin_avg_soil_moisture"] = df[col]
232230
df.drop(columns=[col], inplace=True)

data_assimilation_engine/soil_moisture/mapping/simulated_data.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,36 @@ def __init__(self, csv_directory: str, dates: list, output_file: str):
156156

157157
def convert_units(self, df: pd.DataFrame, mask: pd.DataFrame):
158158
"""Convert Units."""
159-
return df.loc[mask, self.column1].values
159+
return np.average(
160+
df.loc[mask, self.columns].values, axis=1, weights=self.soil_thickness
161+
)
162+
163+
@property
164+
def depths(self):
165+
"""Get depths from column names."""
166+
depths = []
167+
for column in self.columns:
168+
depths.append(
169+
float(
170+
column.replace("sm_profile_", "").replace("_", ".").replace("m", "")
171+
)
172+
)
173+
return depths
174+
175+
@property
176+
def soil_thickness(self):
177+
"""Get soil thickness from column names."""
178+
sorted_depths = sorted(self.depths, reverse=True) + [0]
179+
soil_thickness = [
180+
sorted_depths[i] - sorted_depths[i + 1]
181+
for i in range(len(sorted_depths) - 1)
182+
if i + 1 < len(sorted_depths + [0])
183+
]
184+
ordered_soil_thickness = []
185+
for depth in self.depths:
186+
idx = sorted_depths.index(depth)
187+
ordered_soil_thickness.append(soil_thickness[idx])
188+
return ordered_soil_thickness
160189

161190
def check_columns(self, df: pd.DataFrame, file_path: str):
162191
"""Check that columns exists."""
@@ -165,13 +194,8 @@ def check_columns(self, df: pd.DataFrame, file_path: str):
165194
logger.info(f"{self.variable_name} columns not found in {file_path}")
166195
return False
167196

168-
elif len(columns) > 1:
169-
logger.info(
170-
f"Too many ({len(columns)}) {self.variable_name} columns found in {file_path}"
171-
)
172-
return False
173197
else:
174-
self.column1 = columns[0]
198+
self.columns = columns
175199
return True
176200

177201
@property

data_assimilation_engine/soil_moisture/timeseries/timeseries.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,41 @@ def check_columns(self, df: pd.DataFrame, file_path: str):
113113
logger.info(f"{self.variable_name} columns not found in {file_path}")
114114
return False
115115

116-
elif len(columns) > 1:
117-
logger.info(
118-
f"Too many ({len(columns)}) {self.variable_name} columns found in {file_path}"
119-
)
120-
return False
121-
else:
122-
self.column1 = columns[0]
123-
return True
116+
self.columns = columns
117+
return True
124118

125119
def convert_units(self, df: pd.DataFrame, mask: pd.DataFrame):
126120
"""Convert Units."""
127-
return df.loc[mask, self.column1].values
121+
return np.average(
122+
df.loc[mask, self.columns].values, axis=1, weights=self.soil_thickness
123+
)
124+
125+
@property
126+
def depths(self):
127+
"""Get depths from column names."""
128+
depths = []
129+
for column in self.columns:
130+
depths.append(
131+
float(
132+
column.replace("sm_profile_", "").replace("_", ".").replace("m", "")
133+
)
134+
)
135+
return depths
136+
137+
@property
138+
def soil_thickness(self):
139+
"""Get soil thickness from column names."""
140+
sorted_depths = sorted(self.depths, reverse=True) + [0]
141+
soil_thickness = [
142+
sorted_depths[i] - sorted_depths[i + 1]
143+
for i in range(len(sorted_depths) - 1)
144+
if i + 1 < len(sorted_depths + [0])
145+
]
146+
ordered_soil_thickness = []
147+
for depth in self.depths:
148+
idx = sorted_depths.index(depth)
149+
ordered_soil_thickness.append(soil_thickness[idx])
150+
return ordered_soil_thickness
128151

129152

130153
class SoilMoistureS3Loader(S3Loader):

0 commit comments

Comments
 (0)