• Stars
    star
    188
  • Rank 204,409 (Top 5 %)
  • Language
    JavaScript
  • License
    Other
  • Created about 3 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

interactive multi-dimensional data-driven web maps

carbonplan / maps

interactive data-driven webmaps — demo

GitHub Build Status MIT License NPM Version

background

There are many approaches to making web maps, and many different data sources and use cases.

One common case for us at CarbonPlan is rendering gridded raster data on a map. These data are multi-dimensional, for example, representing multiple time points or variables. We want high performance and flexibility in rendering. We also want to use the same file formats from our analysis.

We're building @carbonplan/maps to address these needs! We'll be releasing early and often so we can use it ourselves, but it's very much in progress, so expect lots of major version bumps and breaking changes.

Check out the demo (site, code) which renders monthly temperature and precipitation data, or read on for more info on the library.

design

The core library wraps lower-level WebGL technologies to expose simple map-building components. For tiled maps, we combine mapbox-gl-js and regl. We use mapbox-gl-js for rendering vector layers and providing basic controls, and we use regl to performantly render data-driven layers. Behind the scenes, the library does some synchronization and simple state management to keep everything smooth and reactive.

We assume raster data is stored in the zarr format, an emerging standard for chunked, compressed, multi-dimensional binary data that's become popular in the scientific Python community. For tiled maps, we also leverage the ndpyramid tool for building multi-scale pyramids. Check out this Jupyter Notebook for an example of creating the required Zarr dataset. Our Raster component makes it easy to render these data.

examples

First, here's a simple map that renders a global temperature dataset at one month. The underlying dataset is a version of WorldClim stored as a zarr pyramid with 6 levels of increasing resolution. We specify the variable we want to show and the dataset's dimensions, and all other metadata is inferred the dataset.

import { Map, Raster } from '@carbonplan/maps'
import { useColormap } from '@carbonplan/colormaps'

const TemperatureMap = () => {
  const colormap = useColormap('warm')

  return (
    <Map>
      <Raster
        colormap={colormap}
        clim={[-20, 30]}
        source={
          'https://storage.googleapis.com/carbonplan-scratch/map-tests/processed/temp'
        }
        variable={'temperature'}
        dimensions={['y', 'x']}
      />
    </Map>
  )
}

With the same component we can render an annual dataset with a different temperature for each month, showing one month at a time via a selector. In this example, the selected month 4 can be static, or it can come from react state and the map will dynamically update!

<Map>
  <Raster
    colormap={colormap}
    clim={[-20, 30]}
    source={
      'https://storage.googleapis.com/carbonplan-scratch/map-tests/processed/temp-month'
    }
    variable={'temperature'}
    dimensions={['month', 'y', 'x']}
    selector={{ month: 4 }}
  />
</Map>

Finally, if we want to render multiple arrays at once (and do math on them), we can specify a list for our selector. This loads all the selected arrays onto the GPU at once and lets us write custom fragment shaders that combine them (in this case, just averaging two months). While this requires writing shader code, it's a powerful and flexible way to do fast raster math for multi-dimensional maps.

<Map>
  <Raster
    colormap={colormap}
    clim={[-20, 30]}
    fillValue={-3.4e38}
    source={
      'https://storage.googleapis.com/carbonplan-scratch/map-tests/processed/temp-month'
    }
    variable={'temperature'}
    dimensions={['month', 'y', 'x']}
    selector={{ month: [1, 2] }}
    frag={`
      float rescaled = ((month_1 + month_2) / 2.0 - clim.x)/(clim.y - clim.x);
      vec4 c = texture2D(colormap, vec2(rescaled, 1.0));
      gl_FragColor = vec4(c.x, c.y, c.z, opacity);
      gl_FragColor.rgb *= gl_FragColor.a;
    `}
  />
</Map>

More docs are coming soon!

thanks

We owe enormous credit to existing open source libraries in the ecosystem, in particular mapbox-gl-js and leaflet. We've also taken inspiration from the design of react-three-fiber in terms of how to wrap a rendering library with react.

license

All the original code in this repository is MIT licensed. The library contains code from mapbox-gl-js version 1.13 (3-Clause BSD licensed). We request that you please provide attribution if reusing any of our digital content (graphics, logo, copy, etc.).

about us

CarbonPlan is a non-profit organization that uses data and science for climate action. We aim to improve the transparency and scientific integrity of climate solutions with open data and tools. Find out more at carbonplan.org or get in touch by opening an issue or sending us an email.

More Repositories

1

cmip6-downscaling

Climate downscaling using CMIP6 data
Jupyter Notebook
164
star
2

ndpyramid

A small utility for generating ND array pyramids using Xarray and Zarr.
Python
89
star
3

extreme-heat

data and analysis on extreme heat under a changing climate
Jupyter Notebook
46
star
4

forest-risks

statistical models of forest carbon potential and risks
Jupyter Notebook
33
star
5

trace

working repo for carbonplan's climate trace project
Jupyter Notebook
33
star
6

carbonplan.org

