Skip to content

Commit 2378cdc

Browse files
authored
Merge pull request #200 from CUAHSI/CAM-876/version-d-hydrocron-simple
[CAM-876] Version D data
2 parents 39c82b7 + 33ea073 commit 2378cdc

File tree

6 files changed

+46
-12
lines changed

6 files changed

+46
-12
lines changed

api/swotvis/app/routers/hydrocron/router.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ async def proxy_hydrocron_timeseries(
4747

4848
try:
4949
async with httpx.AsyncClient() as client:
50+
print(
51+
f"Original request url with params: {client.build_request('GET', HYDROCRON_BASE_URL, params=params).url}"
52+
)
5053
response = await client.get(HYDROCRON_BASE_URL, params=params, timeout=30.0)
5154

5255
# If the response is successful, return the content
@@ -57,7 +60,15 @@ async def proxy_hydrocron_timeseries(
5760
return JSONResponse(content=response.json())
5861
else:
5962
# Forward the error from the external API
60-
raise HTTPException(status_code=response.status_code, detail=f"HydroCron API error: {response.text}")
63+
# check if response has json content
64+
if response.headers.get("Content-Type") == "application/json":
65+
error_detail = response.json()
66+
else:
67+
error_detail = response.text
68+
# ensure we include statusText as well
69+
if "statusText" in response.headers:
70+
error_detail += f": {response.headers['statusText']}"
71+
return JSONResponse(content=error_detail, status_code=response.status_code)
6172

6273
except httpx.TimeoutException:
6374
raise HTTPException(status_code=504, detail="Request timeout")

frontend/docker-entrypoint.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ for file in $DIST_DIR/assets/*.js $DIST_DIR/index.html; do
77
sed -i 's|VITE_APP_API_URL_PLACEHOLDER|'${VITE_APP_API_URL}'|g' $file
88
sed -i 's|VITE_APP_FULL_URL_PLACEHOLDER|'${VITE_APP_FULL_URL}'|g' $file
99
sed -i 's|VITE_APP_BASE_PLACEHOLDER|'${VITE_APP_BASE}'|g' $file
10-
sed -i 's|VITE_HYDROCRON_URL_PLACEHOLDER|'${VITE_HYDROCRON_URL}'|g' $file
1110
sed -i 's|VITE_HYDROSHARE_NOTEBOOKS_COLLECTION_PLACEHOLDER|'${VITE_HYDROSHARE_NOTEBOOKS_COLLECTION}'|g' $file
1211
done
1312

frontend/src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<v-app>
33
<v-main>
44
<TheAppBar :paths="paths" @toggle-mobile-nav="toggleMobileNav" />
5-
<AlertPopup v-bind="alertStore.displayed" />
65
<TheMobileNavDrawer
76
:show="showMobileNavigation"
87
:paths="paths"
@@ -17,6 +16,7 @@
1716
href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900"
1817
rel="stylesheet"
1918
/>
19+
<AlertPopup v-bind="alertStore.displayed" />
2020
<TheFooter />
2121
</v-main>
2222
</v-app>

frontend/src/_helpers/hydroCron.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HYDROCRON_URL } from '@/constants'
1+
import { ENDPOINTS } from '@/constants'
22
import { useFeaturesStore } from '@/stores/features'
33
import { useAlertStore } from '@/stores/alerts'
44
import { useHydrologicStore } from '@/stores/hydrologic'
@@ -87,6 +87,12 @@ const queryHydroCron = async (swordFeature = null, output = 'geojson') => {
8787
const start_time = EARLIEST_HYDROCRON_DATETIME
8888
const end_time = new Date(Date.now() + MS_TO_KEEP_CACHE).toISOString().split('.')[0] + 'Z'
8989

90+
// determine which collection name to use based on feature type ('Reach' or 'PriorLake')
91+
let collection_name = 'SWOT_L2_HR_RiverSP_D'
92+
if (feature_type === 'PriorLake') {
93+
collection_name = 'SWOT_L2_HR_LakeSP_D'
94+
}
95+
9096
params = {
9197
feature: feature_type,
9298
feature_id,
@@ -95,9 +101,15 @@ const queryHydroCron = async (swordFeature = null, output = 'geojson') => {
95101
output,
96102
fields,
97103
// https://podaac.github.io/hydrocron/timeseries.html#compact-string-required-no
98-
compact: 'true'
104+
compact: 'true',
105+
// https://podaac.github.io/hydrocron/timeseries.html#collection-name-string-required-no
106+
collection_name
99107
}
100-
let response = await fetchHydroCronData(HYDROCRON_URL, params, swordFeature)
108+
109+
// Use our API proxy URL instead of the direct HydroCron URL
110+
// This is due to CORS issues with the HydroCron server
111+
// https://github.com/podaac/hydrocron/issues/306
112+
let response = await fetchHydroCronData(ENDPOINTS.hydrocron, params, swordFeature)
101113
if (response == null) {
102114
return
103115
}
@@ -134,19 +146,31 @@ const fetchHydroCronData = async (url, params, swordFeature) => {
134146
})
135147
if (response.status < 500) {
136148
if (response.status == 400) {
149+
let text = 'No data found for: '
150+
if (params.feature && params.feature_id) {
151+
text += `${params.feature} ${params.feature_id}`
152+
} else {
153+
text += JSON.stringify(params)
154+
}
137155
alertStore.displayAlert({
138156
title: 'No data found',
139-
text: `No data found for ${JSON.stringify(params)}`,
157+
text,
140158
type: 'warning',
141159
closable: true,
142160
duration: 6
143161
})
144162
return null
145163
}
146164
} else {
165+
let text = 'Error while fetching SWOT data: '
166+
if (response.statusText) {
167+
text += response.statusText
168+
} else {
169+
text += 'Unknown error'
170+
}
147171
alertStore.displayAlert({
148172
title: 'Error fetching SWOT data',
149-
text: `Error while fetching SWOT data: ${response.statusText}`,
173+
text,
150174
type: 'error',
151175
closable: true,
152176
duration: 3

frontend/src/components/TheLeafletMap.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ onMounted(async () => {
140140
141141
// add reaches layer to map
142142
url =
143-
'https://arcgis.cuahsi.org/arcgis/services/SWOT/world_SWORD_reaches_mercator/MapServer/WMSServer?'
143+
'https://arcgis.cuahsi.org/arcgis/services/SWOT/world_SWORD_reaches_mercator_v17b/MapServer/WMSServer?'
144144
const reachesWMS = L.tileLayer.wms(url, {
145145
layers: 0,
146146
transparent: 'true',
@@ -153,7 +153,7 @@ onMounted(async () => {
153153
154154
// add nodes layer to map
155155
url =
156-
'https://arcgis.cuahsi.org/arcgis/services/SWOT/world_SWORD_nodes_mercator/MapServer/WMSServer?'
156+
'https://arcgis.cuahsi.org/arcgis/services/SWOT/world_SWORD_nodes_mercator_v17b/MapServer/WMSServer?'
157157
L.tileLayer.wms(url, {
158158
layers: 0,
159159
transparent: 'true',

frontend/src/constants.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ let APP_FULL_URL_IN = import.meta.env.VITE_APP_FULL_URL || 'VITE_APP_FULL_URL_PL
44
export const APP_FULL_URL = APP_FULL_URL_IN.endsWith('/') ? APP_FULL_URL_IN : `${APP_FULL_URL_IN}/`
55

66
export const APP_API_URL = import.meta.env.VITE_APP_API_URL || 'VITE_APP_API_URL_PLACEHOLDER'
7-
export const HYDROCRON_URL = import.meta.env.VITE_HYDROCRON_URL || 'VITE_HYDROCRON_URL_PLACEHOLDER'
87
export const VITE_HYDROSHARE_NOTEBOOKS_COLLECTION =
98
import.meta.env.VITE_HYDROSHARE_NOTEBOOKS_COLLECTION ||
109
'VITE_HYDROSHARE_NOTEBOOKS_COLLECTION_PLACEHOLDER'
1110
export const ENDPOINTS = {
12-
openapi: `${APP_API_URL}/openapi.json`
11+
openapi: `${APP_API_URL}/openapi.json`,
12+
hydrocron: `${APP_API_URL}/hydrocron/timeseries`
1313
}
1414

1515
export const NODE_DATETIME_VARIATION = 1 // minutes

0 commit comments

Comments
 (0)