slca

package
v1.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2020 License: GPL-3.0 Imports: 42 Imported by: 0

README

Spatial life cycle assessment (SLCA) model framework

This is a framework for creating spatially (and, if desired, chemical and temporally) detailed well-to-product life cycle inventories.

This model is also coupled to the InMAP model Source-receptor Matrix to automatically calculate PM2.5 concentrations and health impacts caused by emissions of PM2.5 and its precursors.

Installation
  • Download the 2014 US National Emissions Inventory data as described here.
  • Install the go compiler
  • Install the slca package ("go get github.com/spatialmodel/inmap/emissions/slca")
Contact

https://groups.google.com/forum/#!forum/inmap-users

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CSTConfig

type CSTConfig struct {
	// PolTrans translates between GREET pollutants and InMAP pollutants.
	// Format is map[GREET pollution]InMAP pollutant. There must be an
	// entry for each GREET pollutant. GREET pollutants that do not have
	// a corresponding InMAP species should be set equal to "none".
	PolTrans map[string]string

	// SRFile gives the location of the InMAP SR matrix data files in a
	// map where each key is an identifying name of an air quality model
	// and each value is the path to an SR matrix file.
	SRFiles map[string]string

	// SRCacheSize specifies the number of SR records to hold in an in-memory
	// cache to speed up air pollution computations. 1 GB of RAM is required for
	// approximately every 1,000 records.
	SRCacheSize int

	// CensusFile specifies the location of the shapefile holding
	// population counts for each analysis year.
	CensusFile map[string]string

	// CensusPopColumns specifies the names of the population attribute
	// columns in CensusFile.
	CensusPopColumns []string

	// MortalityRateFile specifies the location of the shapefile holding
	// baseline mortality rate information for each analysis year.
	MortalityRateFile map[string]string

	// MortalityRateColumns maps population groups to fields in the mortality rate
	// shapefile containing their respective the mortality rates.
	MortalityRateColumns map[string]string

	// InventoryConfig specifies the configuration of the emissions inventory
	// data used for spatial surrogates.
	InventoryConfig aeputil.InventoryConfig

	// FugitiveDustSector specifies the name of the sectors, if any,
	// that should have a fugitive dust adjustment applied to them.
	FugitiveDustSectors []string

	// FugitiveDustAdjustment specifies the path to the files---one for
	// each air quality model--that contain
	// grid-cell specific fugitive dust adjustment factors.
	FugitiveDustAdjustment map[string]string

	// InventoryConfig specifies the configuration of the emissions inventory
	// data used for air quality model evaluation and calculating average
	// concentration response.
	EvaluationInventoryConfig aeputil.InventoryConfig

	// AdditionalEmissionsShapefilesForEvaluation specifies additional emissions
	// shapefiles to be used for model evaluation. This field will be removed
	// when a better way of doing biogenic emissions is completed. Units = tons/year.
	AdditionalEmissionsShapefilesForEvaluation []string

	// SpatialConfig specifies the spatial configuration used for
	// creating spatial surrogates and for air quality model evaluation and
	// calculating average concentration response.
	SpatialConfig aeputil.SpatialConfig

	// NEIData holds information needed for processing the NEI.
	NEIData struct {
		// These variables specify the locations of files used for
		// chemical speciation.
		SpecRef, SpecRefCombo, SpeciesProperties, GasProfile   string
		GasSpecies, OtherGasSpecies, PMSpecies, MechAssignment string
		MolarWeight, SpeciesInfo                               string

		// ChemicalMechanism specifies which chemical mechanism to
		// use for speciation.
		ChemicalMechanism string

		// MassSpeciation specifies whether to use mass speciation.
		// If false, speciation will convert values to moles.
		MassSpeciation bool

		SCCExactMatch bool
	}

	// NEIBaseYear specifies the year the input NEI emissions data is for,
	// for use in scaling emissions for other years.
	NEIBaseYear int

	// NEITrends specifies the file holding trends in NEI  emissions, downloadable
	// from https://www.epa.gov/air-emissions-inventories/air-pollutant-emissions-trends-data.
	NEITrends string

	// SCCReference specifies the file holding cross references between SCC
	// codes and tier 1 summary codes, for use in scaling emissions for other
	// years, downloadable from https://ofmpub.epa.gov/sccsearch/.
	SCCReference string

	// ConcentrationCache specifies the location for storing concentration
	// data for quick access. If this is left empty, no cache will be used.
	ConcentrationCache string

	// HealthCache specifies the location for storing concentration
	// data for quick access. If this is left empty, no cache will be used.
	HealthCache string

	// SpatialCache specifies the location for storing spatial emissions
	// data for quick access. If this is left empty, no cache will be used.
	SpatialCache string

	// MaxCacheEntries specifies the maximum number of emissions and concentrations
	// surrogates to hold in a memory cache. Larger numbers can result in faster
	// processing but increased memory usage.
	MaxCacheEntries int

	// DefaultFIPS specifies the default FIPS code to use when retrieving gridding
	// surrogates. Set to "00000" by default.
	DefaultFIPS string
	// contains filtered or unexported fields
}

