ztffields package#

Submodules#

ztffields.fields module#

fields#

Module to handle ZTF Fields.

Fields([load_level])

Interact or access ZTF Fields.

ztffields.fields.get_fieldid(grid=None, dec_range=None, ra_range=None, gall_range=None, galb_range=None, ecll_range=None, eclb_range=None, ebv_range=None, verbose=False)[source]#

get the list of fieldid parameters fullfilling the conditions

Parameters:
  • grid (Nonen, str) – Select the grid you want. If None the both will be considered. Available - ‘main’ - ‘secondary’

  • dec_range (None, list) –

    cut paramerers (in degree) 3 formats available: - None: means no selection - [min,max]: means range to be considered, None means no limit.

    example: decrange=[-10,None] means dec>-10.

    • [[min1,max1],[min2,max2], …]: means zones to be considered. example: decrange=[[None, -10],[5,None]] will simply exclude the [-10,5] dec range.

    • None means no selection.

  • ra_range (None, list) –

    cut paramerers (in degree) 3 formats available: - None: means no selection - [min,max]: means range to be considered, None means no limit.

    example: decrange=[-10,None] means dec>-10.

    • [[min1,max1],[min2,max2], …]: means zones to be considered. example: decrange=[[None, -10],[5,None]] will simply exclude the [-10,5] dec range.

    • None means no selection.

  • galb_range (None, list) –

    cut paramerers (in degree) 3 formats available: - None: means no selection - [min,max]: means range to be considered, None means no limit.

    example: decrange=[-10,None] means dec>-10.

    • [[min1,max1],[min2,max2], …]: means zones to be considered. example: decrange=[[None, -10],[5,None]] will simply exclude the [-10,5] dec range.

    • None means no selection.

  • gall_range (None, list) –

    cut paramerers (in degree) 3 formats available: - None: means no selection - [min,max]: means range to be considered, None means no limit.

    example: decrange=[-10,None] means dec>-10.

    • [[min1,max1],[min2,max2], …]: means zones to be considered. example: decrange=[[None, -10],[5,None]] will simply exclude the [-10,5] dec range.

    • None means no selection.

  • ecllg_range (None, list) –

    cut paramerers (in degree) 3 formats available: - None: means no selection - [min,max]: means range to be considered, None means no limit.

    example: decrange=[-10,None] means dec>-10.

    • [[min1,max1],[min2,max2], …]: means zones to be considered. example: decrange=[[None, -10],[5,None]] will simply exclude the [-10,5] dec range.

    • None means no selection.

  • eclb_range (None, list) –

    cut paramerers (in degree) 3 formats available: - None: means no selection - [min,max]: means range to be considered, None means no limit.

    example: decrange=[-10,None] means dec>-10.

    • [[min1,max1],[min2,max2], …]: means zones to be considered. example: decrange=[[None, -10],[5,None]] will simply exclude the [-10,5] dec range.

    • None means no selection.

  • ebv_range (None, list) – same format as e.g., ‘dec_range’ but for Mily way E(B-V) extinction.

Returns:

list of int (fieldid)

Return type:

list

ztffields.fields.get_grid_field(which)[source]#
ztffields.fields.get_layout(level)[source]#
class ztffields.fields.Fields(load_level=None)[source]#

Bases: object

Interact or access ZTF Fields.

Attributes:
geodf_ccd

field geometry at the ccd level

geodf_focalplane

field geometry at the focal plane level

geodf_quadrant

field geometry at the quadrant level

Methods

get_ccd_contours([ccdid, inrad, steps, ra, ...])

get the full ccd contours.

get_contours([level, inrad, steps, ra, dec, ...])

get_field_centroids([fieldid])

get field central coordinates [ra,dec]

get_field_geometry([fieldid, level])

get a geopandas dataframe for the fields.

get_field_multipolygon(fieldid[, level])

get the a (multi)polygon for the given single field

get_field_vertices([fieldid, level, inrad, ...])

get the verticies (or polygon) for the given fields

get_focalplane_contours([inrad, steps, ra, ...])

get the whole focal plane contours (field of view)

get_quadrant_contours([rcid, inrad, steps, ...])

get the quadrant contours.

get_level_geodf

load_level_geometry

Attributes:
geodf_ccd

field geometry at the ccd level

geodf_focalplane

field geometry at the focal plane level

geodf_quadrant

field geometry at the quadrant level

Methods

get_ccd_contours([ccdid, inrad, steps, ra, ...])

get the full ccd contours.

get_contours([level, inrad, steps, ra, dec, ...])

get_field_centroids([fieldid])

get field central coordinates [ra,dec]

get_field_geometry([fieldid, level])

get a geopandas dataframe for the fields.

