safe.impact_functions.styles module

Library of styles that can be used by impact functions

E.g.:

from impact_functions.styles import flood_population_style as style_info
from impact_functions.core import get_function_title

# Create raster object with this style and return
R = Raster(
    I,
    projection=inundation.get_projection(),
    geotransform=inundation.get_geotransform(),
    name='Penduduk yang %s' % (get_function_title(self)),
    keywords={'impact_summary': impact_summary},
    style_info=style_info)

return R
safe.impact_functions.styles.categorical_style(target_field, categories, no_data_value, no_data_label, data_defined_saturation_field=None, max_impact_value=None)[source]

Style with equidistant hue and optional data defined saturation :param target_field: field name that needs to be classified :type: target_field, str

Parameters:
  • categories – values of target_field
  • no_data_value – value for no data
  • no_data_label – label for the no data category
  • data_defined_saturation_field – field for saturation for the generated colors.
  • max_impact_value – maximum value in data_defined_saturation_field, used to normalize saturation values for the generated colors.
Type:

categories, list

Type:

no_data_value, int, str

Type:

no_data_label, str

Type:

data_defined_saturation_field, None, str

Type:

max_impact_value, int, float

Returns:

a dict with target_field, style_classes and style_type

Return type:

dict

safe.impact_functions.styles.generate_categorical_color_ramp(class_count, reverse_hue=True, saturation=0.5, value=0.7)[source]

Makes a color ramp with equal HUE intervals. Sat and value are constant :param class_count: amount of hue steps (class count) :type: class_count, int

Parameters:
  • reverse_hue – if true makes red the END, else the START of the scale
  • saturation – saturation for the generated colors. this stays constant
  • value – value for the generated colors. this stays constant
Type:

reverse_hue, bool

Type:

saturation, float

Type:

value, float

Returns:

a dict of list containing the HSV, RGB and HEX representation of the color ramp. some thing like this:

{‘hsv’: [(1.0, 0.5, 0.7),

(0.8, 0.5, 0.7), (0.6, 0.5, 0.7), (0.3999999999999999, 0.5, 0.7), (0.19999999999999996, 0.5, 0.7)],

‘rgb’: [(178.5, 89.25, 89.25),

(160.65000000000006, 89.25, 178.5), (89.25, 124.95000000000003, 178.5), (89.25, 178.5, 124.94999999999995), (160.65, 178.5, 89.25)],

‘hex’: [‘#b25959’,

‘#a059b2’, ‘#597cb2’, ‘#59b27c’, ‘#a0b259’]}

Return type:

dict

safe.impact_functions.styles.hsv_to_hex(hsv)[source]

Convert hue, saturation, value tuple to an hex sting. :param hsv: a (hue, saturation, value) tuple where hsv are 0-1 :type: hsv, tuple

Returns:the hexadecimal color string.
Return type:str
safe.impact_functions.styles.rgb_to_hex(rgb)[source]

Convert an rgb tuple in an hex sting. :param rgb: a (r, g, b) tuple where r, g, b are 0-255 :type: rgb, tuple

Returns:the hexadecimal color string.
Return type:str
See:http://stackoverflow.com/q/214359/#answer-214657