-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathWindchill.py
62 lines (53 loc) · 2.79 KB
/
Windchill.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import numpy as np
class Windchill():
def __init__(self):
self.name = "Wind Chill Function"
self.description = ("This function computes wind chill on the Fahrenheit "
"scale given wind speed and air temperature.")
def getParameterInfo(self):
return [
{
'name': 'temperature',
'dataType': 'raster',
'value': None,
'required': True,
'displayName': "Temperature Raster",
'description': "A single-band raster where pixel values represent ambient air temperature in Fahrenheit."
},
{
'name': 'ws',
'dataType': 'raster',
'value': None,
'required': True,
'displayName': "Wind-speed Raster",
'description': "A single-band raster where pixel values represent wind speed measured in miles per hour."
},
]
def getConfiguration(self, **scalars):
return {
'inheritProperties': 4 | 8, # inherit all but the pixel type and NoData from the input raster
'invalidateProperties': 2 | 4 | 8, # invalidate statistics & histogram on the parent dataset because we modify pixel values.
'inputMask': False # Don't need input raster mask in .updatePixels(). Simply use the inherited NoData.
}
def updateRasterInfo(self, **kwargs):
kwargs['output_info']['bandCount'] = 1 # output is a single band raster
kwargs['output_info']['statistics'] = () # we know nothing about the stats of the outgoing raster.
kwargs['output_info']['histogram'] = () # we know nothing about the histogram of the outgoing raster.
kwargs['output_info']['pixelType'] = 'f4'
return kwargs
def updatePixels(self, tlc, size, props, **pixelBlocks):
ws = np.array(pixelBlocks['ws_pixels'], dtype='f4', copy=False)
t = np.array(pixelBlocks['temperature_pixels'], dtype='f4', copy=False)
ws16 = np.power(ws, 0.16)
outBlock = 35.74 + (0.6215 * t) - (35.75 * ws16) + (0.4275 * t * ws16)
pixelBlocks['output_pixels'] = outBlock.astype(props['pixelType'], copy=False)
return pixelBlocks
def updateKeyMetadata(self, names, bandIndex, **keyMetadata):
if bandIndex == -1:
keyMetadata['datatype'] = 'Scientific'
keyMetadata['datatype'] = 'Windchill'
elif bandIndex == 0:
keyMetadata['wavelengthmin'] = None # reset inapplicable band-specific key metadata
keyMetadata['wavelengthmax'] = None
keyMetadata['bandname'] = 'Winchill'
return keyMetadata