Skip to content

Commit

Permalink
Remove snow layer from ASA (#3897)
Browse files Browse the repository at this point in the history
Co-authored-by: Conor Brady <con.brad@gmail.com>
  • Loading branch information
dgboss and conbrad committed Sep 5, 2024
1 parent 34fe9c7 commit d2ee27f
Show file tree
Hide file tree
Showing 11 changed files with 3 additions and 178 deletions.
4 changes: 1 addition & 3 deletions api/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
from app import health
from app import hourlies
from app.rocketchat_notifications import send_rocketchat_notification
from app.routers import (fba, forecasts, weather_models, c_haines, stations, hfi_calc,
fba_calc, sfms, morecast_v2, snow)
from app.routers import fba, forecasts, weather_models, c_haines, stations, hfi_calc, fba_calc, sfms, morecast_v2
from app.fire_behaviour.cffdrs import CFFDRS


Expand Down Expand Up @@ -123,7 +122,6 @@ async def catch_exception_middleware(request: Request, call_next):
api.include_router(fba.router, tags=["Auto Spatial Advisory"])
api.include_router(sfms.router, tags=["SFMS", "Auto Spatial Advisory"])
api.include_router(morecast_v2.router, tags=["Morecast v2"])
api.include_router(snow.router, tags=['Snow'])


@api.get('/ready')
Expand Down
30 changes: 0 additions & 30 deletions api/app/routers/snow.py

This file was deleted.

1 change: 0 additions & 1 deletion web/cypress/e2e/fba-map-page.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ describe('Fire Behaviour Advisory Page', () => {
},
{ fixture: 'fba/vectors.json' }
).as('getVectors')
cy.intercept('GET', 'api/snow/most-recent-by-date/*', { fixture: 'fba/processedSnow.json' }).as('processedSnow')

cy.visit(FIRE_BEHAVIOUR_ADVISORY_ROUTE)
})
Expand Down
42 changes: 0 additions & 42 deletions web/src/api/snow.ts

This file was deleted.

40 changes: 1 addition & 39 deletions web/src/features/fba/components/map/FBAMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ import {
fireShapeLabelStyler,
stationStyler,
hfiStyler,
snowStyler,
fireCentreLineStyler
} from 'features/fba/components/map/featureStylers'
import { BC_EXTENT, CENTER_OF_BC } from 'utils/constants'
import { DateTime } from 'luxon'
import { PMTILES_BUCKET } from 'utils/env'
import { RunType } from 'features/fba/pages/FireBehaviourAdvisoryPage'
import { buildPMTilesURL, buildSnowPMTilesURL } from 'features/fba/pmtilesBuilder'
import { buildPMTilesURL } from 'features/fba/pmtilesBuilder'
import { isUndefined, cloneDeep, isNull } from 'lodash'
import { Box } from '@mui/material'
import Legend from 'features/fba/components/map/Legend'
Expand All @@ -53,7 +52,6 @@ export interface FBAMapProps {
fireShapeAreas: FireShapeArea[]
runType: RunType
advisoryThreshold: number
snowDate: DateTime | null
zoomSource?: 'fireCenter' | 'fireShape'
setZoomSource: React.Dispatch<React.SetStateAction<'fireCenter' | 'fireShape' | undefined>>
}
Expand All @@ -72,7 +70,6 @@ const FBAMap = (props: FBAMapProps) => {
const { stations } = useSelector(selectFireWeatherStations)
const [showShapeStatus, setShowShapeStatus] = useState(true)
const [showHFI, setShowHFI] = useState(false)
const [showSnow, setShowSnow] = useState<boolean>(false)
const [map, setMap] = useState<ol.Map | null>(null)
const mapRef = useRef<HTMLDivElement | null>(null) as React.MutableRefObject<HTMLElement>
const scaleRef = useRef<HTMLDivElement | null>(null) as React.MutableRefObject<HTMLElement>
Expand Down Expand Up @@ -244,27 +241,6 @@ const FBAMap = (props: FBAMapProps) => {
}
}, [showHFI, mostRecentRunDate]) // eslint-disable-line react-hooks/exhaustive-deps

useEffect(() => {
if (!map) return
const layerName = 'snowVector'
removeLayerByName(map, layerName)
if (!isNull(props.snowDate)) {
const snowPMTilesSource = new olpmtiles.PMTilesVectorSource({
url: buildSnowPMTilesURL(props.snowDate)
})

const latestSnowPMTilesLayer = new VectorTileLayer({
source: snowPMTilesSource,
style: snowStyler,
zIndex: 40,
minZoom: 4,
properties: { name: layerName },
visible: showSnow
})
map.addLayer(latestSnowPMTilesLayer)
}
}, [props.snowDate]) // eslint-disable-line react-hooks/exhaustive-deps

