1. SPOC APIΒΆ
The SPOC API updates the species occurrence dataframe used in the Streamlit SpOc Verifier application. The FastAPI can be run from the root directory with:
uvicorn src.api.main:app --reload --root-path src/api/
%reload_ext autoreload
%autoreload 2
%matplotlib inline
import pandas as pd
import requests
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-2ef02b9fba8f> in <module>
1 get_ipython().run_line_magic('reload_ext', 'autoreload')
2 get_ipython().run_line_magic('autoreload', '2')
----> 3 get_ipython().run_line_magic('matplotlib', 'inline')
4
5 import pandas as pd
/opt/hostedtoolcache/Python/3.9.5/x64/lib/python3.9/site-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
2346 kwargs['local_ns'] = self.get_local_scope(stack_depth)
2347 with self.builtin_trap:
-> 2348 result = fn(*args, **kwargs)
2349 return result
2350
/opt/hostedtoolcache/Python/3.9.5/x64/lib/python3.9/site-packages/decorator.py in fun(*args, **kw)
230 if not kwsyntax:
231 args, kw = fix(args, kw, sig)
--> 232 return caller(func, *(extras + args), **kw)
233 fun.__name__ = func.__name__
234 fun.__doc__ = func.__doc__
/opt/hostedtoolcache/Python/3.9.5/x64/lib/python3.9/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
185 # but it's overkill for just that one bit of state.
186 def magic_deco(arg):
--> 187 call = lambda f, *a, **k: f(*a, **k)
188
189 if callable(arg):
/opt/hostedtoolcache/Python/3.9.5/x64/lib/python3.9/site-packages/IPython/core/magics/pylab.py in matplotlib(self, line)
97 print("Available matplotlib backends: %s" % backends_list)
98 else:
---> 99 gui, backend = self.shell.enable_matplotlib(args.gui.lower() if isinstance(args.gui, str) else args.gui)
100 self._show_matplotlib_backend(args.gui, backend)
101
/opt/hostedtoolcache/Python/3.9.5/x64/lib/python3.9/site-packages/ipykernel/zmqshell.py in enable_matplotlib(self, gui)
599
600 def enable_matplotlib(self, gui=None):
--> 601 gui, backend = super(ZMQInteractiveShell, self).enable_matplotlib(gui)
602
603 try:
/opt/hostedtoolcache/Python/3.9.5/x64/lib/python3.9/site-packages/IPython/core/interactiveshell.py in enable_matplotlib(self, gui)
3515 """
3516 from IPython.core import pylabtools as pt
-> 3517 from matplotlib_inline.backend_inline import configure_inline_support
3518 gui, backend = pt.find_gui_and_backend(gui, self.pylab_gui_select)
3519
/opt/hostedtoolcache/Python/3.9.5/x64/lib/python3.9/site-packages/matplotlib_inline/backend_inline.py in <module>
4 # Distributed under the terms of the BSD 3-Clause License.
5
----> 6 import matplotlib
7 from matplotlib.backends.backend_agg import ( # noqa
8 new_figure_manager,
ModuleNotFoundError: No module named 'matplotlib'
all_records = pd.read_json("../data/species-records.json")
all_records.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 12148 entries, 0 to 12147
Data columns (total 7 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Paper ID 12148 non-null object
1 Instance ID 12148 non-null object
2 Species 12148 non-null object
3 GBIF 12148 non-null object
4 Time 12148 non-null object
5 Place 12148 non-null object
6 div_enum 12148 non-null int64
dtypes: int64(1), object(6)
memory usage: 759.2+ KB
all_records.head()
Paper ID | Instance ID | Species | GBIF | Time | Place | |
---|---|---|---|---|---|---|
0 | fhl_2011_Brezicha_25959.tei.xml | urn:lsid:marinespecies.org:taxname:240762 | Strongylocentrotus franciscanus | https://www.gbif.org/species/search?q=Strongyl... | Porter,Pacific Ocean,Friday Harbor,Salish Sea,... | |
1 | fhl_2011_Brezicha_25959.tei.xml | urn:lsid:marinespecies.org:taxname:431072 | radius | https://www.gbif.org/species/search?q=radius&q... | Porter,Pacific Ocean,Friday Harbor,Salish Sea,... | |
2 | fhl_2011_Brezicha_25959.tei.xml | urn:lsid:marinespecies.org:taxname:711954 | Parastichopus californicus | https://www.gbif.org/species/search?q=Parastic... | Porter,Pacific Ocean,Friday Harbor,Salish Sea,... | |
3 | fhl_2011_Bockmon_26635.tei.xml | urn:lsid:marinespecies.org:taxname:112078 | Ammonia | https://www.gbif.org/species/search?q=Ammonia&... | San Juan Island,Friday Harbor,north end,North ... | |
4 | fhl_2011_Bockmon_26635.tei.xml | urn:lsid:marinespecies.org:taxname:112078 | ammonia | https://www.gbif.org/species/search?q=ammonia&... | San Juan Island,Friday Harbor,north end,North ... |
borked = all_records[all_records['Paper ID'].isin(['asdfs'])]
all_records.sample(5)
Paper ID | Instance ID | Species | GBIF | Time | Place | |
---|---|---|---|---|---|---|
10690 | ucla_1975_ZimmermanRichard.tei.xml | urn:lsid:marinespecies.org:taxname:106994 | Spirontocaris | https://www.gbif.org/species/search?q=Spironto... | 1975-05-27 | pacifica,The wash,Santa Catalina Island,Cove |
3094 | fhl_2014_McGowan_27210.tei.xml | urn:lsid:marinespecies.org:taxname:370041 | Phyllospadix | https://www.gbif.org/species/search?q=Phyllosp... | San Juan Island,shoreline,Wahl,Cattle Point,Bu... | |
8634 | hms_vd999tv5289.tei.xml | urn:lsid:marinespecies.org:taxname:279812 | Atherinops affinis | https://www.gbif.org/species/search?q=Atherino... | Pajaro,PAJARO RIVER,view,Monterey Bay,Elkhorn,... | |
3976 | hms_bn277dh2861.tei.xml | urn:lsid:marinespecies.org:taxname:138086 | Chaetopleura | https://www.gbif.org/species/search?q=Chaetopl... | Bayne,green,Pacific Grove,tide,post,Division,h... | |
6799 | hms_jw427gt5299.tei.xml | urn:lsid:marinespecies.org:taxname:137928 | Elysia | https://www.gbif.org/species/search?q=Elysia&q... | 1988-06-06 | Santa Barbara,Moss Landing Harbor,Pacific Grove |
all_records[all_records['Paper ID'].isin(['carl_1983_OlanderAndrea.tei.xml']) & all_records['Instance ID'].isin(['urn:lsid:marinespecies.org:taxname:269761'])]
Paper ID | Instance ID | Species | GBIF | Time | Place | |
---|---|---|---|---|---|---|
10360 | carl_1983_OlanderAndrea.tei.xml | urn:lsid:marinespecies.org:taxname:269761 | Lythrypnus | https://www.gbif.org/species/search?q=Lythrypn... | Santa Barbara Island,Santa Barbara,white,Turne... |
result = requests.put("http://localhost:8000/records/",
data={ 'paper_id': 'fhl_2014_Sullivan_27302.tei.xml',
'instance_id': 'urn:lsid:marinespecies.org:taxname:6'})
result.text
'{"detail":[{"loc":["body",0],"msg":"Expecting value: line 1 column 1 (char 0)","type":"value_error.jsondecode","ctx":{"msg":"Expecting value","doc":"paper_id=fhl_2014_Sullivan_27302.tei.xml&instance_id=urn%3Alsid%3Amarinespecies.org%3Ataxname%3A6","pos":0,"lineno":1,"colno":1}}]}'
import json
json.loads(all_records.sample(5).to_json(orient='records'))
[{'Paper ID': 'hms_mj526dg0556.tei.xml',
'Instance ID': 'urn:lsid:marinespecies.org:taxname:249634',
'Species': 'glandula',
'GBIF': 'https://www.gbif.org/species/search?q=glandula&qField=SCIENTIFIC',
'Time': '',
'Place': '',
'div_enum': 5},
{'Paper ID': 'fhl_2014_McMahon_34528.tei.xml',
'Instance ID': 'urn:lsid:marinespecies.org:taxname:395240',
'Species': 'concholepas',
'GBIF': 'https://www.gbif.org/species/search?q=concholepas&qField=SCIENTIFIC',
'Time': '',
'Place': 'Talmage,Anlauf,Blanchard,Taylor,Marshall,Ross,Pacific,bivalve,Davis',
'div_enum': 1},
{'Paper ID': 'fhl_2011_Pierce_26647.tei.xml',
'Instance ID': 'urn:lsid:marinespecies.org:taxname:325914',
'Species': 'Mus',
'GBIF': 'https://www.gbif.org/species/search?q=Mus&qField=SCIENTIFIC',
'Time': '',
'Place': 'view,cascade,University',
'div_enum': 2},
{'Paper ID': 'ucla_1978_SkollerDebbie_EnvComplexity.tei.xml',
'Instance ID': 'urn:lsid:marinespecies.org:taxname:402317',
'Species': 'Hypsypops rubicunda',
'GBIF': 'https://www.gbif.org/species/search?q=Hypsypops rubicunda&qField=SCIENTIFIC',
'Time': '1978-05-05',
'Place': 'tide',
'div_enum': 4},
{'Paper ID': 'hms_ms463wm9540.tei.xml',
'Instance ID': 'urn:lsid:marinespecies.org:taxname:106122',
'Species': 'Balanus',
'GBIF': 'https://www.gbif.org/species/search?q=Balanus&qField=SCIENTIFIC',
'Time': '',
'Place': 'Hopkins Marine Life Refuge,Pacific Grove',
'div_enum': 2}]