def run_starburst(self, run_SB99=True): """ Method to run the starburst model. Simply calls the function "run_starburst" defined below. """ output_data = sb.out_data(self.model_name) output_data = run_starburst(self, run_SB99=run_SB99) return output_data
def run_starburst(input_param, run_SB99=True): """ This is where the work happens. SbInput object must be passed in. Organized as follows: 1. Write input parameters to file. 2. Run Starburst99. 3. Read output files written by Starburst99. Convert to hdf5 if necessary. [Not implemented yet.] """ output_data = sb.out_data(input_param.model_name) """ Step 1 """ output_dir = sb.indata.output_dir file_name = input_param.model_name + '_input.txt' full_name = os.path.join(output_dir, file_name) if os.path.exists(full_name): os.remove(full_name) if input_param.outputs['input']: sb.write_input_txt(input_param, full_name) """ Step 2 """ if run_SB99: file_name = input_param.model_name + '.input' full_name = os.path.join(output_dir, file_name) sb.write_input_original(input_param, full_name) output_data.data, output_data.headers = run_original_SB99( input_param.model_name) """ Step 3 """ return output_data
def read_data_files(self, model_name=None, output_dir=None): """ Method for reading in Starburst99 output. This can be used to load existing data. """ if model_name is None: model_name = self.model_name if output_dir is None: output_dir = self.output_dir self.data, self.headers = sb.read_output_data(model_name=model_name, output_dir=output_dir)
def __init__(self, model_name, chatter=2): """ Creates starburst input object. - A model name is required. - Optional: chatter, this controls how much output is printed to stdout. chatter = 0 : No output chatter = 1 : Only errors chatter = 2 : Errors and warnings [default] chatter = 3 : Errors, warnings, and messages """ self.model_name = model_name self.sb_messages = sb.sb_messages(chatter=chatter) self.init_default()
import StarburstPy as sb import numpy as np import matplotlib.pyplot as plt import matplotlib as mpl mpl.rcParams['font.size'] = 18 datapaths = sb.indata datapaths.output_dir = '../sboutput/sfr' model_name_base = 'happy' sfrrange = np.logspace(1, 2, num=10) y = [] for sfr in sfrrange: model_name = model_name_base + '{0}'.format(int(sfr)) output_data = sb.out_data(model_name) output_data.data, output_data.headers = sb.read_output_data( model_name=model_name, output_dir=datapaths.output_dir) data = output_data.data x = data['power']['Time'] / 1e6 y.append(10**data['power']['Power_All']) fig = plt.figure(figsize=(12, 8)) ax1 = fig.add_subplot(111) for i in range(10): ax1.semilogy(x, y[i], label='SFR {0}'.format(int(sfrrange[i])), linewidth=5)
def run_original_SB99(model_name): """ Runs the original Fortran77 code of Starburst99. Creates a 'go_galaxy.sh' script to run the code. This is the same script that comes with the code. Output directory and Starburst99 directory need to be set previously in sb.indata.output_dir and sb.indata.SB99_dir respectively. """ output_dir = sb.indata.output_dir rel_path = os.path.relpath(sb.indata.SB99_dir, output_dir) file_name = model_name + '.input' full_name = os.path.join(output_dir, file_name) if not os.path.exists(full_name): sb.sb_mess.error( 'Input File does not exist in {0}.'.format(output_dir), 'run_original_SB99') run_file = os.path.join(output_dir, 'go_galaxy.sh') if os.path.exists(run_file): os.remove(run_file) if not os.path.exists(os.path.join(sb.indata.SB99_dir, 'galaxy')): sb.sb_mess.error( 'Starburst99 exacutable not found in {0} directory.'.format( sb.indata.SB99_dir), 'run_original_SB99') f = open(run_file, 'w') lines = [ '#! /bin/csh -f\n', '# -----------------------------------------\n', '# UNIX Script to run galaxy code\n', '# -----------------------------------------\n', '#\n', '# Usage: 1) Edit six user-defined quantities found below\n', '# 2) Run code with \'nice go_galaxy &\' --> output in \'time_used\'\n', '# -----------------------------------------------------------------------\n', '# Six user-defined quantities:\n', '# Directory where the run is made (=directory of this file):\n', 'set drun={0}\n'.format(output_dir), '# Name of input file:\n', 'set ninput={0}\n'.format(model_name + '.input'), '# Name and extension number of output files:\n', '# --> files will be: noutput.colornext, noutput.quantnext etc.\n', 'set noutput={0}\n'.format(model_name), 'set next=1\n', '# Directory where code is:\n', 'set dcode={0}\n'.format(rel_path), '# Name of code: \n', 'set ncode=galaxy\n', '# Directory where libraries are:\n', 'set dlib={0}\n'.format(rel_path), '#- - - - - - - DO NOT MODIFY below this line - - - - - - - - - - - - - -\n', '\n', 'cd $drun\n', '# A) Create links (assign) to directories with input files\n', ' # Tracks + Spectral type calibration:\n', 'if (!(-e tracks)) ln -s $dlib/tracks/ tracks\n', ' # Atmosphere models:\n', 'if (!(-e lejeune)) ln -s $dlib/lejeune/ lejeune\n', ' # Spectral libraries:\n', 'if (!(-e auxil)) ln -s $dlib/auxil/ auxil\n', '\n', '# B) Link input file, RUN code, and save output data\n', 'echo "Job on `hostname` started at `date`" >time_used\n', 'echo " ">>time_used\n', '\n', 'if (-e fort.1) /bin/rm fort.1\n', 'if (-e $ninput) ln -s $ninput fort.1\n', '(/usr/bin/time $dcode/$ncode) >>& time_used\n', 'echo " ">>time_used\n', ' \n', '$dcode/save_output $noutput $next >>time_used\n', 'echo "Done at `date`" >>time_used\n' ] f.writelines(lines) f.close() subprocess.call(['/bin/csh', '-c', run_file]) data, headers = sb.read_output_data(model_name=model_name, output_dir=output_dir) return data, headers
# Sets path links to current directory, output directory, and the directory where # the Starburst99 fortran code is compiled. Defaults set to current directory. datapaths = sb.indata datapaths.output_dir = './sboutput' datapaths.SB99_dir = '../../starburst99' # A model name must be passed in to make the input object. model_name = 'happy' # The input object "sbinput" contains all the input parameters and methods for # setting all parameters, and a method for running Starburst99. # If just the model name is given then the default parameters are set to the # defaults from the Starburst99 webpage. sbinput = sb.SbInput(model_name) # Method for running Starburst99 based on input parameters that have been set. output_data = sbinput.run_starburst() # Data from Starburst99 is in # output_data.data # # Headers from the output files are found in # output_data.headers # # See run_sbpy_all_options.py for examples of all possible input parameters.
Try run_sbpy_simp.py. Only the most common parameters are shown in that example script. Author: Ryan Tanner email: [email protected] """ datapaths = sb.indata datapaths.output_dir = './sboutput' datapaths.SB99_dir = '../../starburst99' model_name = 'happy' sbinput = sb.SbInput(model_name, rank = 3) sbinput.set_star_formation(fixed_mass = False, SFR = 1.0) sbinput.set_star_formation(fixed_mass = True, total_mass = 1e6) sbinput.set_IMF(IMF = 'Salpeter') sbinput.set_IMF(IMF = 'Kroupa') sbinput.set_IMF(IMF_exp = [1.3,2.3], IMF_bound = [0.1, 0.5, 120.0], mass_lo = 0.1, mass_hi = 120.0) sbinput.set_SN_cut_off(lo_mass = 8.0, hi_mass = 120.0) sbinput.set_evolve_track(track = 'Genevav40', Z = 0.002) sbinput.set_wind_model(wind = 'Evolution') sbinput.set_time(start_time = 0, end_time = 1e8, log_scale = True, nsteps = 2000)
# -*- coding: utf-8 -*- """ A script to run multiple Starburst99 models. Runs 10 models with continuous star formation with SFR from 1.0 to 100.0 spaced logarithmically. Author: Ryan Tanner email: [email protected] """ import StarburstPy as sb import numpy as np datapaths = sb.indata datapaths.output_dir = '../sboutput/sfr' datapaths.SB99_dir = '../../starburst99' model_name = 'happy' sbinput = sb.SbInput('happy', chatter = 2) sbinput.set_time(start_time = 0, end_time = 1e7, log_scale = False, dt = 1e5) sbinput.set_output(out_type = 'original') sfrrange = np.logspace(1,2,num=10) for sfr in sfrrange: sbinput.set_model_name(model_name = model_name+'{0}'.format(int(sfr))) sbinput.set_star_formation(fixed_mass = False, SFR = sfr) print(model_name+'{0}'.format(int(sfr))) output_data = sbinput.run_starburst()