第8页
斯潘4
本文将提供有关如何访问的说明移动银行REST API使用HTTPCaller程序.Movebank是一个公共数据库,包含来自世界各地科学研究的动物运动数据。在这次演示中,HTTPCaller将返回不列颠哥伦比亚省一项研究中有关秃鹰移动的数据。该工作区将允许用户在运行时从研究中选择10只带标签的鸟中的一只。HTTPCaller将从movebankapi接收一个响应,其中包含关于所选eagle的空间和时间数据。使用每个GPS读数的时间戳,我们将按季节对点位置进行分类,以创建一个GeoJSON,显示鹰全年的迁徙模式。
Movebank的API需要基本身份验证,这可以在FME中使用三种不同的方法完成:
尽管movebankapi提供了返回JSON数据的请求URL,但我们感兴趣的请求URL只返回CSV。由于每次运行都要修改请求URL,因此HTTPCaller中的查询字符串参数将用于提高可读性并合并用户参数。因为我们对需要基本身份验证并返回CSV数据的API进行动态调用,Movebank是HTTPCaller中处理的理想API。
由于Movebank数据由各自研究的所有者管理,因此根据所需的数据集,访问数据的权限可能会有所不同。虽然有些研究要求用户阅读并接受他们的使用条款,但我们感兴趣的数据只需要用户名和密码。首先,创建银行帐户. You will be instructed to check the email that is immediately sent containing a temporary password. Follow the link that requires you to change your password. Once you have created a new password, click on the “Tracking Data Map” tab along the top of the webpage.
使用搜索栏,输入“秃鹰”并放大到加拿大西部。你应该在不列颠哥伦比亚省温哥华附近看到一个绿点。点击该点以查看其他信息并选择“打开研究页面”。
研究细节概述了Movebank和数据所有者提供的所有相关信息。注意Movebank ID号,它是访问本研究数据的唯一键。我们稍后将在请求URL中使用它作为参数。还要注意的是,虽然研究中有12只动物,但只有10个跟踪标签。这将影响用户参数,我们稍后将创建该参数以向用户提供鹰的列表。
移动银行API文档在GitHub上共享,其中还详细介绍了附加的安全性、数据访问和身份验证信息。因为我们正在创建一个允许用户在运行时选择特定鹰的工作流,所以请从内容中选择“获取研究中动物的信息”。请注意,我们用于获取唯一eagle ID列表的请求URL将采用以下形式:亚搏在线
https://www.movebank.org/movebank/service/direct-read?实体类型=个人和研究id=2911040
From the contents, select “Get event data for an individual animal”. Note the request URL that we will be using to obtain tracking data for our selected eagle will take the form:
https://www.movebank.org/movebank/service/direct-read?实体类型=事件和研究id=2911040和个人id=2911059
从“启动”页面中选择“新建工作区”以打开空白画布。
The parameters can be left as default as this transformer is only used to initiate the workspace without having to input data.
Connect your Creator to the input port of an HTTPCaller and open the parameters. Our first call to the Movebank API will use the request URL to get information about animals in a study. Use the following request URL with the HTTP Method set to GET:
https://www.movebank.org/movebank/service/direct-read?实体类型=个人和研究id=430263960
通过从“将响应正文保存到”下拉菜单中选择“文件”,更改响应正文保存到的位置。对于输出文件名,请选择省略号以选择目录,确保将“.csv”作为文件扩展名添加到输出名称中。
Check the box to Use Authentication. Select Basic as your Authentication Method and enter your username and password.
单击绿色的运行按钮,当翻译成功后,检查目录以确保文件已保存。在文本编辑器或Microsoft Excel中打开文件以查看数据。第五列将显示我们将作为用户参数输入的各个bird id。
在导航窗格中右键单击“用户参数”,然后选择“创建用户参数”。将类型设置为选项。此参数将为用户提供运行时bird id的下拉列表。将用户参数命名为individual\u id,并将提示设置为individual Bird id:。取消选中可选框以确保每次运行时都选择了一个ID。选择“配置”旁边的省略号,然后单击“导入”按钮。导入向导将打开,提示您输入格式和数据集。将格式设置为CSV,并从上一步中选择CSV文件作为数据集。
单击Next并选择Attribute values as your Import Mode.
单击Next并选择id作为您的选择列表。
单击导入,将显示12个独立的eagle ID列表。单击确定,配置框将自动填充您的数据。确保取消选中“可选”(这是一个强制选项),并且默认值保持为空,然后单击“确定”。
我们将重用以前的HTTPCaller,因为我们已经完成了这个请求。下一个请求URL将接收来自eagle研究的个人跟踪数据:
https://www.movebank.org/movebank/service/direct-read?实体类型=事件和研究id=430263960和个体id=<个体鹰id>
我们将使用查询字符串参数来分解URL的组件。在“请求URL”字段中输入以下URL,并设置要获取的方法:
https://www.movebank.org/movebank/service/direct-read?
Enter entity_type, study_id, and individual_id under the Name column of the Query String Parameters as three different rows. In the Value column, set the entity type as event, and the study ID to 430263960. For the individual ID, click on the arrow that appears in the Value column when you click inside the cell. Move your cursor down to User Parameter and then select individual_id.
将输出文件名更改为您选择的目录将文件重命名为跟踪数据.csv.
Make sure your User Parameter will be prompted every time you run the workspace by clicking on Run along the top toolbar and then Prompt for User Parameters. A check mark should appear next to this text. Run the workspace and you will be prompted to select an Individual Bird ID. Select the first value from the list 430270991 and click Run. Check your directory to make sure the response body was saved, and that it contains data.
有12个ID可供选择,但您可能还记得,只有10个跟踪标签。如果使用每个ID运行工作区,您将看到ID768161195和768162242不包含任何数据。这将在以后的工作区中导致问题,因此我们必须在继续之前删除这些值。
Right click on your _individual_id User Parameter in the Navigation pane and select Edit Definition. Click on the ellipses for Configuration and remove the two IDs by selecting them and clicking the minus sign. Click OK twice to exit the Configuration and User Parameter windows. If you try running the workspace now, there are only 10 options to choose from.
Connect your HTTPCaller output to a FeatureReader. In the parameters, set the Format as CSV and use the arrow to the right of Dataset to specify the _response_file_path attribute as your input. Set the coordinate system to LL84 and then expand Output Ports to select Single Output Port.
在启用功能缓存的情况下运行工作区,以便在可视化预览中查看输出。出现提示时,可以选择任何ID。通用端口将有成百上千的输出功能,但如果单击
动态源数据导致属性从工作区中隐藏,因此我们必须公开它们才能在下游使用属性。将FeatureReader的通用输出端口连接到AttributeExposer。使用上一步中“要素信息”窗口中的五个属性名称填写要公开的属性(也可以在跟踪数据.csv选择属性名而不是值(如果愿意)。
再次运行工作区,您将看到这些属性现在在visualpreview中可见。
要按季节对数据进行分类,首先必须将timestamp属性格式化为只显示月份和日期。将AttributeExposer连接到DateTimeConverter并打开参数。从Datetime属性字段旁边的下拉菜单中选择timestamp属性。输入%m%d作为“输出格式”。单击“确定”。
In the parameters, set the X Value as your location_long attribute and the Y Value as location_lat.
AttributeRangeMapper将基于数字范围创建一个新属性。选择timestamp作为源属性,并将Output属性设置为Season。由于分点和至点每年都不同,因此我们将按2019日历年显示每个季节的开始和结束日期。在范围查找表的第一行中,在“开始”列中输入0000,在“结束”列中输入0319。将输出值设置为Winter。这表明从年初(也就是0101年)到3月19日,这个季节是冬天。对以下范围重复此过程:
添加一个Writer并将格式指定为GeoJSON(地理JavaScript对象表示法)。写一个名为EagleOutput.json文件到所需的输出文件夹。确保要素类型定义设置为“自动”。单击“确定”,系统将提示您更改要素类型名称-输入BaldEagle。将您的AttributeMapper连接到作者。如果在导航窗格中查看已发布的参数,您会注意到出现了一个新参数,它要求用户为其输出指定目标。因为每次运行可能包含不同的数据,所以用户必须能够指定不同的文件名,以避免每次运行时覆盖其数据。
当您单击绿色的Run按钮时,系统会提示您为GeoJSON选择bird和目录。填写参数并单击Run。翻译成功后,转到目录以确保文件已写入。
To view migratory patterns, you will have to symbolize your data by the Season attribute. There are many applications that will directly read a GeoJSON file (i.e. QGIS, ArcMap). In this example, we will be using ArcGIS Online (you can also do a quick visualization by reading in the GeoJSON with FME Workbench and then sending it to an Inspector transformer with a Group-By set on Season). Upload your GeoJSON file to ArcGIS Online as a hosted layer and open it in the Map Viewer. When prompted to choose an attribute to show, select Season. The output map will vary depending on which individual ID you selected, but migratory patterns should remain similar. In the Spring and Summer, bald eagles along the coast of BC tend to migrate North towards the Gulf Islands, whereas they fly South in the Fall and Winter when temperatures drop.
© 2019 Safe Software Inc |法律