aeputil

package
v1.9.6 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2022 License: GPL-3.0 Imports: 20 Imported by: 2

Documentation

Overview

Package aeputil provides commonly used configuration and functions for the AEP library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Scale

func Scale(emis map[string][]aep.Record, f ScaleFunc) error

Scale applies scaling factors to the given emissions records.

Types

type InventoryConfig

type InventoryConfig struct {
	// NEIFiles lists National Emissions Inventory emissions files.
	// The file names can include environment variables.
	// The format is map[sector name][list of files].
	NEIFiles map[string][]string

	// COARDSFiles lists COARDS-compliant NetCDF emission files
	// (NetCDF 4 and greater not supported).
	// Information regarding the COARDS NetCDF conventions are
	// available here: https://ferret.pmel.noaa.gov/Ferret/documentation/coards-netcdf-conventions.
	// The file names can include environment variables.
	// The format is map[sector name][list of files].
	// For COARDS files, the sector name will also be used
	// as the SCC code.
	COARDSFiles map[string][]string

	// COARDSYear specifies the year of emissions for COARDS emissions files.
	// COARDS emissions are assumed to be in units of mass of emissions per year.
	// The year will not be used for NEI emissions files.
	COARDSYear int

	// PolsToKeep lists pollutants from the NEI that should be kept.
	PolsToKeep aep.Speciation

	// InputUnits specifies the units of input data. Acceptable
	// values are `tons', `tonnes', `kg', `g', and `lbs'.
	InputUnits string

	// SrgSpecSMOKE gives the location of the SMOKE-formatted
	// surrogate specification file, if any.
	SrgSpecSMOKE string

	// SrgSpecOSM gives the location of the OSM-formatted
	// surrogate specification file, if any.
	SrgSpecOSM string

	// PostGISURL specifies the URL to use to connect to a PostGIS database
	// with the OpenStreetMap data loaded. The URL should be in the format:
	// postgres://username:password@hostname:port/databasename".
	//
	// The OpenStreetMap data can be loaded into the database using the
	// osm2pgsql program, for example with the command:
	// osm2pgsql -l --hstore-all --hstore-add-index --database=databasename --host=hostname --port=port --username=username --create planet_latest.osm.pbf
	//
	// The -l and --hstore-all flags for the osm2pgsql command are both necessary,
	// and the PostGIS database should have the "hstore" extension installed before
	// loading the data.
	PostGISURL string

	// SrgShapefileDirectory gives the location of the directory holding
	// the shapefiles used for creating spatial surrogates.
	// It is used for assigning spatial locations to emissions records.
	SrgShapefileDirectory string

	// GridRef specifies the locations of the spatial surrogate gridding
	// reference files used for processing emissions.
	// It is used for assigning spatial locations to emissions records.
	GridRef []string

	// SCCExactMatch specifies whether SCC codes must match exactly when processing
	// emissions.
	SCCExactMatch bool

	// FilterFunc specifies which records should be kept.
	// If it is nil, all records are kept.
	FilterFunc aep.RecFilter
}

InventoryConfig holds emissions inventory configuration information.

func (*InventoryConfig) ReadEmissions

func (c *InventoryConfig) ReadEmissions() (map[string][]aep.Record, *aep.InventoryReport, error)

ReadEmissions returns emissions records for the files specified in the NEIFiles field in the receiver. The returned records are split up by sector.

type Iterator

type Iterator interface {
	// Next returns the next record.
	Next() (aep.Record, error)

	// Report returns an emissions report on the records that have been
	// processed by this iterator.
	Report() *aep.InventoryReport
}

Iterator is an iterface for types that can iterate through a list of emissions records and return totals at the end.

func IteratorFromMap

func IteratorFromMap(emissions map[string][]aep.Record) Iterator

IteratorFromMap creates an Iterator from a map of emissions. This function is meant to be temporary until Inventory.ReadEmissions is replaced with an iterator.

type ScaleFunc

type ScaleFunc func(aep.Record, aep.Pollutant) (float64, error)

ScaleFunc returns an emissions scaling factor for the given pollutant in the given record.

func ScaleNEIStateTrends

func ScaleNEIStateTrends(summaryFile string, sccDescriptions io.Reader, baseYear, scaleYear int) (ScaleFunc, error)

ScaleNEIStateTrends provides an emissions scaling function to scale NEI emissions from baseYear to the specified scaleYear using EPA emissions summaries by year, state, SCC code, and pollutant available from https://www.epa.gov/sites/production/files/2016-12/state_tier1_90-16.xls. The "xls" file must be converted to an "xlsx" file before opening.

type SpatialConfig

