Skip to content

Commit f248f2a

Browse files
authored
Merge pull request #46 from GlobalFishingWatch/feature/docs
improve API documentation, prerequisites, and usage examples
2 parents 98f3f11 + 84fbc86 commit f248f2a

31 files changed

+1272
-430
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The Global Fishing Watch Python package currently works with the following APIs:
4343

4444
- [References API](https://globalfishingwatch.org/our-apis/documentation#regions): Access metadata for EEZs, MPAs, and RFMOs to use in [Events API](https://globalfishingwatch.org/our-apis/documentation#events-api) and [Map Visualization (4Wings API)](https://globalfishingwatch.org/our-apis/documentation#map-visualization-4wings-api) requests and analyses.
4545

46-
> **Note:** See the [Data Caveats](https://globalfishingwatch.org/our-apis/documentation#data-caveat) and [Terms of Use](https://globalfishingwatch.org/our-apis/documentation#terms-of-use) pages in the [GFW API documentation](https://globalfishingwatch.org/our-apis/documentation#introduction) for details on GFW data, API licenses, and rate limits.
46+
> **Note:** See the [Datasets](https://globalfishingwatch.org/our-apis/documentation#api-dataset), [Data Caveats](https://globalfishingwatch.org/our-apis/documentation#data-caveat), and [Terms of Use](https://globalfishingwatch.org/our-apis/documentation#terms-of-use) pages in the [GFW API documentation](https://globalfishingwatch.org/our-apis/documentation#introduction) for details on GFW data, API licenses, and rate limits.
4747
4848
## Requirements
4949

docs/source/development-guides/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
All notable changes to this project will be documented in this file.
44

55
```{include} ../../../CHANGELOG.md
6+
67
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
```{include} ../../../CODE_OF_CONDUCT.md
2+
23
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
```{include} ../../../CONTRIBUTING.md
2+
23
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
```{include} ../../../GIT_WORKFLOW.md
2+
23
```

docs/source/development-guides/index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
The sections below will help you get started with development, testing, and documentation.
44

5-
65
```{toctree}
76
:maxdepth: 1
87
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# License
22

33
```{include} ../../../LICENSE
4+
45
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
```{include} ../../../SECURITY.md
2+
23
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
```{include} ../../../SETUP.md
2+
23
```

docs/source/getting-started.md

Lines changed: 119 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
This guide introduces you to the basics of using the [gfw-api-python-client](https://github.com/GlobalFishingWatch/gfw-api-python-client). For detailed and alternative installation instructions, please refer to the [Installation](installation) section. Here is a [Jupyter Notebook](https://github.com/GlobalFishingWatch/gfw-api-python-client/blob/develop/notebooks/getting-started.ipynb) version for this guide.
66

7-
> **Note:** See the [Data Caveats](https://globalfishingwatch.org/our-apis/documentation#data-caveat) and [Terms of Use](https://globalfishingwatch.org/our-apis/documentation#terms-of-use) pages in the [GFW API documentation](https://globalfishingwatch.org/our-apis/documentation#introduction) for details on GFW data, API licenses, and rate limits.
7+
> **Note:** See the [Datasets](https://globalfishingwatch.org/our-apis/documentation#api-dataset), [Data Caveats](https://globalfishingwatch.org/our-apis/documentation#data-caveat), and [Terms of Use](https://globalfishingwatch.org/our-apis/documentation#terms-of-use) pages in the [GFW API documentation](https://globalfishingwatch.org/our-apis/documentation#introduction) for details on GFW data, API licenses, and rate limits.
88
99
## Authorization
1010

@@ -42,10 +42,13 @@ For more detailed installation instructions, including setting up a virtual envi
4242

4343
## Basic Usage
4444

45+
<a href="https://colab.research.google.com/github/GlobalFishingWatch/gfw-api-python-client/blob/develop/notebooks/getting-started.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>
46+
4547
Once installed, you can import and use `gfw-api-python-client` in your Python codes:
4648

4749
```python
4850
import os
51+
import datetime
4952

5053
import gfwapiclient as gfw
5154

@@ -66,15 +69,38 @@ gfw_client = gfw.Client(
6669

6770
```python
6871
vessel_search_result = await gfw_client.vessels.search_vessels(
69-
query="368045130",
70-
datasets=["public-global-vessel-identity:latest"],
71-
includes=["MATCH_CRITERIA", "OWNERSHIP", "AUTHORIZATIONS"],
72+
query="412331038",
7273
)
7374

74-
vessel_ids = [
75+
vessel_search_ids = [
7576
self_reported_info.id
76-
for vessel in vessel_search_result.data()
77-
for self_reported_info in vessel.self_reported_info
77+
for vessel_search_item in vessel_search_result.data()
78+
if vessel_search_item.registry_info_total_records >= 1
79+
for self_reported_info in vessel_search_item.self_reported_info
80+
]
81+
82+
print(vessel_search_ids)
83+
```
84+
85+
**Output:**
86+
87+
```
88+
['755a48dd4-4bee-4bcf-7b5f-9baea058fc7b', '3dad49b0b-b2e0-9347-0c4c-e39fea560f9f']
89+
```
90+
91+
**Note:** It is recommended to prioritize vessels that include both `registry_info` and `self_reported_info` (AIS), as this indicates a successful match between registry data and AIS information.
92+
93+
### Getting Details of Vessels Filtered by Vessel Searched IDs
94+
95+
```python
96+
vessels_result = await gfw_client.vessels.get_vessels_by_ids(
97+
ids=vessel_search_ids,
98+
)
99+
100+
vessel_self_reported_infos = [
101+
self_reported_info
102+
for vessel_item in vessels_result.data()
103+
for self_reported_info in vessel_item.self_reported_info
78104
]
79105

80106
print(vessel_ids)
@@ -83,16 +109,85 @@ print(vessel_ids)
83109
**Output:**
84110

85111
```
86-
["3312b30d6-65b6-1bdb-6a78-3f5eb3977e58", "126221ace-e3b5-f4ed-6150-394809737c55"]
112+
['755a48dd4-4bee-4bcf-7b5f-9baea058fc7b', '3dad49b0b-b2e0-9347-0c4c-e39fea560f9f']
87113
```
88114

89-
### Getting Fishing Events for the Searched Vessels
115+
### Getting Insights Related to Fishing Events for the Vessel Searched
116+
117+
**Important:** `start_date` must be on or after `January 1, 2020`
118+
119+
```python
120+
start_datetime = min(
121+
[
122+
self_reported_info.transmission_date_from
123+
for self_reported_info in vessel_self_reported_infos
124+
]
125+
)
126+
start_date = start_datetime.date()
127+
128+
129+
end_datetime = max(
130+
[
131+
self_reported_info.transmission_date_to
132+
for self_reported_info in vessel_self_reported_infos
133+
]
134+
)
135+
end_date = end_datetime.date()
136+
137+
dataset_id = "public-global-vessel-identity:latest"
138+
dataset_ids_vessel_ids = [
139+
{"dataset_id": dataset_id, "vessel_id": vessel_id} for vessel_id in vessel_ids
140+
]
141+
142+
insights_result = await gfw_client.insights.get_vessel_insights(
143+
includes=["FISHING"],
144+
start_date=start_date,
145+
end_date=end_date,
146+
vessels=dataset_ids_vessel_ids,
147+
)
148+
149+
insights_df = insights_result.df()
150+
151+
print(insights_df.info())
152+
```
153+
154+
**Output:**
155+
156+
```
157+
<class 'pandas.core.frame.DataFrame'>
158+
RangeIndex: 1 entries, 0 to 0
159+
Data columns (total 6 columns):
160+
# Column Non-Null Count Dtype
161+
--- ------ -------------- -----
162+
0 period 1 non-null object
163+
1 vessel_ids_without_identity 0 non-null object
164+
2 gap 0 non-null object
165+
3 coverage 0 non-null object
166+
4 apparent_fishing 1 non-null object
167+
5 vessel_identity 0 non-null object
168+
dtypes: object(6)
169+
memory usage: 180.0+ bytes
170+
```
171+
172+
```python
173+
insights_data = insights_result.data()
174+
175+
print(dict(insights_data.apparent_fishing.period_selected_counters))
176+
```
177+
178+
**Output:**
179+
180+
```
181+
{'events': 398, 'events_gap_off': None, 'events_in_rfmo_without_known_authorization': 144, 'events_in_no_take_mpas': 0}
182+
```
183+
184+
### Getting Fishing Events for the Vessels Searched
90185

91186
```python
92187
events_result = await gfw_client.events.get_all_events(
93188
datasets=["public-global-fishing-events:latest"],
94-
start_date="2024-03-01",
95-
end_date="2025-03-31",
189+
start_date=start_date,
190+
end_date=end_date,
96191
vessels=vessel_ids,
97192
)
98193

@@ -101,30 +196,30 @@ events_df = events_result.df()
101196
print(events_df.info())
102197
```
103198

104-
Output:
199+
**Output:**
105200

106201
```
107202
<class 'pandas.core.frame.DataFrame'>
108-
RangeIndex: 3 entries, 0 to 2
203+
RangeIndex: 398 entries, 0 to 397
109204
Data columns (total 14 columns):
110205
# Column Non-Null Count Dtype
111206
--- ------ -------------- -----
112-
0 start 3 non-null datetime64[ns, UTC]
113-
1 end 3 non-null datetime64[ns, UTC]
114-
2 id 3 non-null object
115-
3 type 3 non-null object
116-
4 position 3 non-null object
117-
5 regions 3 non-null object
118-
6 bounding_box 3 non-null object
119-
7 distances 3 non-null object
120-
8 vessel 3 non-null object
207+
0 start 398 non-null datetime64[ns, UTC]
208+
1 end 398 non-null datetime64[ns, UTC]
209+
2 id 398 non-null object
210+
3 type 398 non-null object
211+
4 position 398 non-null object
212+
5 regions 398 non-null object
213+
6 bounding_box 398 non-null object
214+
7 distances 398 non-null object
215+
8 vessel 398 non-null object
121216
9 encounter 0 non-null object
122-
10 fishing 3 non-null object
217+
10 fishing 398 non-null object
123218
11 gap 0 non-null object
124219
12 loitering 0 non-null object
125220
13 port_visit 0 non-null object
126221
dtypes: datetime64[ns, UTC](2), object(12)
127-
memory usage: 468.0+ bytes
222+
memory usage: 43.7+ KB
128223
```
129224

130225
## Next Steps

0 commit comments

Comments
 (0)