CSTConfig holds Chemical, spatial, and temporal (CST) configuration

func (*CSTConfig) ConcentrationResponseAverage

func (c *CSTConfig) ConcentrationResponseAverage(ctx context.Context, request *eieiorpc.ConcentrationResponseAverageInput) (*eieiorpc.Vector, error)

ConcentrationResponseAverage calculates the average concentration response for PM2.5 (deaths per year per ug/m3 per capita) for a non-linear concentration- response function. hr specifies the function used to calculate the hazard ratio.

func (*CSTConfig) ConcentrationSurrogate

func (c *CSTConfig) ConcentrationSurrogate(ctx context.Context, spatialRef *SpatialRef) (*sr.Concentrations, error)

ConcentrationSurrogate calculates the pollutant concentration impacts of spatialRef, accounting for the effects of elevated emissions plumes.

func (*CSTConfig) EmissionsSurrogate

func (c *CSTConfig) EmissionsSurrogate(ctx context.Context, pol Pollutant, spatialRef *SpatialRef) (*sparse.SparseArray, error)

EmissionsSurrogate returns the spatially-explicit emissions caused by spatialRef.

func (*CSTConfig) EvaluationConcentrations

func (c *CSTConfig) EvaluationConcentrations(ctx context.Context, request *eieiorpc.EvaluationConcentrationsInput) (*eieiorpc.Vector, error)

EvaluationConcentrations returns an array of concentrations calculated using the EvaluationInventoryConfig and AdditionalEmissionsShapefilesForEvaluation fields of the receiver, adjusting emissions to the specified year.

func (*CSTConfig) EvaluationEmissions

func (c *CSTConfig) EvaluationEmissions(ctx context.Context, aqm string, year int) ([]*inmap.EmisRecord, error)

EvaluationEmissions returns an array of emissions records calculated using the EvaluationInventoryConfig and AdditionalEmissionsShapefilesForEvaluation fields of the receiver, adjusting emissions to the specified year and gridding them to match the specified air quality model (aqm).

func (*CSTConfig) EvaluationHealth

func (c *CSTConfig) EvaluationHealth(ctx context.Context, request *eieiorpc.EvaluationHealthInput) (*eieiorpc.Vector, error)

EvaluationHealth returns an array of health impacts calculated using the EvaluationInventoryConfig and AdditionalEmissionsShapefilesForEvaluation fields of the receiver, adjusting emissions to the specified year. HR specifies the function used to calculate the hazard ratio. Output format = map[popType][pol]values

func (*CSTConfig) Geometry

func (c *CSTConfig) Geometry(aqm string) ([]geom.Polygonal, error)

Geometry returns the air quality model grid cell geometry when given an identifier for which air quality model to use.

func (*CSTConfig) HealthSurrogate

func (c *CSTConfig) HealthSurrogate(ctx context.Context, spatialRef *SpatialRef, HR string) (map[string]map[string]*sparse.DenseArray, error)

HealthSurrogate calculates the health impact of the given spatial reference. HR specifies the function used to calculate the hazard ratio. Output format = map[popType][pol]values

func (*CSTConfig) PopulationIncidence