type SpatialConfig struct {
	// SrgSpecSMOKE gives the location of the SMOKE-formatted
	// surrogate specification file, if any.
	SrgSpecSMOKE string

	// SrgSpecOSM gives the location of the OSM-formatted
	// surrogate specification file, if any.
	SrgSpecOSM string

	// PostGISURL specifies the URL to use to connect to a PostGIS database
	// with the OpenStreetMap data loaded. The URL should be in the format:
	// postgres://username:password@hostname:port/databasename".
	//
	// The OpenStreetMap data can be loaded into the database using the
	// osm2pgsql program, for example with the command:
	// osm2pgsql -l --hstore-all --hstore-add-index --database=databasename --host=hostname --port=port --username=username --create planet_latest.osm.pbf
	//
	// The -l and --hstore-all flags for the osm2pgsql command are both necessary,
	// and the PostGIS database should have the "hstore" extension installed before
	// loading the data.
	PostGISURL string

	// SrgShapefileDirectory gives the location of the directory holding
	// the shapefiles used for creating spatial surrogates.
	SrgShapefileDirectory string

	// SCCExactMatch specifies whether SCC codes must match exactly when processing
	// emissions.
	SCCExactMatch bool

	// GridRef specifies the locations of the spatial surrogate gridding
	// reference files used for processing the NEI.
	GridRef []string

	// OutputSR specifies the output spatial reference in Proj4 format.
	OutputSR string

	// InputSR specifies the input emissions spatial reference in Proj4 format.
	InputSR string

	// SimplifyTolerance is the tolerance for simplifying spatial surrogate
	// geometry, in units of OutputSR.
	SimplifyTolerance float64

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

	// SrgDataCache specifies the location for caching spatial surrogate input data.
	// If it is empty, the input surrogate data will be stored in SpatialCache.
	SrgDataCache 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

	// GridCells specifies the geometry of the spatial grid.
	GridCells []geom.Polygonal

	// GridName specifies a name for the grid which is used in the names
	// of intermediate and output files.
	// Changes to the geometry of the grid must be accompanied by either a
	// a change in GridName or the deletion of all the files in the
	// SpatialCache directory.
	GridName string
	// contains filtered or unexported fields
}

SpatialConfig holds emissions spatialization configuration information.

func (*SpatialConfig) Iterator

func (c *SpatialConfig) Iterator(parent Iterator, gridIndex int) *SpatialIterator

Iterator creates a SpatialIterator from the given parent iterator for the given gridIndex.

func (*SpatialConfig) SpatialProcessor

func (c *SpatialConfig) SpatialProcessor() (*aep.SpatialProcessor, error)

SpatialProcessor returns the spatial processor associated with the receiver.

type SpatialIterator

type SpatialIterator struct {
	// contains filtered or unexported fields
}

SpatialIterator is an Iterator that spatializes the records that it processes.

func (*SpatialIterator) Next

func (si *SpatialIterator) Next() (aep.Record, error)

Next returns a spatialized a record from the parent iterator to fulfill the iterator interface.

func (*SpatialIterator) NextGridded added in v1.7.0

func (si *SpatialIterator) NextGridded() (aep.RecordGridded, error)

NextGridded returns a spatialized a record from the parent iterator.

func (*SpatialIterator) Report

func (si *SpatialIterator) Report() *aep.InventoryReport

Report returns an emissions report on the records that have been processed by this iterator.

func (*SpatialIterator) SpatialTotals

func (si *SpatialIterator) SpatialTotals() (emissions map[aep.Pollutant]*sparse.SparseArray, units map[aep.Pollutant]unit.Dimensions)

SpatialTotals returns spatial arrays of the total emissions for each pollutant, as well as their units.

type SpeciateConfig

type SpeciateConfig 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 specifies whether SCCs should be expected to match
	// exactly with the the speciation reference, or if partial matches
	// are acceptable.
	SCCExactMatch bool

	Speciation aep.Speciation
	// contains filtered or unexported fields
}

SpeciateConfig holds speciation configuration information.

func (*SpeciateConfig) Iterator

func (c *SpeciateConfig) Iterator(parent Iterator) Iterator

Iterator creates a new iterator that consumes records from the given iterators and chemically speciates them.

func (*SpeciateConfig) Speciate

func (c *SpeciateConfig) Speciate(r aep.Record) (*SpeciatedRecord, error)

Speciate chemically speciates the given record.

type SpeciatedRecord

type SpeciatedRecord struct {
	aep.Record
	// contains filtered or unexported fields
}

SpeciatedRecord is an emissions record where chemical speciation has been performed. It should be created using SpeciateConfig.Speciate().

func (*SpeciatedRecord) CombineEmissions

func (r *SpeciatedRecord) CombineEmissions(r2 aep.Record)

CombineEmissions combines emissions from r2 with the receiver.

func (*SpeciatedRecord) DroppedEmissions

func (r *SpeciatedRecord) DroppedEmissions() *aep.Emissions

DroppedEmissions returns emissions that were dropped from the analysis during speciation to avoid double counting.

func (*SpeciatedRecord) GetEmissions

func (r *SpeciatedRecord) GetEmissions() *aep.Emissions

GetEmissions returns the speciated emissions.

func (*SpeciatedRecord) PeriodTotals

func (r *SpeciatedRecord) PeriodTotals(begin, end time.Time) map[aep.Pollutant]*unit.Unit

PeriodTotals returns total emissions for the given time period.

func (*SpeciatedRecord) Totals

func (r *SpeciatedRecord) Totals() map[aep.Pollutant]*unit.Unit

Totals returns emissions totals.

Jump to

Keyboard shortcuts

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