rushlight.utils package

Submodules

rushlight.utils.acquire_data module

rushlight.utils.acquire_data.get_hinode_xrt_data(**kwargs)
rushlight.utils.acquire_data.get_sdo_aia_data(start_time=<Time object: scale='utc' format='isot' value=2011-03-07T18:06:04.000>, channel: int = 171, duration: int = 24, jsoc_email=None, **kwargs)

Downloads SDO/AIA data from JSOC database :param start_time: Observations start time :param channel: AIA channel :param duration: Observations duration in seconds :param jsoc_email: email address to access JSOC database :param kwargs: Optional keyword arguments :return:

rushlight.utils.dcube module

class rushlight.utils.dcube.Dcube(dataset=None, output_file=None, **kwargs)

Bases: ABC

rushlight.utils.proj_imag_classified module

class rushlight.utils.proj_imag_classified.SyntheticBandImage(dataset, emin, emax, nbins, emission_model, hint=None, units_override=None, view_settings=None, plot_settings=None, **kwargs)

Bases: object

Class to store synthetic X-ray images generated in a given energy band, such as ones from RHESSI.

make_band_image_field(**kwargs)
class rushlight.utils.proj_imag_classified.SyntheticEnergyRangeImage(dataset=None, smap_path: str = None, smap=None, **kwargs)

Bases: SyntheticImage

For Non-thermal emission, like PyXsim

class rushlight.utils.proj_imag_classified.SyntheticFilterImage(dataset=None, smap_path: str = None, smap=None, **kwargs)

Bases: SyntheticImage

For UV and Soft Xrays

make_filter_image_field()

Selects and applies the correct filter image field to the synthetic dataset

Raises:
  • ValueError – Raised if filter instrument is unrecognized

  • ValueError – Raised if AIA wavelength is not from valid selection (1600, 1700, 4500, 94, 131, 171, 193, 211, 304, 335)

class rushlight.utils.proj_imag_classified.SyntheticImage(dataset=None, smap_path: str = None, smap=None, **kwargs)

Bases: ABC

## Parent class for generating synthetic images using rad_transfer

Contains all of the base functionality necessary for:
  • Setting the positions of the observer and of the feature, relative to the center of the sun

  • Orienting and projecting a 3D dataset according to specified lines of sight

  • Generating synthetic brightness maps based on the selected line of sight

  • Plotting arbitrary points into the same projection plane

Child classes should mainly overload make_filter_image_field to use imaging models compatible with the intended observation wavelength, as well as setting appropriate colormap parameters.

append_synthobj(target=None)

Appends the current synthetic object’s data to an existing dictionary or a new one, then saves it to a file if a file path is provided or creates a new file.

Parameters:

target (str or dict, optional) – The target to append to. Can be a file path (str) to a pickled dictionary, an existing dictionary (dir), or None to start with an empty dictionary.

Returns:

A tuple containing the updated synthetic object dictionary and the target file path.

Return type:

tuple[dict, str]

Raises:

TypeError – If target is not a string, a dictionary, or None.

diff_roll(**kwargs)

Calculate amount to shift image by difference between observed foot midpoint and selected “shift origin”

Returns:

Displacement vector x, y

Return type:

tuple (int , int)

make_filter_image_field(**kwargs)

Selects and applies the correct filter image field to the synthetic dataset

Raises:
  • ValueError – Raised if filter instrument is unrecognized

  • ValueError – Raised if AIA wavelength is not from valid selection (1600, 1700, 4500, 94, 131, 171, 193, 211, 304, 335)

make_synthetic_map(**kwargs)

Creates a synthetic map object that can be loaded/edited with sunpy

Returns:

Synthetic sunpy map created with projected dataset and specified header data

Return type:

sunpy.map.Map

proj_and_imag(**kwargs)

Projects the synthetic dataset and applies image zoom and shift

Parameters:

bkg_fill (float, optional) – Value to fill the background (where image values are less than or equal to 0). If None, the background is not filled.

Notes:

The center position is offset by 0.5 in the y-axis, which is dataset-dependent. Transposes the synthetic image to swap axes for imshow. If self.zoom is set and not equal to 1, the image is zoomed out. If self.image_shift is set, the image is shifted by the specified amounts along the y and x axes, respectively.

project_point(y_points)

Identify pixels where three-dimensional points from the original dataset are projected on the image plane

Parameters:

dataset (YTGridDataset, optional) – Dataset containing 3d coordinates for ypoints, defaults to None

Returns:

x, y – pixels on which the point inside synthetic datacube projects to

save_synthobj()

Saves relevant synthetic object parameters into a dictionary.