get_field_multipolygon(fieldid[, level])

get the a (multi)polygon for the given single field

get_field_vertices([fieldid, level, inrad, ...])

get the verticies (or polygon) for the given fields

get_focalplane_contours([inrad, steps, ra, ...])

get the whole focal plane contours (field of view)

get_quadrant_contours([rcid, inrad, steps, ...])

get the quadrant contours.

get_level_geodf

load_level_geometry

FIELDS_RADEC = ra    dec ID                     1       0.00000 -89.05 2      90.00000 -89.05 3     180.00000 -89.05 4     270.00000 -89.05 5      16.36364 -81.85 ...         ...    ... 1891  284.39570  80.15 1892  311.97099  80.15 1893  339.20093  80.15 1894   90.00000  88.50 1895  240.00000  88.50  [1776 rows x 2 columns]#
CCD_COORDS = EW        NS  CCD 0  -3.646513 -3.727898    1 1  -3.647394 -2.001758    1 2  -1.920848 -2.004785    1 3  -1.920383 -3.731333    1 4  -1.790386 -3.729368    2 ..       ...       ...  ... 59  1.789845  2.002826   15 60  1.919878  2.004674   16 61  1.919413  3.731221   16 62  3.645543  3.727789   16 63  3.646424  2.001648   16  [64 rows x 3 columns]#
QUAD_COORDS = EW        NS  CCD  Quad 0   -2.781842 -2.866617    1     0 1   -2.782178 -2.003445    1     0 2   -3.645452 -2.001932    1     0 3   -3.645011 -2.865003    1     0 4   -1.918673 -2.868231    1     1 ..        ...       ...  ...   ... 251  2.782579  2.004180   16    62 252  2.782579  2.004180   16    63 253  2.782243  2.867352   16    63 254  1.919074  2.868968   16    63 255  1.919306  2.005694   16    63  [256 rows x 4 columns]#
load_level_geometry(level)[source]#
get_level_geodf(level)[source]#
classmethod get_field_centroids(fieldid=None)[source]#

get field central coordinates [ra,dec]

Parameters:

fieldid (int, list) – name of the field (or list of). If None, no fieldid selection.

Returns:

dataframe (index as fieldid ; columns ra, dec)

Return type:

pandas.DataFrame

classmethod get_field_geometry(fieldid=None, level='ccd', **kwargs)[source]#

get a geopandas dataframe for the fields.

Parameters:
  • fieldid (int, list) – name of the field (or list of). If None, no fieldid selection.

  • level (str) – level of description of the camera. - focalplane: 1 polygon for the whole footprint - ccd: 1 polygon per CCD (16 per footprint then) - quadrant: 1 polygon per quadrant (64 per per footprint then) ccd and quadrant level will account for gaps between the CCDs.

  • get_field_vertices (**kwargs goes to)

Returns:

geopandas GeoDataFrame containing the [‘geometry’] columns. If level is ccd or quadrant, the dataframe has two level of indexes (fieldid, ccdid/rcid) ; only fieldid if level is focalplane.

Return type:

geopandas.GeoDataFrame

See also

get_field_vertices

get the verticies (or polygon) for the given fields

classmethod get_field_vertices(fieldid=None, level='ccd', inrad=False, steps=5, as_polygon=False)[source]#

get the verticies (or polygon) for the given fields

Parameters:
  • fieldid (int, list) – name of the field (or list of). If None, no fieldid selection.

  • level (str) – level of description of the camera. - focalplane: 1 polygon for the whole footprint - ccd: 1 polygon per CCD (16 per footprint then) - quadrant: 1 polygon per quadrant (64 per per footprint then) ccd and quadrant level will account for gaps between the CCDs.

  • inrad (bool) – should the coordinates be given in radian ? False means in degree.

  • steps (int) – number of points between two corners. These are used to account for square deformation.

  • as_polygon (bool) – should this return a list of shapely.polygon rather than a list of (N,2) verticies ?

Returns:

  • the indexes (fieldid or (fieldid,ccdid/rcid) dependning on level)

  • the list of verticities ([steps, 2] or shapely.Polygon ; see as_polygon).

Return type:

dataframe, list

See also

get_field_geopandas

get a geopandas dataframe for the fields.

classmethod get_field_multipolygon(fieldid, level='ccd', **kwargs)[source]#

get the a (multi)polygon for the given single field

Parameters:
  • fieldid (int) – name of the field.

  • level (str) – level of description of the camera. - focalplane: 1 polygon for the whole footprint - ccd: 1 polygon per CCD (16 per footprint then) - quadrant: 1 polygon per quadrant (64 per per footprint then) ccd and quadrant level will account for gaps between the CCDs.

  • get_field_geometry (**kwargs goes to)