PopulationIncidence returns gridded population counts and underlying mortality incidence rates for the type specified by popType. Valid population types are specified by the CensusPopColumns attribute of the receiver. The returned value Population is population counts and Incidence is underlying incidence rates. hr specifies the function used to calculate the hazard ratio.

func (*CSTConfig) Setup

func (c *CSTConfig) Setup(hr ...epi.HRer) error

setup sets up the chemical, spatial, and temporal configuration, where hr specifies the hazard ratio functions that should be included.

type DB

type DB struct {
	LCADB

	*http.ServeMux

	// Chemical, spatial, and temporal (CST) configuration
	CSTConfig *CSTConfig
}

DB is a holder for an SLCA database.

func (*DB) RegisterHTTPHandlers

func (db *DB) RegisterHTTPHandlers(prefix, staticFileDir string)

RegisterHTTPHandlers configures the HTML user interface. Prefix is a URL prefix: e.g. xxx.com/prefix/xxx.html. staticFileDir is the path to the directory containing the static files, i.e. this directory.

func (*DB) Speciate

func (db *DB) Speciate(r *Results) (*Results, error)

Speciate returns a chemically speciated copy of r.

type Gas

type Gas interface {
	// GetName returns the name of this gas.
	GetName() string

	// GetID returns the ID of this gas.
	GetID() string
}

Gas represents a type of emission.

type Guid

type Guid string

Guid is a globally unique ID

type LCADB

type LCADB interface {
	// EndUses returns the potential end Pathways and their names.
	EndUses() ([]Pathway, []string)

	// EndUseFromID returns an end use Pathway when given its ID.
	EndUseFromID(ID string) (Pathway, error)

	// SpatialSCCs returns a list of all SCC codes used by processes in the
	// receiver.
	SpatialSCCs() []SCC

	// GetYear returns the analysis year.
	GetYear() float64
}

LCADB specifies the methods that an LCA database must have to work with this framework.

type OnsiteResults

type OnsiteResults struct {
	Emissions    map[SubProcess]map[Gas]*unit.Unit
	Resources    map[SubProcess]map[Resource]*unit.Unit
	Requirements map[Process]map[Pathway]map[Output]*unit.Unit
	// contains filtered or unexported fields
}

OnsiteResults is a holder for emissions, resource use, and requirements for a single process.

func NewOnsiteResults

func NewOnsiteResults(db LCADB) *OnsiteResults

NewOnsiteResults initializes a new instance of OnsiteResults.

func (*OnsiteResults) Add

func (or *OnsiteResults) Add(r *OnsiteResults)

Add adds values from another OnsiteResults to this OnsiteResults.

func (*OnsiteResults) AddEmission

func (or *OnsiteResults) AddEmission(sp SubProcess, g Gas, val *unit.Unit)

AddEmission adds an amount of a resource to the results.

func (*OnsiteResults) AddRequirement

func (or *OnsiteResults) AddRequirement(proc Process, path Pathway, o Output, amount *unit.Unit, db LCADB)

AddRequirement adds a requirement of the current process for another process.

func (*OnsiteResults) AddResource

func (or *OnsiteResults) AddResource(sp SubProcess, r Resource, val *unit.Unit, db LCADB)

AddResource adds an amount of a resource to the results.

func (*OnsiteResults) Clone

func (or *OnsiteResults) Clone() *OnsiteResults

Clone returns a copy of or.

func (*OnsiteResults) Div

func (or *OnsiteResults) Div(v *unit.Unit)

Div divides the results by a constant.

func (*OnsiteResults) FilterEmissions

func (or *OnsiteResults) FilterEmissions() *OnsiteResults

FilterEmissions returns an OnsiteResults object that only contains emissions.

func (*OnsiteResults) FilterRequirements

func (or *OnsiteResults) FilterRequirements() *OnsiteResults

FilterRequirements returns an OnsiteResults object that only contains Requirements.

func (*OnsiteResults) FilterResources

func (or *OnsiteResults) FilterResources() *OnsiteResults

FilterResources returns an OnsiteResults object that only contains resource use.

func (*OnsiteResults) FlattenSubprocess

func (or *OnsiteResults) FlattenSubprocess() *OnsiteResultsNoSubprocess

