Skip to content

Commit 5ba7271

Browse files
committed
Updated filtering of lat lon to use Series.between and added lat-lon bug fix from dashboard-prototype (Imageomics#50).
1 parent 2ac552c commit 5ba7271

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ Prototype data dashboard for analyzing telemetry data.
55
## How it works
66

77
For full dashboard functionality, upload a CSV or XLS file with the following columns:
8-
- `lat`*: Latitude at which image was taken or specimen was collected.
9-
- `lon`*: Longitude at which image was taken or specimen was collected.
8+
- `lat`*: Latitude at which image was taken or specimen was collected: number in [-90,90].
9+
- `lon`*: Longitude at which image was taken or specimen was collected: number in [-180,180].
1010

1111

1212
***Note:**
13-
- `lat` and `lon` columns are not required to utilize the dashboard, but there will be no map view if they are not included.
13+
- Blank (or null) entries are recorded as `unknown`, and thus excluded from map view.
1414

1515
## Running Dashboard
1616

components/divs.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
{'label': 'Descending', 'value': 'sum descending'}]
1616

1717
DOCS_URL = "https://github.com/Imageomics/telemetry-dashboard/tree/dev#how-it-works"
18+
DOCS_LINK = html.A("documentation",
19+
href=DOCS_URL,
20+
target='_blank',
21+
style = ERROR_STYLE)
1822

1923
def get_hist_div(cat_list):
2024
'''
@@ -212,20 +216,24 @@ def get_error_div(error_dict):
212216
html.H3("Source data does not have '" + feature + "' column. ",
213217
style = ERROR_STYLE),
214218
html.H4(["Please see the ",
215-
html.A("documentation",
216-
href=DOCS_URL,
217-
target='_blank',
218-
style = ERROR_STYLE),
219+
DOCS_LINK,
219220
" for list of required columns."],
220221
style = ERROR_STYLE)
221222
])
223+
elif 'mapping' in error_dict.keys():
224+
error_msg = error_dict['mapping']
225+
error_div = html.Div([
226+
html.H4("Latitude or longitude columns have non-numeric values: " + error_msg + ".",
227+
style = ERROR_STYLE),
228+
html.H4(["Please see the ",
229+
DOCS_LINK,
230+
"."],
231+
style = ERROR_STYLE)
232+
])
222233
elif 'type' in error_dict.keys():
223234
error_div = html.Div([
224235
html.H4(["The source file is not a valid CSV format, please see the ",
225-
html.A("documentation",
226-
href=DOCS_URL,
227-
target='_blank',
228-
style = ERROR_STYLE),
236+
DOCS_LINK,
229237
"."],
230238
style = ERROR_STYLE)
231239
])

components/query.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,9 @@ def get_points_in_radius(df, radius):
9999
min_lon = lon - rad_deg
100100
max_lon = lon + rad_deg
101101

102-
filtered_df = filtered_df.loc[filtered_df['lat'].astype(float) > min_lat]
103-
filtered_df = filtered_df.loc[filtered_df['lat'].astype(float) < max_lat]
104-
filtered_df = filtered_df.loc[filtered_df['lon'].astype(float) > min_lon]
105-
filtered_df = filtered_df.loc[filtered_df['lon'].astype(float) < max_lon]
102+
filtered_df = filtered_df.loc[filtered_df['lat'].astype(float).between(min_lat, max_lat)]
103+
filtered_df = filtered_df.loc[filtered_df['lon'].astype(float).between(min_lon, max_lon)]
104+
106105
num_samples = len(filtered_df)
107106

108107
pts_per_lat_lon.append(num_samples)

dashboard.py

+11
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ def parse_contents(contents, filename):
8484
else:
8585
included_features = list(df.columns)
8686

87+
# Check for lat/lon bounds & type
88+
try:
89+
# Check lat and lon within appropriate ranges (lat: [-90, 90], lon: [-180, 180])
90+
valid_lat = df['lat'].astype(float).between(-90, 90)
91+
df.loc[~valid_lat, 'lat'] = 'unknown'
92+
valid_lon = df['lon'].astype(float).between(-180, 180)
93+
df.loc[~valid_lon, 'lon'] = 'unknown'
94+
except ValueError as e:
95+
print(e)
96+
return json.dumps({'error': {'mapping': str(e)}})
97+
8798
# get dataset-determined static data:
8899
# the dataframe and categorical features - processed for map view if mapping is True
89100
# all possible species, subspecies

0 commit comments

Comments
 (0)