Returns:

polygon if level is focalplane.

Return type:

shapely.(Multi)Polygon

classmethod get_contours(level='quadrant', inrad=False, steps=5, ra=0, dec=0, as_polygon=False, allow_multipolygon=True, **kwargs)[source]#
classmethod get_quadrant_contours(rcid=None, inrad=False, steps=5, ra=0, dec=0, as_polygon=False)[source]#

get the quadrant contours.

Parameters:
  • rcid (int, list) – id of the quadrant (or list of). If None, all 64 quadrants will be used.

  • inrad (bool) – should the coordinates be given in radian ? False means in degree.

  • steps (int) – number of points between two corners. These are used to account for square deformation.

  • ra (float, array) – field ra centroid (in degree if not inrad)

  • dec (float, array) – field dec centroid

  • as_polygon (bool) – should the return a shapely polygon or the vertices (N,2) array

Returns:

see as_polygon

Return type:

array or lit of polygon

See also

get_ccd_contours

external countour of a full ccd

get_focalplane_contours

external countour of the whole focal plane (Field of view)

classmethod get_ccd_contours(ccdid=None, inrad=False, steps=5, ra=0, dec=0, as_polygon=False)[source]#

get the full ccd contours.

Parameters:
  • ccdid (int, list) – id of the ccd (or list of). If None, all 16 quadrants will be used.

  • inrad (bool) – should the coordinates be given in radian ? False means in degree.

  • steps (int) – number of points between two corners. These are used to account for square deformation.

  • ra (float, array) – field ra centroid (in degree if not inrad)

  • dec (float, array) – field dec centroid

  • as_polygon (bool) – should the return a shapely polygon or the vertices (N,2) array

Returns:

see as_polygon

Return type:

array or lit of polygon

See also

get_quadrant_contours

countour of a single quadrant (ccd amplifier)

get_focalplane_contours

external countour of the whole focal plane (Field of view)

classmethod get_focalplane_contours(inrad=False, steps=5, ra=0, dec=0, as_polygon=False)[source]#

get the whole focal plane contours (field of view)

Parameters:
  • inrad (bool) – should the coordinates be given in radian ? False means in degree.

  • steps (int) – number of points between two corners. These are used to account for square deformation.

  • ra (float, array) – field ra centroid (in degree if not inrad)

  • dec (float, array) – field dec centroid

  • as_polygon (bool) – should the return a shapely polygon or the vertices (N,2) array

Returns:

see as_polygon

Return type:

array or lit of polygon

See also

get_quadrant_contours

countour of a single quadrant (ccd amplifier)

get_ccd_contours

external countour of a full ccd

property geodf_focalplane#

field geometry at the focal plane level

property geodf_ccd#

field geometry at the ccd level

property geodf_quadrant#

field geometry at the quadrant level

ztffields.io module#

ztffields.projection module#

projection#

Project targets (ra, dec) into the fields.

radec_to_fieldid(radecs[, level])

fieldid_to_radec(fieldid[, level])

spatialjoin_radec_to_fields(radec, fields[, ...])

join the radecs with the fields

FieldProjection([level, radec])

Attributes:

ztffields.projection.radec_to_fieldid(radecs, level='focalplane', **kwargs)[source]#
ztffields.projection.fieldid_to_radec(fieldid, level='focalplane', **kwargs)[source]#
ztffields.projection.project_to_radec(verts_or_polygon, ra, dec)[source]#

project a geometry (or its vertices) to given ra, dec coordinates

Parameters:
  • verts_or_polygon (shapely.Polygon or 2d-array) – geometry or vertices representing the camera footprint in the sky if vertices, the format is: x, y = vertices

  • ra (float or array) – poiting(s) R.A.

  • dec (float or array) – poiting(s) declination

Returns:

if input are vertices - list of new verticies if input are geometry - list of new geometries

Return type:

list

ztffields.projection.spatialjoin_radec_to_fields(radec, fields, how='inner', predicate='intersects', index_radec='index_radec', allow_dask=True, **kwargs)[source]#

join the radecs with the fields

Parameters:
  • radec (DataFrame or 2d-array) –

    coordinates of the points. - DataFrame: must have the “ra” and “dec” columns.

    This will use the DataFrame’s index are data index.

    • 2d array (shape N,2): returned index will be ‘range(len(ra))’

  • fields ([geopandas.geoserie, geopandas.geodataframe or dict]) –

    fields contains the fieldid and fields shapes. Several forms are accepted: - dict: {fieldid: 2d-array, fieldid: 2d-array …}

    here, the 2d-array are the field’s vertices.

    • geoserie: geopandas.GeoSeries with index as fieldid and geometry as field’s vertices.

    • geodataframe: geopandas.GeoDataFrame with the ‘fieldid’ column and geometry as field’s vertices.

