def _run_xfoil( self, run_command: str, ) -> Dict[str, np.ndarray]: """ Private function to run XFoil. Args: run_command: A string with any XFoil keystroke inputs that you'd like. By default, you start off within the OPER menu. All of the inputs indicated in the constructor have been set already, but you can override them here (for this run only) if you want. Returns: A dictionary containing all converged solutions obtained with your inputs. """ # Set up a temporary directory with tempfile.TemporaryDirectory() as directory: directory = Path(directory) ### Alternatively, work in another directory: if self.working_directory is not None: directory = Path(self.working_directory) # For debugging # Designate an intermediate file for file I/O output_filename = "output.txt" # Handle the airfoil file airfoil_file = "airfoil.dat" self.airfoil.write_dat(directory / airfoil_file) # Handle the keystroke file keystroke_file_contents = self._default_keystroke_file_contents() keystroke_file_contents += [run_command] keystroke_file_contents += [ "pwrt", f"{output_filename}", "y", "", "quit" ] keystroke_file = "keystroke_file.txt" with open(directory / keystroke_file, "w+") as f: f.write("\n".join(keystroke_file_contents)) ### Set up the run command command = f'{self.xfoil_command} {airfoil_file} < {keystroke_file}' ### Execute subprocess.call( command, shell=True, cwd=directory, stdout=None if self.verbose else subprocess.DEVNULL) ### Parse the polar columns = [ "alpha", "CL", "CD", "CDp", "CM", "xtr_upper", "xtr_lower" ] with warnings.catch_warnings(): warnings.simplefilter("ignore") output_data = np.genfromtxt( directory / output_filename, skip_header=12, usecols=np.arange(len(columns))).reshape(-1, len(columns)) has_valid_inputs = len(output_data) != 0 return { k: output_data[:, index] if has_valid_inputs else np.array([]) for index, k in enumerate(columns) }
""" return winds_95_world_model({ "altitude" : altitude, "latitude" : latitude, "day of year": day_of_year }) ### Prep data for tropopause altitude function # Import data latitudes_trop = np.linspace(-80, 80, 50) day_of_year_trop_boundaries = np.linspace(0, 365, 13) day_of_year_trop = (day_of_year_trop_boundaries[1:] + day_of_year_trop_boundaries[:-1]) / 2 tropopause_altitude_km = np.genfromtxt( root / "datasets" / "winds_and_tropopause_global" / "strat-height-monthly.csv", delimiter="," ) # Extend boundaries extend_bounds = 3 day_of_year_trop = np.hstack(( day_of_year_trop[-extend_bounds:] - 365, day_of_year_trop, day_of_year_trop[:extend_bounds] + 365 )) tropopause_altitude_km = np.hstack(( tropopause_altitude_km[:, -extend_bounds:], tropopause_altitude_km, tropopause_altitude_km[:, :extend_bounds] ))