Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions components/results/download.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { Box, Flex, Spinner } from 'theme-ui'
import { Button } from '@carbonplan/components'
//@ts-expect-error - carbonplan icons types not available
import { Down, X } from '@carbonplan/icons'
import { DATA_VERSION, DATA_URLS, LICENSE_INFO } from '@/lib/config'
import {
DATA_VERSION,
DATA_URLS,
LICENSE_INFO,
PARQUET_BUCKET_URL,
} from '@/lib/config'
import { useStore } from '@/lib/store'
import { getGeographyName, getGeoid } from '@/lib/risk-utils'
import { GeographyKey } from '@/types/location'
Expand Down Expand Up @@ -78,8 +83,6 @@ const REGION_TYPES: Partial<Record<GeographyKey, string>> = {
censusBlock: 'block',
}

const S3_BUCKET = new URL(DATA_URLS.parquetBase).origin

const DURATION_BUCKETS: [number, string][] = [
[1000, '<1s'],
[5000, '1-5s'],
Expand Down Expand Up @@ -123,11 +126,11 @@ async function getPartitionUrls(
): Promise<string[]> {
const stateFips = geoid.slice(0, 2)
const countyFips = geoid.slice(2, 5)
const prefix = DATA_URLS.parquetBase.replace(S3_BUCKET + '/', '')
const prefix = DATA_URLS.parquetBase.replace(PARQUET_BUCKET_URL + '/', '')
const partitionPrefix = `${prefix}/state_fips=${stateFips}/county_fips=${countyFips}/`

const res = await fetch(
`${S3_BUCKET}/?list-type=2&prefix=${partitionPrefix}`,
`${PARQUET_BUCKET_URL}/?list-type=2&prefix=${partitionPrefix}`,
{ signal },
)
const doc = new DOMParser().parseFromString(
Expand All @@ -138,7 +141,7 @@ async function getPartitionUrls(
const urls: string[] = []
for (const el of doc.querySelectorAll('Contents > Key')) {
const key = el.textContent
if (key?.endsWith('.parquet')) urls.push(`${S3_BUCKET}/${key}`)
if (key?.endsWith('.parquet')) urls.push(`${PARQUET_BUCKET_URL}/${key}`)
}

if (urls.length === 0) {
Expand Down
6 changes: 3 additions & 3 deletions components/results/regional-risk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { LngLatBounds } from 'maplibre-gl'
import { getGeographyRisk, getBoundingBox } from '@/lib/risk-utils'
import { useStore } from '@/lib/store'
import {
DATA_VERSION,
DATA_URLS,
GEOGRAPHY_ATTRIBUTE_KEYS,
GEOGRAPHY_MIN_ZOOM,
STATISTICS_PATHS,
Expand Down Expand Up @@ -345,14 +345,14 @@ const RegionalRisk = () => {
label='CSV'
loading={false}
disabled={false}
href={`https://s3.us-west-2.amazonaws.com/us-west-2.opendata.source.coop/carbonplan/carbonplan-ocr/output/fire-risk/vector/production/${DATA_VERSION}/region-analysis/${STATISTICS_PATHS[geographyLevel]}/stats.csv`}
href={`${DATA_URLS.regionAnalysisBase}/${STATISTICS_PATHS[geographyLevel]}/stats.csv`}
ariaLabel={`Download summary data as CSV`}
/>
<DownloadButton
label='GeoJSON'
loading={false}
disabled={false}
href={`https://s3.us-west-2.amazonaws.com/us-west-2.opendata.source.coop/carbonplan/carbonplan-ocr/output/fire-risk/vector/production/${DATA_VERSION}/region-analysis/${STATISTICS_PATHS[geographyLevel]}/stats.geojson`}
href={`${DATA_URLS.regionAnalysisBase}/${STATISTICS_PATHS[geographyLevel]}/stats.geojson`}
ariaLabel={`Download summary data as GeoJSON`}
/>
</Flex>
Expand Down
28 changes: 22 additions & 6 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,42 @@ export const BASE_PATH = '/research/climate-risk'

export const DATA_VERSION = 'v1.1.0'

// Source Coop's bucket name contains dots, so only path-style URLs work —
// virtual-hosted style (bucket.s3.amazonaws.com) fails TLS validation.
const S3_BUCKET_URL =
'https://s3.us-west-2.amazonaws.com/us-west-2.opendata.source.coop'

const dataUrl = (kind: 'vector' | 'pyramid', path: string) =>
`${S3_BUCKET_URL}/carbonplan/carbonplan-ocr/output/fire-risk/${kind}/production/${DATA_VERSION}/${path}`

export const DATA_URLS = {
vector: {
buildings:
process.env.NEXT_PUBLIC_BUILDING_URL ??
`https://carbonplan-ocr.s3.amazonaws.com/output/fire-risk/vector/production/${DATA_VERSION}/pmtiles/buildings.pmtiles`,
dataUrl('vector', 'pmtiles/buildings.pmtiles'),
regions:
process.env.NEXT_PUBLIC_REGIONS_URL ??
`https://carbonplan-ocr.s3.amazonaws.com/output/fire-risk/vector/production/${DATA_VERSION}/pmtiles/regions.pmtiles`,
dataUrl('vector', 'pmtiles/regions.pmtiles'),
buildingPoints:
process.env.NEXT_PUBLIC_BUILDING_POINTS_URL ??
`https://carbonplan-ocr.s3.amazonaws.com/output/fire-risk/vector/production/${DATA_VERSION}/pmtiles/building_centroids.pmtiles`,
dataUrl('vector', 'pmtiles/building_centroids.pmtiles'),
},
raster:
process.env.NEXT_PUBLIC_RISK_ZARR_URL ??
`https://carbonplan-ocr.s3.amazonaws.com/output/fire-risk/pyramid/production/${DATA_VERSION}/pyramid.zarr`,
process.env.NEXT_PUBLIC_RISK_ZARR_URL ?? dataUrl('pyramid', 'pyramid.zarr'),
parquetBase:
process.env.NEXT_PUBLIC_GEOPARQUET_URL ??
`https://carbonplan-ocr.s3.us-west-2.amazonaws.com/output/fire-risk/vector/production/${DATA_VERSION}/geoparquet/buildings.parquet`,
dataUrl('vector', 'geoparquet/buildings.parquet'),
regionAnalysisBase: dataUrl('vector', 'region-analysis'),
}

// Root for ListObjectsV2 requests against whichever bucket holds the parquet.
// Path-style URLs put the bucket after the host; anything else is virtual-hosted.
export const PARQUET_BUCKET_URL = DATA_URLS.parquetBase.startsWith(
S3_BUCKET_URL,
)
? S3_BUCKET_URL
: new URL(DATA_URLS.parquetBase).origin

export const LICENSE_INFO = {
provider: 'CarbonPlan',
termsOfAccess:
Expand Down
5 changes: 1 addition & 4 deletions pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ class MyDocument extends Document {
rel='preconnect'
href='https://carbonplan-maps.s3.us-west-2.amazonaws.com'
/>
<link
rel='preconnect'
href='https://carbonplan-ocr.s3.amazonaws.com'
/>
<link rel='preconnect' href='https://s3.us-west-2.amazonaws.com' />
<link rel='preconnect' href='https://fonts.carbonplan.org' />
</Head>
<body>
Expand Down
Loading