How to use prepare_network method in tempest

Best Python code snippet using tempest_python

gen_map.py

Source:gen_map.py Github

copy

Full Screen

...57# case_path = '../../../examples/capabilities/ercot/case8/'58high_renew_wind_scaling = 2.0059# case_file = 'ercot_8'60# ======== END INPUT SETTINGS ========================61def prepare_network(node, node_col, high_renewables_case, zero_pmin=False, zero_index=False, on_ehv=True, split_start_cost=False, high_ramp_rates=False, coal=True):62 if high_renewables_case:63 case_file = node + '_hi_system_case_config'64 else:65 case_file = node + '_system_case_config'66 book = xlrd.open_workbook(data_path + 'bus_generators.xlsx')67 if high_ramp_rates:68 sheet = book.sheet_by_name('Gen Info-high ramps')69 else:70 sheet = book.sheet_by_name('Gen Info')71 # os.rename(case_path + case_file + '.json', case_path + case_file + '_old.json')72 with open(case_path + case_file + '.json') as json_file:73 data = json.load(json_file)74 genCost = []75 genData = []76 genFuel = []77 if high_renewables_case:78 gentypes = ['solar', 'coal', 'gas', 'nuclear', 'wind', 'hydro']79 else:80 gentypes = ['coal', 'gas', 'nuclear', 'wind', 'hydro']81 if not coal:82 gentypes.remove('coal')83 for irow in range(1, sheet.nrows - 2):84 genidx = int(sheet.cell(irow, 0).value)85 if zero_index:86 busNo = int(sheet.cell(irow, node_col).value) - 187 else:88 busNo = int(sheet.cell(irow, node_col).value)89 mvabase = sheet.cell(irow, 3).value90 if zero_pmin: # Mode to set pmin to zero as part of debugging91 pmin = 0.092 else:93 pmin = sheet.cell(irow, 4).value94 qmin = sheet.cell(irow, 5).value95 qmax = sheet.cell(irow, 6).value96 c2 = sheet.cell(irow, 7).value97 c1 = sheet.cell(irow, 8).value98 c0 = sheet.cell(irow, 9).value99 Gentype = sheet.cell(irow, 10).value100 RampRate = sheet.cell(irow, 11).value101 if split_start_cost:102 StartupCost = sheet.cell(irow, 12).value/2103 ShutdownCost = sheet.cell(irow, 12).value/2104 else:105 StartupCost = sheet.cell(irow, 12).value106 ShutdownCost = 0107 # For the 200 bus case determine if there is a high voltage bus that the generator should be connected to.108 # Solar and Wind are to remain on low-voltage buses:109 if node == '200' and on_ehv and "Wind" not in Gentype and "Solar" not in Gentype: # 1 = 200 node case110 for branch in data['branch']:111 if branch[0] == busNo and branch[1] > 200:112 busNo = branch[1]113 break114 elif branch[1] == busNo and branch[0] > 200:115 busNo = branch[1]116 break117 # If high renewable case scale up the baseline wind capacities118 if high_renewables_case and "Wind" in Gentype:119 mvabase = high_renew_wind_scaling * mvabase120 if "Wind" in Gentype:121 fueltype = 'wind'122 elif "Nuclear" in Gentype:123 fueltype = 'nuclear'124 elif "Coal" in Gentype:125 fueltype = 'coal'126 elif "Gas" in Gentype:127 fueltype = 'gas'128 elif "Hydro" in Gentype:129 fueltype = 'hydro'130 elif "Solar" in Gentype:131 fueltype = 'solar'132 else:133 fueltype = 'other'134 if fueltype in gentypes:135 # gen_id[busNo] = gen_id[busNo] + 1136 genData.append([137 busNo,138 float(0),139 float(0),140 float(qmax),141 float(qmin),142 1.0,143 float(mvabase),144 1,145 float(mvabase),146 float(pmin),147 0,148 0,149 0,150 0,151 0,152 0,153 float(RampRate),154 0.0,155 0.0,156 0.0,157 0.0158 ])159 genCost.append([160 2,161 float(StartupCost),162 float(ShutdownCost),163 3,164 float(c2),165 float(c1),166 float(c0)167 ])168 genFuel.append([169 fueltype,170 Gentype,171 genidx,172 1173 ])174 # divide the generators into parts175 # testing on dividing first generator into 3176 '''177 oldQmax = genData[0][3]178 oldQmin = genData[0][4]179 oldPmax = genData[0][8]180 oldPmin = genData[0][9]181 newPmax = oldPmax/3.0182 newGenData = genData[0]183 newGenCost = genCost[0]184 newGenData[3] = oldQmax * newPmax/oldPmax185 newGenData[4] = oldQmin * newPmax/oldPmax186 newGenData[6] = newPmax187 newGenData[8] = newPmax188 newGenData[9] = oldPmin * newPmax/oldPmax189 data['gen'].pop(0)190 data['gencost'].pop(0)191 for j in range(3):192 data['gen'] = [newGenData] + data['gen']193 data['gencost'] = [newGenCost] + data['gencost']194 genData = data['gen']195 genCost = data['gencost']196 # assigning ramp rate based on fuel type197 for i in range(len(data['gen'])):198 # find the type of generation199 c2 = float(genCost[i][4])200 c1 = float(genCost[i][5])201 c0 = float(genCost[i][6])202 pmax = float(genData[i][8])203 # assign fuel types from the IA State default costs204 if c2 < 2e-5: 205 genfuel = 'wind'206 elif c2 < 0.0003:207 genfuel = 'nuclear'208 elif c1 < 25.0:209 genfuel = 'coal'210 else:211 genfuel = 'gas'212 # calculate ramprate based on fuel type213 ramprate = pctramprate[genfuel]*pmax214 minUpTime = math.ceil(minuptime[genfuel])215 minDownTime = math.ceil(mindowntime[genfuel])216 # update the original data variable217 data['gen'][i][16] = ramprate218 data['gen'][i].append(minUpTime)219 data['gen'][i].append(minDownTime)220 '''221 data['gen'] = genData222 data['gencost'] = genCost223 data['genfuel'] = genFuel224 print('Finished ' + case_file)225 json_file.close()226 # write it in the original data file227 with open(case_path + case_file + '.json', 'w') as outfile:228 json.dump(data, outfile, indent=2)229 outfile.close()230# ------- prepare_network(231# node,232# node_col,233# high_renewables_case,234# zero_pmin=False,235# zero_index=False,236# on_ehv=True,237# split_start_cost=False,238# high_ramp_rates=False,239# coal=True)240node = ['8', '200']241col = [2, 1]242for i in range(2):243 # ----- Use commands below to run with low ramp rates and defaults244 # prepare_network(node[i], col[i], True)245 # prepare_network(node[i], col[i], False)246 # ----- Use the commands below to turn off coal high renewables247 # prepare_network(node[i], col[i], True, False, False, True, False, False, False)248 # prepare_network(node[i], col[i], False, False, False, True, False, False, False)249 # ----- Use commands below to run with high ramp rates250 prepare_network(node[i], col[i], True, False, False, True, False, True)251 prepare_network(node[i], col[i], False, False, False, True, False, True)252 # ----- Use commands below to run with start up costs split 50/50 between start up and shutdown253 # prepare_network(node[i], col[i], True, False, False, True, True)...

