Spaces:
Paused
Paused
Download docs/ingest.html from sammmmmmm25/marine-tracker: direct link, hf CLI and curl.
- Browser
- Download file 9.55 kB
-
https://huggingface.co/spaces/sammmmmmm25/marine-tracker/resolve/main/docs/ingest.html
- Command line
-
hf download hf://spaces/sammmmmmm25/marine-tracker/docs/ingest.html
-
curl -L -o ingest.html https://huggingface.co/spaces/sammmmmmm25/marine-tracker/resolve/main/docs/ingest.html
9.55 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Python: module ingest</title> | |
| </head><body> | |
| <table class="heading"> | |
| <tr class="heading-text decor"> | |
| <td class="title"> <br><strong class="title">ingest</strong></td> | |
| <td class="extra"><a href=".">index</a><br><a href="file:/Users/samuelveliveli/Downloads/marine-tracker/src/ingest.py">/Users/samuelveliveli/Downloads/marine-tracker/src/ingest.py</a></td></tr></table> | |
| <p><span class="code">Study discovery and location-event ingestion from Movebank, with local caching.<br> | |
| <br> | |
| Two data sources are supported, normalized to a common schema:<br> | |
| <br> | |
| - **Live API** (``www.movebank.org/movebank/service/direct-read``): near-live<br> | |
| GPS/Argos events. Every request needs HTTP Basic Auth -- there is no<br> | |
| anonymous tier, confirmed by requesting the study list with no credentials<br> | |
| (returns HTTP 401 with ``WWW-Authenticate: BASIC``). First access to a<br> | |
| study's events also requires accepting that study's license terms: the API<br> | |
| returns the terms as HTML, and the caller must echo back the MD5 hash of<br> | |
| that HTML as ``license-md5`` to receive real data. Used only when<br> | |
| ``MOVEBANK_USERNAME``/``MOVEBANK_PASSWORD`` are set (see auth.py).<br> | |
| - **Movebank Data Repository** (``datarepository.movebank.org``): a separate,<br> | |
| fully public, DOI-archival system with no auth. Confirmed working via its<br> | |
| DSpace REST API (search -> item -> bundles -> bitstreams -> CSV content).<br> | |
| Used as the always-available fallback so the app works with zero setup,<br> | |
| clearly labeled as historical (not live) data.<br> | |
| <br> | |
| Both paths are real research studies with real citations, not synthetic data.<br> | |
| Cached pulls are stored as parquet under data/raw/, named with the study<br> | |
| identifier and pull date, since Movebank tag data changes at most a few<br> | |
| times a day.</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="argparse.html">argparse</a><br> | |
| <a href="hashlib.html">hashlib</a><br> | |
| </td><td class="multicolumn"><a href="io.html">io</a><br> | |
| <a href="pandas.html">pandas</a><br> | |
| </td><td class="multicolumn"><a href="requests.html">requests</a><br> | |
| </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="-default_study_citations"><strong>default_study_citations</strong></a>()</dt><dd><span class="code">Return [{name, taxon, citation, license}] for the currently active default studies.<br> | |
| <br> | |
| Required reading before this data is shown anywhere in the app: Movebank's<br> | |
| terms require surfacing each study's citation, not just noting it in code.<br> | |
| Falls back to principal-investigator attribution when a study's citation<br> | |
| field is empty (seen in practice on the live API), since some form of<br> | |
| attribution must still be surfaced.</span></dd></dl> | |
| <dl><dt><a name="-discover_live_studies"><strong>discover_live_studies</strong></a>()</dt><dd><span class="code">Query the live Movebank API for all studies, filtered to marine mammal taxa.<br> | |
| <br> | |
| Requires MOVEBANK_USERNAME/MOVEBANK_PASSWORD. Returns a DataFrame with<br> | |
| columns id, name, taxon_ids, license_type, i_have_download_access,<br> | |
| timestamp_last_deployed_location -- sorted by most recently active first.<br> | |
| Raises RuntimeError if no live credentials are configured.</span></dd></dl> | |
| <dl><dt><a name="-fetch_live_events"><strong>fetch_live_events</strong></a>(study_id)</dt><dd><span class="code">Download all location events for one live-API study, handling the license-md5 handshake.<br> | |
| <br> | |
| Movebank returns the study's license terms as HTML on first access; this<br> | |
| function accepts by echoing back the MD5 hash of that HTML, then re-requests<br> | |
| to get the actual CSV event data. Returns a DataFrame in the common event schema.</span></dd></dl> | |
| <dl><dt><a name="-fetch_repository_events"><strong>fetch_repository_events</strong></a>(bitstream_url)</dt><dd><span class="code">Download a movement-data CSV bitstream from the Movebank Data Repository. No auth required.</span></dd></dl> | |
| <dl><dt><a name="-ingest"><strong>ingest</strong></a>(refresh=False)</dt><dd><span class="code">Pull (or load from cache) the default studies and return {study_name: DataFrame}.<br> | |
| <br> | |
| Uses the live API if MOVEBANK_USERNAME/MOVEBANK_PASSWORD are set,<br> | |
| otherwise falls back to the public Data Repository. Set refresh=True to<br> | |
| bypass today's cache and re-pull.</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>DATA_RAW_DIR</strong> = PosixPath('/Users/samuelveliveli/Downloads/marine-tracker/data/raw')<br> | |
| <strong>DEFAULT_LIVE_STUDIES</strong> = [{'name': 'Bowhead whale Cumberland Sound', 'study_id': 467034665, 'taxon': 'Balaena mysticetus'}, {'name': 'churchill harbour seals', 'study_id': 3792819345, 'taxon': 'Phoca vitulina'}, {'name': 'Trichechus manatus Sirenia NE Brazil', 'study_id': 1936932457, 'taxon': 'Trichechus manatus'}]<br> | |
| <strong>DEFAULT_REPOSITORY_STUDIES</strong> = [{'bitstream_url': 'https://datarepository.movebank.org/server/api/c...eams/aca1254b-7574-4677-a4d0-5fc23415859f/content', 'citation': 'Andrews-Goff V, Gales N, Childerhouse SJ, Laveri...1:e114729. https://doi.org/10.3897/BDJ.11.e114729', 'doi': '10.5441/001/1.294', 'license': 'CC0 1.0 Universal', 'name': "Movements of Australia's east coast humpback whales", 'taxon': 'Megaptera novaeangliae'}, {'bitstream_url': 'https://datarepository.movebank.org/server/api/c...eams/53183515-d3f3-4a9b-acb4-a90f8b02bcc6/content', 'citation': 'Baker L, Flemming JEM, Jonsen ID, Lidgard DC, Iv...nt Ecology 3(1):20. doi:10.1186/s40462-015-0047-4', 'doi': '10.5441/001/1.910p0c20', 'license': 'CC0 1.0 Universal', 'name': 'Grey seals (Halichoerus grypus) at Sable Island', 'taxon': 'Halichoerus grypus'}, {'bitstream_url': 'https://datarepository.movebank.org/server/api/c...eams/2c398911-0b86-466d-a6d5-8da2d9ca9c18/content', 'citation': 'Andrews-Goff V, Double M. 2022. Deployment detai...ian Antarctic Data Centre. doi:10.26179/jd0n-va59', 'doi': '10.5441/001/1.vr276ns3', 'license': 'CC0 1.0 Universal', 'name': 'Antarctic blue whales, east Antarctic sector of the Southern Ocean', 'taxon': 'Balaenoptera musculus'}]<br> | |
| <strong>EVENT_COLUMNS</strong> = ['timestamp', 'location_lat', 'location_long', 'individual_local_identifier', 'individual_taxon_canonical_name', 'study_name', 'source']<br> | |
| <strong>LIVE_API_BASE</strong> = 'https://www.movebank.org/movebank/service/direct-read'<br> | |
| <strong>MARINE_MAMMAL_GENERA</strong> = {'arctocephalus', 'balaena', 'balaenoptera', 'berardius', 'callorhinus', 'caperea', ...}<br> | |
| <strong>REPOSITORY_API_BASE</strong> = 'https://datarepository.movebank.org/server/api'</td></tr></table> | |
| </body></html> |