@@ -180,41 +180,45 @@ def operation(x):
180180
181181
182182def broadcast_over_assets (
183- technologies : xr .Dataset | xr .DataArray ,
183+ data : xr .Dataset | xr .DataArray ,
184184 template : xr .DataArray | xr .Dataset ,
185185 installed_as_year : bool = True ,
186186) -> xr .Dataset | xr .DataArray :
187- """Broadcasts technologies to the shape of template in given dimension .
187+ """Broadcasts an array to the shape of a template containing asset-level data .
188188
189- The dimensions of the technologies are fully explicit, in that each concept
190- 'technology', 'region', 'year' (for year of issue) is a separate dimension.
191- However, the dataset or data arrays representing other quantities, such as
192- capacity, are often flattened out with coordinates 'region', 'installed',
193- and 'technology' represented in a single 'asset' dimension. This latter
194- representation is sparse if not all combinations of 'region', 'installed',
195- and 'technology' are present, whereas the former representation makes it
196- easier to select a subset of the same.
189+ The dimensions of many arrays (such as technology datasets) are fully explicit, in
190+ that each concept (e.g. 'technology', 'region', 'year') is a separate dimension.
191+ However, other datasets (e.g capacity), are presented on a per-asset basis,
192+ containing a single 'asset' dimension with with coordinates such as 'region',
193+ 'installed' (year of installation), and 'technology'. This latter representation is
194+ sparse if not all combinations of 'region', 'installed' and 'technology' are
195+ present.
197196
198- This function broadcast the first representation to the shape and coordinates
199- of the second.
197+ This function broadcasts the first representation to the shape and coordinates
198+ of the second, selecting the appropriate values for each asset (see example below) .
200199
201- Note: this is not necessarily limited to ` technology` datasets. For
200+ Note: this is not necessarily limited to technology datasets. For
202201 example, it could also be used on a dataset of commodity prices to select prices
203- relevant to each asset (e.g. if assets exist in multiple regions). In this example,
204- installed_as_year should be set to False (see below).
202+ relevant to each asset (e.g. if assets exist in multiple regions).
205203
206204 Arguments:
207- technologies: The dataset to broadcast
208- template: the dataset or data-array to use as a template
209- installed_as_year: True means that the "year" dimension in the technologies
210- dataset corresponds to the year that the asset was installed. Will commonly
211- be True for most technology parameters (e.g. var_par/fix_par are specified
212- the year that an asset is installed, and fixed for the lifetime of the
213- asset). If True, the technologies dataset must have data for every possible
214- "installed" year in the template.
205+ data: The dataset/data-array to broadcast
206+ template: The dataset/data-array to use as a template
207+ installed_as_year: True means that the "year" dimension in 'data`
208+ corresponds to the year that the asset was installed. This will commonly
209+ be the case for most technology parameters (e.g. var_par/fix_par are
210+ specified the year that an asset is installed, and fixed for the lifetime of
211+ the asset). In this case, `data` must have a year coordinate for every
212+ possible "installed" year in the template.
213+
214+ Conversely, if the values in `data` apply to the year of activity, rather
215+ than the year of installation, `installed_as_year` should be False.
216+ An example would be commodity prices, which can change over the lifetime
217+ of an asset. In this case, if "year" is present as a dimension in `data`,
218+ it will be maintained as a separate dimension in the output.
215219
216220 Example:
217- Define the technology array:
221+ Define the data array:
218222 >>> import xarray as xr
219223 >>> technologies = xr.DataArray(
220224 ... data=[[1, 2, 3], [4, 5, 6]],
@@ -255,7 +259,7 @@ def broadcast_over_assets(
255259 in the output is the value in the original technology array that matches the
256260 technology & region of each asset.
257261 """
258- # TODO: this will return `technologies ` unchanged if the template has no "asset"
262+ # TODO: this will return `data ` unchanged if the template has no "asset"
259263 # dimension, but strictly speaking we shouldn't allow this.
260264 # assert "asset" in template.dims
261265
@@ -267,18 +271,16 @@ def broadcast_over_assets(
267271 # TODO: this should be stricter, and enforce that the template has "installed" data,
268272 # and that the technologies dataset has a "year" dimension.
269273 # if installed_as_year:
270- if installed_as_year and "installed" in names and "year" in technologies .dims :
274+ if installed_as_year and "installed" in names and "year" in data .dims :
271275 # assert "installed" in names
272- technologies = technologies .rename (year = "installed" )
276+ data = data .rename (year = "installed" )
273277
274- # The first selection reduces the size of technologies without affecting the
278+ # The first selection reduces the size of the data without affecting the
275279 # dimensions.
276- first_sel = {
277- n : technologies [n ].isin (template [n ]) for n in names if n in technologies .dims
278- }
279- techs = technologies .sel (first_sel )
280+ first_sel = {n : data [n ].isin (template [n ]) for n in names if n in data .dims }
281+ techs = data .sel (first_sel )
280282
281- # Reshape the technology array to match the template
283+ # Reshape the array to match the template
282284 second_sel = {n : template [n ] for n in template .coords if n in techs .dims }
283285 return techs .sel (second_sel )
284286
0 commit comments