Returns:

(geometry.sjoin result)

Return type:

GeoDataFrame

ztffields.projection.parse_fields(fields)[source]#

read various formats for fields and returns it as a geodataframe

Parameters:

fields ([geopandas.geoserie, geopandas.geodataframe or dict]) –

fields contains the fieldid and fields shapes. Several forms are accepted: - dict: {fieldid: 2d-array or regions, fieldid: 2d-array or regions …}

here, the 2d-array are the field’s vertices or a astropy/ds9 regions

  • geoserie: geopandas.GeoSeries with index as fieldid and geometry as field’s vertices.

  • geodataframe: geopandas.GeoDataFrame with the ‘fieldid’ column and geometry as field’s vertices.

Return type:

GeoDataFrame (geometry.sjoin result)

Examples

provide a dict of ds9 regions >>> fields = {450:”box(50,30, 3,4,0)”, 541:”ellipse(190,-10,1.5,1,50)”} >>> geodf = parse_fields(fields)

ztffields.projection.regions_to_shapely(region)[source]#
Parameters:
region: str or Regions (see astropy-regions.readthedocs.io)

if str, it is assumed to be the dr9 ircs format e.g. region = box(40.00000000,50.00000000,5.00000000,4.00000000,0.00000000) if Regions, region will be converted into the str format using ``region = region.serialize(“ds9”).strip().split(”

“)[-1]``

The following format have been implemented: - box - circle - ellipse - polygon

Returns:
Shapely’s Geometry

the geometry will depend on the input regions.

Raises:
NotImplementedError

if the format is not recognised.

Examples

>>> shapely_ellipse = regions_to_shapely('ellipse(54,43.4, 4, 2,-10)')
>>> shapely_rotated_rectangle = regions_to_shapely('box(-30,0.4, 4, 2,80)')
class ztffields.projection.FieldProjection(level=None, radec=None)[source]#

Bases: object

Attributes:
fields
level
projection
target_radec

Methods

get_target_fields([explode])

load_projection(radec, level)

change_level

fieldid_to_radec

get_field_targets

get_geoseries

radec_to_fieldid

classmethod radec_to_fieldid(radec, level='focalplane', explode=True)[source]#
classmethod fieldid_to_radec(fieldid=None, level='focalplane', as_shapely=False)[source]#
get_target_fields(explode=False)[source]#
get_field_targets(explode=False)[source]#
load_projection(radec, level)[source]#
change_level(level)[source]#
get_geoseries(level)[source]#
property fields#
property projection#
property level#
property target_radec#

ztffields.utils module#

utils#

Useful tools used by the package.

cart2sph(vec)

Converts cartesian [x,y,z] to spherical [r, theta, phi] coordinates (in degrees).

sph2cart(vec)

Converts spherical coordinates [r, theta, phi] to cartesian coordinates [x,y,z].

rot_xz(vec, theta)

Rotates cartesian vector v [x,y,z] by angle theta around axis (0,1,0)

rot_xz_sph(l, b, theta)

Rotate spherical coordinate (l,b = theta, phi) by angle theta around axis (0,1,0) (calls does to rot_xz and cart2sph)

ztffields.utils.cart2sph(vec)[source]#

Converts cartesian [x,y,z] to spherical [r, theta, phi] coordinates (in degrees).

Parameters:

vec (array) – x, y, z

Returns:

[r, theta, phi]

Return type:

array

ztffields.utils.sph2cart(vec)[source]#

Converts spherical coordinates [r, theta, phi] to cartesian coordinates [x,y,z].

Parameters:

vec (array) – r, theta, phi ; angles in degrees

Returns:

[x, y, z]

Return type:

array

ztffields.utils.rot_xz(vec, theta)[source]#

Rotates cartesian vector v [x,y,z] by angle theta around axis (0,1,0)

Parameters:
  • vec (array) – x, y, z

  • theta (float) – angle in degree

Returns:

rotated x, y, z

Return type:

array

ztffields.utils.rot_xz_sph(l, b, theta)[source]#

Rotate spherical coordinate (l,b = theta, phi) by angle theta around axis (0,1,0) (calls does to rot_xz and cart2sph)

Parameters:
  • l (float) – spherical coordinate

  • b (float) – spherical coordinate

  • theta (float) – angle in degree

Returns:

[r, theta, phi]

Return type:

array

ztffields.utils.ccdid_qid_to_rcid(ccdid, qid)[source]#

provides the rcid corresponding to the ccdid and qid

ztffields.utils.rcid_to_ccdid_qid(rcid)[source]#

gets the ccdid and qid for the given rcid

Module contents#