Gridder#
- class pyvisgrid.core.gridder.Gridder(u_meter: ndarray, v_meter: ndarray, times: ndarray, img_size: int, fov: float, src_ra: float, src_dec: float, ref_frequency: float, frequency_offsets: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], antenna_layout: Layout | None = None)[source]#
Bases:
objectMethods Summary
from_fits(path, img_size, fov[, uv_colnames])Initializes the gridder with the visibility data in a given FITS file using the default Gridder for the radionets-project.
from_ms(path, img_size, fov, desc_id[, ...])Initializes the Gridder with a measurement which is saved in an NRAO CASA Measurement Set.
from_pyvisgen(vis_data, obs, img_size, fov)Initializes the gridder with the visibility data which is generated by the
pyvisgen.simulation.vis_loopfunction.from_uvh5(file, *, fov[, stokes_components, ...])Initializes the gridder with visibility data from the UVH5 file format.
grid([stokes_component])Grids given visibility data using the default Gridder for the radionets-project.
grid_time_series(step_size[, ...])Grids the visibilites in a time series so that time steps get gridded individually.
plot_dirty_image([stokes_component])Plots the (u,v) dirty image, meaning the 2d Fourier transform of the gridded visibilities.
plot_mask([stokes_component])Plots the (u,v) mask (the binned visibilities) of the gridded interferometric image.
plot_ungridded_uv(**kwargs)Plots the ungridded (u,v) points as a scatter plot.
Methods Documentation
- classmethod from_fits(path: str, img_size: int, fov: float, uv_colnames: dict = None) GridData[source]#
Initializes the gridder with the visibility data in a given FITS file using the default Gridder for the radionets-project. Currently only extraction of the Stokes I component is supported. More on the
Griddercan be found in the constructor of theGridder.- Parameters:
- pathstr
The path to the FITS file.
- img_sizeint
The size of the image in pixels.
- fovfloat
The physical size of the image in asec.
- uv_colnamesdict, optional
Alternative names for the U and V columns in the FITS file. Default is {‘u’: None, ‘v’: None}, meaning the default values of ‘UU’ and ‘VV’ or ‘UU–’ and ‘VV–’ will be used.
- classmethod from_ms(path: str, img_size: int, fov: float, desc_id: int, ref_frequency_id: int = 0, use_calibrated: bool = False, filter_flagged: bool = True) GridData[source]#
Initializes the Gridder with a measurement which is saved in an NRAO CASA Measurement Set. Currently only extraction of the Stokes I component is supported.
- Parameters:
- path: str
The path of the measurement set root directory.
- img_size: int
The size of the image in pixels.
- fov: float
The physical size of the image in asec.
- desc_id: int
The description id of the visibilites which should be gridded. This id corresponds to a way of choosing between the spectral windows of the observation and its polarization setup.
Note: Currently it is not supported to grid all visibilities of the observation in one image. It is planned to add that at a later point.
- ref_frequency_id: int, optional
The index of the reference frequency that will be used if the measurement is a composite observation and no desc_id is given.
- use_calibrated: bool, optional
Whether to use the calibrated data from the MODEL_DATA column or the raw data from the DATA column. Default is
True.- filter_flagged: bool, optional
Whether to filter out flagged data rows. Default is
True.
- classmethod from_pyvisgen(vis_data: Visibilities, obs: Observation, img_size: int, fov: float, stokes_components: list[str] | str = 'I', polarizations: list[str] | str | None = None) GridData[source]#
Initializes the gridder with the visibility data which is generated by the
pyvisgen.simulation.vis_loopfunction. Additionally one can define which stokes components should be calculated with a given polarization.More on the
Griddercan be found in the constructor of theGridder.- Parameters:
- obspyvisgen.simulation.Observation
The observation which is returned by the
pyvisgen.simulation.vis_loopfunction.- vis_datapyvisgen.simulation.Visibilities
The visibility data which is returned by the
pyvisgen.simulation.vis_loopfunction.- img_sizeint
The size of the image in pixels.
- fovfloat
The physical size of the image in asec.
- stokes_componentslist[str] | str, optional
The Stokes components which are to be calculated and saved in the gridder. This can either be a list of components (e.g.
['I', 'V']) or a single string. Default is'I'.- polarizationslist[str] | str | None, optional
The polarization type. Default is
None.
- classmethod from_uvh5(file: str | Path, *, fov: float, stokes_components: str | list[str] = 'I', polarizations: str | list[str] | None = None, station_ids_unavail: float = 0.0, img_size: int | None = None)[source]#
Initializes the gridder with visibility data from the UVH5 file format.
This method allows to select stokes components that will be computed for a given polarization.
- Parameters:
- filestr or
Path Path to the file that you want to grid. This file has to be in the UVH5 file format from pyvisgen.
- fovfloat
The physical size of the image in asec.
- stokes_componentsstr | list[str], optional
The Stokes components which are to be calculated and saved in the gridder. This can either be a list of components (e.g.
['I', 'V']) or a single string. Default:'I'.- polarizationsstr | list[str] | None, optional
The polarization type. Default:
None.- station_ids_unavailfloat, optional
Percentage of station ids that are unavailable during the observation. This allows simulating reduced operation capacity even after the main simulation in pyvisgen and thus avoids having to rerun the same simulation with different reduced arrays. Default:
0.0- img_sizeint or None, optional
Image size is read from the file. In case the image size cannot be read, e.g. because the sky image was not saved to the file (“file/sky/SI”), or you want to grid the image to a different size, it can be set through this keyword argument. Default:
None
- filestr or
See also
UVH5WriterThe UVH5 data writer class as implemented in
pyvisgen, outlining the file structure.
Examples
>>> gridded_vis = Gridder.from_uvh5( ... "/path/to/example.uvh5", ... fov=0.024, ... ).grid() >>> gridded_vis.vis_data.shape (1344,)
Setting the
station_ids_unavailkeyword argument to a value greater0.0, you can reduce the array, without the need to re-simulate the entire dataset:>>> gridded_vis_reduced = Gridder.from_uvh5( ... "/path/to/example.uvh5", ... fov=0.024, ... station_ids_unavail=0.5, ... ).grid() >>> gridded_vis_reduced.vis_data.shape (288,)
Note that this only disables a randomized selection of antennas for the entire observation. Depending on the visibility of the source, the data taken by the antennas may vary during measurement, and the resulting visibilites dataset may be smaller or larger than expected (see, e.g., the shapes
(1344,)vs(288,)although only half of the antennas were unavailable).
- grid(stokes_component: str = 'I') GridData[source]#
Grids given visibility data using the default Gridder for the radionets-project.
- Parameters:
- stokes_componentstr, optional
The stokes component which should be gridded. The specified component has to be initialized first! Otherwise this will result in a
KeyError. Default is'I'.
- Returns:
- masknumpy.ndarray, optional
The mask created from the given (u,v) coordinates. The mask contains the number of (u,v) coordinates per pixel.
- mask_realnumpy.ndarray, optional
The gridded real part of the visibilites.
- mask_imagnumpy.ndarray, optional
The gridded imaginary part of the visibilities.
- dirty_img_complexnumpy.ndarray, optional
The complex Dirty Image. This is the 2-dimensional Fourier transform of the gridded visibilities.
- grid_time_series(step_size: int, time_start_idx: int = 0, time_end_idx: int | None = None, stokes_component: str = 'I', show_progress: bool = True) GridDataSeries[source]#
Grids the visibilites in a time series so that time steps get gridded individually.
- Parameters:
- step_sizeint
The number of visibilites (time steps) per gridded time step. Meaning that the resulting series will have
len(Gridder) // step_sizefor its length.- time_start_idxint, optional
The time index at which the time series starts. Default is
0, meaning the time series starts at the first visibility.- time_endint | None, optional
The time index at which the time series end. Default is
None, meaning that the time series ends at the last visibility.- stokes_componentstr, optional
The Stokes component to grid. Default is
'I'.- show_progressbool, optional
Whether to show a progress bar for the gridding progress. Default is
True.
- Returns:
- GridDataSeries
The series of gridded and ungridded visibilities.
- plot_dirty_image(stokes_component: str = 'I', **kwargs) tuple[matplotlib.figure.Figure, matplotlib.axes.Axes][source]#
Plots the (u,v) dirty image, meaning the 2d Fourier transform of the gridded visibilities.
- Parameters:
- stokes_componentstr, optional
The symbol of the stokes component whose dirty image should be plotted. The specified component has to be initialized and gridded first! Otherwise this will result in a
KeyError. Default is'I'.- modestr, optional
The mode specifying which values of the dirty image should be plotted. Possible values are:
real: Plots the real part of the dirty image.imag: Plots the imaginary part of the dirty image.abs: Plot the absolute value of the dirty image.
Default is
real.- ax_unit: str | astropy.units.Unit, optional
The unit in which to show the ticks of the x and y-axes in. The y-axis is the Declination (DEC) and the x-axis is the Right Ascension (RA). The latter one is defined as increasing from left to right! The unit has to be given as a string or an
astropy.units.Unit. The string must correspond to the string representation of anastropy.units.Unit.Valid units are either
pixelor angle units likearcsec,degreeetc. Default ispixel.- center_pos: tuple | None, optional
The coordinate center of the image. The coordinates have to be given in the unit defined in the parameter
ax_unitabove. Ifax_unitis set topixelthis parameter is ignored. Default isNone, meaning the coordinates of the axes will be given as relative.- normstr | matplotlib.colors.Normalize | None, optional
The name of the norm or a matplotlib norm. Possible values are:
log: Returns a logarithmic norm with clipping on (!), meaningvalues above the maximum will be mapped to the maximum and values below the minimum will be mapped to the minimum, thus avoiding the appearance of a colormaps ‘over’ and ‘under’ colors (e.g. in case of negative values). Depending on the use case this is desirable but in case that it is not, one can set the norm to
log_noclipor provide a custom norm.
log_noclip: Returns a logarithmic norm with clipping off.centered: Returns a linear norm which centered around zero.sqrt: Returns a power norm with exponent 0.5, meaning thesquare-root of the values.
- other: A value not declared above will be returned as is,
meaning that this could be any value which exists in matplotlib itself.
Default is
None, meaning no norm will be applied.- colorbar_shrink: float, optional
The shrink parameter of the colorbar. This can be needed if the plot is included as a subplot to adjust the size of the colorbar. Default is
1, meaning original scale.- cmap: str | matplotlib.colors.Colormap, optional
The colormap to be used for the plot. Default is
'inferno'.- plot_argsdict | None, optional
The additional arguments passed to the scatter plot. Default is
None.- fig_argsdict | None, optional
The additional arguments passed to the figure. If a figure object is given in the
figparameter, this value will be discarded. Default isNone.- save_tostr | PathLike | None, optional
The name of the file to save the plot to. Default is
None, meaning the plot won’t be saved.- save_argsdict | None, optional
The additional arguments passed to the
fig.savefigcall. Default is{"bbox_inches":"tight"}.- figmatplotlib.figure.Figure | None, optional
A custom figure object. If set to
None, theaxparameter also has to beNone! Default isNone.- axmatplotlib.axes.Axes | None, optional
A custom axes object. If set to
None, thefigparameter also has to beNone! Default isNone.
- Returns:
- figmatplotlib.figure.Figure
The figure object.
- axmatplotlib.axes.Axes
The axes object.
- plot_mask(stokes_component: str = 'I', **kwargs) tuple[matplotlib.figure.Figure, matplotlib.axes.Axes][source]#
Plots the (u,v) mask (the binned visibilities) of the gridded interferometric image.
- Parameters:
- stokes_componentstr, optional
The symbol of the stokes component whose mask should be plotted. The specified component has to be initialized and gridded first! Otherwise this will result in a
KeyError. Default is'I'.- modestr, optional
The mode specifying which values of the mask should be plotted. Possible values are:
hist: Plots the number of (u,v) points which are sorted ineach pixel of the image in the (u,v) space.
abs: Plots the absolute value of the gridded visibilities,meaning the magnitude of the complex numbers in Euler representation.
phase: Plots the phase angle of the gridded visibilities,meaning the angle in the exponent of the complex numbers in Euler representation.
real: Plots the real part of the gridded visibilities.imag: Plots the imaginary part of the gridded visibilities.
Default is
hist.- croptuple[list[float | None]], optional
The crop of the image. This has to have the format
([x_left, x_right], [y_left, y_right]), where the left and right values for each axis are the upper and lower limits of the axes which should be shown. IMPORTANT: If one supplies theplt.imshowanextentparameter via theplot_argsparameter, this will be the scale in which one has to give the crop! If not, the crop has to be in pixels.- normstr | matplotlib.colors.Normalize | None, optional
The name of the norm or a matplotlib norm. Possible values are:
log: Returns a logarithmic norm with clipping on (!), meaningvalues above the maximum will be mapped to the maximum and values below the minimum will be mapped to the minimum, thus avoiding the appearance of a colormaps ‘over’ and ‘under’ colors (e.g. in case of negative values). Depending on the use case this is desirable but in case that it is not, one can set the norm to
log_noclipor provide a custom norm.
log_noclip: Returns a logarithmic norm with clipping off.centered: Returns a linear norm which centered around zero.sqrt: Returns a power norm with exponent 0.5, meaning thesquare-root of the values.
- other: A value not declared above will be returned as is,
meaning that this could be any value which exists in matplotlib itself.
Default is
None, meaning no norm will be applied.- cmap: str | matplotlib.colors.Colormap | None, optional
The colormap to be used for the plot. Default is
None, meaning the colormap will be default to a value fitting for the chosen mode.- plot_argsdict, optional
The additional arguments passed to the scatter plot. Default is
{"color":"royalblue"}.- fig_argsdict | None, optional
The additional arguments passed to the figure. If a figure object is given in the
figparameter, this value will be discarded. Default isNone.- save_tostr | PathLike | None, optional
The name of the file to save the plot to. Default is
None, meaning the plot won’t be saved.- save_argsdict | None, optional
The additional arguments passed to the
fig.savefigcall. Default is{"bbox_inches":"tight"}.- figmatplotlib.figure.Figure | None, optional
A custom figure object. If set to
None, theaxparameter also has to beNone! Default isNone.- axmatplotlib.axes.Axes | None, optional
A custom axes object. If set to
None, thefigparameter also has to beNone! Default isNone.
- Returns:
- figmatplotlib.figure.Figure
The figure object.
- axmatplotlib.axes.Axes
The axes object.
- plot_ungridded_uv(**kwargs) tuple[matplotlib.figure.Figure, matplotlib.axes.Axes][source]#
Plots the ungridded (u,v) points as a scatter plot.
- Parameters:
- modestr, optional
The mode specifying the scale of the (u,v) coordinates. This can be either
wave, meaning the coordinates are plotted in units of the reference wavelength, ormeter, meaning the (u,v) coordinates will be plotted in meter. Default iswave.- show_timesbool, optional
Whether to show the timestamps of the measured visibilities as a colormap. Default is
True.- use_relative_timebool, optional
Whether to show the times relative to the timestamp of the first measurement in hours. Default is
True.- times_cmap: str | matplotlib.colors.Colormap, optional
The colormap to be used for the time component of the plot. Default is
'inferno'.- marker_sizefloat | None, optional
The size of the scatter markers in points**2. Default is
None, meaning the default value supplied by your matplotlib rcParams.- plot_argsdict, optional
The additional arguments passed to the scatter plot. Default is
{"color":"royalblue"}.- fig_argsdict, optional
The additional arguments passed to the figure. If a figure object is given in the
figparameter, this value will be discarded. Default is{}.- save_tostr | None, optional
The name of the file to save the plot to. Default is
None, meaning the plot won’t be saved.- save_argsdict, optional
The additional arguments passed to the
fig.savefigcall. Default is{"bbox_inches":"tight"}.- figmatplotlib.figure.Figure | None, optional
A custom figure object. If set to
None, theaxparameter also has to beNone! Default isNone.- axmatplotlib.axes.Axes | None, optional
A custom axes object. If set to
None, thefigparameter also has to beNone! Default isNone.
- Returns:
- figmatplotlib.figure.Figure
The figure object.
- axmatplotlib.axes.Axes
The axes object.