This method compiles key information about the synthetic object, including FITS header data from the reference image, loop parameters, and view vectors, into a dictionary. This dictionary is structured for easy identification using a key composed of the telescope and observation date.

Returns:

A dictionary containing the synthetic object’s data, keyed by a string combining the telescope and observation date.

Return type:

dict

scale_factor()

This function will determine a scale factor to use with zoom_out method based on the ratio between the provided observable window scale and the scale of the 3D dataset.

set_loop_params(**kwargs)

Initializes the properties of the CLB loop required to position and orient the MHD cube.

Parameters:
  • pkl (str, optional) – Path to a pickle file containing loop parameters. If provided, other keyword arguments are ignored.

  • radius (float, optional) – Radius of the circular loop. Used if the loop is circular.

  • majax (float, optional) – Semi-major axis of the elliptical loop. Used if the loop is elliptical.

  • minax (float, optional) – Semi-minor axis of the elliptical loop. Used if the loop is elliptical.

  • height (float) – Height of the loop above the reference plane.

  • phi0 (float) – Initial azimuthal angle (longitude) of the loop in degrees.

  • theta0 (float) – Initial polar angle (latitude) of the loop in degrees.

  • el (float) – Elevation angle of the loop’s normal vector in degrees.

  • az (float) – Azimuthal angle of the loop’s normal vector in degrees.

  • samples_num (int) – Number of discrete points used to represent the loop.

Raises:

KeyError – If required parameters are missing and no pickle file is provided.

update_los(norm: unyt_array = None, north: unyt_array = None, **kwargs)

Updates the normal and north vectors for the view settings and regenerates the image.

Parameters:
  • norm (unyt_array, optional) – The new normal vector. If not provided, the current normal vector is retained.

  • north (unyt_array, optional) – The new north vector. If not provided, the current north vector is retained.

Returns:

A tuple containing the updated normal vector and north vector.

Return type:

tuple[unyt_array, unyt_array]

zoom_out(img, scale)

Move the virtual observer away from from the projected dataset

Parameters:
  • img (numpy.ndarray, other) – Array-like object containing pixel brightness values

  • scale (float) – Value indicating the amount of zoom to apply (<1)

Raises:

ValueError – Raised if the zoom parameter is not less than one (can only zoom in)

Returns:

Zoomed and cropped image array

Return type:

numpy.ndarray, other

class rushlight.utils.proj_imag_classified.SyntheticInterferometricImage(dataset=None, smap_path: str = None, smap=None, **kwargs)

Bases: SyntheticImage

For Radio images (CASA)

rushlight.utils.rimage module

class rushlight.utils.rimage.AIAReferenceImage(ref_img_path)

Bases: ReferenceImage

AIA instrument variant of default reference image object

class rushlight.utils.rimage.ReferenceImage(ref_img_path: str = None, **kwargs)

Bases: ABC, MapFactory

Default object for reference image types

class rushlight.utils.rimage.XRTReferenceImage(ref_img_path: str = None)

Bases: ReferenceImage

XRT instrument variant of default reference image object

rushlight.utils.synth_tools module

rushlight.utils.synth_tools.calc_vect(ref_img: NDData, vector_arr: ndarray = None, loop_coords: ndarray = None, **kwargs)

Calculates the north and normal vectors for the synthetic image

Parameters:
  • loop_coords (astropy.coordinates.SkyCoord) – Coordinates of the CLB loop as an array of astropy.coordinates.SkyCoord objects.

  • ref_img (astropy.nddata.NDData) – A reference FITS image or astropy.nddata.NDData object containing coordinate information (observer, obstime, rotation).

  • default (bool, optional) – If True, sets the north vector in the MHD frame to [0, 1, 0], overriding the calculation based on the reference image. Defaults to False.

Returns:

A tuple containing: normvector (numpy.ndarray): The normal vector of the loop plane in the MHD coordinate system, northvector (numpy.ndarray): The north vector of the camera in the MHD coordinate system, ifpd (float): The inter-footpoint distance of the loop in Mm

Return type:

tuple (numpy.ndarray, numpy.ndarray, float)

Note

The MHD coordinate system is defined such that: - The x-axis points from one footpoint of the loop to the other. - The z-axis is normal to the plane defined by the three loop coordinates (v1, v2, v3). - The y-axis completes the right-handed coordinate system.

  • The north vector is derived from the camera pointing information in the

reference image and transformed into the MHD frame. The y-component of the north vector in the MHD frame is inverted by convention.

  • Setting default=True forces the north vector to be aligned with the

y-axis of the MHD frame, which can be useful for specific alignment purposes.

rushlight.utils.synth_tools.code_coords_to_arcsec(code_coord: unyt_array, ref_img: NDData = None, **kwargs)

