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

added sct_dual method for dataset #28

Merged
merged 3 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
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
24 changes: 21 additions & 3 deletions include/titanlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -612,9 +612,27 @@ namespace titanlib {
*/
void range_check(const vec& min, const vec& max, const ivec& indices=ivec(1, -1));
void range_check_climatology(int unixtime, const vec& pos, const vec& neg, const ivec& indices=ivec(1, -1));
void sct(int num_min, int num_max, float inner_radius, float outer_radius, int num_iterations, int num_min_prof, float min_elev_diff, float min_horizontal_scale, float vertical_scale, const vec& t2pos, const vec& t2neg, const vec& eps2, vec& prob_gross_error, vec& rep, const ivec& indices=ivec(1, -1));
void buddy_check(const vec& radius, const ivec& num_min, float threshold, float max_elev_diff, float elev_gradient, float min_std, int num_iterations, const ivec& obs_to_check=ivec(), const ivec& indices=ivec(1, -1));
void buddy_event_check(const vec& radius, const ivec& num_min, float event_threshold, float threshold, float max_elev_diff, float elev_gradient, int num_iterations, const ivec& obs_to_check=ivec(), const ivec& indices=ivec(1, -1));
void sct(int num_min, int num_max,
float inner_radius, float outer_radius,
int num_iterations, int num_min_prof,
float min_elev_diff, float min_horizontal_scale, float vertical_scale,
const vec& t2pos, const vec& t2neg, const vec& eps2, vec& prob_gross_error,
vec& rep, const ivec& indices=ivec(1, -1));
void sct_dual(const vec& event_thresholds,
ConditionType condition,
int num_min, int num_max,
float inner_radius, float outer_radius,
int num_iterations,
float min_horizontal_scale, float max_horizontal_scale,
int kth_closest_obs_horizontal_scale,
float vertical_scale,
const vec& test_thresholds,
bool debug,
const ivec& obs_to_check=ivec(), const ivec& indices=ivec(1, -1));
void buddy_check(const vec& radius, const ivec& num_min, float threshold, float max_elev_diff, float elev_gradient, float min_std, int num_iterations,
const ivec& obs_to_check=ivec(), const ivec& indices=ivec(1, -1));
void buddy_event_check(const vec& radius, const ivec& num_min, float event_threshold, float threshold, float max_elev_diff, float elev_gradient, int num_iterations,
const ivec& obs_to_check=ivec(), const ivec& indices=ivec(1, -1));
void isolation_check(int num_min, float radius, float vertical_radius=MV, const ivec& indices=ivec(1, -1));
void isolation_check(const ivec& num_min, const vec& radius, const vec& vertical_radius=vec(), const ivec& indices=ivec(1, -1));
void duplicate_check(float radius, float vertical_range=titanlib::MV, const ivec& indices=ivec(1, -1));
Expand Down
22 changes: 22 additions & 0 deletions src/dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,28 @@ void titanlib::Dataset::sct(int num_min, int num_max, float inner_radius, float
merge(new_flags, indices);
}

void titanlib::Dataset::sct_dual(const vec& event_thresholds,
ConditionType condition,
int num_min, int num_max,
float inner_radius, float outer_radius,
int num_iterations,
float min_horizontal_scale, float max_horizontal_scale,
int kth_closest_obs_horizontal_scale,
float vertical_scale,
const vec& test_thresholds,
bool debug,
const ivec& obs_to_check,
const ivec& indices){
// Only keep flags that are not flagged
ivec new_flags = titanlib::sct_dual(get_unflagged_points(), get_unflagged(values), get_unflagged(obs_to_check),
get_unflagged(event_thresholds), condition,
num_min, num_max, inner_radius, outer_radius, num_iterations,
min_horizontal_scale, max_horizontal_scale,
kth_closest_obs_horizontal_scale, vertical_scale,
get_unflagged(test_thresholds), debug);
merge(new_flags, indices);
}

void titanlib::Dataset::buddy_check(const vec& radius, const ivec& num_min, float threshold, float max_elev_diff, float elev_gradient, float min_std, int num_iterations, const ivec& obs_to_check, const ivec& indices) {
ivec new_flags = titanlib::buddy_check(get_unflagged_points(), get_unflagged(values), get_unflagged(radius), get_unflagged(num_min), threshold, max_elev_diff, elev_gradient, min_std, num_iterations, get_unflagged(obs_to_check));
merge(new_flags, indices);
Expand Down
24 changes: 24 additions & 0 deletions tests/dataset_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,30 @@ def test_buddy_check(self):
max_elev_diff, elev_gradient, min_std, num_iterations)
np.testing.assert_array_equal(dataset.flags, [0]*8 + [1]*2)

def test_isolation_check(self):
lats = [60, 60, 60, 60]
lons = [10, 10.1, 10.2, 12]
elevs = [0]*4
points = titanlib.Points(lats, lons, elevs)
values = [0, 0.1, 1, 2]

num_min = [1, 1, 1, 1]
radii = [100000] * 4

# Last value should be flagged
dataset = titanlib.Dataset(points, values)
# Preflag one of the observations
dataset.external_check([0, 1, 0, 0])
dataset.isolation_check(num_min, radii)
np.testing.assert_array_equal(dataset.flags, [0, 1, 0, 1])

# Check that using a single value for radii also works
radii = [100000]
dataset = titanlib.Dataset(points, values)
dataset.external_check([0, 1, 0, 0])
dataset.isolation_check(num_min, radii)
np.testing.assert_array_equal(dataset.flags, [0, 1, 0, 1])

def test_get_values(self):
N = 10
lats = [60]*N
Expand Down
Loading