\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{ipsa\_power} \pdfinfo{ /Title (pyipsa.pdf) /Creator (Cheatography) /Author (ipsa\_power) /Subject (PyIPSA Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{544364} \definecolor{LightBackground}{HTML}{F4F3F5} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{PyIPSA Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{ipsa\_power} via \textcolor{DarkBackground}{\uline{cheatography.com/159139/cs/33570/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}ipsa\_power \\ \uline{cheatography.com/ipsa-power} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 30th August, 2022.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{About PyIPSA}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{\{\{ac\}\}PyIPSA is the scripting application programming interface (API) designed to give engineers with comfortability in Python the chance to build more sophisticated network models. The entire code is built on the principles of object oriented programming, courtesy of our very accessible and powerful PyBind wrapper. The cheat sheet below gives scripters a solid foundation to start their IPSA experiences and give their computers more automated control over network design and functionality.% Row Count 10 (+ 10) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Starting PyIPSA}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{width=35\}\}Starting PyIPSA is as easy as making an interface and uploading the network from there, within a Python console or script} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{Running Python within IPSA}} & {\bf{Running from console /IDE}} \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} `import ipsa\{\{nl\}\}isci = ipsa.GetScriptInterface()\{\{nl\}\}inet = isci.GetNetwork()` & `import ipsa\{\{nl\}\}isci = ipsa.IscInterface()\{\{nl\}\}fname = "some\_network.i2f"\{\{nl\}\}inet = \seqsplit{isci.ReadFile(fname)`} \tn % Row Count 11 (+ 6) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{This is the first level of building a network within IPSA. From this step, you can use the full API functions to modify the network and run many study types.} \tn % Row Count 15 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Creating a Network}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Building a network from scratch can seem daunting but this is done in a similar way to the IPSA UI. \{\{nl\}\}First you designate any busbars that you need and build it up from there} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{`new\_net = \seqsplit{isci.CreateNewNetwork(100},50, True, True, 0 0)\{\{nl\}\}buses = {[}None{]} * 5\{\{nl\}\}branches = {[}{]}\{\{nl\}\}for i in range(5):\{\{nl\}\}~~bus{[}i{]}=new\_net.CreateBusbar("Bus "+str(i))\{\{nl\}\}bid=0\{\{nl\}\}for sid in {[}bus.GetUid() for bus in buses{]}:\{\{nl\}\}~~for rid in {[}bus.GetUID() in buses != sid{]}:\{\{nl\}\}~~~~branches{[}bid{]}=new\_net.CreateBranch(sid, rid, str(bid))\{\{nl\}\}~~~~bid+=1`} \tn % Row Count 13 (+ 9) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Tip}}: It's a good rule of thumb to make all the busbars first and then build from there} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Accessing Line Information}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Two-winding transformers in IPSA are branches with tap-changers mounted ontop. In this case, you need to edit the specific branch information with unique functions such as `GetILineValue`.} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{`tf\_maxtap = \seqsplit{tx.GetDValue(ipsa.IscTransformer}.MaxTapPC)\{\{nl\}\}tf\_resistance = \seqsplit{tx.GetLineDValue(ipsa.IscBranch.Resistance)`}} \tn % Row Count 7 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{For example, while the tap variables are targeted using `IscTransformer`, the impedance values are targeted using `IscBranch`.} \tn % Row Count 10 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Note that the same applies for the Set functions above as well} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4.64 cm} x{3.36 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{List of Components in PyIPSA}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Users can script all our IPSA components within their PyIPSA networks} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{Name}} & {\bf{Python Code}} \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} Busbar & `IscBusbar` \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} Branch & `IscBranch` \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} Two Winding Transformer & \seqsplit{`IscTransformer`} \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} Three Winding Transformer & \seqsplit{`Isc3WTransformer`} \tn % Row Count 8 (+ 2) % Row 6 \SetRowColor{LightBackground} Load & `IscLoad` \tn % Row Count 9 (+ 1) % Row 7 \SetRowColor{white} Induction Motor & `IscIndMachine` \tn % Row Count 10 (+ 1) % Row 8 \SetRowColor{LightBackground} Synchronous Generator & `IscSynMachine` \tn % Row Count 11 (+ 1) % Row 9 \SetRowColor{white} Grid Infeed & `IscGridInfeed` \tn % Row Count 12 (+ 1) % Row 10 \SetRowColor{LightBackground} Harmonic Source & `IscHarmonic` \tn % Row Count 13 (+ 1) % Row 11 \SetRowColor{white} Universal Machine & `IscUMachine` \tn % Row Count 14 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{For more components in IPSA check out our \{\{link="https://ipsa.readthedocs.io"\}\} \{\{nl\}\}PyIPSA ReadTheDocs\{\{/link\}\}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Redrawing Networks in Python}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{The IPSA UI allows you to graphically modify your drawn networks but PyIPSA gives you the chance to automate this} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{`idgr, ix = inet.GetAllDiagrams(),1\{\{nl\}\}for nUid in {[}bus.GetUID() for bus in buses{]}:\{\{nl\}\}~~idgr{[}0{]}.DrawBusbarCircular(nUid,20,ix,ix)\{\{nl\}\}~~ix += 1\{\{nl\}\}~~idgr{[}0{]}.DrawUndrawnItemsAttachedToBusbar(nUid)`} \tn % Row Count 8 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Components and Access Functions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Every component in IPSA has an associated class which can be added, modified or destroyed from your network. These all share the same access functions that require the user to input a particular field value reference (which the code takes as an integer).} \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{`bus1 = inet.GetBusbar(1)\{\{nl\}\}bus1\_voltage = \seqsplit{bus1.GetDValue(ipsa.IscBusbar.NomVoltkV)`}} \tn % Row Count 8 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{This also works for strings, integers and booleans:} \tn % Row Count 10 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{`b1\_name = \seqsplit{bus1.GetSValue(ipsa.IscBusbar}.Name)\{\{nl\}\}b1\_ctrl = \seqsplit{bus1.GetIValue(ipsa.IscBusbar.ControlType)`}} \tn % Row Count 13 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Plus we can set values in a similar way:} \tn % Row Count 14 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{`bus\_volt = 33.\{\{nl\}\}bus1.SetDValue(ipsa.IscBusbar.NomVoltkV,bus\_volt)`} \tn % Row Count 16 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Tip:}} You can also access all the network elements using dictionaries and the `iNet.GetBusbars()` syntax, where the keys are the element names!} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Running an Analysis Study}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{The core principle of IPSA is to run analysis modules such as load flow and fault level in order to evaluate network feasibility and capacity (among many other functions). Once you have built your network, you can specify the run settings in the `IscAnalysisLF` class and run the `DoLoadFlow()` function as shown below.} \tn % Row Count 7 (+ 7) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{`lfset = inet.GetAnalysisLF()\{\{nl\}\}lfset.SetIValue(ipsa.IscAnalysisLF.LockTaps) = 1\{\{nl\}\}\# To use minimum resistance value in multi-section lines\{\{nl\}\}lfset.SetIValue(ipsa.IscAnalysis.WhichImpedance = 1\{\{nl\}\}inet.DoLoadFlow()`} \tn % Row Count 12 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Important:}} This is slightly more complicated for a harmonics or fault analysis. For example, in a harmonic analysis, you have to specify each of the impedance coefficients for lines, transformers etc and also all the specific variables within each of the components.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Computing Load Profiles}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{To run a series of load flow scenarios designed for generators and loads you need to build the scenario set first using dictionaries} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{`cats = \{0:'PF1', 1:'PF2', 2:'PF3'\}\{\{nl\}\}apower = \{0:0.8, 1:0.775, 2:0.75\}\{\{nl\}\}rpower = \{0:0.48, 1:0.465, 2:0.45\}`} \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Then we build a profile instance defined by the class `IscLoadProfilePQActual` using the `IscNetwork` function} \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{`profUID = inet.CreateLoadProfilePQActual('test')\{\{nl\}\}prof = inet.GetLoadProfilePQActual('test')\{\{nl\}\}prof.SetCategoryNames(cats\}\{\{nl\}\}prof.SetPMW(apower)\{\{nl\}\}prof.SetQMVAr(rpower)`} \tn % Row Count 13 (+ 4) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Finally you just have to attach this profile to the load in question} \tn % Row Count 15 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{`load = \seqsplit{ipsa\_net.CreateLoad(send.GetUID()},rec.GetUID)\{\{nl\}\}load.SetIValue(ipsa.IscLoad.ProfileUID,profUID)`} \tn % Row Count 18 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{To run this correctly, make sure that you have\{\{nl\}\} `ProfileUse = 1` and iterate through the `ProfileLoadCategory` value that refers to the strings declared in\{\{nl\}\} \seqsplit{`IscLoadProfilePQActual.SetCategory`}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Finishing Touches}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{When you have finished working on your network, don't forget to use the functions to save the file you've been working on. Otherwise you will lose your progress:} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{`inet.WriteFile("C:\textbackslash{}Documents\textbackslash{}new\_network.i2f\{\{nl\}\}bClosedOK = isci.CloseNetwork()`} \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\emph{Note:}} Try not to open, run or save any IPSA networks if you have them open in the IPSA UI program as well. PyIPSA can only open a file once at a time, same way as the IPSA UI will.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.204 cm} x{2.736 cm} x{2.66 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Additional Packages}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{When using PyIPSA you might find that some additional packages make analysis easier:} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} `numpy` & `scipy` & `opencv` \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} `pandas` & `matplotlib` & `seaborn` \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} `openpyxl` & `numba` & `setuptools` \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{There are many more useful libraries but these are the ones that we know users utilise with PyIPSA} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}