ISPy.io package

Submodules

ISPy.io.lapalma module

Python tools to read and write ‘La Palma’ cubes

Merge of some routines written by Tiago Pereira (github:helita), J. de la Cruz Rodriguez, Alex Pietrow (github:crispy), Carlos Diaz and G. Vissers (ISP/SU 2019)

ISPy.io.lapalma.get(filename, index, verb=False)

Read a 2D image (slice) given a known index from a La Palma cube.

Parameters:
  • filename (str) – file to be opened. Has to be .icube or .fcube

  • index (int) – chosen frame, where frame is t*nw*ns + s*nw + w t: time or scan number s: stokes parameter w: wavelength step

  • verbose (bool, optional) – Verbose model. (Default value = False)

Returns:

image – 2D image slice

Return type:

ndarray

Examples

>>> image = lp_get('cube.fcube', 0)
Authors:
  1. Vissers (ITA UiO, 2016), A.G.M. Pietrow (2018), Carlos Diaz (ISP/SU 2019)

ISPy.io.lapalma.head(name, verbose=False, appendFormat=False)

Get the header of a legacy ‘La Palma’ cube

Parameters:
  • name (str) – name of the file

  • verbose (bool, optional) – print out the header information (Default value = True)

  • appendFormat (bool, optional) – different format to ensure append operation (Default =False)

Returns:

header – header information in order (nx, ny, nt, nstokes, dtype, ndims)

Return type:

tuple

Example

>>> h = head('crispex_3950_2016-09-19T09:28:36_scans=11-117_time-corrected_im.fcube')
('head:', '[dtype=float32, ndims=3, nx=1734, ny=1240, nt=3317, nstokes=1] -> crispex_3950_2016-09-19T09:28:36_scans=11-117_time-corrected_im.fcube')
>>> nx, ny, nt, ns, dtype, ndims = head('crispex_3950_2016-09-19T09:28:36_scans=11-117_time-corrected_im.fcube', verbose=False)
>>> nx, ny, ns
(1734, 1240, 1)
ISPy.io.lapalma.mk_header(image)

Create a La Palma format header of an image array

Parameters:

image (ndarray) – 2D or 3D image array in La Palma ordering (nx, ny, nt)

Returns:

header – header of the cube

Return type:

str

ISPy.io.lapalma.put(filename, image, append=True, verbose=False, stokes=True)

Append a new cube/slice to a pre-existent La Palma cube.

Parameters:
  • filename (str) – name of file with .icube/fcube extention

  • image (ndarray) – datacube in form of [t,s,w,x,y]

  • append (bool, optional) – append image to an existing file (Default value = True)

  • verbose (bool, optional) – verbose mode (default False)

  • stokes (bool, optional) – data has Stokes parameters (default True)

Examples

>>> lp_put('cube.fcube', cube2)
To do:

Insert a slice in a La Palma cube

Authors:

Carlos Diaz, G. Vissers, A.G.M. Pietrow (ISP/SU 2019)

ISPy.io.lapalma.read(cube, spnw=None, spformat='_sp', verb=False)

Read the full cube from a La Palma format file

Parameters:
  • cube (str) – filename, has to be .icube or .fcube

  • spnw (str or int, optional) – Specific filename of spectral cube OR number of wavelength steps (Default value = None)

  • spformat (str, optional) – filename identifier for the spectral cube (Default value = ‘_sp’)

  • verb (bool, optional) – Verbose mode. (Default value = False)

Returns:

cube_array – 5D cube of shape [nt,ns,nw,nx,ny]

Return type:

ndarray

Examples

>>> from ISPy.io import lapalma as lp
>>> cube_a = lp.read('filename.fcube') # It searches for 'filename_sp.fcube' in the same path
>>> cube_b = lp.read('filename.fcube' , 8)
>>> cube_c = lp.read('filename.fcube' , 'filename_sp.fcube')
Authors:

Alex Pietrow (ISP/SU 2019), Carlos Diaz (ISP/SU 2019)

ISPy.io.lapalma.write(cube_array, name, stokes=True, sp=False, path='')

Write a data cube in La Palma format to disc

Parameters:
  • cube_array (ndarray) – datacube in form of [t,s,w,x,y]

  • name (str) – name of file with .icube/fcube extention

  • stokes (bool, optional) – flag for if data has stokes or not. (Default value = True)

  • sp (bool, optional) – Save spectral cube of shape. (Default value = False)

  • path (str, optional) – Filepath where file needs to be saved.(Default value = ‘’)

Examples

>>> from ISPy.io import lapalma as lp
>>> lp.write(cube_array, 'cube.fcube', path='fits/')
Authors:

Alex Pietrow (ISP/SU 2019), Carlos Diaz (ISP/SU 2019)

ISPy.io.lapalma.writeto(filename, image, extraheader='', dtype=None, verbose=False, append=False)

Submodule of “write”. It writes a cube to disk in LaPalma format. Partially from https://github.com/ITA-Solar/helita/blob/master/helita/io/lp.py

Parameters:
  • filename (str) – name of the file

  • image (ndarray) – data allocated in memory

  • extraheader (str, optional) – extra header information to append to standard header (Default value = ‘’)

  • dtype (str, optional) – data type of the image (Default value = None)

  • verbose (bool, optional) – verbose mode (Default value = False)

  • append (bool, optional) – append image to existing file (Default value = False)

Return type:

NoneType