Full Screen

Full Screen

exec_model.py

Source:exec_model.py Github

copy

Full Screen

...22 parser.print_help()23 sys.exit(1)24 args = parser.parse_args()25 return args26def prepare_network(network):27 if network == 'LeNet':28 construct_func = construct_LeNet29 input_shape = (32, 32)30 custom_objects = {}31 elif network == 'VGG_F':32 construct_func = construct_VGG_F33 input_shape = (224, 224)34 custom_objects = {'LRN': LRN}35 else:36 raise ValueError('Unrecognized network "{}"'.format(network))37 return construct_func, input_shape, custom_objects38def make_onehots(labels, num_classes):39 onehot_labels = np.zeros((labels.shape[0], num_classes), dtype=np.float32)40 onehot_labels[range(labels.shape[0]), labels] = 1.041 return onehot_labels42def batch_resize(input_images, output_shape=(224, 224)):43 if input_images.shape[1:3] == output_shape:44 return input_images.astype(np.float32)45 def resize(image, output_shape):46 return scipy.misc.imresize(image, output_shape)47 output_images = map(lambda x:resize(x, output_shape), input_images)48 return np.array(output_images, dtype=np.float32)49def run_train(args):50 construct_func, input_shape, custom_objects = prepare_network(args.network)51 train_x = np.load('spectrogram_data/train_X.npy')52 train_x = batch_resize(train_x, input_shape)[..., np.newaxis]53 train_y = make_onehots(np.load('spectrogram_data/train_Y.npy').astype(np.int32), 20)54 val_x = np.load('spectrogram_data/val_X.npy')55 val_x = batch_resize(val_x, input_shape)[..., np.newaxis]56 val_y = make_onehots(np.load('spectrogram_data/val_Y.npy').astype(np.int32), 20)57 print('train_x: {}, train_y: {}'.format(train_x.shape, train_y.shape))58 print('val_x: {}, val_y: {}'.format(val_x.shape, val_y.shape))59 model = construct_func(input_shape=input_shape+(1,), num_classes=20)60 model.summary()61 optim = optimizers.Adam(lr=0.0001)62 model_checkpoint = callbacks.ModelCheckpoint(os.path.join('models/'+args.res_dir, 'best_model.h5'),63 monitor='val_categorical_accuracy',64 period=1, save_best_only=True)65 early_stopping = callbacks.EarlyStopping(monitor='val_categorical_accuracy',66 patience=10)67 csv_logger = callbacks.CSVLogger(os.path.join('models/'+args.res_dir, 'log.txt'))68 model.compile(loss='categorical_crossentropy', optimizer=optim,69 metrics=['categorical_accuracy'])70 model.fit(x=train_x, y=train_y,71 validation_data=(val_x, val_y),72 callbacks=[model_checkpoint, csv_logger],73 batch_size=100, epochs=100, verbose=1, shuffle=True)74 return75def run_test(args):76 construct_func, input_shape, custom_objects = prepare_network(args.network)77 model = load_model(os.path.join('models/'+args.res_dir, 'best_model.h5'),78 custom_objects=custom_objects)79 results = {}80 for split_name in ['train', 'val', 'test']:81 x = np.load('spectrogram_data/%s_X.npy' % split_name)82 x = batch_resize(x, input_shape)[..., np.newaxis]83 y = np.load('spectrogram_data/%s_Y.npy' % split_name).astype(np.int32)84 print('{}_x: {}, {}_y: {}'.format(split_name, x.shape,85 split_name, y.shape))86 pred = np.argmax(model.predict(x), axis=1)87 print('{}_pred: {}'.format(split_name, pred.shape))88 acc = float(np.sum(pred == y)) / float(y.shape[0])89 print('{} Accuracy: {:f}'.format(split_name.upper(), acc))90 results[split_name] = acc...

