firestudio.studios.simple_studio.SimpleStudio

class firestudio.studios.simple_studio.SimpleStudio(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.Studio

__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_name

  • snapnum (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 to None

  • gas_snapdict (dict, optional) – a dictionary containing SPH data, defaults to None

  • star_snapdict (dict, optional) – a dictionary containing collisionless particle data, defaults to None

  • galaxy_kwargs (dict, optional) – dictionary that contains kwargs that should be passed to the opened abg_python.galaxy.Galaxy instance that is used to load snapshot data from disk, defaults to None

  • master_loud (bool, optional) – flag for enabling/disabling all print statements, defaults to True

  • setup_id_append (str, optional) – suffix to append to the setup_id in 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_

computeFrameBoundaries()

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).

gradientBlendImages(image_1[, image_2, ...])

_summary_

load_SnapshotData([gas_mask, star_mask])

Binds simulation output to self.gas_snapdict and self.star_snapdict.

plotImage(ax, final_image, **kwargs)

Base method for overlaying artists on top of projected image.

prepareCoordinates([snapdict_name, age_max_gyr])

filters coordinates and extracts any necessary field arrays.

print_ImageParams()

Prints the current image parameters.

produceImage([quick, alpha, scale_alpha, ...])

Make a scatter plot rather than do any kind of projection.

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_

set_CacheFile()

Creates the cache hdf5 file.

set_ImageParams([this_setup_id, ...])

Changes the parameters of the image such as camera orientation, frame size, etc.

Attributes

required_snapdict_keys

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.Xmaxself.Ymin, self.Ymaxself.Zmin, self.Zmaxself.npix_x, self.npix_yself.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 1

  • length (float, optional) – _description_, defaults to 10

  • colors (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 True

  • save_meta (bool, optional) – flag to save the result in the cache, defaults to True

  • assert_cached (bool, optional) – flag to require a cache hit and raise an exception otherwise, defaults to False

  • loud (bool, optional) – flag for whether cache hits/misses should be announced to the console, defaults to True

Returns

estimated smoothing lengths

Return type

np.float32 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 None

  • gradient_width_percent (float, optional) – _description_, defaults to 0.1

  • angle (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_snapdict and self.star_snapdict.

Parameters
  • gas_mask (np.ndarray, optional) – boolean mask that should be applied to the galaxy.sub_snap, defaults to None

  • star_mask (np.ndarray, optional) – boolean mask that should be applied to the galaxy.sub_star_snap, defaults to None

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 False

  • del_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.Galaxy if del_galaxy == False, otherwise returns None

Return type

None/abg_python.galaxy.Galaxy object

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

prepareCoordinates(snapdict_name='star', age_max_gyr=14, **extra_kwargs)[source]

filters coordinates and extracts any necessary field arrays.

Parameters
  • snapdict_name (str) – one of gas or star to identify which of self.gas_snapdict or self.star_snapdict to read data from.

  • age_max_gyr (int, optional) – maximum age of star particles to filter in Gyr, defaults to 14

Returns

xs - x coordinates
ys - y coordinates
zs - z coordinates

Return type

np.ndarray, np.ndarray, np.ndarray

print_ImageParams()

Prints the current image parameters.

produceImage(quick=True, alpha='column_density', scale_alpha=0.065, scale_radius=10.0, **kwargs)[source]

Make a scatter plot rather than do any kind of projection.

Parameters
  • quick (bool, optional) – If True do a hackup that mimics a better program, defaults to True

  • alpha (str or float, optional) – Opacity of each scatter point. Either ‘column_density’ for alpha to scale with column density, or a number to apply to all alphas, defaults to 'column_density'

  • scale_alpha (float, optional) – What to scale alpha by. The default value is tuned for displaying ~50,000 particles, defaults to 0.065

  • scale_radius (float, optional) – What to scale the radius by. The default value is tuned for displaying on ~100 kpc scales, defaults to 10

Kwargs
  • snapdict_name (str, optional) – one of gas or star to identify which of self.gas_snapdict or self.star_snapdict to read data from.

  • age_max_gyr (float, optional) – maximum age in Gyr to show stellar emission from. If None then emission from all star particles is considered, defaults to None

Returns

rgb image array

Return type

np.array

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 = ['Coordinates']

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(this_setup_id: Optional[str] = None, use_defaults: bool = False, loud: bool = True, **kwargs)

Changes the parameters of the image such as camera orientation, frame size, etc. If use_defaults=True then default values of the parameters will be set and will overwrite the current state. Leave use_defaults=False to adjust only the keywords passed.

Parameters
  • this_setup_id (str, optional) – string to use to identify this combination of image parameters. If None, then the image parameters are stringified and combined, defaults to None

  • use_defaults (bool, optional) – overwrite current state with default values of each parameter, useful for initialization or resetting after making changes, defaults to False

  • loud (bool, optional) – flag to print which parameters are being set/updated, defaults to True

Kwargs
  • frame_half_thickness (float, optional) – half-thickness of image in z direction, defaults to self.camera.camera_dist

  • aspect_ratio (float, optional) – ratio of number of pixels in each direction determining the shape of image, y/x, defaults to 1

  • pixels (int, optional) – pixels in x direction, resolution of image, defaults to 1200

  • figure_label (str, optional) – string to be put in upper right corner, defaults to ''

  • figure_label_side (str, optional) – side of the image to put label in, defaults to 'right'

  • scale_bar (bool, optional) – flag to plot length scale bar in lower left corner, defaults to True

  • scale_line_length (float, optional) – length of the scale bar in kpc, defaults to 5

  • noaxis (bool, optional) – turns off axis ticks and labels, defaults to True

  • savefig (str, optional) – save the image as a png if passed a string or does not save a figure if None, defaults to None

  • fontsize (int, optional) – fontsize (in pt) of figure label and scale bar text, defaults to 12

  • font_color (str/RGBA tuple, optional) – color of the subtitle font, defaults to 'white'

  • snapdir (str, optional) – path to simulation output

  • snapnum (int, optional) – which snapshot to open/use for naming the cache

  • sim_name (str, optional) – name of simulation (i.e. 'm12i_res7100')

Raises

ValueError – if camera=None is passed explicitly, instead pass an open firestudio.utils.camera_utils.Camera instance

Example usage
studio.set_ImageParams(
    this_setup_id='my_custom_setup',
    scale_bar=False,
    figure_label='high redshift')