Python Reference

cimhub package

cimhub.api module

cimhub.CIMAdapter module

class cimhub.CIMAdapter.AdapterModel(in_filename: str, out_filename: str, subst=[])

Bases: object

get_in_nodes(node: Node, node_type: QName)
get_node_by_id_type(node_id, node_type)
get_nodes_by_type(node_type: QName) list[Node]
get_nsmap()
get_out_nodes(node, path: list[QName])
write_out_file()
class cimhub.CIMAdapter.Edge(node_qname: QName, element: Element)

Bases: object

get_linked_id() str
get_linked_name() str
get_prop_name()
is_local() bool
set_linked_name(name)
set_prop_name(name)
class cimhub.CIMAdapter.Literal(node_qname, element)

Bases: object

get_prop_name()
get_val()
is_local()
set_prop_name(name)
set_val(val: str)
class cimhub.CIMAdapter.Node(element: Element)

Bases: object

add_edge(element)
add_prop(tag, text=None, attrib=None)
change_type(node_type: QName, clear=False, include_props=False)
create_tag(namespace, localname)
get_edges_by_name(name)
get_literal_val(qname: QName) str
get_node_id()
get_type() QName
is_edge_prop(se)
move_edges(from_node, to_type: QName, keys: list[QName] = []) list[Edge]
remove_edge(edge, ignore_missing=True)
remove_literal(literal)
remove_props()
set_type(node_type: QName)
cimhub.CIMAdapter.epri_to_pnnl(cli_args)
cimhub.CIMAdapter.in_file_not_exists(filename)
cimhub.CIMAdapter.out_file_exists(filename)
cimhub.CIMAdapter.setup() AdapterModel

cimhub.CIMHubConfig module

Set the CIM namespace and Blazegraph URL

cimhub.CIMHubConfig.ConfigFromJsonFile(fname)

cimhub.ClearDB module

cimhub.ClearDB.clear_db(cfg_file)

cimhub.CombineModelXMLFiles module

class cimhub.CombineModelXMLFiles.ModelCombiner

Bases: object

combine_files()
input_file_exists(filename)
parse_base_file(filename)
parse_base_files(files)
parse_supp_file(filename)
parse_supp_files(files)
setup()
class cimhub.CombineModelXMLFiles.Node(tag=None, attrib=None, text=None, children=None, uuid=None)

Bases: object

class cimhub.CombineModelXMLFiles.XMLFile(tag=None, attrib=None, namespaces=None, namespacedict=None, children=None)

Bases: object

cimhub.CombineModelXMLFiles.combine_xml_files(input_root_name, output_filename, extensions=None)

cimhub.Compare_Cases module

cimhub.Compare_Cases.compare_cases(casefiles, basepath, dsspath, glmpath)
cimhub.Compare_Cases.dss_phase(col)
cimhub.Compare_Cases.error_norm(diffs, limit=None)
cimhub.Compare_Cases.error_norm_tuple(diffs)
cimhub.Compare_Cases.glmVpu(v, bases)
cimhub.Compare_Cases.load_currents(fname, ordname)
cimhub.Compare_Cases.load_glm_currents(fname)
cimhub.Compare_Cases.load_glm_voltages(fname, voltagebases)
cimhub.Compare_Cases.load_summary(fname)
cimhub.Compare_Cases.load_taps(fname)
cimhub.Compare_Cases.load_voltages(fname)
cimhub.Compare_Cases.print_dss_flow(vtag, itag, volts, vang, amps, iang, label=None)
cimhub.Compare_Cases.print_glm_flow(vtag, itag, volts, vang, amps, iang)
cimhub.Compare_Cases.write_comparisons(basepath, dsspath, glmpath, rootname, voltagebases, check_branches=[], do_gld=True)
cimhub.Compare_Cases.write_dss_flows(dsspath, rootname, check_branches)
cimhub.Compare_Cases.write_glm_flows(glmpath, rootname, voltagebases, check_branches)

cimhub.CountClasses module