Full Screen

Full Screen

test_rootNode.py

Source:test_rootNode.py Github

copy

Full Screen

...3__author__ = 'andyguo'4import pytest5from dayu_ffmpeg.network import *6class TestRootNode(object):7 def prepare_network(self):8 self.i1 = Input()9 self.root = RootNode()10 self.ih1 = self.root.create_node(InputHolder)11 self.root.set_input(self.i1)12 self.i2 = self.root.create_node(Input)13 self.cf = self.root.create_node(ComplexFilterGroup)14 self.ih2 = self.cf.create_node(InputHolder)15 self.ih3 = self.cf.create_node(InputHolder)16 self.cf.set_input(self.ih1, 0)17 self.cf.set_input(self.i2, 1)18 self.over = self.cf.create_node(Overlay)19 self.over.set_input(self.ih2, 0)20 self.over.set_input(self.ih3, 1)21 self.oh1 = self.cf.create_node(OutputHolder)22 self.oh1.set_input(self.over)23 self.o1 = self.root.create_node(Output)24 self.o1.set_input(self.cf)25 def test_cmd(self):26 from pprint import pprint27 self.prepare_network()28 # print self.root.cmd()29 pprint(self.root.to_script())30 def test__find_all_inputs(self):31 self.prepare_network()32 assert self.root._find_all_inputs(self.root._find_all_outputs()) == [self.i1, self.i2]33 def test__find_all_outputs(self):34 self.prepare_network()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful