Giter Club home page Giter Club logo

hdc-colors's Introduction

hdc-colors

This repository contains the color-ramp sources for all* data from the HumanitarianDataCube (HDC), along with some thin python code for user / system interface.

Installation

# mamba/conda
mamba install -c wfp-ram hdc-colors

# pip
pip install --extra-index-url=https://data.earthobservation.vam.wfp.org/pypi/ hdc-colors

Important

The main purpose of this repo is to contain the color source, keeping the dependencies minimal. To install all dependencies that might be required for users, please use extras install hdc-colors[all].

Available color ramps

To see a table with all available color ramps, check out the rendered markdown!

Alternatively, the following table can be directly generated using hdc-colors by running hdc-colors-table.

hdc-colors ramps

To inspect the color ramps for a specific category, you can add the category name to the call (note the lowercase):

hdc-colors-table rainfall

and all color ramps for the category will be visualized in the console.

To look at one or more specific ramps, you can add one or more --filer / -f flags:

hdc-colors-table rainfall -f rxs
hdc-colors rxs-ramp

Usage example

Note

To run this example, you need the matplotlib package installed (comes with hdc-colors[all])

import matplotib.pyplot as plt
import rioxarray

from hdc.colors.rainfall import rxs

# load raster and drop time dim
x = rioxarray.open_rasterio(
    "https://data.earthobservation.vam.wfp.org/docs-data/spi/ethr1s202303d3.tif",
    mask_and_scale=True,
).squeeze()


# need to set min/max and levels but exclude last one (which is inf)
x.plot.imshow(cmap=rxs.cmap, vmin=-2000, vmax=2000, levels=rxs.vals[:-1], extend="both")

# set title
plt.title("Ethiopia SPI-1 ending on the 31st of March, 2023")
Plot example

hdc-colors's People

Contributors

kirill888 avatar valpesendorfer avatar

Watchers

 avatar  avatar  avatar  avatar

hdc-colors's Issues

Add documentation

Add list of available color ramps, descriptions and mapping to indicators

publish package

@Kirill888 as discussed, this is the repo containing the color maps for various data products.

There are still a couple of todos on my side, but if you could look into packaging and publishing so it can be a) wrapped in hdc-tools if we wish so, and more importantly b) integrated into hdc-ows

Add additional features

To improve user interface I'd like to add two additional features:

  • property or method that creates a matplotlib object that can be used to plot xarray arrays with the selected color ramp
  • a HTML representation of the color ramp object, so when selected and executed in a jupyter notebook it shows a useful and nice visual (maybe similar to what odc.geo.GeoBox does?)

@Kirill888 for your input

Support config from a single list of tuples

Current interface expects 2/3 arrays of equal size to configure value,color[,label]

class HDCBaseClass:
"""Parent class for HDC color classes"""
def __init__(
self,
values: List[Union[int, float]],
colors: List[str],
labels: Optional[List[str]] = None,
):

This leads to hard to manage and inspect definitions like here:

rfh_16_0_300 = HDCDiscreteRamp(
values=[
0,
2,
5,
10,
20,
30,
40,
50,
60,
80,
100,
120,
150,
200,
300,
INF,
],
colors=[
"#fafafa",
"#fffadf",
"#d3f9d0",
"#a9e4a3",
"#7cc594",
"#5eab91",
"#9fffe8",
"#90e0ef",
"#00b1de",
"#0083f3",
"#0052cd",
"#0000c8",
"#6003b8",
"#a002fa",
"#fa78fa",
"#ffc4ee",
],
labels=[
"0 mm",
"1-2 mm",
"2-5 mm",
"5-10 mm",
"10-20 mm",
"20-30 mm",
"30-40 mm",
"40-50 mm",
"50-60 mm",
"60-80 mm",
"80-100 mm",
"100-120 mm",
"120-150 mm",
"150-200 mm",
"200-300 mm",
"> 300 mm",
],
)

I suggest either changing interface to expect a List[Tuple[Number, Color, Label]|Tuple[Number, Color]] only, or adding an option to accept list of tuples instead of 3 separate named lists.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.