marvin.utils.general.general.
convertCoords
(coords, mode='sky', wcs=None, xyorig='center', shape=None)[source]¶Convert input coordinates to array indices.
Converts input positions in x, y or RA, Dec coordinates to array indices
(in Numpy style) or spaxel extraction. In case of pixel coordinates, the
origin of reference (either the center of the cube or the lower left
corner) can be specified via xyorig
.
If shape
is defined (mandatory for mode='pix'
, optional for
mode='sky'
) and one or more of the resulting indices are outside the
size of the input shape, an error is raised.
This functions is mostly intended for internal use.
Parameters: |
|
---|---|
Returns: | result (Numpy array) – An array with the same shape as |
marvin.utils.general.general.
parseIdentifier
(galid)[source]¶Determine if a string input is a plate, plateifu, or manga-id.
Parses a string object id and determines whether it is a plate ID, a plate-IFU, or MaNGA-ID designation.
Parameters: | galid (str) – The string of an id name to parse |
---|---|
Returns: | idtype (str) – String indicating either plate, plateifu, mangaid, or None |
marvin.utils.general.general.
mangaid2plateifu
(mangaid, mode='auto', drpall=None, drpver=None)[source]¶Return the plate-ifu for a certain mangaid.
Uses either the DB or the drpall file to determine the plate-ifu for
a mangaid. If more than one plate-ifu are available for a certain ifu,
and mode='drpall'
, the one with the higher SN2 (calculated as the sum
of redSN2 and blueSN2) will be used. If mode='db'
, the most recent one
will be used.
Parameters: |
|
---|---|
Returns: | plateifu (str) – The plate-ifu string for the input |
marvin.utils.general.general.
findClosestVector
(point, arr_shape=None, pixel_shape=None, xyorig=None)[source]¶Find the closest array coordinates from pixel coordinates.
Find the closest vector of array coordinates (x, y) from an input vector of pixel coordinates (x, y).
Parameters: |
|
---|---|
Returns: | minind –
|
marvin.utils.general.general.
getWCSFromPng
(image)[source]¶Extract any WCS info from the metadata of a PNG image.
Extracts the WCS metadata info from the PNG optical image of the galaxy using PIL (Python Imaging Library). Converts it to an Astropy WCS object.
Parameters: | image (str) – The full path to the image |
---|---|
Returns: | pngwcs (WCS) – an Astropy WCS object |
marvin.utils.general.general.
convertImgCoords
(coords, image, to_pix=None, to_radec=None)[source]¶Transform the WCS info in an image.
Convert image pixel coordinates to RA/Dec based on PNG image metadata or vice_versa
Parameters: | |
---|---|
Returns: | newcoords (tuple) – Tuple of either (x, y) pixel coordinates or (RA, Dec) coordinates |
marvin.utils.general.general.
getSpaxelXY
(cube, plateifu, x, y)[source]¶Get a spaxel from a cube in the DB.
This function is mostly intended for internal use.
Parameters: | |
---|---|
Returns: | spaxel (SQLAlchemy object) – The SQLAlchemy spaxel with coordinates |
marvin.utils.general.general.
downloadList
(inputlist, dltype='cube', **kwargs)[source]¶Download a list of MaNGA objects.
Uses sdss_access to download a list of objects via rsync. Places them in your local sas path mimicing the Utah SAS.
i.e. $SAS_BASE_DIR/mangawork/manga/spectro/redux
Can download cubes, rss files, maps, mastar cubes, png images, default maps, or the entire plate directory.
Parameters: |
|
---|---|
Returns: | NA – Downloads |
marvin.utils.general.general.
getSpaxel
(cube=True, maps=True, modelcube=True, x=None, y=None, ra=None, dec=None, xyorig=None, **kwargs)[source]¶Returns the Spaxel
matching certain coordinates.
The coordinates of the spaxel to return can be input as x, y
pixels
relative to``xyorig`` in the cube, or as ra, dec
celestial
coordinates.
This function is intended to be called by
getSpaxel()
or
getSpaxel()
, and provides shared code for
both of them.
Parameters: |
|
---|---|
Returns: | spaxels (list) – The |
marvin.utils.general.general.
get_drpall_row
(plateifu, drpver=None, drpall=None)[source]¶Returns a dictionary from drpall matching the plateifu.
marvin.utils.general.general.
getDefaultMapPath
(**kwargs)[source]¶Retrieve the default Maps path.
Uses sdss_access Path to generate a url download link to the default MAPS file for a given MPL.
Parameters: |
|
---|---|
Returns: | maplink (str) – The sas url to download the default maps file |
marvin.utils.general.general.
getDapRedux
(release=None)[source]¶Retrieve SAS url link to the DAP redux directory.
Parameters: | release (str) – The release version of the data to download. Defaults to Marvin config.release. |
---|---|
Returns: | dapredux (str) – The full redux path to the DAP MAPS |
marvin.utils.general.general.
get_nsa_data
(mangaid, source='nsa', mode='auto', drpver=None, drpall=None)[source]¶Returns a dictionary of NSA data from the DB or from the drpall file.
Parameters: |
|
---|---|
Returns: | nsa_data (dict) – A dictionary containing the columns and values from the NSA catalogue for
|
marvin.utils.general.general.
get_plot_params
(dapver, prop)[source]¶Return default plotting parameters for a property.
marvin.utils.general.general.
invalidArgs
(func, argdict)[source]¶Return invalid arguments from an input dictionary
Parameters: |
|
---|---|
Returns: | A list of invalid arguments |
Example
>>> import matplotlib.pyplot as plt
>>> testdict = {'edgecolors': 'black', 'c': 'r', 'xlim': 5, 'xlabel': 9, 'ylabel': 'y', 'ylim': 6}
>>> # test for invalid args
>>> invalidArgs(plt.scatter, testdict)
>>> {'xlabel', 'xlim', 'ylabel', 'ylim'}
marvin.utils.general.general.
missingArgs
(func, argdict, arg_type='args')[source]¶Return missing arguments from an input dictionary
Parameters: | |
---|---|
Returns: | A list of missing arguments |
Example
>>> import matplotlib.pyplot as plt
>>> testdict = {'edgecolors': 'black', 'c': 'r', 'xlim': 5, 'xlabel': 9, 'ylabel': 'y', 'ylim': 6}
>>> # test for missing required args
>>> missginArgs(plt.scatter, testdict)
>>> {'x', 'y'}
>>> # test for missing optional args
>>> missingArgs(plt.scatter, testdict, arg_type='opt')
>>> ['vmin', 'linewidths', 'marker', 's', 'cmap', 'verts', 'vmax', 'alpha', 'hold', 'data', 'norm']
marvin.utils.general.general.
getRequiredArgs
(func)[source]¶Gets the required arguments from a function or method
Uses this difference between arguments and defaults to indicate required versus optional arguments
Parameters: | func (func) – The function or method to inspect |
---|---|
Returns: | A list of required arguments |
Example
>>> import matplotlib.pyplot as plt
>>> getRequiredArgs(plt.scatter)
>>> ['x', 'y']
marvin.utils.general.general.
getKeywordArgs
(func)[source]¶Gets the keyword arguments from a function or method
Parameters: | func (func) – The function or method to inspect |
---|---|
Returns: | A list of keyword arguments |
Example
>>> import matplotlib.pyplot as plt
>>> getKeywordArgs(plt.scatter)
>>> ['edgecolors', 'c', 'vmin', 'linewidths', 'marker', 's', 'cmap',
>>> 'verts', 'vmax', 'alpha', 'hold', 'data', 'norm']
marvin.utils.general.general.
isCallableWithArgs
(func, argdict, arg_type='opt', strict=False)[source]¶Test if the function is callable with the an input dictionary
Parameters: |
|
---|---|
Returns: | Boolean indicating whether the function is callable |
Example
>>> import matplotlib.pyplot as plt
>>> testdict = {'edgecolors': 'black', 'c': 'r', 'xlim': 5, 'xlabel': 9, 'ylabel': 'y', 'ylim': 6}
>>> # test for invalid args
>>> isCallableWithArgs(plt.scatter, testdict)
>>> False
marvin.utils.general.general.
map_bins_to_column
(column, indices)[source]¶Maps a dictionary of array indices to column data
Takes a given data column and a dictionary of indices (see the indices key
from output of the histgram data in marvin.utils.plot.scatter.hist()
),
and produces a dictionary with the data values from column mapped in
individual bins.
Parameters: | |
---|---|
Returns: | A dictionary containing, for each binid, a list of column data in that bin. |
Example
>>>
>>> # provide a list of data in each bin of an output histogram
>>> x = np.random.random(10)*10
>>> hdata = hist(x, bins=3, return_fig=False)
>>> inds = hdata['indices']
>>> pmap = map_bins_to_column(x, inds)
>>> OrderedDict([(1,
>>> [2.5092488009906235,
>>> 1.7494530589363955,
>>> 2.5070840461208754,
>>> 2.188355400587354,
>>> 2.6987990403658992,
>>> 1.6023553861428441]),
>>> (3, [7.9214280403215875, 7.488908995456573, 7.190598204420587]),
>>> (4, [8.533028236560906])])
marvin.utils.general.general.
get_dapall_file
(drpver, dapver)[source]¶Returns the path to the DAPall file for (drpver, dapver)
.
marvin.utils.general.general.
temp_setattr
(ob, attrs, new_values)[source]¶Temporarily set attributed on an object
Temporarily set an attribute on an object for the duration of the context manager.
Parameters: |
---|
Example
>>> c = Cube(plateifu='8485-1901')
>>> print('before', c.mangaid)
>>> with temp_setattr(c, 'mangaid', None):
>>> # do stuff
>>> print('new', c.mangaid)
>>> print('after' c.mangaid)
>>>
>>> # Output
>>> before '1-209232'
>>> new None
>>> after '1-209232'
>>>
marvin.utils.general.general.
map_dapall
(header, row)[source]¶Retrieves a dictionary of DAPall db column names
For a given row in the DAPall file, returns a dictionary of corresponding DAPall database columns names with the appropriate values.
Parameters: |
|
---|---|
Returns: | A dictionary with db column names as keys and row data as values |
Example
>>> hdu = fits.open('dapall-v2_3_1-2.1.1.fits')
>>> header = hdu[0].header
>>> row = hdu[1].data[0]
>>> dbdict = map_dapall(header, row)
marvin.utils.general.general.
turn_off_ion
(show_plot=True)[source]¶Turns off the Matplotlib plt interactive mode
Context manager to temporarily disable the interactive Matplotlib plotting functionality. Useful for only returning Figure and Axes objects
Parameters: | show_plot (bool) – If True, turns off the plotting |
---|
Example
>>>
>>> with turn_off_ion(show_plot=False):
>>> do_some_stuff
>>>
marvin.utils.dap.bpt.
bpt_kewley06
(maps, snr_min=3, return_figure=True, use_oi=True, **kwargs)[source]¶Returns a classification of ionisation regions, as defined in Kewley+06.
Makes use of the classification system defined by
Kewley et al. (2006)
to return classification masks for different ionisation mechanisms. If return_figure=True
,
produces and returns a matplotlib figure with the classification plots (based on
Kewley+06 Fig. 4) and the 2D spatial distribution of classified spaxels (i.e., a map of the
galaxy in which each spaxel is colour-coded based on its emission mechanism).
While it is possible to call this function directly, its normal use will be via the
get_bpt()
method.
Parameters: |
|
---|---|
Returns: | bpt_return – |
Example
>>> maps_8485_1901 = Maps(plateifu='8485-1901')
>>> bpt_masks, fig, axes = bpt_kewley06(maps_8485_1901)
Gets the global mask for star forming spaxels
>>> sf = bpt_masks['sf']['global']
Gets the seyfert mask based only on the SII/Halpha vs OIII/Hbeta diagnostics
>>> seyfert_sii = bpt_masks['seyfert']['sii']
marvin.utils.dap.bpt.
kewley_sf_nii
(log_nii_ha)[source]¶Star forming classification line for log([NII]/Ha).
marvin.utils.dap.bpt.
kewley_sf_sii
(log_sii_ha)[source]¶Star forming classification line for log([SII]/Ha).
marvin.utils.dap.bpt.
kewley_sf_oi
(log_oi_ha)[source]¶Star forming classification line for log([OI]/Ha).
marvin.utils.dap.bpt.
kewley_comp_nii
(log_nii_ha)[source]¶Composite classification line for log([NII]/Ha).
Created by Brian Cherinka on 2016-04-29 00:04:16 Licensed under a 3-clause BSD license.
marvin.utils.general.images.
getRandomImages
(num=10, download=False, mode=None, as_url=None, verbose=None, release=None)[source]¶Get a list of N random images from SAS
Retrieve a random set of images from either your local filesystem SAS or the Utah SAS. Optionally can download the images by rsync using sdss_access.
When as_url is False, both local and remote modes will allow you to access the full path to the images in your local SAS. WHen as_url is True, local mode generates the Utah SAS url links, while remote mode generates the Utah SAS rsync links.
Auto mode defaults to remote.
Parameters: |
|
---|---|
Returns: | listofimages (list) – The list of images |
marvin.utils.general.images.
getImagesByPlate
(plateid, download=False, mode=None, as_url=None, verbose=None, release=None)[source]¶Get all images belonging to a given plate ID
Retrieve all images belonging to a given plate ID from either your local filesystem SAS or the Utah SAS. Optionally can download the images by rsync using sdss_access.
When as_url is False, both local and remote modes will allow you to access the full path to the images in your local SAS. WHen as_url is True, local mode generates the Utah SAS url links, while remote mode generates the Utah SAS rsync links.
Auto mode defaults to remote.
Parameters: |
|
---|---|
Returns: | listofimages (list) – The list of images |
marvin.utils.general.images.
getImagesByList
(inputlist, download=False, mode=None, as_url=None, verbose=None, release=None)[source]¶Get all images from a list of ids
Retrieve a list of images from either your local filesystem SAS or the Utah SAS. Optionally can download the images by rsync using sdss_access.
When as_url is False, both local and remote modes will allow you to access the full path to the images in your local SAS. WHen as_url is True, local mode generates the Utah SAS url links, while remote mode generates the Utah SAS rsync links.
Auto mode defaults to remote.
Parameters: |
|
---|---|
Returns: | listofimages (list) – The list of images you have requested |
marvin.utils.general.images.
showImage
(path=None, plateifu=None, release=None, return_image=True, show_image=True, mode=None)[source]¶Crudely and coarsely show a galaxy image that has been downloaded
This utility function quickly allows you to display a PNG IFU image that is located in your local SAS or from the remote Utah SAS. A PIL Image object is also returned which allows you to manipulate the image after the fact. See Displaying Images for example usage.
Either the path or plateifu keyword is required.
Parameters: |
|
---|---|
Returns: | image (PIL Image or None) – If return_image is set, returns a PIL Image object to allow for image manipulation, else returns None. |
marvin.utils.plot.map.
ax_setup
(sky_coords, fig=None, ax=None, facecolor='#A8A8A8')[source]¶Do basic axis setup for maps.
Parameters: |
|
---|---|
Returns: | tuple – (plt.figure object, plt.figure axis object) |
marvin.utils.plot.map.
mask_low_snr
(value, ivar, snr_min)[source]¶Mask spaxels with a signal-to-noise ratio below some threshold.
Parameters: | |
---|---|
Returns: | array – Boolean array for mask (i.e., True corresponds to value to be masked out). |
marvin.utils.plot.map.
mask_neg_values
(value)[source]¶Mask spaxels with negative values.
This method is primarily for using a logarithmic colorbar.
Parameters: | value (array) – Value for image. |
---|---|
Returns: | array – Boolean array for mask (i.e., True corresponds to value to be masked out). |
marvin.utils.plot.map.
plot
(*args, **kwargs)[source]¶Make single panel map or one panel of multi-panel map plot.
Please see the Plotting Tutorial for examples.
Parameters: |
|
---|---|
Returns: | fig, ax (tuple) – matplotlib.figure, matplotlib.axes |
Example
>>> import marvin.utils.plot.map as mapplot
>>> maps = Maps(plateifu='8485-1901')
>>> ha = maps['emline_gflux_ha_6564']
>>> fig, ax = mapplot.plot(dapmap=ha)
Functions for colorbars.
marvin.utils.plot.colorbar.
linearlab
()[source]¶Make linearlab color map.
Description of linearlab palatte.
Returns: | cm, cm_r (tuple) – matplotlib.cm object and reversed matplotlib.cm object |
---|
marvin.utils.general.maskbit.
Maskbit
(name, schema=None, description=None)[source]¶Bases: object
A class representing a maskbit.
Parameters: |
---|
get_mask
(labels, mask=None, dtype=<class 'int'>)[source]¶Create mask from a list of labels.
If dtype
is int
, then get_mask
can effectively
perform an OR or AND operation. However, if dtype
is
bool
, then get_mask
does an OR.
Parameters: | |
---|---|
Returns: | array – Mask for given labels. |
Example
>>> maps = Maps(plateifu='8485-1901')
>>> ha = maps['emline_gflux_ha_6564']
>>> ha.pixmask.get_mask(['NOCOV', 'LOWCOV'])
array([[3, 3, 3, ..., 3, 3, 3],
...,
[3, 3, 3, ..., 3, 3, 3]])
>>> ha.pixmask.get_mask(['NOCOV', 'LOWCOV'], dtype=bool)
array([[ True, True, True, ..., True, True, True],
...,
[ True, True, True, ..., True, True, True]], dtype=bool)
labels_to_bits
(labels)[source]¶Convert bit labels into bits.
Parameters: | labels (str or list) – Labels of bits. |
---|---|
Returns: | list – Bits that correspond to the labels. |
Example
>>> maps = Maps(plateifu='8485-1901')
>>> ha = maps['emline_gflux_ha_6564']
>>> ha.pixmask.labels_to_bits('DONOTUSE')
[30]
>>> ha.pixmask.labels_to_value(['NOCOV', 'LOWCOV'])
[0, 1]
labels_to_value
(labels)[source]¶Convert bit labels into a bit value.
Parameters: | labels (str or list) – Labels of bits to set. |
---|---|
Returns: | int – Integer bit value. |
Example
>>> maps = Maps(plateifu='8485-1901')
>>> ha = maps['emline_gflux_ha_6564']
>>> ha.pixmask._labels_to_value('DONOTUSE')
1073741824
>>> ha.pixmask._labels_to_value(['NOCOV', 'LOWCOV'])
3
values_to_bits
(values=None)[source]¶Convert mask values to a list of bits set.
Parameters: | values (int or array) – Mask values. If None , apply to entire
Maskbit.mask array. Default is None . |
---|---|
Returns: | list – Bits that are set. |
Example
>>> maps = Maps(plateifu='8485-1901')
>>> ha = maps['emline_gflux_ha_6564']
>>> ha.pixmask.values_to_bits()
[[[0, 1, 4, 30],
[0, 1, 4, 30],
...
[0, 1, 4, 30]]]
values_to_labels
(values=None)[source]¶Convert mask values to a list of the labels of bits set.
Parameters: | values (int or array) – Mask values. If None , apply to entire
Maskbit.mask array. Default is None . |
---|---|
Returns: | list – Bits that are set. |
Example
>>> maps = Maps(plateifu='8485-1901')
>>> ha = maps['emline_gflux_ha_6564']
>>> ha.pixmask.values_to_labels()
[[['NOCOV', 'LOWCOV', 'NOVALUE', 'DONOTUSE'],
['NOCOV', 'LOWCOV', 'NOVALUE', 'DONOTUSE'],
...
['NOCOV', 'LOWCOV', 'NOVALUE', 'DONOTUSE']]]
bits
¶labels
¶marvin.utils.plot.scatter.
compute_stats
(data)[source]¶Compute some statistics given a data array
Computes some basic statistics given a data array, excluding NaN values. Computes and returns the following Numpy statistics: mean, standard deviation, median, and the 10th, 25th, 75th, and 90th percentiles.
Parameters: | data (list|ndarray) – A list or Numpy array of data |
---|---|
Returns: | A dictionary of statistics values |
marvin.utils.plot.scatter.
hist
(arr, mask=None, fig=None, ax=None, bins=None, **kwargs)[source]¶Create a histogram of an array
Plots a histogram of an input column of data. Input can be a list or a Numpy array. Converts the input into a Numpy MaskedArray, applying the optional mask. If no mask is supplied, it masks any NaN values. This uses Astropy’s enhanced hist function under the hood. Accepts all the same keyword arguments as matplotlib hist method.
Parameters: |
|
---|---|
Returns: | tuple – histogram data, matplotlib figure, and axis objects. The histogram data returned is a dictionary containing: {
'bins': The number of bins used,
'counts': A list of the count of objects within each bin,
'binedges': A list of the left binedge used in defining each bin,
'binids': An array of the same shape as input data, containing the binid of each element,
'indices': A dictionary of a list of array indices within each bin
}
|
Example
>>> # histogram some random data
>>> from marvin.utils.plot.scatter import hist
>>> import numpy as np
>>> x = np.random.random(100)
>>> hist_data, fig, ax = hist(x)
marvin.utils.plot.scatter.
plot
(x, y, **kwargs)[source]¶Create a scatter plot given two columns of data
Creates a Matplotlib plot using two input arrays of data. Creates either a Matplotlib scatter plot, hexbin plot, or scatter density plot depending on the size of the input data. For data with < 1000 values, creates a scatter plot. For data with values between 1000 and 500,000, creates a hexbin plot. For data with > 500,000 values, creates a scatter density plot.
By default, will also create and display histograms for the x and y data. This can be disabled setting the “with_hist” keyword to False, or “x”, or “y” for displaying only that column. Accepts all the same keyword arguments as matplotlib scatter, hexbin, and hist methods.
See scatter-density See matplotlib.pyplot.scatter See matplotlib.pyplot.hexbin
Parameters: |
|
---|---|
Returns: | A tuple of the matplotlib figure, axes, and histogram data (if returned) |
Example
>>> # create a scatter plot
>>> import numpy as np
>>> from marvin.utils.scatter import plot
>>> x = np.random.random(100)
>>> y = np.random.random(100)
>>> plot(x, y)