ISPy.util package

Submodules

ISPy.util.azimuth module

ISPy.util.azimuth.BQBU2BTAZI(BQ, BU)

Transformation from BQ and BU to transverse field and azimuth according to https://arxiv.org/abs/1904.03714

Parameters:

BQ, BU (float) – Values to be transformed

ISPy.util.azimuth.BQBU2BTAZI_cube(model_BQ, model_BU)

Transformation from BQ and BU to transverse field and azimuth for a 2D cube array.

ISPy.util.azimuth.BTAZI2BQBU(Bt, azi)

Transformation from transverse field and azimuth to BQ and BU according to https://arxiv.org/abs/1904.03714

Parameters:

Bt, azi (float) – Values to be transformed

ISPy.util.azimuth.BTAZI2BQBU_cube(model_Bho, model_azi)

Transformation from transverse field and azimuth to BQ and BU for a 2D cube array.

ISPy.util.cubeshow module

ISPy.util.cubeshow.animate_cube(cube_array, name=None, show=True, cut=True, mn=0, sd=0, interval=75, cmap='gray', fps=20)

Animates a python cube for quick visualisation and saves mp4.

Parameters:
  • cube_array (3D array[t,x,y]) – The array to be animated.

  • name (bool, optional) – name of file to save, must end with .mp4. Will not save if not used. Default = None

  • show (bool, optional) – Wheather or not to display animation. Default = True.

  • cut (int, optional) – trims pixels off of the images edge to remove edge detector effects. Default = True as 0 returns empty array.

  • mn (float, optional) – mean value to used for contrast. Default=0

  • sd (float, optional) – Std value to used for contrast. Default=0

  • interval (int, optional) – #of ms between each frame. Default=75

  • cmap (str, optional) – colormap used for animation. Default=’gray’

  • fps (float, optional) – frames per second. Default = 20

Return type:

Video file if name is given.

Example

from ISPy.util import cubeshow as cs

a = np.random.random([90,100,100]) cs.animate_cube(a, ‘video.mp4’,cut=20,interval=100)

Authors:

Alex Pietrow (ISP-SU 2021)

ISPy.util.cubeshow.plotall(cube_array, fignum=array([4, 6]), title='Title', save=False)

Plot a 3D cube into a subplot array

Parameters:
  • cube_array (3D array[t,x,y]) – The array to be animated.

  • fignum (2D array) – Number of subplots. Default = np.array([4,6])

  • title (str, optional) – Title of plot, defealt=’Title’

  • save (bool, optional) – Saves output to file named after title. Default = False

Example

a = np.random.random([9,100,100]) plotall(a, fignum=np.array([3,3]), title=’test’,save=1)

Authors:

Alex Pietrow (ISP-SU 2021)

ISPy.util.find module

Convenience wrappers around glob.glob() to list common file types.

ISPy.util.find.cube(path='./', pattern='', verbose=True)

Convenience wrapper around find.files to get *.cube files

ISPy.util.find.files(extension, path='./', pattern='', verbose=True)

Find files with certain pattern and extension in specified path.

Parameters:
  • extension (str) – extension of the files to list, excluding ‘.’ marker.

  • path (str, optional) – path to directory to search in (default ‘./’)

  • pattern (str, optional) – pattern in filenames to filter on (default ‘’)

  • verbose (bool, optional) – verbosity switch controlling printout of search results (default True)

Returns:

lsfiles – A list with absolute paths to the files found.

Return type:

list

Example

>>> f = find.files('fits', path='~/Desktop', pattern='aia304')
Author:

Gregal Vissers (ISP/SU 2019)

ISPy.util.find.fits(path='./', pattern='', verbose=True)

Convenience wrapper around find.files to get *.fits files

ISPy.util.find.idlsave(path='./', pattern='', verbose=True)

Convenience wrapper around find.files to get *.idlsave files

ISPy.util.find.nc(path='./', pattern='', verbose=True)

