gnome.outputters.renderer¶
renderer_gd.py
module to hold all the map rendering code.
This one used the new map_canvas, which uses the gd rendering lib.
Classes¶
Map Renderer |
|
Module Contents¶
- class gnome.outputters.renderer.Renderer(map_filename=None, output_dir='./', image_size=(800, 600), projection=None, viewport=None, map_BB=None, land_polygons=None, draw_back_to_fore=True, draw_map_bounds=False, draw_spillable_area=False, formats=['png', 'gif'], draw_ontop='forecast', cache=None, output_timestep=None, output_zero_step=True, output_last_step=True, output_single_step=False, output_start_time=None, on=True, timestamp_attrib={}, point_size=2, depth_colors=None, min_color_depth=0, max_color_depth=100, **kwargs)¶
Bases:
gnome.outputters.Outputter
,gnome.utilities.map_canvas.MapCanvas
Map Renderer
class that writes map images for GNOME results.
Writes the frames for the LE “movies”, etc.
Init the image renderer.
- Parameters:
map_filename=None – GnomeMap or name of file for basemap (BNA)
output_dir='./' (str) – directory to output the images
600) (2-tuple image_size=(800,) – size of images to output
projection=None – projection instance to use: If None, set to projections.FlatEarthProjection()
viewport (pair of (lon, lat) tuples ( lower_left, upper right )) – viewport of map – what gets drawn and on what scale. Default is full globe: (((-180, -90), (180, 90))) If not specifies, it will be set to the map’s bounds.
map_BB=None – bounding box of map if None, it will use the bounding box of the mapfile.
draw_back_to_fore=True – draw the background (map) to the foregound image when outputting the images each time step.
formats=['gif'] – list of formats to output.
draw_ontop (str) – draw ‘forecast’ or ‘uncertain’ LEs on top. Default is to draw ‘forecast’ LEs, which are in black on top
Following args are passed to base class Outputter’s init:
- Parameters:
cache – sets the cache object from which to read prop. The model will automatically set this param
output_timestep (timedelta object) – default is None in which case everytime the write_output is called, output is written. If set, then output is written every output_timestep starting from model_start_time.
output_zero_step (boolean) – default is True. If True then output for initial step (showing initial release conditions) is written regardless of output_timestep
output_last_step (boolean) – default is True. If True then output for final step is written regardless of output_timestep
point_size=2 – size to draw elements, in pixels
depth_colors=None –
colorscheme to use to color elements according to their depth for 3D modeling. Any scheme that py_gd provides can be used:: py_gd.colorschemes.keys() Currently: ‘cividis’, ‘inferno’, ‘magma’, ‘plasma’, ‘turbo’, ‘twilight’, ‘viridis’ (borrowed from matplotlib)
If None, elements will not be colored by depth
min_color_depth=0 – depth to map the first color in the scheme (m)
max_color_depth=100 – depth to map the last color in the scheme (m)
Remaining kwargs are passed onto Outputter.__init__(…)
- map_colors = [('background', (255, 255, 255)), ('lake', (255, 255, 255)), ('land', (255, 204, 153)), ('LE',...¶
- background_map_name = 'background_map.'¶
- foreground_filename_format = 'foreground_{0:05d}.'¶
- foreground_filename_glob = 'foreground_?????.*'¶
- output_dir = './'¶
- property map_filename¶
- last_filename = ''¶
- property draw_ontop¶
- draw_back_to_fore = True¶
- point_size = 2¶
- map_BB = None¶
- draw_map_bounds = False¶
- draw_spillable_area = False¶
- raster_map = None¶
- raster_map_fill = True¶
- raster_map_outline = False¶
- background_color = 'background'¶
- anim_filename¶
- property formats¶
- property delay¶
- property repeat¶
- timestamp_attribs¶
- grids = []¶
- props = []¶
- depth_colors = None¶
- output_dir_to_dict()¶
- start_animation(filename)¶
- prepare_for_model_run(*args, **kwargs)¶
prepares the renderer for a model run.
Parameters passed to base class (use super): model_start_time, cache
Does not take any other input arguments; however, to keep the interface the same for all outputters, define
**kwargs
and pass into the base classIn this case, it draws the background image and clears the previous images. If you want to save the previous images, a new output dir should be set.
- set_timestamp_attrib(**kwargs)¶
Function to set details of the timestamp’s appearance when printed. These details are stored as a dict.
Recognized attributes:
- Parameters:
on (Boolean) – Turn the draw function on or off
dt_format (String) – Format string for strftime to format the timestamp
background (str) – Color of the text background. Color must be present in foreground palette
color (str) – Color of the font. Note that the color must be present in the foreground palette
size (str) – Size of the font, one of {‘tiny’, ‘small’, ‘medium’, ‘large’, ‘giant’}
position (tuple) – x, y pixel coordinates of where to draw the timestamp.
align (str) – The reference point of the text bounding box. One of: {‘lt’(left top), ‘ct’, ‘rt’, ‘l’, ‘r’, ‘lb’, ‘cb’, ‘rb’}
- draw_timestamp(time)¶
Function that draws the timestamp to the foreground. Uses self.timestamp_attribs to determine it’s appearance.
- Parameters:
time (datetime) – the datetime object representing the timestamp
- clean_output_files()¶
Cleans out the output dir
This should be implemented by subclasses that dump files.
Each outputter type dumps different types of files, and this should only clear out those.
See the OutputterFilenameMixin for a simple example.
- draw_background()¶
Draws the background image – land and optional graticule
This should be called whenever the scale changes
- add_grid(grid, on=True, color='grid_1', width=2)¶
- draw_grids()¶
- add_vec_prop(prop, on=True, color='LE', mask_color='uncert_LE', size=3, width=1, scale=1000)¶
- draw_props(time)¶
- draw_masked_nodes(grid, time)¶
- draw_land()¶
Draws the land map to the internal background image.
- draw_elements(sc)¶
Draws the individual elements to a foreground image
- Parameters:
sc – a SpillContainer object to draw
- draw_raster_map()¶
draws the raster map used for beaching to the image.
draws a grid for the pixels
this is pretty slow, but only used for diagnostics. (not bad for just the lines)
- write_output(step_num, islast_step=False)¶
Render the map image, according to current parameters.
- Parameters:
step_num (int) – the model step number you want rendered.
islast_step (bool) – default is False. Flag that indicates that step_num is last step. If ‘output_last_step’ is True then this is written out
- Returns:
A dict of info about this step number if this step is to be output, None otherwise. ‘step_num’: step_num ‘image_filename’: filename ‘time_stamp’: time_stamp # as ISO string
use super to call base class write_output method
If this is last step, then prop is written; otherwise prepare_for_model_step determines whether to write the output for this step based on output_timestep
- post_model_run()¶
Override this method if a derived class needs to perform any actions after a model run is complete (StopIteration triggered)
- projection_to_dict()¶
store projection class as a string for now since that is all that is required for persisting todo: This may not be the case for all projection classes, but keep simple for now so we don’t have to make the projection classes serializable
- to_dict(json_=None)¶
Returns a dictionary representation of this object. Uses the schema to determine which attributes are put into the dictionary. No extra processing is done to each attribute. They are presented as is.
The
json_
parameter is ignored in this base class. ‘save’ is passed in when the schema is saving the object. This allows an override of this function to do any custom stuff necessary to prepare for saving.