How to use list_segments method in tempest

Best Python code snippet using tempest_python

CrossSectStator.py

Source:CrossSectStator.py Github

copy

Full Screen

1from pylab import np, cos, sin, arctan2class CrossSectInnerRotorStator:3 # CrossSectInnerRotorPMStator Describes the inner rotor PM stator.4 # Properties are set upon class creation and cannot be modified.5 # The anchor point for this is the center of the stator,6 # with the x-axis directed down the center of one of the stator teeth.7 def __init__(self,8 name = 'StatorCore',9 color = '#BAFD01',10 deg_alpha_st = 40, # span angle of tooth: class type DimAngular11 deg_alpha_so = 20, # angle of tooth edge: class type DimAngular12 mm_r_si = 40,# inner radius of stator teeth: class type DimLinear13 mm_d_so = 5,# tooth edge length: class type DimLinear14 mm_d_sp = 10,# tooth tip length: class type DimLinear15 mm_d_st = 15,# tooth base length: class type DimLinear16 mm_d_sy = 15,# back iron thickness: class type DimLinear17 mm_w_st = 13,# tooth base width: class type DimLinear18 mm_r_st = 0,# fillet on outter tooth: class type DimLinear19 mm_r_sf = 0,# fillet between tooth tip and base: class type DimLinear20 mm_r_sb = 0,# fillet at tooth base: class type DimLinear21 Q = 6, # number of stator slots (integer)22 location = None23 ):2425 self.name = name26 self.color = color27 self.deg_alpha_st = deg_alpha_st28 self.deg_alpha_so = deg_alpha_so29 self.mm_r_si = mm_r_si 30 self.mm_d_so = mm_d_so 31 self.mm_d_sp = mm_d_sp 32 self.mm_d_st = mm_d_st 33 self.mm_d_sy = mm_d_sy 34 self.mm_w_st = mm_w_st 35 self.mm_r_st = mm_r_st 36 self.mm_r_sf = mm_r_sf 37 self.mm_r_sb = mm_r_sb 38 self.Q = Q 39 self.location = location 4041 def draw(self, drawer):4243 drawer.getSketch(self.name, self.color)4445 alpha_st = self.deg_alpha_st * np.pi/18046 alpha_so = -self.deg_alpha_so * np.pi/18047 r_si = self.mm_r_si48 d_so = self.mm_d_so49 d_sp = self.mm_d_sp50 d_st = self.mm_d_st51 d_sy = self.mm_d_sy52 w_st = self.mm_w_st53 r_st = self.mm_r_st54 r_sf = self.mm_r_sf55 r_sb = self.mm_r_sb56 Q = self.Q5758 alpha_slot_span = 360/Q * np.pi/1805960 P1 = [r_si, 0]61 P2 = [r_si*cos(alpha_st*0.5), r_si*-sin(alpha_st*0.5)]62 P3_temp = [ d_so*cos(alpha_st*0.5), 63 d_so*-sin(alpha_st*0.5)]64 P3_local_rotate = [ cos(alpha_so)*P3_temp[0] + sin(alpha_so)*P3_temp[1],65 -sin(alpha_so)*P3_temp[0] + cos(alpha_so)*P3_temp[1] ]66 P3 = [ P3_local_rotate[0] + P2[0],67 P3_local_rotate[1] + P2[1] ]6869 三角形的底 = r_si + d_sp70 三角形的高 = w_st*0.571 三角形的角度 = arctan(三角形的高 / 三角形的底)72 P4 = [ 三角形的底*cos(三角形的角度), 73 三角形的底*-sin(三角形的角度)]7475 P5 = [ P4[0] + d_st, 76 P4[1]]7778 P6 = [ (r_si+d_sp+d_st)*cos(alpha_slot_span*0.5),79 (r_si+d_sp+d_st)*-sin(alpha_slot_span*0.5) ]8081 P7 = [ (r_si+d_sp+d_st+d_sy)*cos(alpha_slot_span*0.5),82 (r_si+d_sp+d_st+d_sy)*-sin(alpha_slot_span*0.5) ]83 P8 = [ r_si+d_sp+d_st+d_sy, 0]8485 list_segments = []86 list_segments += drawer.drawArc([0,0], P2, P1)87 list_segments += drawer.drawLine(P2, P3)88 list_segments += drawer.drawLine(P3, P4)89 list_segments += drawer.drawLine(P4, P5)90 list_segments += drawer.drawArc([0,0], P6, P5)91 list_segments += drawer.drawLine(P6, P7)92 # l, vA = drawer.drawArc([0,0], P6, P5, returnVertexName=True)93 # list_segments += l94 # l, vB = drawer.drawLine(P6, P7, returnVertexName=True)95 # list_segments += l96 # drawer.addConstraintCocentricity(vA[0], vB[0])97 # raise9899 list_segments += drawer.drawArc([0,0], P7, P8)100 list_segments += drawer.drawLine(P8, P1)101102 return [list_segments]103104def get_area_polygon(a,b,c,d):105 x1, x2, x3, x4 = a[0], b[0], c[0], d[0]106 y1, y2, y3, y4 = a[1], b[1], c[1], d[1]107108 return 0.5*abs( x1*y2-y1*x2 + x2*y3-y2*x3 + x3*y4-y3*x4 + x4*y1-y4*x1 )109110class CrossSectInnerRotorStatorWinding(object):111 def __init__(self, 112 name = 'Coils',113 color = '#3D9970',114 stator_core = None115 ):116 self.name = name117 self.color = color118 self.stator_core = stator_core119120 def draw(self, drawer, bool_re_evaluate=False):121122 if False == bool_re_evaluate:123 drawer.getSketch(self.name, self.color)124125 alpha_st = self.stator_core.deg_alpha_st * np.pi/180126 alpha_so = self.stator_core.deg_alpha_so * np.pi/180127 r_si = self.stator_core.mm_r_si128 d_so = self.stator_core.mm_d_so129 d_sp = self.stator_core.mm_d_sp130 d_st = self.stator_core.mm_d_st131 d_sy = self.stator_core.mm_d_sy132 w_st = self.stator_core.mm_w_st133 r_st = self.stator_core.mm_r_st134 r_sf = self.stator_core.mm_r_sf135 r_sb = self.stator_core.mm_r_sb136 Q = self.stator_core.Q137138 alpha_slot_span = 360/Q * np.pi/180139140 P1 = [r_si, 0]141142 # 乘以0.99或0.95避免上层导体和下层导体重合导致导入Designer时产生多余的Parts。143 POpen = [(r_si+d_sp)*cos(alpha_slot_span*0.5*1.00), (r_si+d_sp)*-sin(alpha_slot_span*0.5*1.00)]144145 # P2 = [r_si*cos(alpha_st*0.5), r_si*-sin(alpha_st*0.5)]146147 # P3_temp = [ d_so*cos(alpha_st*0.5), 148 # d_so*-sin(alpha_st*0.5)]149 # P3_local_rotate = [ cos(alpha_so)*P3_temp[0] + sin(alpha_so)*P3_temp[1],150 # -sin(alpha_so)*P3_temp[0] + cos(alpha_so)*P3_temp[1] ]151 # P3 = [ P3_local_rotate[0] + P2[0],152 # P3_local_rotate[1] + P2[1] ]153154 三角形的底 = r_si + d_sp155 三角形的高 = w_st*0.5156 三角形的角度 = arctan(三角形的高 / 三角形的底)157 P4 = [ 三角形的底*cos(三角形的角度), 158 三角形的底*-sin(三角形的角度) ]159160 P5 = [ P4[0] + d_st, 161 P4[1]]162163 PMiddle45 = [0.5*(P4[0] + P5[0]), P4[1]]164 TheRadius = (P5[0] - P4[0])*0.45165166 # 为了使得槽和导体之间不要接触,试着添加5%的clearance?167 P6 = [ (r_si+d_sp+d_st)*cos(alpha_slot_span*0.5) *1.00,168 (r_si+d_sp+d_st)*-sin(alpha_slot_span*0.5) *1.00 ]169170 self.mm2_slot_area = 2 * get_area_polygon(P4, P5, P6, POpen)171 print('Slot area is %g mm^2'%(self.mm2_slot_area))172 if bool_re_evaluate:173 return self.mm2_slot_area174175 PMiddle6Open = [ 0.5*(P6[0]+POpen[0]), 0.5*(P6[1]+POpen[1])]176 self.PCoil = PCoil = [ 0.5*(PMiddle45[0]+PMiddle6Open[0]), 0.5*(PMiddle45[1]+PMiddle6Open[1])]177178 # P7 = [ (r_si+d_sp+d_st+d_sy)*cos(alpha_slot_span*0.5),179 # (r_si+d_sp+d_st+d_sy)*-sin(alpha_slot_span*0.5) ]180 # P8 = [ r_si+d_sp+d_st+d_sy, 0]181182 # Compute the vector starting from PCoil to one of the corner of the polygon.183 def shrink(PC, P):184 vector = [ P[0] - PC[0], P[1] - PC[1]]185 return [ PC[0]+0.95*vector[0], PC[1]+0.95*vector[1] ]186 P6_Shrink = shrink(PCoil, P6)187 P5_Shrink = shrink(PCoil, P5)188 P4_Shrink = shrink(PCoil, P4)189 POpen_Shrink = shrink(PCoil, POpen)190191 list_regions = []192193 list_segments = []194 # list_segments += drawer.drawCircle(PCoil, TheRadius)195 list_segments += drawer.drawArc([0,0], P6_Shrink, P5_Shrink)196 list_segments += drawer.drawLine(P5_Shrink, P4_Shrink)197 list_segments += drawer.drawLine(P4_Shrink, POpen_Shrink)198 list_segments += drawer.drawLine(POpen_Shrink, P6_Shrink)199 list_regions.append(list_segments)200201 PCoil[1] *= -1202 P6_Shrink[1] *= -1203 P5_Shrink[1] *= -1204 P4_Shrink[1] *= -1205 POpen_Shrink[1] *= -1206 list_segments = []207 # list_segments += drawer.drawCircle(PCoil, TheRadius)208 list_segments += drawer.drawArc([0,0], P5_Shrink, P6_Shrink)209 list_segments += drawer.drawLine(P5_Shrink, P4_Shrink)210 list_segments += drawer.drawLine(P4_Shrink, POpen_Shrink)211 list_segments += drawer.drawLine(POpen_Shrink, P6_Shrink)212 list_regions.append(list_segments)213 list_segments = []214215 return list_regions216217if __name__ == '__main__':218 import JMAG219 import Location2D220 if True:221 from utility import my_execfile222 my_execfile('./default_setting.py', g=globals(), l=locals())223 fea_config_dict224225 toolJd = JMAG.JMAG(fea_config_dict)226227 project_name = 'proj%d'%(0)228 expected_project_file_path = './' + "%s.jproj"%(project_name)229 toolJd.open(expected_project_file_path)230231 stator_core = CrossSectInnerRotorStator( name = 'StatorCore',232 deg_alpha_st = 40,233 deg_alpha_so = 20,234 mm_r_si = 40,235 mm_d_so = 5,236 mm_d_sp = 10,237 mm_d_st = 15,238 mm_d_sy = 15,239 mm_w_st = 13,240 mm_r_st = 0,241 mm_r_sf = 0,242 mm_r_sb = 0,243 Q = 6,244 location = Location2D.Location2D(anchor_xy=[0,0], deg_theta=0)245 )246247 list_regions = stator_core.draw(toolJd)248 toolJd.bMirror = True249 toolJd.iRotateCopy = stator_core.Q250 region1 = toolJd.prepareSection(list_regions)251252 coils = CrossSectInnerRotorStatorWinding(name = 'Coils',253 stator_core = stator_core)254255 list_regions = coils.draw(toolJd)256 toolJd.bMirror = False257 toolJd.iRotateCopy = coils.stator_core.Q258 region2 = toolJd.prepareSection(list_regions)259260 # Import Model into Designer261 toolJd.doc.SaveModel(False) # True: Project is also saved. 262 model = toolJd.app.GetCurrentModel()263 model.SetName('BPMSM Modeling')264 model.SetDescription('BPMSM Test')265266 ...

