Spaces:
Sleeping
Sleeping
File size: 6,963 Bytes
27b6a20 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Python: module predict</title>
</head><body>
<table class="heading">
<tr class="heading-text decor">
<td class="title"> <br><strong class="title">predict</strong></td>
<td class="extra"><a href=".">index</a><br><a href="file:/Users/samuelveliveli/Downloads/marine-tracker/src/predict.py">/Users/samuelveliveli/Downloads/marine-tracker/src/predict.py</a></td></tr></table>
<p><span class="code">Near-term movement projection: two honesty-first tiers.<br>
<br>
`heading` (default): estimate current bearing and speed from the last N<br>
fixes, project forward linearly, and grow an uncertainty cone whose width is<br>
grounded in that individual's own historical bearing/speed variance -- not an<br>
arbitrary constant. This is the credible baseline.<br>
<br>
`markov` (optional upgrade): discretize the individual's own historical<br>
bearing changes into direction bins, build a transition model from its own<br>
track, and simulate a small ensemble of forward paths. The output is a<br>
spread of plausible paths, not one line.<br>
<br>
Neither tier should be read as a forecast of certainty. Both are labeled<br>
"projected range of motion" by the callers in analysis.py/app.py.</span></p>
<p>
<table class="section">
<tr class="decor pkg-content-decor heading-text">
<td class="section-title" colspan=3> <br><strong class="bigsection">Modules</strong></td></tr>
<tr><td class="decor pkg-content-decor"><span class="code"> </span></td><td> </td>
<td class="singlecolumn"><table><tr><td class="multicolumn"><a href="numpy.html">numpy</a><br>
</td><td class="multicolumn"><a href="pandas.html">pandas</a><br>
</td><td class="multicolumn"></td><td class="multicolumn"></td></tr></table></td></tr></table><p>
<table class="section">
<tr class="decor functions-decor heading-text">
<td class="section-title" colspan=3> <br><strong class="bigsection">Functions</strong></td></tr>
<tr><td class="decor functions-decor"><span class="code"> </span></td><td> </td>
<td class="singlecolumn"><dl><dt><a name="-bearing_deg"><strong>bearing_deg</strong></a>(lat1, lon1, lat2, lon2)</dt><dd><span class="code">Initial great-circle bearing in degrees (0=north, 90=east) from point 1 to point 2.</span></dd></dl>
<dl><dt><a name="-circular_mean_deg"><strong>circular_mean_deg</strong></a>(bearings)</dt><dd><span class="code">Mean of a list of compass bearings (degrees), handling the 0/360 wraparound.</span></dd></dl>
<dl><dt><a name="-circular_std_deg"><strong>circular_std_deg</strong></a>(bearings)</dt><dd><span class="code">Circular standard deviation of compass bearings (degrees), handling wraparound.</span></dd></dl>
<dl><dt><a name="-destination_point"><strong>destination_point</strong></a>(lat, lon, bearing, distance_km)</dt><dd><span class="code">Great-circle destination point given a start point, bearing (deg), and distance (km).</span></dd></dl>
<dl><dt><a name="-predict"><strong>predict</strong></a>(individual_df, mode='heading', **kwargs)</dt><dd><span class="code">Dispatch to predict_heading (default) or predict_markov.</span></dd></dl>
<dl><dt><a name="-predict_heading"><strong>predict_heading</strong></a>(individual_df, window=10, horizon_hours=24, step_hours=1)</dt><dd><span class="code">Linear heading/speed projection with a variance-grounded expanding uncertainty cone.<br>
<br>
Uses the last `window` segments to estimate current heading and speed,<br>
and the individual's *entire* track history to estimate bearing/speed<br>
variance (so the cone reflects how erratically this individual actually<br>
moves, not an arbitrary assumption). Returns a dict with:<br>
- centerline: list of (timestamp, lat, lon) for the projected path<br>
- cone_left / cone_right: matching boundary lat/lon lists<br>
- summary: short plain-language description<br>
- heading_deg, speed_kmh, bearing_std_deg, speed_std_deg (for transparency)</span></dd></dl>
<dl><dt><a name="-predict_markov"><strong>predict_markov</strong></a>(
individual_df,
n_bins=16,
horizon_hours=24,
step_hours=1,
n_runs=50,
random_state=None
)</dt><dd><span class="code">Sample an ensemble of forward paths from a bearing-transition model built on this individual's own history.<br>
<br>
Returns a dict with `paths`: a list of n_runs paths, each a list of<br>
(timestamp, lat, lon), plus a `summary`. Communicates uncertainty as a<br>
spread of simulated paths rather than a single predicted line.</span></dd></dl>
<dl><dt><a name="-track_segments"><strong>track_segments</strong></a>(individual_df)</dt><dd><span class="code">Return per-consecutive-fix bearing (deg) and speed (km/h) for one individual's sorted track.<br>
<br>
Expects individual_df sorted by timestamp with location_lat/location_long columns.<br>
Returns a DataFrame of len(individual_df) - 1 rows with columns bearing, speed_kmh, dt_hours.</span></dd></dl>
</td></tr></table><p>
<table class="section">
<tr class="decor data-decor heading-text">
<td class="section-title" colspan=3> <br><strong class="bigsection">Data</strong></td></tr>
<tr><td class="decor data-decor"><span class="code"> </span></td><td> </td>
<td class="singlecolumn"><strong>EARTH_RADIUS_KM</strong> = 6371.0088</td></tr></table>
</body></html> |