FlattenSubprocess returns a version of the results with the resource use and emissions from all subprocesses combined.

func (*OnsiteResults) Mul

func (or *OnsiteResults) Mul(v *unit.Unit)

Mul multiplies the results by a constant.

func (*OnsiteResults) ScaleCopy

func (or *OnsiteResults) ScaleCopy(factor *unit.Unit) *OnsiteResults

ScaleCopy returns a copy of or, multiplying the values in or by factor.

func (*OnsiteResults) SortOrder

func (or *OnsiteResults) SortOrder() (subProcesses []SubProcess, gases []Gas, resources []Resource)

SortOrder returns the gases emitted and resources used by the sub processes in the receiver in alphabetical order.

func (*OnsiteResults) String

func (or *OnsiteResults) String() string

func (*OnsiteResults) SubEmission

func (or *OnsiteResults) SubEmission(sp SubProcess, g Gas, val *unit.Unit)

SubEmission subtracts an amount of a resource from the results.

func (*OnsiteResults) SubResource

func (or *OnsiteResults) SubResource(sp SubProcess, r Resource, val *unit.Unit, db LCADB)

SubResource subtracts an amount of a resource from the results.

type OnsiteResultsNoSubprocess

type OnsiteResultsNoSubprocess struct {
	Emissions map[Gas]*unit.Unit
	Resources map[Resource]*unit.Unit
}

OnsiteResultsNoSubprocess holds onsite results without any subprocess information.

func (*OnsiteResultsNoSubprocess) SortOrder

func (r *OnsiteResultsNoSubprocess) SortOrder() (gases []Gas, resources []Resource)

SortOrder returns the gases emitted and resources used in the receiver in alphabetical order.

func (*OnsiteResultsNoSubprocess) String

func (or *OnsiteResultsNoSubprocess) String() string

type Output

type Output interface {
	// GetResource returns the Resource that is output by the receiver.
	GetResource(LCADB) Resource

	// GetID returns the ID of the receiver.
	GetID() OutputID
}

Output represents an output from a process or pathway.

type OutputID

type OutputID Guid

OutputID holds the ID code for an output

type Pathway

type Pathway interface {
	// GetName gets the name of this Pathway.
	GetName() string

	// GetIDStr returns the ID of the receiver in string format.
	GetIDStr() string

	// MainProcessAndOutput returns the process that outputs the main
	// output of the receiver, and also returns that output.
	MainProcessAndOutput(LCADB) (Process, Output)
}

Pathway represents a series of processes in a life cycle.

type Pollutant

type Pollutant int

Pollutant specifies air pollutant names

const (
	PM25 Pollutant = iota
	NH3
	NOx
	SOx
	VOC
)

These are the valid air pollutant names.

func (Pollutant) String

func (i Pollutant) String() string

type Process

type Process interface {
	// Type returns the ProcessType of the reciever.
	Type() ProcessType

	// SpatialRef returns the spatial reference information associated
	// with the receiver, for the given air quality model.
	SpatialRef(aqm string) *SpatialRef

	// GetName returns the name of the receiver.
	GetName() string

	// GetIDStr returns the ID of the receiver in string format.
	GetIDStr() string

	GetOutput(Resource, LCADB) Output
	GetMainOutput(LCADB) Output

	// OnsiteResults returns the onsite emissions and input resource
	// requirements per unit of the specified Output, as part
	// of the specified Pathway.
	OnsiteResults(Pathway, Output, LCADB) *OnsiteResults
}

Process represents a process in a life cycle.

type ProcessType

type ProcessType int

ProcessType specifies a type of a Process.

const (
	// Stationary specifies a process is one that is at
	// a fixed location or locations.
	Stationary ProcessType = iota + 1

	// Transportation specifies a process is one that needs to be routed from a
	// source to a destination.
	Transportation

	// Vehicle specifies an end-use vehicle.
	Vehicle

	// NoSpatial represents a process that does not have any spatial information.
	NoSpatial
)

type Resource

type Resource interface {
	// GetName returns the name of this resource.
	GetName() string

	// GetID returns the ID of this resource.
	GetID() string

	// ConvertToDefaultUnits converts the speceified amount to the
	// default units of the receiver.
	ConvertToDefaultUnits(amount *unit.Unit, db LCADB) *unit.Unit
}

