sr

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2016 License: GPL-3.0 Imports: 17 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 s to start listening for requests over RPCPort

Types

type Cluster

type Cluster struct {

	// StartupTime specifies how long a worker is expected to take to initialize.
	// The default is 10 seconds.
	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 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
	// 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(e *inmap.EmisRecord) ([]float64, error)

Concentrations returns the change in Total PM2.5 concentrations caused by the emissions specified by e, after accounting for plume rise.

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) 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
	GridGeom   []geom.Polygonal // Geometry of the output grid.
}

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, error)

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.

Jump to

Keyboard shortcuts

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