# earthlab/earthpy architecture

> Architecture diagram of the GitHub repository earthlab/earthpy, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/earthlab/earthpy
- Repository: https://github.com/earthlab/earthpy

## Overview

##### Main Components

a. Core Modules Layer:
- Plot Module (earthpy.plot)
- Spatial Module (earthpy.spatial)
- IO Module (earthpy.io)
- Mask Module (earthpy.mask)
- Clip Module (earthpy.clip)

b. Dependencies Layer:
- Rasterio (for raster data handling)
- Geopandas (for vector data handling)
- NumPy (for array operations)
- Matplotlib (for plotting)

c. Data Layer:
- Example Data Repository
- External Data Sources
- Data Cache System

**┌─────────────────────────────────────────────────────┐**
- Client Applications                 │
- ┘
- ↓
**┌─────────────────────────────────────────────────────┐**
- EarthPy API                      │
- ┬─────────────┬────────────┬───────────┤
- Plot API   │ Spatial API │   IO API   │ Mask API  │
- ┴─────────────┴────────────┴───────────┘
- ↓
**┌─────────────────────────────────────────────────────┐**
- Core Processing Layer                 │
- ┬─────────────┬────────────┬───────────┤
- Plot Module │   Spatial   │ IO Module  │   Mask    │
- Module    │            │  Module   │
- ┴─────────────┴────────────┴───────────┘
- ↓
**┌─────────────────────────────────────────────────────┐**
- External Dependencies                  │
- ┬─────────────┬────────────┬───────────┤
- Rasterio   │  Geopandas  │   NumPy    │Matplotlib │
- ┴─────────────┴────────────┴───────────┘
- ↓
**┌─────────────────────────────────────────────────────┐**
- Data Sources                     │
- ┬─────────────┬────────────────────────┤
- Example    │  External   │      User Data         │
- Data      │    Data     │                        │
- ┴─────────────┴────────────────────────┘

##### Important Elements to Highlight

a. Data Flow:
- How data moves from source through processing to visualization
- Transformation points between raster and vector data
- Where masking and clipping operations occur

b. Integration Points:
- How EarthPy interfaces with external libraries
- Where user customization is possible
- Extension points for future functionality

##### Implementation Details

- The modular nature of the package
- Clear separation of concerns between modules
- Data processing workflows
- Integration with scientific Python ecosystem

##### Key Workflows to Highlight

- Raster band stacking and cropping
- Mask application process
- Vegetation index calculation
- Hillshade generation
- Data download and caching

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef client fill:#E0E0E0,stroke:#333,stroke-width:2px
    classDef api fill:#9C27B0,stroke:#333,stroke-width:2px,color:white
    classDef core fill:#2196F3,stroke:#333,stroke-width:2px,color:white
    classDef deps fill:#4CAF50,stroke:#333,stroke-width:2px,color:white
    classDef data fill:#FF9800,stroke:#333,stroke-width:2px,color:white
    classDef cicd fill:#795548,stroke:#333,stroke-width:2px,color:white

    %% Client Layer
    Client["Client Applications"]

    %% API Layer
    subgraph API
        PlotAPI["Plot API"]
        SpatialAPI["Spatial API"]
        IOAPI["IO API"]
        MaskAPI["Mask API"]
        ClipAPI["Clip API"]
    end

    %% Core Processing Layer
    subgraph Core
        Plot["Plot Module"]
        Spatial["Spatial Module"]
        IO["IO Module"]
        Mask["Mask Module"]
        Clip["Clip Module"]
        Tests["Module Tests"]
    end

    %% External Dependencies Layer
    subgraph Dependencies
        Rasterio["Rasterio"]
        Geopandas["Geopandas"]
        NumPy["NumPy"]
        Matplotlib["Matplotlib"]
    end

    %% Data Sources Layer
    subgraph Data
        ExampleData["Example Data Repository"]
        ExternalData["External Data"]
        UserData["User Data"]
    end

    %% CI/CD Layer
    subgraph CICD
        Testing["Testing Pipeline"]
        CodeCov["Code Coverage"]
        DocGen["Documentation"]
        Publish["Package Publishing"]
    end

    %% Relationships
    Client --> PlotAPI & SpatialAPI & IOAPI & MaskAPI & ClipAPI
    
    PlotAPI --> Plot
    SpatialAPI --> Spatial
    IOAPI --> IO
    MaskAPI --> Mask
    ClipAPI --> Clip

    Plot & Spatial & IO & Mask & Clip --> Rasterio & Geopandas & NumPy & Matplotlib
    
    IO --> ExampleData & ExternalData & UserData

    Tests --> Plot & Spatial & IO & Mask & Clip
    
    Testing --> Tests
    CodeCov --> Tests
    DocGen --> API
    Publish --> Core

    %% Click Events
    click Plot "https://github.com/earthlab/earthpy/blob/main/earthpy/plot.py"
    click Spatial "https://github.com/earthlab/earthpy/blob/main/earthpy/spatial.py"
    click IO "https://github.com/earthlab/earthpy/blob/main/earthpy/io.py"
    click Mask "https://github.com/earthlab/earthpy/blob/main/earthpy/mask.py"
    click Clip "https://github.com/earthlab/earthpy/blob/main/earthpy/clip.py"
    click ExampleData "https://github.com/earthlab/earthpy/tree/main/earthpy/example-data/"
    click Tests "https://github.com/earthlab/earthpy/tree/main/earthpy/tests/"
    click PlotAPI "https://github.com/earthlab/earthpy/blob/main/docs/api/earthpy.plot.rst"
    click SpatialAPI "https://github.com/earthlab/earthpy/blob/main/docs/api/earthpy.spatial.rst"
    click IOAPI "https://github.com/earthlab/earthpy/blob/main/docs/api/earthpy.io.rst"
    click MaskAPI "https://github.com/earthlab/earthpy/blob/main/docs/api/earthpy.mask.rst"
    click ClipAPI "https://github.com/earthlab/earthpy/blob/main/docs/api/earthpy.clip.rst"
    click Testing "https://github.com/earthlab/earthpy/blob/main/.github/workflows/run-tests.yml"
    click CodeCov "https://github.com/earthlab/earthpy/blob/main/.github/workflows/code-cov.yml"
    click DocGen "https://github.com/earthlab/earthpy/blob/main/.github/workflows/lint-docs.yml"
    click Publish "https://github.com/earthlab/earthpy/blob/main/.github/workflows/publish-pypi.yml"

    %% Style Applications
    class Client client
    class PlotAPI,SpatialAPI,IOAPI,MaskAPI,ClipAPI api
    class Plot,Spatial,IO,Mask,Clip,Tests core
    class Rasterio,Geopandas,NumPy,Matplotlib deps
    class ExampleData,ExternalData,UserData data
    class Testing,CodeCov,DocGen,Publish cicd
```
