Documentation ¶
Index ¶
- Variables
- func CalcBenefitsWithData(regions []Region, rows Fetchable, region string, ...) (map[string]float64, error)
- func CalcOneTree(factorDataForRegion []*Datafile, itreecode string, diameter float64, ...)
- func DestroyPt(p Point)
- func FactorArrayToMap(factors []float64) map[string]float64
- func GeosDestroy(geom Geom)
- func GetITreeCodesByRegion(regionData map[string][]*Datafile) map[string][]string
- func GetXYOnSurface(g Geom) (float64, float64)
- func InitGeos()
- func Intersects(g Geom, p Point) (bool, error)
- func LoadFiles(basePath string) map[string][]*Datafile
- func LoadSpeciesMap(speciesMasterList string) (map[string]map[string]string, error)
- func OpenDatabaseConnection(info *DBInfo) (*sql.DB, error)
- type DBContext
- func (dbc *DBContext) ExecSql(query string) (Fetchable, error)
- func (dbc *DBContext) GetOverrideMap() (map[int]map[string]map[int]string, error)
- func (dbc *DBContext) GetRegionGeoms() (map[int]Region, error)
- func (dbc *DBContext) GetRegionsForInstance(regions map[int]Region, instance int) ([]Region, error)
- type DBInfo
- type DBRow
- type DataBackend
- type Datafile
- type Fetchable
- type Geom
- type Point
- type Region
Constants ¶
This section is empty.
Variables ¶
var CentimetersPerInch = 2.54
var ( // List of "factor" files that we will load. Files generally have the form: // output__{region}__{factor}.csv Factors = []string{"natural_gas", "electricity", "hydro_interception", "co2_sequestered", "co2_avoided", "co2_storage", "aq_nox_dep", "aq_ozone_dep", "aq_nox_avoided", "aq_pm10_dep", "aq_pm10_avoided", "aq_sox_dep", "aq_sox_avoided", "aq_voc_avoided", "bvoc"} )
Functions ¶
func CalcBenefitsWithData ¶
func CalcBenefitsWithData( regions []Region, rows Fetchable, region string, speciesdata map[string]map[string]string, regiondata map[string][]*Datafile, overrides map[string]map[int]string) (map[string]float64, error)
Calculate ecobenefits over an instance in the given backend
Regions are a list of intersecting regions the check. This can be nil or empty only if the "region" parameter is specified
To use a fixed region pass in a valid "region" parameter if this parameter is passed in the regions array will be ignored
Rows is the fetchable set to use ¶
speciesdata is a map to itreecode: region --> otmcode --> itreecode
Static data can be loaded for this via LoadSpeciesMap ¶
regiondata maps regions to factor lists region -> slice of datafiles
Overrides is a map like: region -> species id -> itree code
That allows itree overrides on a per-species/instance level
Note that the ith element of the datafiles slice is the ith factor from eco.Factors
func CalcOneTree ¶
func CalcOneTree( factorDataForRegion []*Datafile, itreecode string, diameter float64, factorsum []float64)
Calculate benefits for a single tree
The diameter must be in centimeters ¶
The benefits will be added to the factorsum slice
func FactorArrayToMap ¶
Convert an array of factors into a map by matching up their indicies
func GeosDestroy ¶
func GeosDestroy(geom Geom)
func GetITreeCodesByRegion ¶
func GetXYOnSurface ¶
func LoadFiles ¶
Load the data files
the relevant data files are stored in the format: output__<regioncode>__<factor_with_csv??>.csv
for example: output__TropicPacXXX__property_value.csv
The returned data stucture has region codes as keys and an array of data files as values. the data file array is indexed by factor id, as determined by the global `Factors`.
For instance, Factors[3] = hydro_interception so the datafile for NoCalXXX region and hydro interception would be:
files = LoadFiles('/path/to/data/folder') hydro_data = files['NoCalXXX'][3]
func LoadSpeciesMap ¶
Load the master species map
The output map combines regions with species codes and returns the iTree Code
Types ¶
type DBContext ¶
func (*DBContext) GetOverrideMap ¶
type DataBackend ¶
type DataBackend interface { // Given a mapping of region ids to region geoms // return the set of regions that intersect the given // instance GetRegionsForInstance( regions map[int]Region, instance int) ([]Region, error) // Get a fetchable with the given sql string ExecSql(string) (Fetchable, error) // Get a map for all of the overrides on the database // The map should end up looking something like: // instanceid -> region -> species id -> itreecode GetOverrideMap() (map[int]map[string]map[int]string, error) // Get all itree geometries GetRegionGeoms() (map[int]Region, error) }
Data backends are used to fetch the actual tree data. The main backend right now is a postgres database.
The testing code also provides a mock implementation
type Datafile ¶
type Datafile struct { // Breaks are values that form the endpoints of a range // of diameter values that all receive the same ecobenefit value. Breaks []float64 Values map[string][]float64 }
A datafile contains a particular set of dbh breaks and data points For example, the datafile: Datafile{[12, 15, 17, 200], [5, 10, 15, 20]} would imply that diameter values of 0-12 have a benefit value of 5, 12-15 have a benefit of 10 value of 10, and so on.
TODO: clarify whether breaks are inclusive/exclusive and at which ends of the range.
type Fetchable ¶
type Fetchable interface { // This method should only be called on a "region" fetchable // object and will get the current record's data // // The diameter will be in centimeters GetDataWithRegion( diameter *float64, otmcode *string, speciesid *int, x *float64, y *float64) error // This method can be called on any fetchable object and // will get the current record's data // // The diameter will be in centimeters GetDataWithoutRegion( diameter *float64, otmcode *string, speciesid *int) error // Closes this fetchable Close() error // Move to the next item in the internal iterator // returns false if there are no more records Next() bool }
Fetchables come out of the database backend and essentially wrap a database rowset
The testing code also provides a mock implementation
type Geom ¶
type Geom struct {
// contains filtered or unexported fields
}
func MakeGeosGeom ¶
Create a new geometry from the given wkt string
The geometry will be 'prepared' to make intersects/contains queries faster
The caller is responsible for destroying the returned geometry with "GeosDestroy"
type Point ¶
type Point struct {
// contains filtered or unexported fields
}
func CreateGeosPtWithXY ¶
The caller is responsible for destroying the returned geometry with "DestroyPt"