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

Interpolate and group ais #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

MorganMasters
Copy link
Collaborator

No description provided.

# then apply an interpolation function for each timepoint. The
# interpolation function will take a dataframe and a timepoint,
# and will determine, based on the nearest records before/after
# the timepoint, which interpolation rule to apply.
#
# While this function sounds like it takes a long time, its ok at
# the outset to accomplish this somewhat inefficiently.
mmsi_set = ais_df.groupby["mmsi"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

groupby is a function, needs parentheses (e.g. groupby("mmsi"))

Also, be careful naming things *_set when they're not a set object. Try mmsi_gb since this is a groupby object.

Comment on lines +550 to +552
MWM: "near" = entries before and after the given time,
"very near" = one entry within a neighborhood of the given time

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what the point of this is. These aren't definitions, despite the equals sign. These are cases when each term is used.

time: when to interpolate the ship positions.
delta: the "very near" threshold
"""
time_col = mmsi["BaseDateTime"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try something like this, but faster:

for target_time in times:
    last_before = max(obs_time - target_time for obs_time in time_col if obs_time < target_time)
    first_after = min(obs_time - target_time for obs_time in time_col if obs_time > target_time)
    if (
        last_before
        and target_time - last_before < near
        and first_after
        and first_after - target_time < near
    ):
        # C1
    elif last_before and target_time - last_before < very_near:
        # C2
    elif first_after and first_after - target_time < very_near:
        # C2

Comment on lines +582 to +583
time: when to interpolate the ship positions.
delta: the "very near" threshold

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to do this for a list of times, so either _interpolate_and_group_ais() needs to apply this to each time, or _ais_interpolator_dispatcher() needs to take a list of times.

Also, you need deltas for the "near" and "very near" thresholds.

Comment on lines +1 to +10
from tehom import downloads, _persistence


def test_download_ais_to_temp(declare_stateful):
year = 2014
month = 1
zone = 1
downloads._download_ais_to_temp(year, month, zone)
path = _persistence.AIS_TEMP_DIR / f"{year}_{month}_{zone}.zip"
assert path.exists()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants