@@ -2065,3 +2065,87 @@ def FF_slurm_submit(self, qos='normal', A=None, t=None, delay=4):
20652065 time .sleep (delay ) # Sometimes the same job gets submitted twice. This gets around it.
20662066
20672067
2068+
2069+
2070+
2071+ def plot (self , figsize = (15 ,7 ), fontsize = 14 , saveFig = True , returnFig = False ):
2072+ import matplotlib .pyplot as plt
2073+
2074+ fig , ax = plt .subplots (figsize = figsize )
2075+
2076+ # for plotting different inflow angles
2077+ alphas = np .append (1 , np .linspace (0.5 ,0.2 , len (self .wts_rot_ds ['inflow_deg' ])- 1 ))
2078+
2079+ # low-res box
2080+ try :
2081+ ax .plot ([self .TSlowbox .xmin , self .TSlowbox .xmax , self .TSlowbox .xmax , self .TSlowbox .xmin , self .TSlowbox .xmin ],
2082+ [self .TSlowbox .ymin , self .TSlowbox .ymin , self .TSlowbox .ymax , self .TSlowbox .ymax , self .TSlowbox .ymin ],'--k' ,lw = 2 ,label = 'Low' )
2083+ except AttributeError :
2084+ print (f'WARNING: The exact limits of the low-res box have not been computed yet. Showing extents given as inputs' )
2085+ xmin = self .allCases ['Tx' ].min ()- self .extent_low [0 ]* self .D
2086+ xmax = self .allCases ['Tx' ].max ()+ self .extent_low [1 ]* self .D
2087+ ymin = self .allCases ['Ty' ].min ()- self .extent_low [2 ]* self .D
2088+ ymax = self .allCases ['Ty' ].max ()+ self .extent_low [3 ]* self .D
2089+ ax .plot ([xmin , xmax , xmax , xmin , xmin ],
2090+ [ymin , ymin , ymax , ymax , ymin ],'--k' ,lw = 2 ,label = 'Low' )
2091+
2092+
2093+ for j , inflow in enumerate (self .wts_rot_ds ['inflow_deg' ]):
2094+ ax .set_prop_cycle (None ) # Reset the colormap for every inflow
2095+ for i , currTurbine in enumerate (self .wts_rot_ds .turbine ):
2096+ color = next (ax ._get_lines .prop_cycler )['color' ]
2097+
2098+ dst = self .wts_rot_ds .sel (turbine = currTurbine , inflow_deg = inflow )
2099+
2100+ # plot high-res boxes
2101+ xmin , xmax = [dst .x - self .extent_high * dst .D / 2 , dst .x + self .extent_high * dst .D / 2 ]
2102+ ymin , ymax = [dst .y - self .extent_high * dst .D / 2 , dst .y + self .extent_high * dst .D / 2 ]
2103+ # Only add label entry on first (darker) curves
2104+ if j == 0 :
2105+ ax .plot ([xmin , xmax , xmax , xmin , xmin ],
2106+ [ymin , ymin , ymax , ymax , ymin ], c = color , alpha = alphas [j ], label = f'HighT{ i + 1 } ' )
2107+ else :
2108+ ax .plot ([xmin , xmax , xmax , xmin , xmin ],
2109+ [ymin , ymin , ymax , ymax , ymin ], c = color , alpha = alphas [j ])
2110+
2111+ # plot turbine location
2112+ ax .scatter (dst .x , dst .y , s = dst .D / 6 , c = color , marker = 'o' ) #, label=f'WT{i+1}')
2113+
2114+ # plot turbine disk accoding to all yaws in current wdir
2115+ allyaw_currwdir = self .allCases .where (self .allCases ['inflow_deg' ]== inflow ,drop = True ).sel (turbine = currTurbine )['yaw' ]
2116+ _ , ind = np .unique (allyaw_currwdir , axis = 0 , return_index = True )
2117+ yaw_currwdir = allyaw_currwdir [np .sort (ind )].values # duplicates removed, same order as original array
2118+ for yaw in yaw_currwdir :
2119+ ax .plot ([dst .x .values - (dst .D .values / 2 )* sind (yaw - inflow .values ), dst .x .values + (dst .D .values / 2 )* sind (yaw - inflow .values )],
2120+ [dst .y .values - (dst .D .values / 2 )* cosd (yaw - inflow .values ), dst .y .values + (dst .D .values / 2 )* cosd (yaw - inflow .values )], c = color , alpha = alphas [j ])
2121+
2122+ # plot convex hull of farm (or line) for given inflow
2123+ turbs = self .wts_rot_ds .sel (inflow_deg = inflow )[['x' ,'y' ]].to_array ().transpose ()
2124+ try :
2125+ hull = ConvexHull (turbs )
2126+ for simplex in hull .simplices :
2127+ ax .plot (turbs [simplex , 0 ], turbs [simplex , 1 ], 'gray' , alpha = alphas [j ], label = f'Inflow { inflow .values } deg' )
2128+ except :
2129+ # All turbines are in a line. Plotting a line instead of convex hull
2130+ ax .plot (turbs [:,0 ], turbs [:,1 ], 'gray' , alpha = alphas [j ], label = f'Inflow { inflow .values } deg' )
2131+
2132+
2133+ # Remove duplicate entries from legend
2134+ handles , labels = plt .gca ().get_legend_handles_labels ()
2135+ by_label = dict (zip (labels , handles ))
2136+ plt .legend (by_label .values (), by_label .keys (), loc = 'upper left' , bbox_to_anchor = (1.02 ,1.015 ), fontsize = fontsize )
2137+
2138+ ax .set_xlabel ("x [m]" , fontsize = fontsize )
2139+ ax .set_ylabel ("y [m]" , fontsize = fontsize )
2140+ ax .tick_params (axis = 'both' , which = 'major' , labelsize = fontsize )
2141+ ax .grid ()
2142+ ax .set_aspect ('equal' )
2143+
2144+ if saveFig :
2145+ fig .savefig (os .path .join (self .path ,'farm.png' ), bbox_inches = 'tight' , facecolor = 'white' , transparent = False )
2146+
2147+ if returnFig :
2148+ return fig , ax
2149+
2150+
2151+
0 commit comments