landing page
JavaScript
28
star
7

research

datasets, tools, explainers, and commentary
JavaScript
26
star
8

components

shared react components for our sites
JavaScript
25
star
9

glsl-geo-projection

shader math for geographic projections
JavaScript
25
star
10

cdr-database

reports on carbon removal projects and technologies
JavaScript
24
star
11

ton-year

A sandbox for exploring ton-year accounting
Jupyter Notebook
19
star
12

forest-offsets

retrospective analysis of complience IFM projects
Python
17
star
13

data

data catalogs and utilities
Jupyter Notebook
16
star
14

offsets-db-data

Utilities for cleaning, and processing data for carbonplan/offsets-db-web
Python
11
star
15

forest-risks-web

mapping climate risks to forest carbon
JavaScript
10
star
16

kerchunk-NEX-GDDP-CMIP6

Read NASA-Nex Climate Downscaled Data with Kerchunk
Jupyter Notebook
8
star
17

charts

responsive reactive themeable charts
JavaScript
8
star
18

carbon-removal-application

application for soliciting carbon removal procurement
JavaScript
7
star
19

styles

plotting styles for altair and matplotlib
Python
7
star
20

theme

theme for styling our websites
JavaScript
7
star
21

margo-js

MARGO climate model in pure javascript
JavaScript
6
star
22

python-project-template

A carbonplan template for a developing a python project
Python
6
star
23

forest-offsets-fires

Monitoring of active fires within listed offset projects
Python
5
star
24

seaweed-farming-web

Mapping seaweed farming potential
Jupyter Notebook
5
star
25

notebooks

Jupyter notebooks for sharing analyses and research
Jupyter Notebook
5
star
26

design

showcasing the theme and components that form our design system
JavaScript
4
star
27

minimaps

small maps for figures
JavaScript
4
star
28

carbonplan-buffer-analysis

Quantitative analysis of the risks to the California forest carbon buffer pool
Python
4
star
29

article-template

template for a developing a standalone research article
JavaScript
4
star
30

cmip6-web

JavaScript
3
star
31

cdr-timescale-accounting

Jupyter Notebook
3
star
32

blog

short updates on what we do at CarbonPlan
JavaScript
3
star
33

simple-map-demo

minimal demo of using the @carbonplan/maps library
JavaScript
3
star
34

ncview-js

JavaScript
3
star
35

benchmark-maps

benchmarks for web maps
Python
3
star
36

prototype-maps

A consolidated project for prototyping multiple mapping solutions
JavaScript
3
star
37

extreme-heat-extension-data

data and analysis of extreme heat for Southeastern Europe
Jupyter Notebook
3
star
38

forest-offsets-web

explorable maps of forest offset projects and fires
JavaScript
2
star
39

forest-offsets-mismatch

Analysis of California forest offset projects and vegetation climate mismatch
Jupyter Notebook
2
star
40

api

retired api
Python
2
star
41

carbonplan-datasette

Code to package CarbonPlan data using Datasette
Python
2
star
42

dac-costing

Jupyter Notebook
2
star
43

forest-carbon-web

global forest carbon mapping
JavaScript
2
star
44

forest-climate-risks

code to reproduce figure in review article on climate risks for forests
Python
2
star
45

cdr-verification

mapping uncertainties for CDR pathways
JavaScript
2
star
46

layouts

page layout components for documents and tools
JavaScript
2
star
47

colormaps

color scales for data visualization
JavaScript
2
star
48

zarr-webgl-mapbox

playground for rendering zarr arrays for mapping
JavaScript
2
star
49

toucan-crypto-offsets

Jupyter Notebook
2
star
50

xrefcoord

Python
1
star
51

extreme-heat-extension

Jupyter Notebook
1
star
52

drought

Python
1
star
53

hub

Internal JupyterHub for CarbonPlan staff (now archived)
Shell
1
star
54

forest-offsets-paper

jupyter notebooks for reproducing figures from an analysis of forest offset projects
Jupyter Notebook
1
star
55

climate-risks-insurance

Jupyter Notebook
1
star
56

pangeo-forge-ndpyramid

Pangeo-Forge extension library used to generate pyramids via ndpyramid
Jupyter Notebook
1
star
57

oae-web

JavaScript
1
star
58

fair-equivalence-graphs

Run stylized experiments that explore the temperature dynamics of perturbing the global carbon cycle
Python
1
star
59

pangeo-ml-demos

Jupyter Notebook
1
star
60

leap-data-catalog

data catalog for the LEAP project
JavaScript
1
star
61

offsets-db-api

accounting of voluntary and compliance offset programs
Python
1
star
62

soil-depth-sampling

R
1
star
63

offset-fires-embed

visualizing and analyzing fires in forest offset projects
Jupyter Notebook
1
star
64

carbonplan-python

namespace package for python utilities and subprojects
Python
1
star
65

simple-site

simple template for a website using our web stack
JavaScript
1
star
66

fire-forests-inventories

analysis for article on fire, forests, and greenhouse gas inventories
Jupyter Notebook
1
star