cimhub.CountClasses.clear_database(sparql)
cimhub.CountClasses.count_classes(sparql)
cimhub.CountClasses.count_platform_circuit_classes(cfg_file=None, xml_path='../model_output_tests/')

cimhub.CreateHouses module

Created on Jun 25, 2018

@author: thay838

class cimhub.CreateHouses.CreateHouses(region, log=None, seed=None)

Bases: object

Class which uses data derived from EIA RECS to generate houses.

EIA RECS data is used to create various distributions, and then house properties are drawn from these distributions.

drawAC(housingType, n)

Draw all AC related parameters for ‘n’ houses.

INPUTS: housingType: string (from self.data[‘TYPEHUQ’].index) representing housing type. n: number of houses to determine properties for.

OUTPUTS: coolingSystem: pandas Series which containes either ‘electric’ for standard AC, ‘none’ if there’s no cooling, or ‘heatPump’ if the AC is from a heatpump. coolingSetpoint: pandas Series containing a thermostat cooling setpoint (in degrees F) for each home. np.nan will be used for homes with ‘none’ in coolingSystem

drawFromDist(pmf, bin_edges, num=1)
Select a discrete bin from a distribution, then use the uniform

distribution to choose a value within that bin.

INPUTS: pmf: probability mass function (sums to 1) for the distribution bin_edges: edges for binned data. These should have originated from a call to numpy’s histogram function.

drawHeating(coolingSystem, housingType, n)

Draw all heating related parameters for ‘n’ houses.

INPUTS: coolingSystem: one of the returns from “drawAC.” Used for heat pumps. housingType: string (from self.data[‘TYPEHUQ’].index) representing housing type. n: number of houses to determine properties for.

OUTPUTS: heatingSystem: pandas Series with a string for each of the ‘n’ housing units. Options are ‘none,’ ‘electric,’ ‘heatPump,’ or ‘gas.’ heatingSetpoint: pandas Series with a number for each of the ‘n’ housing units. Represents heating setpoint in degrees F. If the corresponding heating system is ‘none,’ the setpoint will be np.nan

drawNumStories(housingType, n)

Draw number of stories for ‘n’ houses.

INPUTS: housingType: string (from self.data[‘TYPEHUQ’].index) representing housing type. n: number of houses to determine properties for.

OUTPUTS: numberOfStories: pandas Series indicating the number of stories for each of the ‘n’ housing units. Note that mobile homes and apartments will always be 1 story.

drawThermalIntegrity(housingType, n)

Decide thermal integrity levels for ‘n’ houses.

housingType: string (from self.data[‘TYPEHUQ’].index) representinghousing type. n: number of houses to determine properties for.