Resource represents a material that can be input to or output from a process.

type ResultEdge

type ResultEdge struct {
	FromID, ToID, ID string
	FromResults      *OnsiteResults
}

ResultEdge is a holder for information about the relation between two Nodes and the emissions created and resources used by the From process to supply the To process.

type ResultNode

type ResultNode struct {
	ID      string
	Process Process
	Pathway Pathway
	Output  Output
	// contains filtered or unexported fields
}

ResultNode is a holder for information about a single pathway/process/output combination.

type Results

type Results struct {
	Nodes map[string]*ResultNode
	Edges []*ResultEdge
	// contains filtered or unexported fields
}

Results is a holder for life cycle process requirements, emissions, and resource use. It allows the determination of which downstream processes are causing the resource use and emissions of the upstream process.

func NewResults

func NewResults(db LCADB) *Results

NewResults initializes a new instance of results.

func SolveGraph

func SolveGraph(path Pathway, amount *unit.Unit, db *DB) *Results

SolveGraph calculates the life cycle resource use and emissions of the specified amount of the specified pathway, using a graph-based solving method.

func (*Results) GetEdge

func (r *Results) GetEdge(from, to *ResultNode) *ResultEdge

GetEdge returns the edge connecting from and to if it exist, otherwise a new edge is created, added to the results, and returned.

func (*Results) GetFromNode

func (r *Results) GetFromNode(e *ResultEdge) *ResultNode

GetFromNode gets the upstream node associated with this edge.

func (*Results) GetNode

func (r *Results) GetNode(proc Process, path Pathway, o Output) *ResultNode

GetNode checks whether the Results already have a node for the given process, pathway, and output. If the node exists, it is returned, otherwise a new node is created, added to the results, and returned.

func (*Results) GetToNode

func (r *Results) GetToNode(e *ResultEdge) *ResultNode

GetToNode gets the downstream node associated with this edge.

func (*Results) Len

func (r *Results) Len() int

func (*Results) Less

func (r *Results) Less(i, j int) bool

func (*Results) String

func (r *Results) String() string

String prints the results in sorted format, so they are the same every time.

func (Results) Sum

Sum returns a sum of the results.

func (*Results) SumFor

func (r *Results) SumFor(n *ResultNode) *OnsiteResults

SumFor sums all of the results for the node.

func (*Results) Swap

func (r *Results) Swap(i, j int)

func (*Results) Table

func (r *Results) Table() ([][]string, error)

Table creates a table from the results, suitable for outputting to a CSV file.

type SCC

type SCC string

SCC is an EPA source classification code

type SpatialRef

type SpatialRef struct {
	// EPA Source Classification codes corresponding to this process.
	SCCs []SCC `xml:"scc"`

	// SCCFractions specifies adjustment factors to multiply emissions by
	// for each SCC code in SCCs. If SCCFractions is nil, no adjustments
	// are applied.
	SCCFractions []float64

	// EmisYear specifies the year to adjust emissions amounts to
	// for the SCCs codes corresponding to this process.
	EmisYear int

	// Surrogate code for this process.
	Surrogate string `xml:"spatial_srg"`

	// The FIPS code to be used with Surrogate for this process.
	SurrogateFIPS string `xml:"spatial_srg_fips"`

	// NoSpatial is true if this process is intentionally lacking spatial information.
	NoSpatial bool

	Type ProcessType

	// AQM is an identifier for the air quality model grid emissions should be
	// allocated to.
	AQM string

	// NoNormalization specifies whether the spatial surrogate
	// should be normalized so that its sum==1. The default is
	// to perform normalization.
	NoNormalization bool
}

SpatialRef holds reference information about the spatial location of this process.

type SpatialResults

type SpatialResults struct {
	*Results
	// contains filtered or unexported fields
}

SpatialResults is a wrapper for Results that can do spatial calculations.

func NewSpatialResults

func NewSpatialResults(res *Results, db *DB) *SpatialResults

NewSpatialResults returns a new SpatialResults variable.

