-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- I ended up leaving the main logic as it is (CMR layer doesn't call CMR endpoint directly - There seem to be some cases that stac collection id doesn't match with cmr's short_name? ex. https://cmr.earthdata.nasa.gov/search/collections.umm_json?short_name=TRMM_3B42_Daily.v7&version=07 - I get an empty response _ all in all, I thought it is better to keep the source of truth in one place for now.) - Make CMR layer (that shares zarr paint layer with Zarr layer) - We currently have two map components (which we should consolidate in the near future related issue: #712 ) This is why there are two places for the layers. - CMR layer won't show up for Analysis. (The timeline will fail for new E&A. User can still explore the map.- you can check new E&A page by putting a feature flagging variable in `.env`: `FEATURE_NEW_EXPLORATION = 'TRUE'`. I also attached a screenshot below.) 
- Loading branch information
Showing
18 changed files
with
493 additions
and
141 deletions.
There are no files selected for viewing
This file contains 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
38 changes: 38 additions & 0 deletions
38
app/scripts/components/common/map/style-generators/cmr-timeseries.tsx
This file contains 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,38 @@ | ||
import React from 'react'; | ||
|
||
import { BaseGeneratorParams } from '../types'; | ||
import { ZarrPaintLayer } from './zarr-timeseries'; | ||
import { useCMR } from './hooks'; | ||
import { ActionStatus } from '$utils/status'; | ||
|
||
interface AssetUrlReplacement { | ||
from: string; | ||
to: string; | ||
} | ||
|
||
export interface CMRTimeseriesProps extends BaseGeneratorParams { | ||
id: string; | ||
stacCol: string; | ||
date?: Date; | ||
sourceParams?: Record<string, any>; | ||
stacApiEndpoint?: string; | ||
tileApiEndpoint?: string; | ||
assetUrlReplacements?: AssetUrlReplacement; | ||
zoomExtent?: number[]; | ||
onStatusChange?: (result: { status: ActionStatus; id: string }) => void; | ||
} | ||
|
||
export function CMRTimeseries(props:CMRTimeseriesProps) { | ||
const { | ||
id, | ||
stacCol, | ||
stacApiEndpoint, | ||
date, | ||
assetUrlReplacements, | ||
onStatusChange, | ||
} = props; | ||
|
||
const stacApiEndpointToUse = stacApiEndpoint?? process.env.API_STAC_ENDPOINT; | ||
const assetUrl = useCMR({ id, stacCol, stacApiEndpointToUse, date, assetUrlReplacements, stacApiEndpoint, onStatusChange }); | ||
return <ZarrPaintLayer {...props} assetUrl={assetUrl} />; | ||
} |
113 changes: 113 additions & 0 deletions
113
app/scripts/components/common/map/style-generators/hooks.ts
This file contains 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,113 @@ | ||
import {useState, useEffect} from 'react'; | ||
import { requestQuickCache } from '../utils'; | ||
import { S_FAILED, S_LOADING, S_SUCCEEDED } from '$utils/status'; | ||
|
||
interface AssetUrlReplacement { | ||
from: string; | ||
to: string; | ||
} | ||
interface ZarrResponseData { | ||
assets: { | ||
zarr: { | ||
href: string | ||
} | ||
} | ||
} | ||
interface CMRResponseData { | ||
features: { | ||
assets: { | ||
data: { | ||
href: string | ||
} | ||
} | ||
}[] | ||
} | ||
|
||
export function useZarr({ id, stacCol, stacApiEndpointToUse, date, onStatusChange }){ | ||
const [assetUrl, setAssetUrl] = useState(''); | ||
|
||
useEffect(() => { | ||
const controller = new AbortController(); | ||
|
||
async function load() { | ||
try { | ||
onStatusChange?.({ status: S_LOADING, id }); | ||
const data:ZarrResponseData = await requestQuickCache({ | ||
url: `${stacApiEndpointToUse}/collections/${stacCol}`, | ||
method: 'GET', | ||
controller | ||
}); | ||
|
||
setAssetUrl(data.assets.zarr.href); | ||
onStatusChange?.({ status: S_SUCCEEDED, id }); | ||
} catch (error) { | ||
if (!controller.signal.aborted) { | ||
setAssetUrl(''); | ||
onStatusChange?.({ status: S_FAILED, id }); | ||
} | ||
return; | ||
} | ||
} | ||
|
||
load(); | ||
|
||
return () => { | ||
controller.abort(); | ||
}; | ||
}, [id, stacCol, stacApiEndpointToUse, date, onStatusChange]); | ||
|
||
return assetUrl; | ||
} | ||
|
||
|
||
|
||
export function useCMR({ id, stacCol, stacApiEndpointToUse, date, assetUrlReplacements, stacApiEndpoint, onStatusChange }){ | ||
const [assetUrl, setAssetUrl] = useState(''); | ||
|
||
const replaceInAssetUrl = (url: string, replacement: AssetUrlReplacement) => { | ||
const {from, to } = replacement; | ||
const cmrAssetUrl = url.replace(from, to); | ||
return cmrAssetUrl; | ||
}; | ||
|
||
|
||
useEffect(() => { | ||
const controller = new AbortController(); | ||
|
||
async function load() { | ||
try { | ||
onStatusChange?.({ status: S_LOADING, id }); | ||
if (!assetUrlReplacements) throw (new Error('CMR layer requires asset url remplacement attributes')); | ||
|
||
// Zarr collections in _VEDA_ should have a single entrypoint (zarr or virtual zarr / reference) | ||
// CMR endpoints will be using individual items' assets, so we query for the asset url | ||
const stacApiEndpointToUse = `${stacApiEndpoint}/search?collections=${stacCol}&datetime=${date?.toISOString()}`; | ||
|
||
const data:CMRResponseData = await requestQuickCache({ | ||
url: stacApiEndpointToUse, | ||
method: 'GET', | ||
controller | ||
}); | ||
|
||
const assetUrl = replaceInAssetUrl(data.features[0].assets.data.href, assetUrlReplacements); | ||
setAssetUrl(assetUrl); | ||
onStatusChange?.({ status: S_SUCCEEDED, id }); | ||
} catch (error) { | ||
if (!controller.signal.aborted) { | ||
setAssetUrl(''); | ||
onStatusChange?.({ status: S_FAILED, id }); | ||
} | ||
return; | ||
} | ||
} | ||
|
||
load(); | ||
|
||
return () => { | ||
controller.abort(); | ||
}; | ||
}, [id, stacCol, stacApiEndpointToUse, date, assetUrlReplacements, stacApiEndpoint, onStatusChange]); | ||
|
||
return assetUrl; | ||
|
||
} |
This file contains 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 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
Oops, something went wrong.