def writeBroadBands(inFilePaths, outFilePaths): # loop over all builtin bands for name in bnd.builtinBandNames(): band = bnd.BroadBand(name) # construct the output file path based on the band ID outFilePath = outFilePaths[0].replace("*",name) # get the transmission curve w, T = band.transmissionCurve() # write stored table stab.writeStoredTable(outFilePath, ['lambda'], ['m'], ['lin'], [w.to_value(u.m)], ['T'], ['1'], ['lin'], [T.to_value(u.m**(-1))])
def do() -> "list all built-in broadbands": import logging import pts.band as bnd # load all bands bands = [bnd.BroadBand(name) for name in bnd.builtinBandNames()] logging.info("There are {} built-in bands:".format(len(bands))) # sort them on pivot wavelength within each band family bands = sorted(bands, key=bnd.BroadBand.pivotWavelength) bands = sorted(bands, key=lambda b: b.name().split('_')[0]) # list band info logging.info("| Band name | Pivot wavelength") logging.info("|--------------------|-----------------") for band in bands: logging.info("| {:18s} | {:1.5g}".format(band.name(), band.pivotWavelength())) logging.info("|--------------------|-----------------")
def do( simDirPath: (str, "SKIRT simulation output directory"), prefix: (str, "SKIRT simulation prefix") = "", type: (str, "type of SKIRT instrument output files to be handled") = "total", name: (str, "name segment that will be added to the image file names") = "", colors: (str, "three comma-separated wavelength values or broadband names defining the R,G,B colors" ) = "", ) -> "create RGB images for surface brightness maps generated by SKIRT instruments": import pts.band as bnd import pts.simulation as sm import pts.utils as ut import pts.visual as vis # get the simulations to be handled sims = sm.createSimulations(simDirPath, prefix if len(prefix) > 0 else None) # parse the colors and handle accordingly # no colors given if len(colors) == 0: if len(name) > 0: raise ut.UserError( "name argument is not supported when colors are not specified") for sim in sims: vis.makeRGBImages(sim, fileType=type) return # get segments segments = colors.split(',') if len(segments) != 3: raise ut.UserError( "colors argument must have three comma-separated segments") # try wavelengths try: wavelengths = [float(segment) for segment in segments] except ValueError: wavelengths = None if wavelengths is not None: tuples = {name: wavelengths << sm.unit("micron")} for sim in sims: vis.makeRGBImages(sim, wavelengthTuples=tuples, fileType=type) return # try bands try: bands = [bnd.BroadBand(segment) for segment in segments] except ValueError: bands = None if bands is not None: contributions = [(bands[0], 1, 0, 0), (bands[1], 0, 1, 0), (bands[1], 0, 0, 1)] for sim in sims: vis.makeConvolvedRGBImages(sim, contributions=contributions, fileType=type, name=name) return raise ut.UserError( "colors argument must specify three wavelengths in micron or three broadband names" )
def plotBuiltinBands(minWavelength=1e-6 * u.micron, maxWavelength=1e6 * u.micron, nameSegments=None, *, outDirPath=None, outFileName=None, outFilePath=None, figSize=(20, 6), interactive=None): # load all bands that satisfy the specified criteria bands = [bnd.BroadBand(name) for name in bnd.builtinBandNames()] bands = [ band for band in bands if minWavelength <= band.pivotWavelength() <= maxWavelength ] if nameSegments is not None: if isinstance(nameSegments, str): nameSegments = [nameSegments] bands = [ band for band in bands if any([ s.lower() in band.name().lower().split("_") for s in nameSegments ]) ] # sort the remaining bands on pivot wavelength bands = sorted(bands, key=bnd.BroadBand.pivotWavelength) logging.info("Plotting {} built-in bands...".format(len(bands))) # setup the figure plt.figure(figsize=figSize) colors = ('r', 'g', 'b', 'c', 'm', 'y') # loop over bands labelpos = 0.25 colorindex = 0 for band in bands: wavelengths, transmissions = band.transmissionCurve() wavelengths <<= u.micron # convert to micron transmissions /= transmissions.max() # normalize to a maximum of 1 plt.plot(wavelengths.value, transmissions.value, color=colors[colorindex]) labelpos += 0.05 if labelpos > 0.69: labelpos = 0.25 plt.text(band.pivotWavelength().to_value(wavelengths.unit), labelpos, band.name(), horizontalalignment='center', fontsize='x-small', color=colors[colorindex], backgroundcolor='w') colorindex = (colorindex + 1) % len(colors) # set axis details plt.xscale('log') plt.grid(True, axis='y') # add axis labels and a legend plt.xlabel(r"$\lambda$" + sm.latexForUnit(wavelengths), fontsize='large') plt.ylabel("Transmission", fontsize='large') # if not in interactive mode, save the figure; otherwise leave it open if not ut.interactive(interactive): saveFilePath = ut.savePath("FigBuiltinBands.pdf", (".pdf", ".png"), outDirPath=outDirPath, outFileName=outFileName, outFilePath=outFilePath) plt.savefig(saveFilePath, bbox_inches='tight', pad_inches=0.25) plt.close() logging.info("Created {}".format(saveFilePath))
parser.add_argument("--galaxy") # name of galaxy args = parser.parse_args() galaxy = args.galaxy colors = "SDSS_Z,SDSS_R,SDSS_G" #colors = "PACS_100,SDSS_R,GALEX_NUV" name = "custom_image" type = "total" path = '/scratch/ntf229/RT_fit/resources/SKIRT/'+galaxy+'/maxLevel13/wavelengths601/numPhotons1e9/inc0/dust/dustFraction0.2/maxTemp16000/' os.chdir(path) # get the simulations to be handled sims = sm.createSimulations(path, None) # get segments segments = colors.split(',') if len(segments) != 3: raise ut.UserError("colors argument must have three comma-separated segments") bands = [ bnd.BroadBand(segment) for segment in segments ] #contributions = [ (bands[0], 1, 0, 0), (bands[1], 0, 1, 0), (bands[1], 0, 0, 1) ] # original contributions = [ (bands[0], 1, 0, 0), (bands[1], 0, 1, 0), (bands[2], 0, 0, 1) ] # altered from original for sim in sims: #vis.makeConvolvedRGBImages(sim, contributions=contributions, fileType=type, name=name, decades=6) makeConvolvedRGBImages(sim, contributions=contributions, fileType=type, name=name, decades=6) os.system("mv sph_i00_total_custom_image.png "+image_path+galaxy+"_image.png") print('made it to the end')