func (*SpatialResults) Concentrations

func (sr *SpatialResults) Concentrations(aqm string) (map[string]*sparse.DenseArray, error)

Concentrations gets the total change in concentrations of PM2.5 and its subspecies caused by life cycle sr.

func (*SpatialResults) EdgeConcentrations

func (sr *SpatialResults) EdgeConcentrations(e *ResultEdge, aqm string) (map[SubProcess]map[string]*sparse.DenseArray, error)

EdgeConcentrations gets the change in concentrations of PM2.5 and its subspecies caused by the emissions in e.

func (*SpatialResults) EdgeEmissions

func (sr *SpatialResults) EdgeEmissions(e *ResultEdge, aqm string) (map[SubProcess]map[Gas]*sparse.SparseArray, error)

EdgeEmissions returns the spatialized emissions associated with edge e, for the given air quality model.

func (*SpatialResults) EdgeHealth

func (sr *SpatialResults) EdgeHealth(e *ResultEdge, HR, aqm string) (map[SubProcess]map[string]map[string]*sparse.DenseArray, error)

EdgeHealth gets the spatialized health impacts caused by the emissions in edge e. It calculates the number of deaths in each demographic group caused by these emissions. The format of the output is map[population][pollutant]effects. HR specifies the function used to calculate the hazard ratio.

func (*SpatialResults) EdgeHealthTotals

func (sr *SpatialResults) EdgeHealthTotals(e *ResultEdge, HR, aqm string) (map[SubProcess]map[string]map[string]float64, error)

EdgeHealthTotals gets the total (non-spatialized) health impacts caused by the emissions in edge e. It calculates the number of deaths in each demographic group caused by these emissions. HR specifies the function used to calculate the hazard ratio. The format of the output is map[population][pollutant]total effects.

func (*SpatialResults) EdgeResourceUse

func (sr *SpatialResults) EdgeResourceUse(e *ResultEdge, aqm string) (map[SubProcess]map[Resource]*sparse.SparseArray, error)

EdgeResourceUse returns the spatialized resource use associated with edge e.

func (*SpatialResults) Emissions

func (sr *SpatialResults) Emissions(aqm string) (map[Gas]*sparse.SparseArray, error)

Emissions gets the total spatially explicit emissions caused by life cycle sr.

func (*SpatialResults) Health

func (sr *SpatialResults) Health(HR, aqm string) (map[string]map[string]*sparse.DenseArray, error)

Health gets the total PM2.5 health impacts caused by life cycle sr. The format of the output is map[population][pollutant]impacts. HR specifies the function used to calculate the hazard ratio.

func (*SpatialResults) ResourceUse

func (sr *SpatialResults) ResourceUse(aqm string) (map[Resource]*sparse.SparseArray, error)

ResourceUse gets the total spatially explicit resource use caused by life cycle sr.

func (*SpatialResults) Sum

Sum returns a sum of the (non-spatial) results.

func (*SpatialResults) Table

func (sr *SpatialResults) Table(HR, aqm string) ([][]string, error)

Table creates a table from the results, suitable for outputting to a CSV file. HR specifies the function used to calculate the hazard ratio, and aqm specifies the air quality model.

type SubProcess

type SubProcess interface {
	GetName() string
	GetSCC() SCC
}

SubProcess gives information about the specific source of emissions or resource use within a process.

Directories

Path Synopsis
Package eieio implements an Extended InMAP Economic Input-Output (EIEIO) life cycle assessment model based on the US Bureau of Economic Analysis (BEA) Annual Input-Output Accounts Data from https://www.gov/industry/io_annual.htm.
Package eieio implements an Extended InMAP Economic Input-Output (EIEIO) life cycle assessment model based on the US Bureau of Economic Analysis (BEA) Annual Input-Output Accounts Data from https://www.gov/industry/io_annual.htm.
ces
Package ces translates Consumer Expenditure Survey (CES) demographic data to EIO categories.
Package ces translates Consumer Expenditure Survey (CES) demographic data to EIO categories.
eieiorpc/eieiorpcjs
Package eieiorpc is a generated protocol buffer package.
Package eieiorpc is a generated protocol buffer package.
gui

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL