FastSPA
website·Indexed 30 days ago
https://docs.fastspa.netA modern Python interface for Structural Path Analysis (SPA) in Environmentally Extended Input-Output (EEIO) models. It provides tools for sector-specific and economy-wide analysis, including Iterative Proportional Fitting (IPF) for table adjustments, Monte Carlo uncertainty propagation, consequential mode for 'what-if' analysis, and interactive Plotly visualizations for supply chain pathways.
What's inside FastSPA
- Fastspa provides IPF functionality to adjust Input-Output (IO) tables, technical coefficients, and satellite data to match updated sector constraints. This process preserves the underlying structure and cross-product ratios of the original data. Common use cases include IO table balancing, technical coefficients adjustment, satellite data scaling, and scenario analysis for policy research.
Overview of FastSPA for Structural Path Analysis
FastSPA is a NumPy-native Python interface designed for Structural Path Analysis (SPA) within Environmentally Extended Input-Output (EEIO) analysis. It allows developers to decompose environmental impacts across supply chains by tracing pathways from direct sources through multiple tiers of suppliers. Key features include an array-first design for NumPy/pandas integration, support for multiple environmental flows (multi-satellite), and Iterative Proportional Fitting (IPF) for sector adjustments.Overview of Iterative Proportional Fitting (IPF) in EEIO
Iterative Proportional Fitting (IPF) is a mathematical technique used in Environmentally Extended Input-Output (EEIO) analysis to adjust economic and environmental data to match new constraints while preserving the underlying structure.
Common use cases include:
- Economic scenario analysis: Updating IO tables for policy changes or projections.
- Technology transitions: Adjusting technical coefficients for new technologies.
- Environmental targets: Scaling satellite data to meet emission reduction goals.
- Cross-classification: Mapping data between different sector classifications.
RAS vs. IPF: RAS (Biproportional Scaling) is a 2D application of IPF specifically used for balancing IO transaction matrices (scaling rows and columns). IPF is used for more complex, multi-dimensional constraints, such as regionalizing tables or disaggregating sectors.
Integrate IPF results with other FastSPA features
Adjusted matrices and data produced by IPF can be used across the FastSPA ecosystem:
- SPA Analysis: Use adjusted A matrices and satellite data for pathway analysis.
- Concordance: Combine IPF with sector mapping for cross-classification adjustments.
- Visualization: Use FastSPA plotting functions to visualize scenario results.
- Multi-satellite: Use IPF to balance multiple environmental accounts consistently.
Export PathCollection data
Path data can be exported to DataFrames, CSV files, or JSON strings/files. The.summary()method provides a quick text-based overview of the collection.# To Pandas DataFrame df = paths.to_dataframe() # To CSV (include_metadata=False to omit header) paths.to_csv("results.csv", include_metadata=False) # To JSON file or string paths.to_json("results.json") json_str = paths.to_json() # Text summary print(paths.summary())Inspect and analyze supply chain paths
The results of an analysis are returned as a collection of paths. Each path object contains metadata about the supply chain route, including its contribution to total intensity and the sequence of sectors involved.# Get the top path top_path = paths[0] # Sector indices in the path (0-indexed internally) print(top_path.nodes) # e.g., (1, 0, 1) # Sector names in the path print(top_path.sectors) # e.g., ('Manufacturing', 'Agriculture', 'Manufacturing') # Contribution to total intensity (as a float/percentage) print(f"{top_path.contribution:.2%}") # Direct intensity at the emission source (leaf node) print(top_path.direct_intensity) # Path depth (0 for direct, 1+ for upstream) print(top_path.depth)Understand Path structure and flow
A path represents the flow from a target sector back through its supply chain to the emission source. The structure follows:
Target (root) → Tier 1 → Tier 2 → ... → Emission Source (leaf).For example, a path defined by nodes
(42, 15, 3)indicates that Sector 42 purchases from Sector 15, and Sector 15 purchases from Sector 3, with the emissions occurring at Sector 3.Perform sector-specific or economy-wide matrix analysis with fastspa
Use theSPAclass infastspato analyze contributing sectors and pathways. This allows for sector-specific analysis (by specifying a sector index) or economy-wide analysis. The tool supports multi-satellite analysis, enabling the simultaneous evaluation of multiple environmental flows such as GHG, water, and energy. Results can be visualized using interactive icicle plots.from fastspa import SPA # A: Your A-matrix # emissions: direct intensities paths = SPA(A, emissions).analyze(sector=42, depth=8) # Print the top 10 contributing pathways for path in paths.top(10): print(f"{path.contribution:.2%}: {' → '.join(path.sectors)}") # Export the results to a pandas DataFrame df = paths.to_dataframe()Aggregate sectors using semantic and hierarchical groupings
fastspa supports semantic aggregation to simplify granular IO (Input-Output) sectors into stakeholder-friendly groupings. This allows for the communication of results without exposing proprietary details. It also supports hierarchical aggregation (e.g., division → group → industry) to align results with standard statistical classifications.Install FastSPA visualization dependencies
FastSPA visualization features require theplotlylibrary to generate interactive charts.pip install plotlyCreate a supply chain Icicle Plot
Theicicle_plotis the primary tool for supply chain decomposition. It represents supply chain links as rectangles where the width/area indicates the relative contribution to total intensity, color intensity represents the magnitude of the value, and the vertical hierarchy shows the depth from the target sector to suppliers.from fastspa import SPA, icicle_plot # Run analysis spa = SPA(A_matrix, emissions, sectors=sector_names) paths = spa.analyze(sector=0, depth=6, threshold=0.001) # Generate interactive plot fig = icicle_plot(paths, output_html="supply_chain.html")Conduct temporal and dynamic supply-chain analysis
Compare SPA (Socio-economic Process Analysis) results across multiple years to identify whether supply-chain hotspots are structurally changing over time.