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

Bug at smooth_temp_ends in jasmine #280

Merged
merged 3 commits into from
Dec 19, 2024
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
14 changes: 14 additions & 0 deletions src/forest/jasmine/traj2stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,10 @@ def smooth_temp_ends(
temp[0, 4] = (1 - p1) * x0 + p1 * x1
temp[0, 5] = (1 - p1) * y0 + p1 * y1
temp[0, 6] = t1_temp

# if expanding range, then convert to imputed status and not observed
if max(p0, p1) > 1:
temp[0, 7] = 0
else:
if parameters.split_day_night and i % 2 != 0:
t0_temp_l = [start_time, end_time2]
Expand Down Expand Up @@ -558,6 +562,11 @@ def smooth_temp_ends(
end_temp[j], 2
] + p1 * temp[end_temp[j], 5]
temp[end_temp[j], 6] = t1_temp_l[j]

if p0 > 1:
temp[start_temp[j], 7] = 0
if p1 > 1:
temp[end_temp[j], 7] = 0
else:
p0 = (temp[0, 6] - t0_temp) / (temp[0, 6] - temp[0, 3])
p1 = (
Expand All @@ -571,6 +580,11 @@ def smooth_temp_ends(
temp[-1, 5] = (1 - p1) * temp[-1, 2] + p1 * temp[-1, 5]
temp[-1, 6] = t1_temp

if p0 > 1:
temp[0, 7] = 0
if p1 > 1:
temp[-1, 7] = 0

return temp


Expand Down
22 changes: 3 additions & 19 deletions tests/jasmine/test_traj2stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,40 +418,26 @@ def test_gps_summaries_summary_vals(
parameters=parameters,
)

assert np.all(summary["obs_duration"] == 24)
assert summary["obs_duration"].iloc[0] == 24
assert summary["obs_day"].iloc[0] == 10
assert summary["obs_night"].iloc[0] == 14
assert summary["obs_day"].iloc[1] == 24
assert summary["obs_day"].iloc[1] == 0
assert summary["obs_night"].iloc[1] == 0
assert np.all(summary["home_time"] == 0)
assert summary["home_time"].iloc[0] == 0
assert summary["dist_traveled"].iloc[0] == 0.208
assert summary["dist_traveled"].iloc[1] == 0
assert np.round(summary["max_dist_home"].iloc[0], 3) == 0.915
assert np.round(summary["max_dist_home"].iloc[1], 3) == 0.915
assert np.round(summary["radius"].iloc[0], 3) == 0.013
assert summary["radius"].iloc[1] == 0
assert np.round(summary["diameter"].iloc[0], 3) == 0.064
assert summary["diameter"].iloc[1] == 0
assert summary["num_sig_places"].iloc[0] == 2
assert summary["num_sig_places"].iloc[1] == 1
assert np.round(summary["entropy"].iloc[0], 3) == 0.468
assert summary["entropy"].iloc[1] == 0
assert round(summary["total_flight_time"].iloc[0], 3) == 1.528
assert summary["total_flight_time"].iloc[1] == 0
assert round(summary["av_flight_length"].iloc[0], 3) == 0.052
assert summary["av_flight_length"].iloc[1] == 0
assert round(summary["sd_flight_length"].iloc[0], 3) == 0.012
assert summary["sd_flight_length"].iloc[1] == 0
assert round(summary["av_flight_duration"].iloc[0], 3) == 0.382
assert summary["av_flight_duration"].iloc[1] == 0
assert round(summary["sd_flight_duration"].iloc[0], 3) == 0.132
assert summary["sd_flight_duration"].iloc[1] == 0
assert round(summary["total_pause_time"].iloc[0], 3) == 22.472
assert summary["total_pause_time"].iloc[1] == 24
assert round(summary["av_pause_duration"].iloc[0], 3) == 4.494
assert summary["av_pause_duration"].iloc[1] == 24
assert round(summary["sd_pause_duration"].iloc[0], 3) == 3.496
assert summary["sd_pause_duration"].iloc[1] == 0


def test_gps_summaries_pcr(
Expand All @@ -475,9 +461,7 @@ def test_gps_summaries_pcr(
)

assert summary["physical_circadian_rhythm"].iloc[0] == 0
assert summary["physical_circadian_rhythm"].iloc[1] == 1
assert summary["physical_circadian_rhythm_stratified"].iloc[0] == 0
assert summary["physical_circadian_rhythm_stratified"].iloc[1] == 0


@pytest.fixture
Expand Down