sr

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2018 License: GPL-3.0 Imports: 22 Imported by: 1

Documentation

Overview

Package sr contains functions for creating a source-receptor (SR) matrix from the InMAP air pollution model and interacting with it.

Index

Constants

This section is empty.

Variables

View Source
var RPCPort = "6060"

RPCPort specifies the port for RPC communications. The default is 6060.

Functions

func PBSNodes

func PBSNodes() ([]string, error)

PBSNodes reads the contents of $PBS_NODEFILE and returns a list of unique nodes.

func WorkerListen

func WorkerListen(s *Worker, RPCPort string) error

WorkerListen directs the Worker to start listening for requests over RPCPort. It is a top-level function rather than a method of s to avoid problems with RPC registration.

Types

type AboveTopErr added in v1.4.1

type AboveTopErr struct {
	PlumeHeight float64
}

AboveTopErr is returned when the plume height of an emissions source is above the top layer in the SR matrix.

func (AboveTopErr) Error added in v1.4.1

func (e AboveTopErr) Error() string

type Cluster

type Cluster struct {

	// StartupTime specifies how long a worker is expected to take to initialize.
	// The default is 3 minutes.
	StartupTime time.Duration
	// contains filtered or unexported fields
}

Cluster manages and distributes work to a group of workers.

func NewCluster

func NewCluster(command, logDir, exitService string, RPCPort string) *Cluster

NewCluster creates a new cluster of workers where log output will be directed to logDir. exitService is the name of the RPC service that should be called to shut down each worker, which will not be be sent any input data. RPCPort is the port over which RPC communication will occur.

func (*Cluster) NewRequest

func (c *Cluster) NewRequest(ctx context.Context, service string, requestPayload *IOData) *Request

NewRequest creates a new request where service is the RPC service that should be called and requestPayload is the input data that will be used to generate the results. The result of the RPC call must be of the same type as the request payload.

func (*Cluster) NewWorker

func (c *Cluster) NewWorker(addr string) error

NewWorker creates a new worker at addr using the external ssh command and prepares it to receive direction through RPC calls.

func (*Cluster) Shutdown

func (c *Cluster) Shutdown()

Shutdown sends a signal to the workers to run the exitService after all existing requests have finished processing.

type Concentrations added in v1.4.1

type Concentrations struct {
	PNH4, PNO3, PSO4, SOA, PrimaryPM25 []float64
}

Concentrations holds pollutant concentration information [μg/m3] for the PM2.5 subspecies.

func (*Concentrations) TotalPM25 added in v1.4.1

func (c *Concentrations) TotalPM25() []float64

TotalPM25 returns total combined PM2.5 concentration [μg/m3].

type Empty

type Empty struct{}

Empty is used for passing content-less messages.

type IOData

type IOData struct {
	Emis       []*inmap.EmisRecord
	Output     map[string][]float64
	Row, Layer int
}

IOData holds the input to and output from a simulation request.

func (*IOData) Result

func (io *IOData) Result() (*IOData, error)

Result allows a local worker to look like a distributed request.

type Reader

type Reader struct {
	cdf.File

	// CacheSize specifies the number of records to be held in the memory cache.
	// Larger numbers lead to faster operation but greater memory use.
	// If the SR matrix is created from a version of InMAP with 50,000 grid cells
	// in each vertical layer, then a CacheSize of 50,000 would be the equivalent
	// of storing an entire vertical layer in the cache. The default is 100.
	// CacheSize can only be changed before the Reader has been used to read
	// concentrations for the first time.
	CacheSize int
	// contains filtered or unexported fields
}

Reader allows the interaction with a NetCDF-formatted source-receptor (SR) database.

func NewReader

func NewReader(r cdf.ReaderWriterAt) (*Reader, error)

NewReader creates a new SR reader from the netcdf database specified by r.

func (*Reader) Concentrations

func (sr *Reader) Concentrations(emis ...*inmap.EmisRecord) (*Concentrations, error)

