:py:mod:`gnome.outputters.renderer` =================================== .. py:module:: gnome.outputters.renderer .. autoapi-nested-parse:: renderer_gd.py module to hold all the map rendering code. This one used the new map_canvas, which uses the gd rendering lib. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: gnome.outputters.renderer.Renderer gnome.outputters.renderer.GridVisLayer gnome.outputters.renderer.GridPropVisLayer .. py:class:: 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: :py:obj:`gnome.outputters.Outputter`, :py:obj:`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. :param map_filename=None: GnomeMap or name of file for basemap (BNA) :type map_filename: GnomeMap or PathLike (str or Path) :param str output_dir='./': directory to output the images :param 2-tuple image_size=(800, 600): size of images to output :param projection=None: projection instance to use: If None, set to projections.FlatEarthProjection() :type projection: a gnome.utilities.projection.Projection instance :param viewport: 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. :type viewport: pair of (lon, lat) tuples ( lower_left, upper right ) :param map_BB=None: bounding box of map if None, it will use the bounding box of the mapfile. :param draw_back_to_fore=True: draw the background (map) to the foregound image when outputting the images each time step. :type draw_back_to_fore: boolean :param formats=['gif']: list of formats to output. :type formats: string or list of strings. Options are: ['bmp', 'jpg', 'jpeg', 'gif', 'png'] :param draw_ontop: draw 'forecast' or 'uncertain' LEs on top. Default is to draw 'forecast' LEs, which are in black on top :type draw_ontop: str Following args are passed to base class Outputter's init: :param cache: sets the cache object from which to read prop. The model will automatically set this param :param output_timestep: 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. :type output_timestep: timedelta object :param output_zero_step: default is True. If True then output for initial step (showing initial release conditions) is written regardless of output_timestep :type output_zero_step: boolean :param output_last_step: default is True. If True then output for final step is written regardless of output_timestep :type output_last_step: boolean :param point_size=2: size to draw elements, in pixels :param 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 :param min_color_depth=0: depth to map the first color in the scheme (m) :param max_color_depth=100: depth to map the last color in the scheme (m) Remaining kwargs are passed onto Outputter.__init__(...) .. py:property:: delay .. py:property:: repeat .. py:property:: map_filename .. py:property:: draw_ontop .. py:property:: formats .. py:attribute:: map_colors :value: [('background', (255, 255, 255)), ('lake', (255, 255, 255)), ('land', (255, 204, 153)), ('LE',... .. py:attribute:: background_map_name :value: 'background_map.' .. py:attribute:: foreground_filename_format :value: 'foreground_{0:05d}.' .. py:attribute:: foreground_filename_glob :value: 'foreground_?????.*' .. py:attribute:: _schema .. py:method:: output_dir_to_dict() .. py:method:: start_animation(filename) .. py:method:: 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 class In 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. .. py:method:: set_timestamp_attrib(**kwargs) Function to set details of the timestamp's appearance when printed. These details are stored as a dict. Recognized attributes: :param on: Turn the draw function on or off :type on: Boolean :param dt_format: Format string for strftime to format the timestamp :type dt_format: String :param background: Color of the text background. Color must be present in foreground palette :type background: str :param color: Color of the font. Note that the color must be present in the foreground palette :type color: str :param size: Size of the font, one of {'tiny', 'small', 'medium', 'large', 'giant'} :type size: str :param position: x, y pixel coordinates of where to draw the timestamp. :type position: tuple :param align: The reference point of the text bounding box. One of: {'lt'(left top), 'ct', 'rt', 'l', 'r', 'lb', 'cb', 'rb'} :type align: str .. py:method:: draw_timestamp(time) Function that draws the timestamp to the foreground. Uses self.timestamp_attribs to determine it's appearance. :param time: the datetime object representing the timestamp :type time: datetime .. py:method:: 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. .. py:method:: draw_background() Draws the background image -- land and optional graticule This should be called whenever the scale changes .. py:method:: add_grid(grid, on=True, color='grid_1', width=2) .. py:method:: draw_grids() .. py:method:: add_vec_prop(prop, on=True, color='LE', mask_color='uncert_LE', size=3, width=1, scale=1000) .. py:method:: draw_props(time) .. py:method:: draw_masked_nodes(grid, time) .. py:method:: draw_land() Draws the land map to the internal background image. .. py:method:: draw_elements(sc) Draws the individual elements to a foreground image :param sc: a SpillContainer object to draw .. py:method:: 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) .. py:method:: write_output(step_num, islast_step=False) Render the map image, according to current parameters. :param step_num: the model step number you want rendered. :type step_num: int :param islast_step: default is False. Flag that indicates that step_num is last step. If 'output_last_step' is True then this is written out :type islast_step: bool :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 .. py:method:: post_model_run() Override this method if a derived class needs to perform any actions after a model run is complete (StopIteration triggered) .. py:method:: _draw(step_num) create a small function so prop arrays are garbage collected from memory after this function exits - it returns current_time_stamp .. py:method:: 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 .. py:method:: 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. .. py:class:: GridVisLayer(grid, projection, on=True, color='grid_1', width=1) Bases: :py:obj:`object` .. py:method:: _get_lines(grid) .. py:method:: draw_to_image(img) Draws the grid to the image .. py:class:: GridPropVisLayer(prop, projection, on=True, color='LE', mask_color='uncert_LE', size=3, width=1, scale=1000) Bases: :py:obj:`object` .. py:method:: draw_to_image(img, time)