Skip to content

Commit b593017

Browse files
authored
Merge pull request #63 from ecmwf/feat/add_filters
add flexible filtering
2 parents d5a1f9c + dd08cc6 commit b593017

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

hat/extract_timeseries/extractor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ def create_mask_from_coords(coords_config, df, gridx, gridy, shape):
5252

5353
def process_inputs(station_config, grid_config):
5454
df = pd.read_csv(station_config["file"])
55+
filters = station_config.get("filter")
56+
if filters is not None:
57+
df = df.query(filters)
5558
station_names = df[station_config["name"]].values
5659

5760
index_config = station_config.get("index", None)

hat/station_mapping/mapper.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ def get_grid_inputs(grid_config):
2727

2828
def get_station_inputs(station_config):
2929
df = pd.read_csv(station_config["file"])
30+
filters = station_config.get("filter")
31+
if filters is not None:
32+
df = df.query(filters)
3033
coord_x = station_config["coords"]["x"]
3134
coord_y = station_config["coords"]["y"]
3235
station_coords1 = df[coord_x].values

notebooks/workflow/station_mapping.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"config = {\n",
2121
" \"station\": {\n",
2222
" \"file\": \"stations.csv\",\n",
23+
" \"filter\": \"(StationLon >= 0) and (drainage_area_provided >= 0)\",\n",
2324
" \"coords\": {\n",
2425
" \"x\": \"StationLat\",\n",
2526
" \"y\": \"StationLon\"\n",
@@ -63,7 +64,7 @@
6364
],
6465
"metadata": {
6566
"kernelspec": {
66-
"display_name": "Python 3",
67+
"display_name": "hat",
6768
"language": "python",
6869
"name": "python3"
6970
},

notebooks/workflow/timeseries_extraction.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"config = {\n",
2121
" \"station\": {\n",
2222
" \"file\": \"mapped_stations.csv\",\n",
23+
" \"filter\": \"(StationLon >= 0) and (drainage_area_provided >= 0)\",\n",
2324
" # EITHER USE INDEX OR COORDS, NOT BOTH\n",
2425
" # INDEX is preferred but requires you to have the exact same grid\n",
2526
" # as the upstream area used in station mapping\n",

0 commit comments

Comments
 (0)