useEffect(() => {
// The React ref is used to attach to the div rendered in our
// return statement of which this map's target is set to.
Expand Down Expand Up @@ -331,17 +307,6 @@ const FBAMap = (props: FBAMapProps) => {
map?.addLayer(stationsLayer)
}, [stations]) // eslint-disable-line react-hooks/exhaustive-deps

// Generate a message to display about the snow layer in the legend.
const getSnowDateMessage = () => {
if (!showSnow) {
return null
}
if (isNull(props.snowDate)) {
return 'No data available'
}
return `as of ${props.snowDate?.toISODate()}`
}

return (
<ErrorBoundary>
<MapContext.Provider value={map}>
Expand All @@ -361,9 +326,6 @@ const FBAMap = (props: FBAMapProps) => {
setShowShapeStatus={setShowShapeStatus}
showHFI={showHFI}
setShowHFI={setShowHFI}
showSnow={showSnow}
setShowSnow={setShowSnow}
snowDescription={getSnowDateMessage()}
/>
</Box>
<ScalebarContainer ref={scaleRef} />
Expand Down
15 changes: 1 addition & 14 deletions web/src/features/fba/components/map/Legend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,14 @@ interface LegendProps {
setShowShapeStatus: React.Dispatch<React.SetStateAction<boolean>>
showHFI: boolean
setShowHFI: React.Dispatch<React.SetStateAction<boolean>>
showSnow: boolean
setShowSnow: React.Dispatch<React.SetStateAction<boolean>>
snowDescription: string | null
}

const Legend = ({
onToggleLayer,
showShapeStatus,
setShowShapeStatus,
showHFI,
setShowHFI,
showSnow,
setShowSnow,
snowDescription
setShowHFI
}: LegendProps) => {
const handleLayerChange = (
layerName: string,
Expand Down Expand Up @@ -148,13 +142,6 @@ const Legend = ({
onChange={() => handleLayerChange('hfiVector', showHFI, setShowHFI)}
subItems={hfiSubItems}
/>
<LegendItem
label="Snow Coverage"
checked={showSnow}
onChange={() => handleLayerChange('snowVector', showSnow, setShowSnow)}
description={snowDescription}
renderEmptyDescription={true}
></LegendItem>
</LegendGrid>
)
}
Expand Down
1 change: 0 additions & 1 deletion web/src/features/fba/components/map/fbaMap.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ describe('FBAMap', () => {
setZoomSource={function (): void {
throw new Error('Function not implemented.')
}}
snowDate={DateTime.now()}
/>
</Provider>
)
Expand Down
13 changes: 0 additions & 13 deletions web/src/features/fba/components/map/featureStylers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { FireCenter, FireShape, FireShapeArea } from 'api/fbaAPI'

const GREY_FILL = 'rgba(128, 128, 128, 0.8)'
const EMPTY_FILL = 'rgba(0, 0, 0, 0.0)'
const SNOW_FILL = 'rgba(255, 255, 255, 0.75)'
export const ADVISORY_ORANGE_FILL = 'rgba(255, 147, 38, 0.4)'
export const ADVISORY_RED_FILL = 'rgba(128, 0, 0, 0.4)'

Expand Down Expand Up @@ -230,15 +229,3 @@ export const hfiStyler = (feature: RenderFeature | ol.Feature<Geometry>): Style
}
return hfiStyle
}

// A styling function for the snow coverage pmtiles layer.
export const snowStyler = (feature: RenderFeature | ol.Feature<Geometry>): Style => {
const snow = feature.get('snow')
const snowStyle = new Style({})
if (snow === 1) {
snowStyle.setFill(new Fill({ color: SNOW_FILL }))
} else {
snowStyle.setFill(new Fill({ color: EMPTY_FILL }))
}
return snowStyle
}
8 changes: 0 additions & 8 deletions web/src/features/fba/components/map/legend.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@ describe('Legend', () => {
const onToggleLayer = jest.fn()
const setShowZoneStatus = jest.fn()
const setShowHFI = jest.fn()
const setShowSnow = jest.fn()
const { getByTestId } = render(
<Legend
onToggleLayer={onToggleLayer}
setShowShapeStatus={setShowZoneStatus}
setShowHFI={setShowHFI}
showHFI={false}
showShapeStatus={true}
showSnow={false}
setShowSnow={setShowSnow}
snowDescription="foo"
/>
)
const legendComponent = getByTestId('asa-map-legend')
Expand All @@ -39,17 +35,13 @@ describe('Legend', () => {
const onToggleLayer = jest.fn()
const setShowZoneStatus = jest.fn()
const setShowHFI = jest.fn()
const setShowSnow = jest.fn()
const { getByTestId } = render(
<Legend
onToggleLayer={onToggleLayer}
setShowShapeStatus={setShowZoneStatus}
setShowHFI={setShowHFI}
showHFI={false}
showShapeStatus={true}
showSnow={false}
setShowSnow={setShowSnow}
snowDescription="foo"
/>
)

Expand Down
15 changes: 0 additions & 15 deletions web/src/features/fba/pages/FireBehaviourAdvisoryPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { fetchFireShapeAreas } from 'features/fba/slices/fireZoneAreasSlice'
import { fetchfireZoneElevationInfo } from 'features/fba/slices/fireZoneElevationInfoSlice'
import { fetchfireZoneTPIStats } from 'features/fba/slices/fireZoneTPIStatsSlice'
import { StyledFormControl } from 'components/StyledFormControl'
import { getMostRecentProcessedSnowByDate } from 'api/snow'
import InfoPanel from 'features/fba/components/infoPanel/InfoPanel'
import FireZoneUnitSummary from 'features/fba/components/infoPanel/FireZoneUnitSummary'
import { fetchProvincialSummary } from 'features/fba/slices/provincialSummarySlice'
Expand Down Expand Up @@ -63,22 +62,10 @@ const FireBehaviourAdvisoryPage: React.FunctionComponent = () => {
: DateTime.now().setZone(`UTC${PST_UTC_OFFSET}`).plus({ days: 1 })
)
const [runType, setRunType] = useState(RunType.FORECAST)
const [snowDate, setSnowDate] = useState<DateTime | null>(null)
const { mostRecentRunDate } = useSelector(selectRunDates)
const { fireShapeAreas } = useSelector(selectFireShapeAreas)
const [selectedFireZoneTPIStats, setSelectedFireZoneTPIStats] = useState<FireZoneTPIStats | null>(null)

// Query our API for the most recently processed snow coverage date <= the currently selected date.
const fetchLastProcessedSnow = async (selectedDate: DateTime) => {
const data = await getMostRecentProcessedSnowByDate(selectedDate)
if (isNull(data)) {
setSnowDate(null)
} else {
const newSnowDate = data.forDate
setSnowDate(newSnowDate)
}
}

useEffect(() => {
const findCenter = (id: string | null): FireCenter | undefined => {
return fireCenters.find(center => center.id.toString() == id)
Expand Down Expand Up @@ -119,7 +106,6 @@ const FireBehaviourAdvisoryPage: React.FunctionComponent = () => {
if (!isNull(doiISODate)) {
dispatch(fetchSFMSRunDates(runType, doiISODate))
}
fetchLastProcessedSnow(dateOfInterest)
}, [dateOfInterest]) // eslint-disable-line react-hooks/exhaustive-deps

useEffect(() => {
Expand Down Expand Up @@ -241,7 +227,6 @@ const FireBehaviourAdvisoryPage: React.FunctionComponent = () => {
advisoryThreshold={ADVISORY_THRESHOLD}
setSelectedFireShape={setSelectedFireShape}
fireShapeAreas={fireShapeAreas}
snowDate={snowDate}
zoomSource={zoomSource}
setZoomSource={setZoomSource}
/>
Expand Down
12 changes: 0 additions & 12 deletions web/src/features/fba/pmtilesBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,3 @@ export const buildPMTilesURL = (for_date: DateTime, run_type: RunType, run_date:

return PMTilesURL
}

/**
* Builds the URL for snow coverage pmtiles layers.
* @param snowDate The target date for snow coverage.
* @returns A URL to the snow coverage PMTiles stored in S3
*/
export const buildSnowPMTilesURL = (snowDate: DateTime) => {
const snowPMTilesUrl = `${PMTILES_BUCKET}snow/${snowDate.toISODate()}/snowCoverage${snowDate.toISODate({
format: 'basic'
})}.pmtiles`
return snowPMTilesUrl
}

0 comments on commit d2ee27f

Please sign in to comment.