@@ -130,55 +130,139 @@ def __post_init__(self):
130130 self ._impact_label = f"Impact [{ self .input .exposure .value_unit } ]"
131131
132132 def plot_impf_set (self , ** plot_kwargs ):
133- """Plot the optimized impact functions"""
133+ """Plot the optimized impact functions
134+
135+ This calls the plot function of the respective impact function set.
136+
137+ Parameters
138+ ----------
139+ plot_kwargs
140+ Plotting keyword arguments passed to the underlying plotting method.
141+
142+ See Also
143+ --------
144+ :py:meth:`~climada.entity.impact_funcs.impact_func_set.ImpactFuncSet.plot`
145+ """
134146 return self .impf_set .plot (** plot_kwargs )
135147
136- def plot_at_event (self , ** plot_kwargs ):
137- data = (
138- pd .concat (
139- [
140- pd .Series ([self .impact .at_event ]),
141- self .input .data .sum (axis = "columns" ),
142- ],
143- ignore_index = True ,
144- axis = 1 ,
145- )
146- .rename (columns = {0 : "Model" , 1 : "Data" })
147- .set_index (self .input .hazard .event_name )
148- )
148+ def plot_at_event (
149+ self ,
150+ data_transf : Callable [[pd .DataFrame ], pd .DataFrame ] = lambda x : x ,
151+ ** plot_kwargs ,
152+ ):
153+ """Create a bar plot comparing estimated model output and data per event
154+
155+ Every row of the :py:attr:`Input.data` is considered an event.
156+ The data to be plotted can be transformed with a generic function
157+ ``data_transf``.
158+
159+ Parameters
160+ ----------
161+ data_transf : Callable (pd.DataFrame -> pd.DataFrame), optional
162+ A function that transforms the data to plot before plotting.
163+ It receives a dataframe whose rows represent events and whose columns
164+ represent the modelled impact and the calibration data, respectively.
165+ By default, the data is not transformed.
166+ plot_kwargs
167+ Keyword arguments passed to the ``DataFrame.plot.bar`` method.
168+
169+ Returns
170+ -------
171+ ax : matplotlib.axes.Axes
172+ The plot axis returned by ``DataFrame.plot.bar``
173+ """
174+ data = pd .concat (
175+ [
176+ self .input .impact_to_dataframe (self .impact ).sum (axis = "columns" ),
177+ self .input .data .sum (axis = "columns" ),
178+ ],
179+ axis = 1 ,
180+ ).rename (columns = {0 : "Model" , 1 : "Data" })
181+
182+ # Transform data before plotting
183+ data = data_transf (data )
184+
185+ # Now plot
149186 ylabel = plot_kwargs .pop ("ylabel" , self ._impact_label )
150187 return data .plot .bar (ylabel = ylabel , ** plot_kwargs )
151188
152- def plot_at_region (self , agg_regions = None , ** plot_kwargs ):
189+ def plot_at_region (
190+ self ,
191+ data_transf : Callable [[pd .DataFrame ], pd .DataFrame ] = lambda x : x ,
192+ ** plot_kwargs ,
193+ ):
194+ """Create a bar plot comparing estimated model output and data per event
195+
196+ Every column of the :py:attr:`Input.data` is considered a region.
197+ The data to be plotted can be transformed with a generic function
198+ ``data_transf``.
199+
200+ Parameters
201+ ----------
202+ data_transf : Callable (pd.DataFrame -> pd.DataFrame), optional
203+ A function that transforms the data to plot before plotting.
204+ It receives a dataframe whose rows represent regions and whose columns
205+ represent the modelled impact and the calibration data, respectively.
206+ By default, the data is not transformed.
207+ plot_kwargs
208+ Keyword arguments passed to the ``DataFrame.plot.bar`` method.
209+
210+ Returns
211+ -------
212+ ax : matplotlib.axes.Axes
213+ The plot axis returned by ``DataFrame.plot.bar``.
214+ """
153215 data = pd .concat (
154216 [
155- self .impact . impact_at_reg ( agg_regions ).sum (axis = "index" ),
217+ self .input . impact_to_dataframe ( self . impact ).sum (axis = "index" ),
156218 self .input .data .sum (axis = "index" ),
157219 ],
158220 axis = 1 ,
159221 ).rename (columns = {0 : "Model" , 1 : "Data" })
160222
161- # Use nice country names if no agg_regions were given
162- if agg_regions is None :
163- data = data .rename (
164- index = lambda x : u_coord .country_to_iso (x , representation = "name" )
165- )
223+ # Transform data before plotting
224+ data = data_transf (data )
166225
226+ # Now plot
167227 ylabel = plot_kwargs .pop ("ylabel" , self ._impact_label )
168228 return data .plot .bar (ylabel = ylabel , ** plot_kwargs )
169229
170- def plot_event_region_heatmap (self , agg_regions = None , ** plot_kwargs ):
230+ def plot_event_region_heatmap (
231+ self ,
232+ data_transf : Callable [[pd .DataFrame ], pd .DataFrame ] = lambda x : x ,
233+ ** plot_kwargs ,
234+ ):
235+ """Plot a heatmap comparing all events per all regions
236+
237+ Every column of the :py:attr:`Input.data` is considered a region, and every
238+ row is considered an event.
239+ The data to be plotted can be transformed with a generic function
240+ ``data_transf``.
241+
242+ Parameters
243+ ----------
244+ data_transf : Callable (pd.DataFrame -> pd.DataFrame), optional
245+ A function that transforms the data to plot before plotting.
246+ It receives a dataframe whose rows represent events and whose columns
247+ represent the regions, respectively.
248+ By default, the data is not transformed.
249+ plot_kwargs
250+ Keyword arguments passed to the ``DataFrame.plot.bar`` method.
251+
252+ Returns
253+ -------
254+ ax : matplotlib.axes.Axes
255+ The plot axis returned by ``DataFrame.plot.bar``.
256+
257+ """
171258 # Data preparation
172- agg = self .impact . impact_at_reg ( agg_regions )
259+ agg = self .input . impact_to_dataframe ( self . impact )
173260 data = (agg + 1 ) / (self .input .data + 1 )
174261 data = data .transform (np .log10 ).replace (0 , np .nan )
175- data = data .where ((agg < 1 ) & (self .input .data < 1 ))
262+ data = data .where ((agg > 0 ) | (self .input .data > 0 ))
176263
177- # Use nice country names if no agg_regions were given
178- if agg_regions is None :
179- data = data .rename (
180- index = lambda x : u_coord .country_to_iso (x , representation = "name" )
181- )
264+ # Transform data
265+ data = data_transf (data )
182266
183267 # Default plot settings
184268 annot = plot_kwargs .pop ("annot" , True )
0 commit comments