Convenience wrapper around find.files to get *.nc files

ISPy.util.gentools module

ISPy.util.gentools.findclose(value, array)

Finds the index of the closest value in array

Parameters:
  • value (float) – value we want to find

  • array (ndarray) – array with values where we want to search

  • Authors: – Carlos Diaz (ISP/SU 2020)

ISPy.util.gentools.findindex(array1, array2)

Outputs an array with the indices of the closes element in array2 for each element in array1

Parameters:
  • array1 (ndarray) – Array with values that we want to find

  • array2 (ndarray) – Array with values where we want to search

  • Authors: – Carlos Diaz (ISP/SU 2020)

ISPy.util.gentools.rotate_cube(cube, angle_index)

Rotate a cube with dim=[x,y,z] a multiple of 90 degrees in plane x,y

Parameters:
  • cube (3D ndarray) – Array with values to rotate

  • angle_index (int) – Times to rotate 90 degrees the cube

  • Authors: – Carlos Diaz (ISP/SU 2020)

ISPy.util.lineplot module

ISPy.util.neural_estimation module

ISPy.util.obs module

ISPy.util.obs.viewangle(xy, date=None, heliographic=False, r_sun=960.469)

Return the viewing angle theta (and mu = cos(theta)) given a set of solar coordinates in the helioprojective or heliographic Stonyhurst system

Parameters:
  • xy (array_like) – 2-element list or array with the coordinate values (in arcsec if helioprojective, in degrees if heliographic)

  • date (str, optional) – date for which to get the viewing angle (default: today’s date)

  • heliographic (bool, optional) – switch to indicate input coordinates are heliographic Stonyhurst (default False, i.e. coordinates are helioprojective)

  • r_sun (float, optional) – Define solar radius in arcseconds. Defeault is average radius (960.469)

Returns:

viewangle – 2-element list with [theta, mu]. Theta is given in degrees.

Return type:

list

Example

>>> from ISPy.util import obs
>>> result = obs.viewangle([240,-380], date='2017-08-02')
>>> result = obs.viewangle([30,-50], date='2019-01-12', heliographic=True) # S50 W30
Author:

Gregal Vissers (ISP/SU 2019)

ISPy.util.plottools module

class ISPy.util.plottools.MidpointNormalize(vmin=None, vmax=None, midpoint=None, clip=False)

Bases: Normalize

ISPy.util.plottools.add_colorbar(im, aspect=20, pad_fraction=0.5, **kwargs)

Add a vertical color bar to an image plot

ISPy.util.plottools.make_colormap(seq)

ISPy.util.rebin module

ISPy.util.rebin.avg1D(xdata, ydata, nbin)

Rebin 1D arrays into nbin bins by averaging

Parameters:
  • xdata (array_like) – 1D array with abcissa

  • ydata (array_like) – 1D array with ordinate

  • nbin (int) – number of bins

Returns:

xbin, ybin – rebinned 1D arrays

Return type:

array_like

Example

>>> xbin, ybin = avg1D(xdata, ydata, 5)
Author:

Rahul Yadav (ISP/SU 2019)

ISPy.util.rebin.avg2D(data, nbin)

Rebin a 2D array into nbin bins by averaging

Parameters:
  • data (ndarray) – a 2D array

  • nbin (int) – number of bins

Returns:

rebin – rebinned 2D array

Return type:

ndarray

Example

>>> databin = avg2D(data, 10)
Author:

Rahul Yadav (ISP/SU 2019)

ISPy.util.remap module

ISPy.util.remap.bvec2cea(dict_header, field_x, field_y, field_z)

Transformation to Cylindrical equal area projection (CEA) from CCD detector as it is donde with SHARPs according to Xudong Sun (2018).