Concentrations returns the change in Total PM2.5 concentrations caused by the emissions specified by e, after accounting for plume rise. If the emission plume height is above the highest layer in the SR matrix, the function will allocate the emissions to the top layer and an error of type AboveTopErr will be returned. In some cases it may be appropriate to ignore errors of this type. As specified in the EmisRecord documentation emission units should be in μg/s.

func (*Reader) Geometry

func (sr *Reader) Geometry() []geom.Polygonal

Geometry returns the SR matrix grid geometry in the native grid projection.

func (*Reader) Source added in v1.2.1

func (sr *Reader) Source(pol string, layer, index int) ([]float64, error)

Source returns concentrations in μg m-3 for emissions in μg s-1 of pollutant pol in SR layer index 'layer' and horizontal grid cell index 'index'. This function uses a cache with the size specified by the CacheSize attribute of the receiver to speed up repeated requests and is concurrency-safe. Users desiring to make changes to the returned values should make a copy first to avoid inadvertently editing the cached results which could cause subsequent results from this function to be incorrect. If the layer and index are not known, use the Concentrations method instead.

func (*Reader) Variables

func (sr *Reader) Variables(names ...string) (map[string][]float64, error)

Variables returns the data for the InMAP variables named by names. Any changes to the returned data may also alter the underlying data.

type Request

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

Request holds information about a request that is to be handled by a cluster

func (*Request) Result

func (r *Request) Result() (*IOData, error)

Result waits for the result, and returns the result and any errors that occurred while processing. Result should be called after send.

func (*Request) Send

func (r *Request) Send()

Send sends the request for processing,

type SR

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

SR can be used to create a source-receptor matrix.

func NewSR

func NewSR(varGridFile, inmapDataFile, command, logDir string, config *inmap.VarGridConfig, nodes []string) (*SR, error)

NewSR initializes an SR object. varGridFile specifies the location of the InMAP variable grid data. inmapDataFile specifies the location of the InMAP regular grid data. command is the command that should be executed to start slave processes. nodes specify unique addresses of the machines that the simulations should be carried out on. If len(nodes) == 0, then calculations will be carried out locally instead of on a cluster.

func (*SR) Run

func (sr *SR) Run(outfile string, layers []int, begin, end int) error

Run runs the simulations necessary to create a source-receptor matrix and writes out the results. layers specifies the grid layers that SR relationships should be calculated for. begin and end are indices in the static variable grid where the computations should begin and end. if end<0, then end will be set to the last grid cell in the static grid. outfile is the location of the output file. The units of the SR matrix will be μg/m3 PM2.5 concentration at each receptor per μg/s emission at each source.

type Worker

type Worker struct {
	Config        *inmap.VarGridConfig
	CTMData       *inmap.CTMData
	Pop           *inmap.Population
	PopIndices    inmap.PopIndices
	MR            *inmap.MortalityRates
	MortIndices   inmap.MortIndices
	GridGeom      []geom.Polygonal // Geometry of the output grid.
	InMAPDataFile string           // inmapDataFile is the path to the input data file in .gob format.
}

Worker is a worker for performing InMAP simulations. It should not be interacted with directly, but it is exported to meet RPC requirements.

func NewWorker

func NewWorker(config *inmap.VarGridConfig, InMAPDataFile string, GridGeom []geom.Polygonal) *Worker

NewWorker sets up an RPC listener for performing simulations. InMAPDataFile specifies the location of the inmap regular-gridded data, and GridGeom specifies the output grid geometry.

func (*Worker) Calculate

func (s *Worker) Calculate(input *IOData, output *IOData) error

Calculate performs an InMAP simulation. It meets the requirements for use with rpc.Call.

func (*Worker) Exit

func (s *Worker) Exit(in, out *Empty) error

Exit shuts down the worker. It meets the requirements for use with rpc.Call.

func (*Worker) Init added in v1.2.1

func (s *Worker) Init(_, _ *Empty) error

Init initializes the worker. It needs to be called after NewWorker and before any simulations are performed. It meets the requirements for use with rpc.Call.

Jump to

Keyboard shortcuts

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