firestudio.studios.star_studio.StarStudio
- class firestudio.studios.star_studio.StarStudio(datadir: str, snapnum: int, sim_name: str, cache_file_name: Optional[str] = None, gas_snapdict: Optional[dict] = None, star_snapdict: Optional[dict] = None, galaxy_kwargs: Optional[dict] = None, master_loud: bool = True, setup_id_append: str = '', **kwargs)[source]
Bases:
firestudio.studios.studio.StudioStudioclass for making mock hubble images with attenuation along the line of sight.- __init__(datadir: str, snapnum: int, sim_name: str, cache_file_name: Optional[str] = None, gas_snapdict: Optional[dict] = None, star_snapdict: Optional[dict] = None, galaxy_kwargs: Optional[dict] = None, master_loud: bool = True, setup_id_append: str = '', **kwargs)
Base class that handles camera manipulation and data caching.
- Parameters
datadir (str) – directory to put intermediate and output files,
'firestudio'is appended if the directory contains sim_namesnapnum (int) – snapshot number (feel free to lie if you aren’t using FIRE_studio to open a snapshot, it is needed for cache file name though)
sim_name (str) – name of the simulation, i.e.
'm12i_res7100'. prepends the cache_file_name if the sim_name isn’t already in the path to disambiguate caches.cache_file_name (str, optional) – the name of the file to save maps to, if None
'proj_maps_%03d.hdf5'%snapnum, defaults toNonegas_snapdict (dict, optional) – a dictionary containing SPH data, defaults to
Nonestar_snapdict (dict, optional) – a dictionary containing collisionless particle data, defaults to
Nonegalaxy_kwargs (dict, optional) – dictionary that contains kwargs that should be passed to the opened
abg_python.galaxy.Galaxyinstance that is used to load snapshot data from disk, defaults toNonemaster_loud (bool, optional) – flag for enabling/disabling all print statements, defaults to True
setup_id_append (str, optional) – suffix to append to the
setup_idin the cache file, defaults to ‘’
Methods
__init__(datadir, snapnum, sim_name[, ...])Base class that handles camera manipulation and data caching.
addScaleBar(image)_summary_
addText(ax)_summary_
Uses the camera to calculate the minimum and maximum x, y, and z limits as well as the physical resolution of the image.
cullFrameIndices(Coordinates)boolean mask of those particles within the volume defined by Xmin-Xmax, Ymin-Ymax, and Zmin-Zmax
drawCoordinateAxes(ax[, spacing, length, colors])_summary_
get_HSML(snapdict_name[, use_metadata, ...])Compute smoothing lengths for particles that don't have them, typically collisionless particles (like stars).
get_mockHubbleImage([use_metadata, ...])Projects starlight and approximates attenuatation along line of sight into SDSS u, g, and r bands.
gradientBlendImages(image_1[, image_2, ...])_summary_
load_SnapshotData([gas_mask, star_mask])Binds simulation output to
self.gas_snapdictandself.star_snapdict.plotImage(ax, final_image, **kwargs)Base method for overlaying artists on top of projected image.
plotParameterGrid([dynrange_init, ...])Plots a grid of images that steps in maxden and dynrange to help the user decide what values to use, based on their aesthetic preference.
predictParameters([left_percentile, ...])Guesses what the "best" values for maxden and dynrange are from the distribution of surface brightnesses in the current image.
prepareCoordinates([lums, nu_effs, BAND_IDS])Reads snapshot data from self.snapdict and self.star_snapdict in the imaging volume defined by self.Xmin,`self.Xmax`,`self.Ymin`,`self.Ymax`,`self.Zmin`,`self.Zmax`.
Prints current image setup to console.
produceImage([quick])Generates a mock hubble image, along with any annotations/scale bars, using the stored image parameters.
quick_get_mockHubbleImage([lums, nu_effs, ...])Approximate the ~firestudio.studios.StarStudio.get_mockHubbleImage routine using a 2d histogram.
render([ax])Generates an image with the produceImage method and then plots it with the plotImage method.
renormalizeTransposeImage(image, min_val, ...)_summary_
saveFigure(fig[, image_name])_summary_
Creates the cache hdf5 file.
set_ImageParams([use_defaults, loud])Changes the parameters of the image.
Attributes
these are minimum required keys for
render()function to run.- addScaleBar(image: numpy.ndarray)
_summary_
- Parameters
image (np.ndarray) – array of RGB image pixel values
- Returns
image
- Return type
np.ndarray
- addText(ax: matplotlib.axes._axes.Axes)
_summary_
- Parameters
ax (plt.Axes) – _description_
- computeFrameBoundaries()
Uses the camera to calculate the minimum and maximum x, y, and z limits as well as the physical resolution of the image.
- Sets following attributes
self.Xmin,self.Xmax–self.Ymin,self.Ymax–self.Zmin,self.Zmax–self.npix_x,self.npix_y–self.Acell–
- cullFrameIndices(Coordinates: numpy.ndarray)
boolean mask of those particles within the volume defined by Xmin-Xmax, Ymin-Ymax, and Zmin-Zmax
- Parameters
Coordinates (np.ndarray) – array of particle coordinates
- Returns
a boolean mask which is True for particles in the extraction volume and False outside.
- Return type
bool np.ndarray
- drawCoordinateAxes(ax: matplotlib.axes._axes.Axes, spacing: float = 1, length: float = 10, colors: Optional[list] = None)
_summary_
- Parameters
ax (plt.Axes) – _description_
spacing (float, optional) – _description_, defaults to
1length (float, optional) – _description_, defaults to
10colors (list, optional) – _description_, defaults to
None
- Returns
_description_
- Return type
_type_
- get_HSML(snapdict_name: str, use_metadata: bool = True, save_meta: bool = True, assert_cached: bool = False, loud: bool = True, **kwargs)
Compute smoothing lengths for particles that don’t have them, typically collisionless particles (like stars).
- Parameters
snapdict_name (str) – string identifying which snapdict should be used to compute smoothing lengths, either
'gas'or'star'use_metadata (bool, optional) – flag for whether a cached result should be used (if it exists), defaults to
Truesave_meta (bool, optional) – flag to save the result in the cache, defaults to
Trueassert_cached (bool, optional) – flag to require a cache hit and raise an exception otherwise, defaults to
Falseloud (bool, optional) – flag for whether cache hits/misses should be announced to the console, defaults to
True
- Returns
estimated smoothing lengths
- Return type
np.float32np.ndarray
- get_mockHubbleImage(use_metadata: bool = True, save_meta: bool = True, assert_cached: bool = False, loud: bool = True, **kwargs)[source]
Projects starlight and approximates attenuatation along line of sight into SDSS u, g, and r bands.
BAND_IDSindexes the following list:lambda_eff = np.array([ ## Bolometric (?) 1.e-5, ## SDSS u g r i z 3551. , 4686. , 6165., 7481., 8931., ## U B V R 3600. , 4400. , 5556., 6940., ## I J H K 8700., 12150., 16540., 21790.])
- Parameters
use_metadata (bool, optional) – flag for whether a cached result should be used (if it exists), defaults to
Truesave_meta (bool, optional) – flag to save the result in the cache, defaults to
Trueassert_cached (bool, optional) – flag to require a cache hit and raise an exception otherwise, defaults to
Falseloud (bool, optional) – flag for whether cache hits/misses should be announced to the console, defaults to
True
- Kwargs
lums (np.ndarray, optional) – array of luminosities for each star particle. If None then luminosities are calculated in the bands specified by
BAND_IDS, defaults toNonenu_effs (list, optional) – list of effective frequencies corresponding to the bands of luminosities provides in the
lums. If None, uses the frequencies corresponding to the specifiedBAND_IDS, defaults toNoneBAND_IDS (list, optional) – List of indices that identify which bands to model stellar emission in. If
Noneuses Sloan UGR bands(1,2,3), defaults toNone
- Returns
metal_mass_map- 2d map of metal mass used to attenuate luminosities along LOS in pixel, in Msun/kpc^2out_0- 2d map of luminosities in first band in Lsun/kpc^2out_1- 2d map of luminosities in second band in Lsun/kpc^2out_2- 2d map of luminosities in third band in Lsun/kpc^2- Return type
np.ndarray, np.ndarray, np.ndarray, np.ndarray
- gradientBlendImages(image_1: numpy.ndarray, image_2: Optional[numpy.ndarray] = None, gradient_width_percent: float = 0.1, angle: Optional[float] = None, **kwargs)
_summary_
- Parameters
image_1 (np.ndarray) – _description_
image_2 (np.ndarray, optional) – _description_, defaults to
Nonegradient_width_percent (float, optional) – _description_, defaults to
0.1angle (float, optional) – _description_, defaults to
None
- Returns
_description_
- Return type
_type_
- load_SnapshotData(gas_mask: Optional[numpy.ndarray] = None, star_mask: Optional[numpy.ndarray] = None, **kwargs)
Binds simulation output to
self.gas_snapdictandself.star_snapdict.- Parameters
gas_mask (np.ndarray, optional) – boolean mask that should be applied to the
galaxy.sub_snap, defaults toNonestar_mask (np.ndarray, optional) – boolean mask that should be applied to the
galaxy.sub_star_snap, defaults toNone
- Kwargs
fuse_saved_subsnapshots (bool, optional) – save/load subsnapshots, uncompressed copies of the snapshot oriented on the main disk with particles within the virial radius. This can take up lots of disk space, defaults to
Falsedel_galaxy (bool, optional) – flag for whether the abg_python.galaxy.gal_utils.Galaxy object should be deleted after being used to get the snapshot dictionaries, defaults to
True
- Returns
abg_python.galaxy.Galaxyifdel_galaxy == False, otherwise returnsNone- Return type
None/abg_python.galaxy.Galaxyobject
- plotImage(ax: matplotlib.axes._axes.Axes, final_image: numpy.ndarray, **kwargs)
Base method for overlaying artists on top of projected image.
if self.scale_bar: overlays a scale bar by filling the RGB pixel values with white if self.noaxis: removes the coordinate axes, labels, and ticks
Will also add self.figure_label as text to the image. See
set_ImageParams()for details.- Parameters
ax (plt.Axes) – axis to plot image to
final_image (np.ndarray) – array of RGB image pixel values
- plotParameterGrid(dynrange_init: float = 100.0, maxden_init: float = 0.01, dynrange_step: Optional[float] = None, maxden_step: Optional[float] = None, nsteps: int = 4, **kwargs)[source]
Plots a grid of images that steps in maxden and dynrange to help the user decide what values to use, based on their aesthetic preference. Step is applied multiplicatively. Accepts keyword arguments for
set_ImageParams()- Parameters
dynrange_init (float, optional) – initial value in top left corner of grid, defaults to
1e2maxden_init (float, optional) – initial value in top left corner of grid, defaults to
1e-2dynrange_step (float, optional) – step between grid thumbnails, defaults to sqrt(10), defaults to
Nonemaxden_step (float, optional) – step between grid thumbnails, defaults to sqrt(10), defaults to
Nonensteps (int, optional) – number of steps in (square) thumbnail grid, defaults to
4
- Returns
fig- the matplotlib figure drawn toaxs- the matplotlib axes in the grid- Return type
plt.figure, list of plt.Axes
- Example usage
starStudio.plotParameterGrid( dynrange_init=1e3, maxden_init=1, dynrange_step=.1, maxden_step=.1, nsteps=2, use_colorscheme_nasa=False)
- predictParameters(left_percentile: float = 0.1, right_percentile: float = 0.99, L_sfc_densities: Optional[numpy.ndarray] = None, ax: Optional[matplotlib.axes._axes.Axes] = None, quick: bool = False)[source]
Guesses what the “best” values for maxden and dynrange are from the distribution of surface brightnesses in the current image. Looks for the left_percentile and right_percentile and returns right_percentile and the distance between it and left_percentile (in log space).
- Parameters
left_percentile (float, optional) – lower bound on image surface brightness percentile, defaults to
0.1right_percentile (float, optional) – upper bound on image surface brightness percentile, defaults to
0.99L_sfc_densities (np.ndarray, optional) – surface densities to find the percentiles of. If
Noneusesget_mockHubbleImage()to retrieve the surface densities of the projected mock hubble image, defaults toNoneax (plt.Axes, optional) – axis to plot distribution of surface brightnesses with overlay of percentiles and such to, defaults to
Nonequick (bool, optional) – flag to use ~firestudio.studios.star_studio.StarStudio.quick_get_mockHubbleImage, defaults to
False
- Returns
maxden- maximum surface brightness of the imagedynrange- distance between maximum and minimum surface brightness in log space.- Return type
float, float
- prepareCoordinates(lums: Optional[numpy.ndarray] = None, nu_effs: Optional[list] = None, BAND_IDS: Optional[list] = None)[source]
Reads snapshot data from self.snapdict and self.star_snapdict in the imaging volume defined by self.Xmin,`self.Xmax`,`self.Ymin`,`self.Ymax`,`self.Zmin`,`self.Zmax`. Unpacks necessary arrays and provides them to the calling imaging routine.
BAND_IDSindexes the following list:lambda_eff = np.array([ ## Bolometric (?) 1.e-5, ## SDSS u g r i z 3551. , 4686. , 6165., 7481., 8931., ## U B V R 3600. , 4400. , 5556., 6940., ## I J H K 8700., 12150., 16540., 21790.])
- Parameters
lums (np.ndarray, optional) – array of luminosities for each star particle. If None then luminosities are calculated in the bands specified by
BAND_IDS, defaults toNonenu_effs (list, optional) – list of effective frequencies corresponding to the bands of luminosities provides in the
lums. If None, uses the frequencies corresponding to the specifiedBAND_IDS, defaults toNoneBAND_IDS (list, optional) – List of indices that identify which bands to model stellar emission in. If
Noneuses Sloan UGR bands(1,2,3), defaults toNone
- Returns
kappas- array of effective cross sections in each bandlums- array of luminosities in each bandstar_pos- coordinate data for emitting stars in kpch_star- effective smoothing length/radius for each star particle in kpcgas_pos- coordinate data for attenuating gas in kpcmgas- mass data for attenuating gas in 10^10 Msungas_metals- total metal mass fraction for each gas particleh_gas- smoothing length/radius for each gas particle in kpc- Return type
np.ndarray(3), np.ndarray(Nstar,3), np.ndarray(Nstar,3), np.ndarray(Ngas), np.ndarray(Ngas,3), np.ndarray(Ngas), np.ndarray(Ngas), np.ndarray(Ngas)
- produceImage(quick: bool = False, **kwargs)[source]
Generates a mock hubble image, along with any annotations/scale bars, using the stored image parameters.
- Parameters
quick (bool, optional) – flag to use a simple 2d histogram (for comparison or for quick iteration as you choose image parameters), defaults to False
- Returns
RGB pixel array of the produced image
- Return type
np.ndarray(npix_x,npix_y,3)
- quick_get_mockHubbleImage(lums: Optional[numpy.ndarray] = None, nu_effs: Optional[list] = None, BAND_IDS: Optional[list] = None, **kwargs)[source]
Approximate the ~firestudio.studios.StarStudio.get_mockHubbleImage routine using a 2d histogram.
BAND_IDSindexes the following list:lambda_eff = np.array([ ## Bolometric (?) 1.e-5, ## SDSS u g r i z 3551. , 4686. , 6165., 7481., 8931., ## U B V R 3600. , 4400. , 5556., 6940., ## I J H K 8700., 12150., 16540., 21790.])
- Parameters
lums (np.ndarray, optional) – array of luminosities for each star particle. If None then luminosities are calculated in the bands specified by
BAND_IDS, defaults toNonenu_effs (list, optional) – list of effective frequencies corresponding to the bands of luminosities provides in the
lums. If None, uses the frequencies corresponding to the specifiedBAND_IDS, defaults toNoneBAND_IDS (list, optional) – List of indices that identify which bands to model stellar emission in. If
Noneuses Sloan UGR bands(1,2,3), defaults toNone
- Returns
metal_mass_map- 2d map of metal mass used to attenuate luminosities along LOS in pixel, in Msun/kpc^2out_0- 2d map of luminosities in first band in Lsun/kpc^2out_1- 2d map of luminosities in second band in Lsun/kpc^2out_2- 2d map of luminosities in third band in Lsun/kpc^2- Return type
np.ndarray, np.ndarray, np.ndarray, np.ndarray
- render(ax: Optional[matplotlib.axes._axes.Axes] = None, **kwargs)
Generates an image with the produceImage method and then plots it with the plotImage method.
- Parameters
ax (plt.Axes, optional) – axis to plot image to, if None will create a new figure, defaults to
None- Returns
ax – the axis the image was plotted to final_image – Npixels x Npixels x 3 RGB pixel array
- Return type
plt.Axes, np.ndarray
- renormalizeTransposeImage(image: numpy.ndarray, min_val: float, max_val: float, quantity_name: str)
_summary_
- Parameters
image (np.ndarray) – _description_
min_val (float) – _description_
max_val (float) – _description_
quantity_name (str) – _description_
- Returns
_description_
- Return type
_type_
- required_snapdict_keys = ['Masses', 'Coordinates', 'SmoothingLength', 'Temperature', 'AgeGyr', 'Metallicity']
these are minimum required keys for
render()function to run.
- saveFigure(fig, image_name: Optional[str] = None, **savefig_args)
_summary_
- Parameters
fig (_type_) – _description_
image_name (str, optional) – _description_, defaults to
None
- set_CacheFile()
Creates the cache hdf5 file. Requires self.snapnum and sim_name be set.
- Raises
IOError – if self.snapnum and self.sim_name are not set to disambiguate the cache file
- Returns
cache file for storing image maps
- Return type
abg_python.galaxy.metadata_utils.Metadata
- set_ImageParams(use_defaults: bool = False, loud: bool = True, **kwargs)[source]
Changes the parameters of the image. Also calls
Studio’sset_ImageParams(), passing along any unmatched kwargs.- Parameters
use_defaults (bool, optional) – If
Truethen default values of the parameters will be set (potentially overwriting any previously specified parameters). IfFalseadjust only the keywords passed, defaults toFalseloud (bool, optional) – flag to print which parameters are being set/updated, defaults to
True
- Kwargs
maxden (float, optional) – controls the saturation of the image, sets the upper limit of the “colorbar” if
Noneuses the 99 %’ile of the image surface brightness, defaults toNonedynrange (float, optional) – controls the saturation of the image, sets the lower limit of the “colorbar” with respect to maxden, if None uses the dynamic range between maxden and the 10th %’ile of the image surface brightness, defaults to
Nonenodust (bool, optional) – flag for whether dust attenuantion should be ignored, defaults to
Falseage_max_gyr (float, optional) – maximum age in Gyr to show stellar emission from. If
Nonethen emission from all star particles is considered, defaults toNonecolor_scheme_nasa (bool, optional) – flag for switching between Hubble vs. SDSS false color remapping, defaults to
True
- Example usage
starStudio.set_ImageParams( maxden=0.1, dynrange=10, figure_label='Hubble')