Parameters:
  • field_x, field_y, field_z (array) – 2D array with the magnetic field in cartesian coordinates

  • dict_header (dictionary) – Header with information of the observation. It works with a SDO header or it can be created from other data. It should include: dict_header = {‘CRLT_OBS’:float, ‘RSUN_OBS’:float, ‘crota2’:float, ‘CDELT1’:float, ‘crpix1’:float, ‘crpix2’:float, ‘LATDTMAX’:float, ‘LATDTMAX’:float ‘LATDTMAX’:float, ‘LONDTMAX’:float, ‘LATDTMIN’:float, ‘LONDTMIN’:float, ‘naxis1’:float, ‘naxis2’:float} They should follow the same definition as given for SDO data: https://www.lmsal.com/sdodocs/doc?cmd=dcur&proj_num=SDOD0019&file_type=pdf

Returns:

Three components of the magnetic field in heliocentric spherical coordinates and in cylindrical equal are projection.

Return type:

arrays

Example

>>> field_z = field * np.cos(inclination * np.pi / 180.0)
>>> field_hor = field * np.sin(inclination * np.pi / 180.0)
>>> field_y = field_hor * np.cos(azimuth * np.pi / 180.0)
>>> field_x = -field_hor * np.sin(azimuth * np.pi / 180.0)
>>> field_x_h2, field_y_h2, field_z_h2 = bvec2cea(file.header, field_x, field_y, field_z)
Authors:

Carlos Diaz (ISP/SU 2020), Gregal Vissers (ISP/SU 2020)

ISPy.util.remap.remap2cea(dict_header, field_x, field_y, field_z, deltal=0.03)

Map projection of the original input into the cylindical equal area system (CEA).

Parameters:
  • dict_header (dictionary) – Header with information of the observation. It works with a SDO header or it can be created from other data. It should include: dict_header = {‘CRLT_OBS’:float, ‘RSUN_OBS’:float, ‘crota2’:float, ‘CDELT1’:float, ‘crpix1’:float, ‘crpix2’:float, ‘LATDTMAX’:float, ‘LATDTMAX’:float ‘LATDTMAX’:float, ‘LONDTMAX’:float, ‘LATDTMIN’:float, ‘LONDTMIN’:float, ‘naxis1’:float, ‘naxis2’:float} They should follow the same definition as given for SDO data: https://www.lmsal.com/sdodocs/doc?cmd=dcur&proj_num=SDOD0019&file_type=pdf

  • field_x, field_y, field_z (array) – 2D array with the magnetic field in cartesian coordinates

  • deltal (float) – Heliographic degrees in the rotated coordinate system. SHARP CEA pixels are 0.03

Returns:

  • array – Remaping of the magnetic field to the cylindical equal area system (CEA).

  • Authors: – Carlos Diaz (ISP/SU 2020), Gregal Vissers (ISP/SU 2020)

ISPy.util.remap.sphere2img(lat, lon, latc, lonc, xcenter, ycenter, rsun, peff)

Conversion between Heliographic coordinates to CCD coordinates. Ported from sphere2img written in IDL : Adapted from Cartography.c by Rick Bogart, by Xudong Sun [Eq 5&6 in https://arxiv.org/pdf/1309.2392.pdf]

Parameters:
  • lat, lon (array, array) – input heliographic coordinates (latitude and longitude)

  • latc, lonc (float, float) – Heliographic longitud and latitude of the refenrence (center) pixel

  • xcenter, ycenter (float, float) – Center coordinates in the image

  • rsun (float) – Solar radius in pixels

  • peff (float) – p-angle: the position angle between the geocentric north pole and the solar rotational north pole measured eastward from geocentric north.

Returns:

Latitude and longitude in the new CCD coordinate system.

Return type:

array

ISPy.util.remap.vector_transformation(peff, latitude_out, longitude_out, B0, field_x_cea, field_y_cea, field_z_cea, lat_in_rad=False)

Magnetic field transformation matrix (see Allen Gary & Hagyard 1990) [Eq 7 in https://arxiv.org/pdf/1309.2392.pdf]

Module contents

Tools and scripts for miscellaneous utilities (e.g., math, file crawler).