Converts coordinates in simulated datcube into arcsecond coordinates from the reference image observer.

Parameters:
  • code_coord (unyt_array) – Projected 2D coordinates of synthetic footpoint

  • smap (astropy.nddata.NDData) – Sunpy map object

Returns:

Arcsecond coordinates in observer’s frame of reference

Return type:

SkyCoord

rushlight.utils.synth_tools.coord_projection(data, coord: unyt_array, orientation: Orientation = None, **kwargs)

Reproduces yt plot_modifications _project_coords functionality

Parameters:
  • coord (unyt_array) – Coordinates of the point in the datacube domain

  • orientation (Orientation, optional) – Orientation object calculated from norm / north vector, defaults to None

Returns:

Cooordinates of the projected point from the viewing camera perspective

Return type:

tuple

rushlight.utils.synth_tools.get_loop_coords(loop_params)

Generates Cartesian coordinates for a semi-circular loop based on the provided parameters.

Parameters:

loop_params (dict) – A dictionary containing the parameters defining the loop. Required keys include at least one of ‘radius’ (for circular loops) or ‘majax’ and ‘minax’ (for elliptical loops). Other optional keys are ‘height’, ‘phi0’, ‘theta0’, ‘el’, ‘az’, and ‘samples_num’.

Returns:

An astropy.coordinates.CartesianRepresentation object containing the x, y, and z coordinates of the points defining the semi-circular loop.

Return type:

astropy.coordinates.CartesianRepresentation

rushlight.utils.synth_tools.get_loop_params(loop_params, **kwargs)

Loads or initializes a dictionary of loop parameters.

This function attempts to load loop parameters from either a provided dictionary or a pickle file. If neither is provided or if there’s an error loading, it initializes the parameters using keyword arguments or default values.

Parameters:
  • loop_params (dict or str or None) – Either a dictionary containing loop parameters or a string path to a pickle file containing such a dictionary. If None or loading fails, parameters are initialized from kwargs.

  • kwargs

    Keyword arguments to override default loop parameters. Valid keys include:

    • 'radius' (astropy.units.quantity.Quantity): Radius of the loop. Default: 10.0 Mm.

    • 'majax' (astropy.units.quantity.Quantity): Semi-major axis of the loop. Default: 0.0 Mm.

    • 'minax' (astropy.units.quantity.Quantity): Semi-minor axis of the loop. Default: 0.0 Mm.

    • 'height' (astropy.units.quantity.Quantity): Height of the loop. Default: 0.0 Mm.

    • 'phi0' (astropy.units.quantity.Quantity): Initial azimuthal angle. Default: 0.0 deg.

    • 'theta0' (astropy.units.quantity.Quantity): Initial polar angle. Default: 0.0 deg.

    • 'el' (astropy.units.quantity.Quantity): Elevation angle. Default: 90.0 deg.

    • 'az' (astropy.units.quantity.Quantity): Azimuthal angle. Default: 0.0 deg.

    • 'samples_num' (int): Number of sampling points. Default: 100.

Raises:
  • FileNotFoundError – If loop_params is a string path to a pickle file and the file does not exist.

  • pickle.PickleError – If there is an error during unpickling the loop_params file.

Returns:

A dictionary containing the loop parameters. The keys are: 'majax', 'minax', 'radius', 'height', 'phi0', 'theta0', 'el', 'az', and 'samples_num'.

Return type:

dict

Note

If loop_params is a dictionary, it is used directly, provided it contains the key 'phi0' as a basic check. If it’s a string, it’s assumed to be a path to a pickle file which is loaded. If loop_params is None or if loading the pickle file fails, the function falls back to using the keyword arguments provided in kwargs or their default values.

The function prioritizes loading from loop_params if it’s a valid dictionary or a readable pickle file. Only if this fails are the kwargs and default values used.

rushlight.utils.synth_tools.get_reference_image(smap_path: str = None, smap=None, **kwargs)

Loads a reference SunPy Map object.

Parameters:
  • smap_path (str, optional) – Path to a pickle file containing a SunPy Map object or a path to a standard solar data file (e.g., FITS) that SunPy can read.

  • smap (sunpy.map.Map, optional) – A pre-loaded SunPy Map object. If provided, this takes precedence over smap_path.

  • kwargs – Keyword arguments passed to rimage.ReferenceImage if a default reference image needs to be generated.

Raises:
  • FileNotFoundError – If smap_path is provided but the file does not exist.

  • pickle.PickleError – If smap_path points to a pickle file but there is an error during unpickling.

  • sunpy.io.header.FileError – If smap_path points to a file that SunPy cannot recognize or read.

Returns:

The loaded or generated SunPy Map object.

Return type:

sunpy.map.Map

Module contents