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

grabbing gbif downloads #77

Merged
merged 1 commit into from
May 23, 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
10 changes: 10 additions & 0 deletions ioos_metrics/ioos_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ def mbon_stats():
'doi': [df['results'].values[0][0]['doi']]
})], ignore_index=True)


df_gbif = pd.DataFrame()
for key in df_mapping['gbif_uuid']:

Expand All @@ -601,6 +602,15 @@ def mbon_stats():
# merge the OBIS and GBIF data frames together
df_obis = df_obis.merge(df_mapping, on='obis_id')

# add gbif download stats

for key in df_obis['gbif_uuid']:
url = f'https://api.gbif.org/v1/occurrence/download/statistics/export?datasetKey={key}'
df2 = pd.read_csv(url,sep='\t')
df2_group = df2.groupby('year').agg({'number_downloads':'sum'})

df_obis.loc[df_obis['gbif_uuid']==key,'gbif_downloads'] = str(df2_group.to_dict())

df_out = df_gbif.merge(df_obis, on='gbif_uuid')

return df_out
Expand Down
3 changes: 2 additions & 1 deletion tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ def test_mbon_stats():
'obis_statistics', 'obis_extent', 'obis_title', 'obis_citation',
'obis_citation_id', 'obis_abstract', 'obis_intellectualrights',
'obis_feed', 'obis_institutes', 'obis_contacts', 'obis_nodes',
'obis_keywords', 'obis_downloads', 'obis_records', 'title', 'doi']
'obis_keywords', 'obis_downloads', 'obis_records', 'title', 'doi',
'gbif_downloads']

assert isinstance(df, pd.DataFrame)
assert all([col in df.columns for col in columns])
Expand Down