Full Screen

Full Screen

dataset.py

Source:dataset.py Github

copy

Full Screen

1import math2import os3import pandas as pd4from sklearn.model_selection import train_test_split5import torch6from torch.utils.data import TensorDataset7from sklearn import preprocessing8le = preprocessing.LabelEncoder()9def get_dict(le):10 classes = le.classes_11 final_dict = {}12 for abc,ra in zip(classes,range(len(classes))):13 final_dict[abc] = ra14 return final_dict15 16def _load_20newsgroup(directory, max_length=512):17 text = []18 tags = []19 dir = directory20 for a in os.listdir(dir):21 new = os.path.join(dir,a)22 23 for x in os.listdir(new):24 if x.endswith(".txt"):25 read_dir = os.path.join(new,x)26 b = open(read_dir,"r",encoding="utf8", errors='ignore')27 text_file = b.read()28 text_file = text_file[:1]29 text.append(text_file)30 tags.append(a)31 dict = {'Text':text, 'number':tags}32 data = pd.DataFrame(dict) 33 34 data["number"] = le.fit_transform(data["number"])35 label2id = get_dict(le)36 data_train,data_test = train_test_split(data,test_size=0.7)37 X_train = data_train["Text"].to_list()38 y_train = data_train["number"].to_list()39 X_test = data_test["Text"].to_list()40 y_test = data_test["number"].to_list()41 return X_train, y_train, X_test, y_test, label2id42def load_20newsgroup_segments1(text, max_length=512, size_segment=200, size_shift=50):43 X_test_full = [text]44 y_test = [0]45 label2id = {"aa":0}46 47 def get_segments(sentence):48 list_segments = []49 lenght_ = size_segment - size_shift50 tokens = sentence.split()51 num_tokens = len(tokens)52 num_segments = math.ceil(len(tokens) / lenght_)53 if num_tokens > lenght_:54 for i in range(0, num_tokens, lenght_):55 j = min(i+size_segment, num_tokens)56 list_segments.append(" ".join(tokens[i:j]))57 else:58 list_segments.append(sentence) 59 return list_segments, len(list_segments)60 def get_segments_from_section(sentences):61 list_segments = []62 list_num_segments = []63 for sentence in sentences:64 ls, ns = get_segments(sentence)65 list_segments += ls66 list_num_segments.append(ns)67 return list_segments, list_num_segments68 69 X_test, num_segments_test = get_segments_from_section(X_test_full)70 71 return X_test, y_test, num_segments_test, label2id72def load_20newsgroup_segments(directory, max_length=512, size_segment=200, size_shift=50):73 X_train_full, y_train, X_test_full, y_test, label2id = _load_20newsgroup(directory, max_length=max_length)74 def get_segments(sentence):75 list_segments = []76 lenght_ = size_segment - size_shift77 tokens = sentence.split()78 num_tokens = len(tokens)79 num_segments = math.ceil(len(tokens) / lenght_)80 if num_tokens > lenght_:81 for i in range(0, num_tokens, lenght_):82 j = min(i+size_segment, num_tokens)83 list_segments.append(" ".join(tokens[i:j]))84 else:85 list_segments.append(sentence) 86 return list_segments, len(list_segments)87 def get_segments_from_section(sentences):88 list_segments = []89 list_num_segments = []90 for sentence in sentences:91 ls, ns = get_segments(sentence)92 list_segments += ls93 list_num_segments.append(ns)94 return list_segments, list_num_segments95 X_train, num_segments_train = get_segments_from_section(X_train_full)96 X_test, num_segments_test = get_segments_from_section(X_test_full)97 98 return X_train, y_train, num_segments_train, X_test, y_test, num_segments_test, label2id99def generate_dataset_20newsgroup_segments(X, Y, num_segments, tokenizer, pad_to_max_length=True, add_special_tokens=True, max_length=200, return_attention_mask=True, 100 return_tensors='pt'):101 tokens = tokenizer.batch_encode_plus(102 X, 103 pad_to_max_length=pad_to_max_length,104 add_special_tokens=add_special_tokens,105 max_length=max_length,106 return_attention_mask=return_attention_mask, # 0: padded tokens, 1: not padded tokens; taking into account the sequence length107 return_tensors="pt",108 )109 num_sentences = len(Y)110 max_segments = max(num_segments)111 input_ids = torch.zeros((num_sentences, max_segments, max_length), dtype=tokens["input_ids"].dtype)112 attention_mask = torch.zeros((num_sentences, max_segments, max_length), dtype=tokens["attention_mask"].dtype)113 token_type_ids = torch.zeros((num_sentences, max_segments, max_length), dtype=tokens["token_type_ids"].dtype)114 # pad_token = 0115 pos_segment = 0116 for idx_segment, n_segments in enumerate(num_segments):117 for n in range(n_segments):118 input_ids[idx_segment, n] = tokens["input_ids"][pos_segment]119 attention_mask[idx_segment, n] = tokens["attention_mask"][pos_segment]120 token_type_ids[idx_segment, n] = tokens["token_type_ids"][pos_segment]121 pos_segment += 1 122 dataset = TensorDataset(input_ids, attention_mask, token_type_ids, torch.tensor(num_segments), torch.tensor(Y))...

Full Screen

Full Screen

covering_segments.py

Source:covering_segments.py Github

copy

Full Screen

1# Uses python32import sys3from collections import namedtuple4Segment = namedtuple('Segment', 'start end')5def optimal_points(segments):6 points = []7 list_segments = []8 #write your code here9 for s in segments:10 list_segments.append(s.start)11 list_segments.append(s.end)12 13 14 min_right = 10 ** 1015 position_min_right = 016 cont_segments = 017 i = 018 while i < len(list_segments) and (cont_segments < len(list_segments) / 2):19 for j in range(1, len(list_segments), 2):20 if min_right > list_segments[j]:21 min_right = list_segments[j]22 position_min_right = j23 points.append(min_right)24 for k in range(0, len(list_segments), 2):25 if list_segments[k] <= min_right and min_right <= list_segments[k + 1]:26 list_segments[k] = 10 ** 1027 list_segments[k + 1] = 10 ** 1028 cont_segments += 129 min_right = 10 ** 1030 return points31if __name__ == '__main__':32 input = sys.stdin.read()33 n, *data = map(int, input.split())34 segments = list(map(lambda x: Segment(x[0], x[1]), zip(data[::2], data[1::2])))35 points = optimal_points(segments)36 print(len(points))37 for p in points:...

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