Code Duplication    Length = 31-36 lines in 3 locations

src/oemof/solph/views.py 3 locations

@@ 220-255 (lines=36) @@
217
        return [node_names.get(n, None) for n in names]
218
219
220
def node_weight_by_type(results, node_type):
221
    """
222
    Extracts node weights (if exist) of all components of the specified
223
    `node_type`.
224
225
    Node weight are endogenous optimzation variables associated with the node
226
    and not the edge between two node, foxample the variable representing the
227
    storage level.
228
229
    Parameters
230
    ----------
231
    results: dict
232
        A result dictionary from a solved oemof.solph.Model object
233
    node_type: oemof.solph class
234
        Specifies the type for which node weights should be collected,
235
        e.g. solph.components.GenericStorage
236
237
    Example
238
    --------
239
    ::
240
241
        from oemof.solph import views
242
243
        # solve oemof model 'm'
244
        # Then collect node weights
245
        views.node_weight_by_type(
246
            m.results(),
247
           node_type=solph.components.GenericStorage
248
        )
249
    """
250
251
    group = {
252
        k: v["sequences"]
253
        for k, v in results.items()
254
        if isinstance(k[0], node_type) and k[1] is None
255
    }
256
    if not group:
257
        logging.error(
258
            "No node weights for nodes of type `{}`".format(node_type)
@@ 268-299 (lines=32) @@
265
        return df
266
267
268
def node_input_by_type(results, node_type, droplevel=None):
269
    """Gets all inputs for all nodes of the type `node_type` and returns
270
    a dataframe.
271
272
    Parameters
273
    ----------
274
    results: dict
275
        A result dictionary from a solved oemof.solph.Model object
276
    node_type: oemof.solph class
277
        Specifies the type of the node for that inputs are selected,
278
        e.g. solph.components.Sink
279
    droplevel: list
280
281
    Examples
282
    -----
283
    ::
284
285
        from oemof import solph
286
        from oemof.solph import views
287
288
        # solve oemof solph model 'm'
289
        # Then collect node weights
290
        views.node_input_by_type(
291
            m.results(),
292
            node_type=solph.components.Sink
293
        )
294
    """
295
    if droplevel is None:
296
        droplevel = []
297
298
    group = {
299
        k: v["sequences"]
300
        for k, v in results.items()
301
        if isinstance(k[1], node_type) and k[0] is not None
302
    }
@@ 312-342 (lines=31) @@
309
        return df
310
311
312
def node_output_by_type(results, node_type, droplevel=None):
313
    """Gets all outputs for all nodes of the type `node_type` and returns
314
    a dataframe.
315
316
    Parameters
317
    ----------
318
    results: dict
319
        A result dictionary from a solved oemof.solph.Model object
320
    node_type: oemof.solph class
321
        Specifies the type of the node for that outputs are selected,
322
        e.g. solph.components.Converter
323
    droplevel: list
324
325
    Examples
326
    --------
327
    ::
328
329
        import oemof.solph as solph
330
        from oemof.solph import views
331
332
        # solve oemof solph model 'm'
333
        # Then collect node weights
334
        views.node_output_by_type(
335
            m.results(),
336
            node_type=solph.components.Converter
337
        )
338
    """
339
    if droplevel is None:
340
        droplevel = []
341
    group = {
342
        k: v["sequences"]
343
        for k, v in results.items()
344
        if isinstance(k[0], node_type) and k[1] is not None
345
    }