Skip to content

Commit afd28a0

Browse files
committed
Delete filter_with_template
1 parent 8792cb1 commit afd28a0

2 files changed

Lines changed: 4 additions & 41 deletions

File tree

src/muse/quantities.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,24 +158,17 @@ def consumption(
158158
dimensions as `production`.
159159
160160
"""
161-
from muse.utilities import filter_with_template
162-
163-
params = filter_with_template(
164-
technologies[["fixed_inputs", "flexible_inputs", "fixed_outputs"]],
165-
production,
166-
)
167-
168161
# Calculate degree of technology activity
169-
prod_amplitude = production_amplitude(production, params)
162+
prod_amplitude = production_amplitude(production, technologies)
170163

171164
# Calculate consumption of fixed commodities
172165
consumption_fixed = prod_amplitude * broadcast_timeslice(
173-
params.fixed_inputs, level=timeslice_level
166+
technologies.fixed_inputs, level=timeslice_level
174167
)
175168
assert all(consumption_fixed.commodity.values == production.commodity.values)
176169

177170
# If there are no flexible inputs, then we are done
178-
if not (params.flexible_inputs > 0).any():
171+
if not (technologies.flexible_inputs > 0).any():
179172
return consumption_fixed
180173

181174
# If prices are not given, then we can't consider flexible inputs, so just return
@@ -184,7 +177,7 @@ def consumption(
184177
return consumption_fixed
185178

186179
# Flexible inputs
187-
flexs = broadcast_timeslice(params.flexible_inputs, level=timeslice_level)
180+
flexs = broadcast_timeslice(technologies.flexible_inputs, level=timeslice_level)
188181

189182
# Calculate the cheapest fuel for each flexible technology
190183
priceflex = prices * flexs

src/muse/utilities.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -331,36 +331,6 @@ def filter_input(
331331
return dataset
332332

333333

334-
def filter_with_template(
335-
data: xr.Dataset | xr.DataArray,
336-
template: xr.DataArray | xr.Dataset,
337-
**kwargs,
338-
):
339-
"""Filters data to match template.
340-
341-
If the `asset_dimension` is present in `template.dims`, then the call is
342-
forwarded to `broadcast_over_assets`. Otherwise, the set of dimensions and indices
343-
in common between `template` and `data` are determined, and the resulting
344-
call is forwarded to `filter_input`.
345-
346-
Arguments:
347-
data: Data to transform
348-
template: Data from which to figure coordinates and dimensions
349-
kwargs: passed on to `broadcast_over_assets` or `filter_input`
350-
351-
Returns:
352-
`data` transformed to match the form of `template`
353-
"""
354-
if "asset" in template.dims:
355-
return broadcast_over_assets(data, template)
356-
357-
match_indices = set(data.dims).intersection(template.dims) - set(kwargs)
358-
match = {d: template[d].isin(data[d]).values for d in match_indices if d != "year"}
359-
if "year" in match_indices:
360-
match["year"] = template.year.values
361-
return filter_input(data, **match, **kwargs) # type: ignore
362-
363-
364334
def tupled_dimension(array: np.ndarray, axis: int):
365335
"""Transforms one axis into a tuples."""
366336
if array.shape[axis] == 1:

0 commit comments

Comments
 (0)