def test_model_runs(self): result = utils.run_gld(self.out_file) self.assertEqual(0, result.returncode)
def setUpClass(cls): """Read and run GridLAB-D model, store ZIP parameters.""" # Read GridLAB-D model. glm_manager = glm.GLMManager(TEST_FILE, True) # Run GridLAB-D model. result = utils.run_gld(model_path=TEST_FILE) # Raise an error if the model didn't successfully run. if result.returncode != 0: raise UserWarning('Failed to run model, {}'.format(TEST_FILE)) # Get a listing of the recorders. recorders = glm_manager.get_objects_by_type('recorder') # Grab triplex_loads, keyed by name. load_data = glm_manager.get_items_by_type(item_type='object', object_type='triplex_load') # Extract file and load names from the recorder dictionaries. load_dict = {} # Get lists of ZIP terms to use. zip.py doesn't have the # '_12' at the end. zip_terms = ['base_power_12', 'impedance_fraction_12', 'current_fraction_12', 'power_fraction_12', 'impedance_pf_12', 'current_pf_12', 'power_pf_12'] zip_keys = [s.replace('_12', '') for s in zip_terms] cls.out_files = [] for r in recorders: # Grab the meter the recorder is associated with. meter_name = r['parent'] # Loop over the nodes and figure out which one is the child # of this meter. # TODO: This is terrible. While it'll be very fast for this # toy example, it's an expensive lookup when we have a # large number of nodes. We may want to add graph # functionality to the GLMManager. for name, data in load_data.items(): if data['parent'] == meter_name: # Track this load name. load_name = name # Initialize entry. load_dict[load_name] = {} # Read the file into a DataFrame. this_file = os.path.join(MODEL_DIR, r['file']) gld_out = utils.read_gld_csv(this_file) cls.out_files.append(this_file) # Rename columns. gld_out.rename(columns={'measured_real_power': 'p', 'measured_reactive_power': 'q'}, inplace=True) # Combine the two voltage measurements, get the magnitude. v = (gld_out['measured_voltage_1'] + gld_out['measured_voltage_2']).abs() # Add v to the DataFrame. gld_out['v'] = v # Drop the "measured_voltage" columns. gld_out.drop(['measured_voltage_1', 'measured_voltage_2'], axis=1, inplace=True) # Add the data to the dictionary. load_dict[load_name]['gld_out'] = gld_out # Add the ZIP terms. zip_gld = {} for idx in range(len(zip_terms)): # Map the zip_term in the model into a zip_key in the # load_dict. zip_gld[zip_keys[idx]] = \ float(load_data[load_name][zip_terms[idx]]) load_dict[load_name]['zip_gld'] = zip_gld # Set the nominal voltage. Note that GridLAB-D nominal # voltage is phase to neutral, but we want line to line. v_n = float(load_data[load_name]['nominal_voltage']) * 2 load_dict[load_name]['v_n'] = v_n # Use zip.py to compute P and Q. p, q = zip._zip_model_gld(v=gld_out['v'], v_n=v_n, s_n=zip_gld['base_power'], gld_terms=zip_gld) load_dict[load_name]['zip_model_out'] = \ pd.DataFrame({'p_predicted': p, 'q_predicted': q}) # Assign the final load dictionary. cls.load_dict = load_dict
def test_run_gld_bad_env(self): result = utils.run_gld(TEST_GLM2, env={'PATH': '/usr/bin'}) self.assertNotEqual(0, result.returncode)
def test_run_gld_bad_dir(self): with self.assertRaises(FileNotFoundError): utils.run_gld('/some/bad/path.glm')
def test_run_gld_bad_model(self): result = utils.run_gld(os.path.join(MODEL_DIR, 'nonexistent.glm')) self.assertNotEqual(0, result.returncode)
def test_run_gld_simple(self): """Ensure the model runs.""" result = utils.run_gld(TEST_GLM2) self.assertEqual(0, result.returncode)