Commit dfcd85bb authored by Paulo Medeiros's avatar Paulo Medeiros
Browse files

Use thin_obs method in select_stations

parent 7530577b
......@@ -339,21 +339,14 @@ def select_stations(args):
df_accepted["rejection_rate"].sort_values(ascending=True).index
]
# (c) Add grid (i, j) info
icol, jcol = domain.thinning_grid.lonlat2grid(
df_accepted["lon"].to_numpy(), df_accepted["lat"].to_numpy(),
# (c) Thin data keeping only the first entry found at each (i, j).
# As we've sorted by rejection rate (lower to higher), all but the
# lowest-rejection-rate station at each grid (i, j) will be kept.
grid_trimmed_stations = domain.thinning_grid.thin_obs(
df_accepted, method="first"
)
df_accepted["i"] = icol
df_accepted["j"] = jcol
# (d) rm all but the lowest-rejection-rate station at each grid (i, j)
grid_trimmed_stations = df_accepted.groupby(
["i", "j"], as_index=False, sort=False
).first()
grid_trimmed_stations = grid_trimmed_stations.drop(["i", "j"], axis=1)
df_accepted = df_accepted.drop(["i", "j"], axis=1)
# (e) Finally, move to df_rejected those stations that appear in
# (d) Finally, move to df_rejected those stations that appear in
# df_accepted but not in grid_trimmed_stations
grid_trimmed_mask = df_accepted["id"].isin(grid_trimmed_stations["id"])
df_rejected = df_rejected.append(df_accepted[~grid_trimmed_mask])
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment