A Python package for interactive geospatial analysis and visualization with Google Earth Engine
—
Advanced visualization tools including charts, plots, legends, timelapse animations, and color management for comprehensive geospatial data analysis and presentation.
Create various chart types for data visualization and analysis using integrated plotting libraries.
def bar_chart(
data,
x: str,
y: str,
width: int = 400,
height: int = 300,
**kwargs
) -> None:
"""
Create bar chart from data.
Args:
data: Input data (DataFrame, list, or dict)
x: Column name for x-axis
y: Column name for y-axis
width: Chart width in pixels
height: Chart height in pixels
**kwargs: Additional chart parameters
"""
def line_chart(
data,
x: str,
y: str,
width: int = 400,
height: int = 300,
**kwargs
) -> None:
"""
Create line chart from data.
Args:
data: Input data (DataFrame, list, or dict)
x: Column name for x-axis
y: Column name for y-axis
width: Chart width in pixels
height: Chart height in pixels
**kwargs: Additional chart parameters
"""
def histogram(
data,
column: str,
bins: int = 20,
width: int = 400,
height: int = 300,
**kwargs
) -> None:
"""
Create histogram from data.
Args:
data: Input data (DataFrame, list, or dict)
column: Column name for histogram
bins: Number of histogram bins
width: Chart width in pixels
height: Chart height in pixels
**kwargs: Additional chart parameters
"""
def pie_chart(
data,
names: str,
values: str,
width: int = 400,
height: int = 300,
**kwargs
) -> None:
"""
Create pie chart from data.
Args:
data: Input data (DataFrame, list, or dict)
names: Column name for pie slice names
values: Column name for pie slice values
width: Chart width in pixels
height: Chart height in pixels
**kwargs: Additional chart parameters
"""Object-oriented chart creation with extensive customization options.
class Chart:
"""Base chart class for data visualization."""
def __init__(self, **kwargs) -> None:
"""Initialize base chart."""
class BarChart(Chart):
"""Bar chart implementation."""
def __init__(self, **kwargs) -> None:
"""Initialize bar chart."""
class LineChart(Chart):
"""Line chart implementation."""
def __init__(self, **kwargs) -> None:
"""Initialize line chart."""
class DataTable:
"""Enhanced pandas DataFrame with additional functionality."""
def __init__(self, data, **kwargs) -> None:
"""
Initialize enhanced data table.
Args:
data: Input data
**kwargs: Additional parameters
"""Specialized charts for Earth Engine feature collections and geospatial data analysis.
class Feature_ByFeature:
"""Chart features by individual feature properties."""
def __init__(self, **kwargs) -> None:
"""Initialize feature-by-feature chart."""
class Feature_ByProperty:
"""Chart features by property values."""
def __init__(self, **kwargs) -> None:
"""Initialize feature-by-property chart."""Create animated visualizations and timelapse sequences from Earth Engine data.
def create_timeseries(
ee_object,
region: ee.Geometry,
start_date: str,
end_date: str,
bands: List[str] = None,
frequency: str = 'month',
reducer: str = 'mean',
**kwargs
) -> None:
"""
Create time series visualization.
Args:
ee_object: Earth Engine ImageCollection
region: Region of interest
start_date: Start date (YYYY-MM-DD)
end_date: End date (YYYY-MM-DD)
bands: Bands to include
frequency: Time frequency ('day', 'month', 'year')
reducer: Reduction method ('mean', 'median', 'sum')
**kwargs: Additional parameters
"""
def make_gif(
out_gif: str,
fps: int = 5,
loop: int = 0,
**kwargs
) -> str:
"""
Create GIF animation from images.
Args:
out_gif: Output GIF file path
fps: Frames per second
loop: Number of loops (0 for infinite)
**kwargs: Additional GIF parameters
Returns:
Path to created GIF
"""
def gif_to_mp4(
in_gif: str,
out_mp4: str = None,
fps: int = 10,
**kwargs
) -> str:
"""
Convert GIF to MP4 video.
Args:
in_gif: Input GIF file path
out_mp4: Output MP4 file path
fps: Frames per second
**kwargs: Additional parameters
Returns:
Path to MP4 file
"""
def add_text_to_gif(
in_gif: str,
out_gif: str,
xy: tuple = None,
text_sequence: List[str] = None,
font_size: int = 20,
font_color: str = "black",
**kwargs
) -> str:
"""
Add text overlay to GIF frames.
Args:
in_gif: Input GIF file path
out_gif: Output GIF file path
xy: Text position (x, y)
text_sequence: List of text for each frame
font_size: Font size in points
font_color: Font color
**kwargs: Additional parameters
Returns:
Path to output GIF
"""
def add_image_to_gif(
in_gif: str,
out_gif: str,
in_image: str,
xy: tuple = None,
image_size: tuple = None,
**kwargs
) -> str:
"""
Add image overlay to GIF frames.
Args:
in_gif: Input GIF file path
out_gif: Output GIF file path
in_image: Overlay image path
xy: Image position (x, y)
image_size: Image size (width, height)
**kwargs: Additional parameters
Returns:
Path to output GIF
"""
def reduce_gif_size(
in_gif: str,
out_gif: str = None,
**kwargs
) -> str:
"""
Reduce GIF file size.
Args:
in_gif: Input GIF file path
out_gif: Output GIF file path
**kwargs: Optimization parameters
Returns:
Path to optimized GIF
"""Comprehensive color palette and colormap management for data visualization.
def get_palette(
cmap_name: str = None,
n_class: int = 8,
hashtag: bool = False,
**kwargs
) -> List[str]:
"""
Get color palette for visualization.
Args:
cmap_name: Colormap name
n_class: Number of color classes
hashtag: Include # prefix for hex colors
**kwargs: Additional parameters
Returns:
List of color hex codes
"""
def get_colorbar(
colors: List[str],
vmin: float = 0,
vmax: float = 1.0,
index: List[float] = None,
step: int = None,
**kwargs
) -> str:
"""
Generate colorbar for visualization.
Args:
colors: List of colors
vmin: Minimum value
vmax: Maximum value
index: Value indices for colors
step: Step size for colorbar
**kwargs: Additional parameters
Returns:
Colorbar HTML string
"""
def list_colormaps() -> List[str]:
"""
List available colormaps.
Returns:
List of colormap names
"""
def plot_colormap(
cmap_name: str,
width: int = 8,
height: int = 0.4,
**kwargs
) -> None:
"""
Plot single colormap visualization.
Args:
cmap_name: Colormap name
width: Plot width
height: Plot height
**kwargs: Additional plot parameters
"""
def plot_colormaps(
width: int = 8,
height: int = 0.4,
**kwargs
) -> None:
"""
Plot all available colormaps.
Args:
width: Plot width
height: Plot height per colormap
**kwargs: Additional plot parameters
"""Create and manage map legends for data visualization.
def ee_table_to_legend(
ee_table: ee.FeatureCollection,
color_column: str,
label_column: str,
**kwargs
) -> Dict:
"""
Convert Earth Engine table to legend.
Args:
ee_table: Earth Engine FeatureCollection
color_column: Column containing color values
label_column: Column containing labels
**kwargs: Additional parameters
Returns:
Legend configuration dictionary
"""
# Built-in legends
builtin_legends: Dict[str, Dict] = {}Utilities for processing and transforming data for visualization purposes.
def transpose_df(df, **kwargs):
"""
Transpose DataFrame for visualization.
Args:
df: Input DataFrame
**kwargs: Additional parameters
Returns:
Transposed DataFrame
"""
def pivot_df(
df,
index: str,
columns: str,
values: str,
**kwargs
):
"""
Pivot DataFrame for visualization.
Args:
df: Input DataFrame
index: Index column
columns: Columns to pivot
values: Values column
**kwargs: Additional parameters
Returns:
Pivoted DataFrame
"""
def array_to_df(
array,
column_names: List[str] = None,
**kwargs
):
"""
Convert array to DataFrame.
Args:
array: Input array
column_names: Column names for DataFrame
**kwargs: Additional parameters
Returns:
DataFrame object
"""import geemap
import pandas as pd
# Create sample data
data = pd.DataFrame({
'year': [2018, 2019, 2020, 2021, 2022],
'temperature': [14.2, 15.1, 14.8, 15.3, 15.7]
})
# Create line chart
geemap.line_chart(data, x='year', y='temperature', width=500, height=300)
# Create bar chart
geemap.bar_chart(data, x='year', y='temperature')
# Create histogram
sample_data = pd.DataFrame({'values': [1, 2, 2, 3, 3, 3, 4, 4, 5]})
geemap.histogram(sample_data, column='values', bins=5)import ee
# Initialize Earth Engine
ee.Initialize()
# Create time series from NDVI data
collection = (ee.ImageCollection('MODIS/006/MOD13A2')
.filterDate('2020-01-01', '2020-12-31')
.select('NDVI'))
roi = ee.Geometry.Point([-122.4, 37.8])
geemap.create_timeseries(
collection,
region=roi,
start_date='2020-01-01',
end_date='2020-12-31',
bands=['NDVI'],
frequency='month'
)# Create GIF from image collection
collection = (ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
.filterDate('2020-01-01', '2020-12-31')
.filterBounds(roi)
.limit(12))
# Export frames and create GIF
geemap.make_gif(
'landsat_timelapse.gif',
fps=2,
loop=0
)
# Add text to GIF
text_sequence = ['Jan 2020', 'Feb 2020', 'Mar 2020']
geemap.add_text_to_gif(
'landsat_timelapse.gif',
'landsat_with_text.gif',
xy=(50, 50),
text_sequence=text_sequence,
font_size=16,
font_color='white'
)
# Convert to MP4
geemap.gif_to_mp4('landsat_with_text.gif', 'landsat_timelapse.mp4', fps=5)# Get color palette
colors = geemap.get_palette('viridis', n_class=10)
print(colors)
# List available colormaps
colormaps = geemap.list_colormaps()
print(f"Available colormaps: {len(colormaps)}")
# Plot specific colormap
geemap.plot_colormap('RdYlBu', width=10, height=0.5)
# Create colorbar
colorbar = geemap.get_colorbar(
colors=['blue', 'green', 'red'],
vmin=0,
vmax=100
)# Chart data types
ChartData = Union[pd.DataFrame, List, Dict]
# Color specification
Color = Union[str, tuple, List[float]]
# Color palette
Palette = List[str]
# Chart dimensions
ChartDimensions = Dict[str, int] # {'width': int, 'height': int}
# Legend configuration
LegendConfig = Dict[str, Union[str, List[str], Dict]]
# Animation parameters
AnimationParams = Dict[str, Union[int, float, str, bool]]Install with Tessl CLI
npx tessl i tessl/pypi-geemap