Examples

writeto(‘path/cube.fcube’, image, append=True)

ISPy.io.pyio module

Python tools for I/O to binary files with named variables Written by J. de la Cruz Rodriguez (ISP-SU 2019)

The idea is to write variables, one after the other in a binary file. The file has a 5 byte header at the beginning. Then variables are written as follow:

Variable header: 1 int32 tell the routines the size of the header, 50 bytes contain the variable name, 1 int32 contain the number of dimensions, 1 int32 contains the dataype, ndim*int64 contain the dimensions of the variable, and then comes the raw data.

class ISPy.io.pyio.bio(filename, mode='r', verbose=True)

Bases: object

create_empty_variable(vname, dim, dtype)
get_data_tree()
map_variable(vname)
read_variable(vname)
variable_exists(vname)
write_variable(vname, d)
class ISPy.io.pyio.container

Bases: object

ISPy.io.pyio.create_header(vname, dim, dtype='float32')
ISPy.io.pyio.file_exists(fname)
ISPy.io.pyio.get_header_size(ndim)
ISPy.io.pyio.number2dtype(num)
ISPy.io.pyio.number2size(num)
ISPy.io.pyio.type2number(dtype)
ISPy.io.pyio.unpack_header(head)

ISPy.io.sn module

Python tools to read SST data formatted as FITS files conforming to the SOLARNET standard.

Written by Jorrit Leenaarts (ISP/SU 2021)

class ISPy.io.sn.sstdata(filename)

Bases: object

class for reading and handling SST data formatted as FITS files conforming to the SOLARNET standard.

ISPy.io.solarnet module

Python tools to read and write ‘SOLARNET’ cubes

Written by Carlos Diaz (ISP/SU 2019)

ISPy.io.solarnet.get_coord(filename, pix_x, pix_y, timeFrame=0)

Converts pixel values to solar coordinates

Parameters:
  • filename (str) – name of the data cube

  • pix_x, pix_y (int) – pixel location to convert

  • timeFrame (int) – selected frame to the coordinates for (Default value = 0)

Returns:

xy_output – solar coordinates in arcsec

Return type:

list

Example

>>> from ISPy.io import solarnet
>>> [x_output, y_output] = solarnet.get_coord(filename, pix_x,pix_y)
Author:

Carlos Diaz Baso (ISP/SU 2019)

ISPy.io.solarnet.get_extent(filename, timeFrame=0)

Read the coordinates of the corners to use them with imshow/extent

Parameters filename : str

name of the data cube

timeFrameint

selected frame to get the coordinates for (Default value = 0)

Returns:

extent_output – 1D array with solar coordinates in arcsec of the corners.

Return type:

array_like

Example

>>> from ISPy.io import solarnet
>>> extent = solarnet.get_extent(filename)
>>> plt.imshow(data, extent=extent)
Author:

Carlos Diaz Baso (ISP/SU 2019)

ISPy.io.solarnet.get_time(filename, fulltime=False, utc=False)

Reads the time information of a ‘SOLARNET’ FITS file

Parameters:
  • filename (str) – name of the data cube

  • fulltime (bool, optional) – information at each wavelength point (Default value = False)

  • utc (bool, optional) – the output is given in ‘HH:MM:SS’ format (Default value = False)

Returns:

time_output – array with time information. If fulltime=False, a 1D array with time at middle wavelength tuning; if fulltime=True, a 2D array with tuning-dependent time information.

Return type:

array_like

Example

>>> from ISPy.io import solarnet
>>> data_time = solarnet.get_time(filename, fulltime=False, utc=True)
Author:

Carlos Diaz Baso (ISP/SU 2019)

ISPy.io.solarnet.get_wav(filename)

Read the wavelength information of a ‘SOLARNET’ FITS file

Parameters:

filename (str) – name of the data cube

Returns:

wav_output – 1D wavelength array. It is assumed that spectral sampling does not change over time.

Return type:

array_like

Example

>>> from ISPy.io import solarnet
>>> wav_array = solarnet.get_wav('filename.fits')
Authors:

Carlos Diaz Baso (ISP/SU 2019)

ISPy.io.solarnet.read(filename)

Read the data of a ‘SOLARNET’ FITS file

Parameters:

filename (str) – name of the data cube

Returns:

data – multidimensional data array

Return type:

ndarray

Example

>>> from ISPy.io import solarnet
>>> data = solarnet.read('filename.fits')
>>> data.shape
(30, 4, 41, 1914, 206)
Author:

Carlos Diaz Baso (ISP/SU 2019)

ISPy.io.solarnet.seconds2string(number)

Convert time in seconds to ‘HH:MM:SS’ format

Parameters:

number (float) – value in seconds

Returns:

time_string – time in ‘HH:MM:SS’ format

Return type:

str

Example

>>> from ISPy.io import solarnet
>>> solarnet.seconds2string(63729.3)
'17:42:09.300000'
Author:

Carlos Diaz Baso (ISP/SU 2019)

ISPy.io.solarnet.write(filename, d)

Write the data as a standard FITS file (without proper SOLARNET header)

Parameters:
  • filename (str) – name of the data cube

  • d (ndarray) – data in memory

Example

>>> from ISPy.io import solarnet
>>> solarnet.write('filename.fits', data)
Author:

Carlos Diaz Baso (ISP/SU 2019)

Module contents

Tools and scripts for (synthetic) data I/O.