Skip to content

Use Case: Modifying Utility Agent Mapping

Trevor Stanley edited this page Jul 27, 2021 · 3 revisions

Although dGen is overall accurate with mapping counties to appropriate utilities, sometimes it is necessary to readjust the mapping. For instance, there are cases where counties are mapped to only one utility in dGen, even though in reality the area is split between two different utilities. Depending on the scenario the user is interested in, this might require manual adjustment of utility mappings within the model. It is also common for utility territories to change, adding or losing counties. Since the dGen model does not get updated with the latest utility territory maps on a regular basis, the user might need to adjust the underlying utility mapping to account for such changes. This section describes the process for making these updates. You will need to use Jupyter Notebook. For the purpose of illustration, we will update county mappings for a Wisconsin Utility.

A pre-populated jupyter notebook detailing these steps can be found here.

Step 1: Obtain the most recent list of county names within a given utility territory. This information can usually be found on utility websites.

Step 2: Open a new Jupyter Notebook and Import the necessary modules/packages

import pandas as pd 
import numpy as np   

Step 3: Create a list of county names for a given utility territory by loading the utility territory table and saving all county names to a list

alliant_cnty_df = pd.read_csv(“utility_counties.csv”) 
cnty_list = alliant_cnty_df['County'].tolist() 

Step 4: Load dGen's County to FIPS mapping table

cfp = 'dgen_county_fips_mapping.csv' 
cfm_df = pd.read_csv(cfp) 

Step 5: Download and load the appropriate agent file. In this example we will use WI’s residential agent file

Residential:

rp='agent_df_base_res_wi_revised.pkl' 
res_agents = pd.read_pickle(rp) 

Commercial:

cp='agent_df_base_com_wi_revised.pkl' 
com_agents = pd.read_pickle(cp) 

Step 6: Look up county ids for the most recently updated county list in the utility’s territory

cfm_wi_df = cfm_df.loc[cfm_df['state_abbr']=='WI'] 
cfm_wi_df = cfm_wi_df.loc[cfm_wi_df['county'].isin(cnty_lst)] 
ids = cfm_wi_df['county_id'].tolist() 

Step 7: Look up the EIA id for a given utility in the Utility Rate Database (URDB)

You can find the EIA id for a given utility by looking for look for “Entity ID” here.

Step 8: Look up tariff information for your utility by eia_id (in this example, we are using ‘20856’) and save tariff name, tariff id, and tariff dictionary to respective variables

tn = res_agents[res_agents.eia_id == '20856'].iloc[0]['tariff_name'] 
td = res_agents[res_agents.eia_id == '20856'].iloc[0]['tariff_dict'] 
t_id = res_agents[res_agents.eia_id == '20856'].iloc[0]['tariff_id'] 

Step 9: Assign the correct tariff name, tariff id and tariff dictionary to all agents in your utilities counties by using the most updated county list

for _id in ids: 
    for i, r in res_agents.iterrows(): 
        if r['county_id'] == _id: 
            res_agents.at[i,'tariff_name'] = tn 
            res_agents.at[i,'tariff_dict'] = td 
            res_agents.at[i,'tariff_id'] = t_id 
            res_agents.at[i,'eia_id'] = '20856' 

Step 10: Saved the amended DF as a new pkl file

rsp='agent_df_base_res_wi_revised_v2.pkl' 
res_agents.to_pickle(rsp) 

Repeat Steps 8 through 10 for the commercial agent file. After you are finished with the updates, you can run the dGen model for Commercial and/or Residential. You will need to update the input sheet to reflect the revised agent file name like so:

Clone this wiki locally