OUTPUTS: thermalIntegrity: pandas Series indicating thermal integrity level for each of the ‘n’ housing units. Options (from GridLAB-D, http://gridlab-d.shoutwiki.com/wiki/Thermal_integrity_level) are:

‘veryLittle’: old, uninsulated ‘little’: old, insulated ‘belowNormal’: old, weatherized ‘normal’: old, retrofit upgraded ‘aboveNormal’: moderately insulated ‘good’: very well insulated ‘veryGood’: extermely well insulated ‘unknown’: unkown. “Built-in defaults or user-specified values are used.”

NOTES: We’ll be using three parameters to make a decision here: YEARMADERANGE, ADQINSUL, and DRAFTY.

year made will decide if house is ‘old’ or not, adequate insulation will determine ‘insulated,’ and ‘drafty’ will determine weatherized.

TODO: I don’t love this one… The mapping is too.. hand-wavy. Maybe instead of this intersection method we could come up with a ‘score’ where equal points are possible from the three categories? TODO: Get someone to review and weigh in.

estimateTotalHouses(magS, scale)

Estimate total number of housing units that will be generated.

This is used to help ensure we’re doing a good job tracking the housing

type distribution.

Rough flow:
  1. Compute mean square footage by housing type

  2. Use factor (VA_PER_SQFT/scale) to estimate peak power by housing type.

  3. Given distribution of housing types and associated average

    power, estimate how many housing units will be generated.

INPUTS: magS: Magnitude of apparent power for all the loads in the system. scale: scaling factor on the number of houses placed, to mitigate overloads

OUTPUTS: num: Estimate of total number of housing units that will be generated.

genHousesForFeeder(loadDf, magS, scale)

‘Main’ function for class. Generates houses for a given set of loads

NOTE: The intention is that this function is called by the insertHouses

module, and so the inputs are taken in a form they exist there.

INPUTS: loadDf: pandas dataframe, indices are names of loads, and column ‘magS’ indicates apaprent power magnitude under peak conditions magS: total magnitude of all loads [MVA] scale: scaling factor on the number of houses placed, to mitigate overloads

OUTPUT: housingDict: dictionary with nodes/loads (index from loadDf) as keys. Each key maps to a two-element tuple - the first is a dataframe containing housing data and the second is the chosen housing type code (see eia_recs.housingData.TYPEHUQ). Using the code instead of the full name for efficiency.

note: We may want to use a different datatype other than a dictionary.

When we loop back over the items, this will be inefficient as the key will have to be looked up every time.

static mapHeating(code)

Helper function for mapping heating codes to values.

typeAndSQFTForLoad(magS, scale)

Randomly draw a housing type, then choose number of housing units.

INPUTS: magS: Magnitude of peak apparent power for load in question (VA). scale: scaling factor on the number of houses placed, to mitigate overloads

OUTPUTS: housingType: Selected housing type string. housingCode: index from TYPEHUQ that matches up with the housingType string floorArea: pandas Series of square footages for houses to be added.

cimhub.DropCircuit module

cimhub.DropCircuit.drop_circuit(cfg_file, mRID)
cimhub.DropCircuit.print_count(lbl, resp)
cimhub.DropCircuit.run_query(lbl, qstr)

cimhub.DropDER module

cimhub.DropDER.drop_der(cfg_file, uuid_fname)

cimhub.DropHouses module

cimhub.DropHouses.drop_houses(cfg_file, mRID)

cimhub.DropMeasurements module

cimhub.DropMeasurements.drop_measurements(cfg_file, mRID)

cimhub.InsertDER module

cimhub.InsertDER.GetCIMID(cls, nm, uuids)
cimhub.InsertDER.ParsePhases(sphs)
cimhub.InsertDER.PostDER(sparql, qtriples)
cimhub.InsertDER.get_category(name, tok)
cimhub.InsertDER.get_cim_control_mode(mode)
cimhub.InsertDER.get_control_mode(name, tok)
class cimhub.InsertDER.ieee1547

Bases: object

append_cim_triples(qtriples)
assign_pec(ratedS, kWmax, ratedU, category, ctrlMode, p, q, pecID, name, bBattery, uuids)
print_dicts()
cimhub.InsertDER.insert_der(cfg_file, fname)

cimhub.InsertHouses module

Module to extract EnergyConsumers from the CIM database and replace loads with houses, HVAC systems, and plug loads. We may also want water heaters.

Created on Jun 1, 2018

@author: thay838

cimhub.InsertHouses.ConfigureCIMHub(fname)
cimhub.InsertHouses.PostHouses()
cimhub.InsertHouses.getEnergyConsumers(fdrid)

Method to get nominal voltages from each ‘EnergyConsumer.’

Query source is Powergrid-Models/blazegraph/queries.txt, and it was modified from there.

For now, we’ll just get the ‘bus’ (which is really the object name in the GridLAB-D model) and nominal voltage. Nominal voltage is given as 3-phase phase-to-phase, even if we’re talking about a split-phase. I suppose that’s what you get when you apply a transmission standard to the secondary side of a distribution system…

TODO: Later, we may want to act according to the load connection/phases

cimhub.InsertHouses.insertHouse(ecName, ecID, houseNum, houseData, uuids)

Insert a single house into the CIM triplestore.

cimhub.InsertHouses.insert_houses(cfgfile, mRID, region, seed, uuidfile, scale)
cimhub.InsertHouses.main(fdrid, region, loglevel='INFO', logfile=None, seed=None, uuidfile=None, scale=1.0)
cimhub.InsertHouses.setupLog(logger, loglevel, logfile)

Helper function to setup the module’s log.

cimhub.eia_recs.housingData module

Module to map relevant EIA RECS data into climate regions.

For now, we’re creating a very crude house model. In the future, RECS has a wealth of additional data we can leverage to augment this.

Created on Jun 21, 2018

@author: thay838

cimhub.eia_recs.housingData.buildHouseDist()

Build a pd.Series object which will hold housing distribution data.

This helper is necessary, because if we don’t call this for each houseDist object we need, we’ll get pointers and end up incidentally modifying data we didn’t want to. I tried all sorts of copy/deepcopy stuff before landing here.

cimhub.InsertMeasurements module

cimhub.InsertMeasurements.InsertMeasurement(meascls, measid, eqname, eqid, trmid, meastype, phases)
cimhub.InsertMeasurements.PostMeasurements(fname)
cimhub.InsertMeasurements.getMeasurementID(key, uuidDict)
cimhub.InsertMeasurements.insert_measurements(cfg_file, fname, uuidfile=None)

cimhub.LineConstants module

cimhub.ListFeeders module

cimhub.ListFeeders.list_feeders(cfg_file=None)

cimhub.ListMeasureables module

cimhub.ListMeasureables.FlatPhases(phases)
cimhub.ListMeasureables.list_measurables(cfg_file, froot, mRID, outpath=None, taxonomy=False)

cimhub.MakeConversionScript module

cimhub.MakeConversionScript.append_cases(casefiles, dsspath, outpath, region, subregion, fp)
cimhub.MakeConversionScript.make_dss2xml_script(casefiles, inpath, outpath, outfile)

cimhub.MakeGlmTestScript module

cimhub.MakeGlmTestScript.make_glmrun_script(casefiles, inpath, outpath, scriptname, movefiles=True, bHouses=False)
cimhub.MakeGlmTestScript.write_glm_case(c, v, fp, bHouses=False)

cimhub.MakeLoopScript module

cimhub.MakeLoopScript.append_dss_case(cases, inpath, outpath, fp)
cimhub.MakeLoopScript.append_xml_case(cases, xmlpath, outpath, fp)
cimhub.MakeLoopScript.append_xml_case_windows(cases, xmlpath, outpath, fp)
cimhub.MakeLoopScript.make_blazegraph_script(casefiles, xmlpath, dsspath, glmpath, scriptname, csvpath=None, clean_dirs=True)
cimhub.MakeLoopScript.make_dssrun_script(casefiles, scriptname, bControls=False, tol=1e-08)
cimhub.MakeLoopScript.make_export_script(scriptname, cases, dsspath=None, glmpath=None, csvpath=None, clean_dirs=True)

cimhub.MakeTable module

cimhub.SPARQL_Dict module

cimhub.SPARQL_Dict.build_dict(ret)
cimhub.SPARQL_Dict.build_query(prefix, base, fid)
cimhub.SPARQL_Dict.initialize_SPARQL(cfg_file=None)
cimhub.SPARQL_Dict.list_dict_table(dict, tag)
cimhub.SPARQL_Dict.list_feeders(dict)
cimhub.SPARQL_Dict.load_feeder(dict, fid, bTime=True)
cimhub.SPARQL_Dict.load_feeder_dict(cfg_file, xml_file, fid, bTime=True)
cimhub.SPARQL_Dict.query_for_values(tbl, fid)
cimhub.SPARQL_Dict.summarize_feeder_dict(dict)

cimhub.SummarizeDB module

cimhub.SummarizeDB.run_query(sparql, prefix, lbl, qstr)
cimhub.SummarizeDB.summarize_db(cfg_file)