generated from mintlify/starter
-
Notifications
You must be signed in to change notification settings - Fork 7
mapping location data with Axiom and Hex #254
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c6297d7
initial commit
thecraftman 0ddcae8
Merge main into mapping-location-data-with-axiom-guide
thecraftman 944f957
add url for api token and dataset
thecraftman 9b787ed
add description to technical guide
thecraftman c722828
add sidebartitle and tags
thecraftman f9ff195
add conclusion session
thecraftman 4557927
Merge branch 'main' into mapping-location-data-with-axiom-guide
tothmano 16f4b24
TW review
tothmano 84b37a3
Merge branch 'main' into mapping-location-data-with-axiom-guide
thecraftman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
--- | ||
title: 'Map location data with Axiom and Hex' | ||
description: "This page exlains how to visualize geospatial log data from Axiom using Hex interactive maps." | ||
sidebarTitle: 'Hex' | ||
--- | ||
|
||
import Prerequisites from "/snippets/standard-prerequisites.mdx" | ||
import ReplaceDatasetToken from "/snippets/replace-dataset-token.mdx" | ||
import ReplaceDomain from "/snippets/replace-domain.mdx" | ||
import ReplaceDataset from "/snippets/replace-dataset.mdx" | ||
|
||
Hex is a powerful collaborative data platform that allows you to create notebooks with Python/SQL code and interactive visualizations. | ||
|
||
This page explains how to integrate Hex with Axiom to visualize geospatial data from your logs. You ingest location data into Axiom, query it using APL, and create interactive map visualizations in Hex. | ||
|
||
<Prerequisites /> | ||
{/* list separator */} | ||
- [Create a Hex account](https://app.hex.tech/). | ||
|
||
## Send geospatial data to Axiom | ||
|
||
Send your sample location data to Axiom using the API endpoint. For example, the following HTTP request sends sample robot location data with latitude, longitude, status, and satellite information. | ||
|
||
```bash | ||
curl -X 'POST' 'https://AXIOM_DOMAIN/v1/datasets/DATASET_NAME/ingest' \ | ||
-H 'Authorization: Bearer API_TOKEN' \ | ||
-H 'Content-Type: application/json' \ | ||
-d '[ | ||
{ | ||
"data": { | ||
"robot_id": "robot-001", | ||
"latitude": 37.7749, | ||
"longitude": -122.4194, | ||
"num_satellites": 8, | ||
"status": "active" | ||
} | ||
} | ||
]' | ||
``` | ||
|
||
<ReplaceDatasetToken /> | ||
<ReplaceDomain /> | ||
|
||
Verify that your data has been ingested correctly by running an APL query in the Axiom UI. | ||
|
||
## Set up your Hex project | ||
|
||
1. Create a new Hex project. For more information, see the [Hex documentation](https://learn.hex.tech/docs/getting-started/create-your-first-project). | ||
1. Save your Axiom API token as a secret in Hex. This example uses the secret name `AXIOM_API_TOKEN`. For more information, see the [Hex documentation](https://learn.hex.tech/docs/explore-data/projects/environment-configuration/environment-views#secrets). | ||
|
||
## Query data from Axiom | ||
|
||
Write the Python code in your Hex notebook that retrieves data from Axiom. For example, customize the code below: | ||
|
||
```python | ||
import requests | ||
import pandas as pd | ||
from datetime import datetime, timedelta | ||
import os | ||
|
||
# Retrieve the API token from Hex secrets | ||
axiom_token = os.environ.get("AXIOM_API_TOKEN") | ||
|
||
# Define Axiom API endpoint and headers | ||
base_url = "https://AXIOM_DOMAIN/v1/datasets/_apl" | ||
headers = { | ||
'Authorization': f'Bearer {axiom_token}', | ||
'Content-Type': 'application/json', | ||
'Accept': 'application/json', | ||
'Accept-Encoding': 'gzip' | ||
} | ||
|
||
# Define the time range for your query | ||
end_time = datetime.utcnow() | ||
start_time = end_time - timedelta(days=3) # Get data from the last 3 days | ||
|
||
# Construct the APL query | ||
query = { | ||
"apl": """DATASET_NAME | ||
| project ['data.latitude'], ['data.longitude'], ['data.num_satellites'], ['data.robot_id'], ['data.status']""", | ||
"startTime": start_time.strftime("%Y-%m-%dT%H:%M:%SZ"), | ||
"endTime": end_time.strftime("%Y-%m-%dT%H:%M:%SZ") | ||
} | ||
|
||
try: | ||
# Send the request to Axiom API | ||
response = requests.post( | ||
f"{base_url}?format=tabular", | ||
headers=headers, | ||
json=query, | ||
timeout=10 | ||
) | ||
|
||
# Print request details for debugging | ||
print("Request Details:") | ||
print(f"URL: {base_url}?format=tabular") | ||
print(f"Query: {query['apl']}") | ||
print(f"Response Status: {response.status_code}") | ||
|
||
if response.status_code == 200: | ||
data = response.json() | ||
if 'tables' in data: | ||
table = data['tables'][0] | ||
if table.get('columns') and len(table['columns']) > 0: | ||
columns = [field['name'] for field in table['fields']] | ||
rows = table['columns'] | ||
|
||
# Create DataFrame with proper column orientation | ||
df = pd.DataFrame(list(zip(*rows)), columns=columns) | ||
|
||
# Ensure data types are appropriate for mapping | ||
df['data.latitude'] = pd.to_numeric(df['data.latitude']) | ||
df['data.longitude'] = pd.to_numeric(df['data.longitude']) | ||
df['data.num_satellites'] = pd.to_numeric(df['data.num_satellites']) | ||
|
||
# Display the first few rows to verify our data | ||
print("\nDataFrame Preview:") | ||
display(df.head()) | ||
|
||
# Store the DataFrame for visualization | ||
robot_locations = df | ||
else: | ||
print("\nNo data found in the specified time range.") | ||
else: | ||
print("\nNo tables found in response") | ||
print("Response structure:", data.keys()) | ||
|
||
except Exception as e: | ||
print(f"\nError: {str(e)}") | ||
``` | ||
|
||
<ReplaceDomain /> | ||
<ReplaceDataset /> | ||
|
||
## Create map visualisation | ||
|
||
Create an interactive map visualization in Hex and customize it. For more information, see the [Hex documentation](https://learn.hex.tech/docs/explore-data/cells/visualization-cells/map-cells). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
Replace `DATASET_NAME` with the name of the Axiom dataset where you want to send data. | ||
- Replace `DATASET_NAME` with the name of the Axiom dataset where you want to send data. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Replace `AXIOM_DOMAIN` with `api.axiom.co` if your organization uses the US region, and with `api.eu.axiom.co` if your organization uses the EU region. For more information, see [Regions](/reference/regions). |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.