NREL / buildstock-query

BuildStockQuery is a python library for querying datasets generated by ResStock™ and ComStock™.
https://nrel.github.io/buildstock-query/
BSD 3-Clause "New" or "Revised" License
9 stars 1 forks source link

Add filter yaml capability to upgrades_analyzer #38

Closed rajeee closed 9 months ago

rajeee commented 9 months ago

Resolves #[issue number here].

Pull Request Description

This PR introduces "filter_yaml" capability to upgrades_analyzer. filter_yamls are add-ons to the project definition files used for running ResStock or ComStock. The filter_yaml has the following schema which is similar to the schema of the regular project definition file except there are only two top level keys (besides the schema version): all_upgrades_remove_logic and upgrades.

all_upgrades_remove_logic can be used to define a removal logic (following the same syntax as any apply_logic) that will be used to remove buildings from all upgrades. The logic can greedy and include more buildings than what's in the upgrade - only the buildings that are actually available in the upgrade will be impacted, and the buildings not in the upgrade will be ignored.

upgrades block can be used to define (additional) removal logic for individual upgrades. The upgrades are referred to by the corresponding name in the project yaml, and the removal logic is specified under remove_logic key.

# xx_upgrades_filter.yaml_schema
schema_version: enum('0.1')
all_upgrades_remove_logic:  include('apply-logic-spec', required=False)
upgrades: list(include('upgrade-spec'), required=False)
---
upgrade-spec:
  upgrade_name: str(required=True)
  remove_logic: include('apply-logic-spec', required=True)
apply-logic-spec: >
  any(
    list(
      include('and-spec'),
      include('or-spec'),
      include('not-spec'),
      include('param_option-spec'),
    ),
    include('and-spec'),
    include('or-spec'),
    include('not-spec'),
    include('param_option-spec')
  )
or-spec:
  or: list(include('apply-logic-spec'))
and-spec:
  and: list(include('apply-logic-spec'))
not-spec:
  not: any(include('apply-logic-spec'), list(include('apply-logic-spec')))