mocpy.STMOC

class mocpy.STMOC(store_index)[source]

Time-Spatial Coverage class.

Is a Time-Spatial Coverage (ST-MOC).

Args:

create_key: Object ensure __init__ is called by super-class/class-methods only store_index: index of the ST-MOC in the rust-side storage

add_neighbours()

Extend the MOC instance so that it includes the HEALPix cells touching its border.

The depth of the HEALPix cells added at the border is equal to the maximum depth of the MOC instance.

Returns:
mocMOC

self extended by one degree of neighbours.

complement()

Return the complement of the MOC instance.

Returns:
resultMOC or TimeMOC

The resulting MOC.

contains(times, lon, lat, inside=True)[source]

Return a boolean mask array of the (times, positions) lying inside (or outside) the Space-Time coverage.

Parameters:
timesastropy.time.Time

The times of each sky coordinates.

lonastropy.units.Quantity

The longitudes of the sky coordinates observed at a specific time.

latastropy.units.Quantity

The latitudes of the sky coordinates observed at a specific time.

insidebool, optional

True by default. The returned mask array has true values for (time, position) lying inside the Space-Time coverage.

Returns:
arrayndarray

A mask boolean array

Raises:
ValueErrorIf times, lon and lat do not have the same length.
contracted()

Return the MOC contracted by removing the internal border made of cells at the MOC maximum depth.

The only difference with respect to remove_neighbours is that contracted returns a new MOC instead of modifying the existing one.

Returns:
mocMOC

The extended MOC

degrade_to_order(new_order)

Degrade the MOC instance to a new, less precise, MOC.

The maximum depth (i.e. the depth of the smallest cells that can be found in the MOC) of the degraded MOC is set to new_order.

Parameters:
new_orderint

Maximum depth of the output degraded MOC.

Returns:
mocMOC or TimeMOC

The degraded MOC.

difference(another_moc, *args)

Difference between the MOC instance and other MOCs.

Parameters:
another_mocMOC

The MOC used that will be substracted to self.

argsMOC

Other additional MOCs to perform the difference with.

Returns:
resultMOC or TimeMOC

The resulting MOC.

empty()

(e.g. a numpy boolean array).

Returns:
result: bool

True if the MOC instance is empty.

extended()

Return the MOC extended by the external border made of cells at the MOC maximum depth.

The only difference with respect to add_neighbours is that extended returns a new MOC instead of modifying the existing one.

Returns:
mocMOC

The extended MOC

flatten()

Return the list of indices of all cells in the MOC at the MOC depth.

classmethod from_fits(path_or_url, timeout=1000)

Load a MOC from a FITS file.

The specified FITS file must store the MOC (i.e. the list of HEALPix cells it contains) in a binary HDU table.

Parameters:
pathstr

The path to the FITS file.

timeoutfloat

Timeout for the query, defaults to 1000s

Returns:
resultMOC or TimeMOC

The resulting MOC.

classmethod from_json(json_moc)

Create a MOC from a dictionary of HEALPix cell arrays indexed by their depth.

Parameters:
json_mocdict(str[int]

A dictionary of HEALPix cell arrays indexed by their depth.

Returns:
mocMOC or TimeMOC

the MOC.

classmethod from_spatial_coverages(times_start, times_end, spatial_coverages, time_depth=61)[source]

Create a 2D Coverage from a set of time ranges and spatial coverages associated to them.

Parameters:
times_startastropy.time.Time

The starting times of each observations.

times_endastropy.time.Time

The ending times of each observations.

spatial_coverageslist

List of mocpy.MOC spatial coverage objects.

time_depthint, optional

Time depth. By default, the time resolution chosen is 1µs.

Returns:
resultSTMOC

The resulting Spatial-Time Coverage map.

classmethod from_str(value)

Create a MOC from a str.

This grammar is expressed is the MOC IVOA specification at section 2.3.2.

Parameters:
valuestr

The MOC as a string following the grammar rules.

Returns:
mocMOC or TimeMOC

The resulting MOC

See also

from_string

a duplicate of this method, with added fold option

Examples

>>> from mocpy import MOC
>>> moc = MOC.from_str("2/2-25 28 29 4/0 6/")
classmethod from_string(value, format='ascii')[source]

Deserialize the Spatial MOC from the given string.

Format can be ‘ascii’ or ‘json’, though the json format is not officially supported by the IVOA.

Parameters:
formatstr, optional

The format in which the MOC will be serialized before being saved. Possible formats are “ascii” or “json”. By default, format is set to “ascii”.

classmethod from_time_ranges_positions(times_start, times_end, lon, lat, time_depth=61, spatial_depth=29)[source]

Create a 2D Coverage from a set of times and positions associated to each time.

Parameters:
times_startastropy.time.Time

The starting times of each observations.

times_endastropy.time.Time

The ending times of each observations.

lonastropy.units.Quantity

The longitudes of the sky coordinates observed at a specific time.

latastropy.units.Quantity

The latitudes of the sky coordinates observed at a specific time.

time_depthint, optional

Time depth. By default, the time resolution chosen is 1µs.

spatial_depthint, optional

Spatial depth. By default, the space resolution chosen is 393.2μas.

Returns:
resultSTMOC

The resulting Spatial-Time Coverage map.

classmethod from_times_positions(times, time_depth, lon, lat, spatial_depth)[source]

Create a 2D Coverage from a set of times and positions associated to each time.

Parameters:
timeastropy.time.Time

The times of each sky coordinates.

time_depthint

Time depth.

lonastropy.units.Quantity

The longitudes of the sky coordinates observed at a specific time.

latastropy.units.Quantity

The latitudes of the sky coordinates observed at a specific time.

spatial_depthint

Spatial depth.

Returns:
resultSTMOC

The resulting Spatial-Time Coverage map.

intersection(another_moc, *args)

Intersection between the MOC instance and other MOCs.

Parameters:
another_mocMOC

The MOC used for performing the intersection with self.

argsMOC

Other additional MOCs to perform the intersection with.

Returns:
resultMOC/TimeMOC

The resulting MOC.

is_empty()[source]

Check whether the Space-Time coverage is empty.

classmethod load(path, format='fits')[source]

Load the Spatial MOC from a file.

Format can be ‘fits’, ‘ascii’, or ‘json’, though the json format is not officially supported by the IVOA.

Parameters:
pathstr or pathlib.Path

The path to the file to load the MOC from.

formatstr, optional

The format from which the MOC is loaded. Possible formats are “fits”, “ascii” or “json”. By default, format is set to “fits”.

property max_depth

Return max depth of MOC.

property max_index

Return the largest index (at the deepest absolute resolution) the MOC contains.

property max_order

Is a clone of max_depth, to preserve the api between moc types.

property max_time

Return STMOC max time.

property min_index

Return the smallest index (at the deepest absolute resolution) the MOC contains.

property min_time

Return STMOC min time.

classmethod n_cells(depth, dimension)[source]

Get the number of cells for a given depth.

Parameters:
depthint

The depth. It is comprised between 0 and MAX_ORDER if dimension=’space’ and between 0 and MAX_ORDER if dimension=’time’.

dimensionstr

Can be either ‘time’ or ‘space’.

Returns:
int

The number of cells at the given order

Examples

>>> from mocpy import STMOC
>>> STMOC.n_cells(0, dimension='space')
12
classmethod new_empty()[source]

Create a new empty STMOC.

query_by_space(smoc)[source]

Query the ST-MOC by space coverage.

This will perform the union of all the time ranges whose associated spatial coverages lie in moc.

Parameters:
smocMOC

The spatial coverage.

Returns:
resultTimeMOC

The time ranges observing in the spatial_coverage

query_by_time(tmoc)[source]

Query the ST-MOC by time T-MOC.

This will perform the union of all the spatial coverages lying in a set of time ranges.

Parameters:
tmoc~mocpy.tmoc.TimeMOC``

Time ranges. Must be a Nx2 shaped astropy time array.

Returns:
resultMOC

The spatial coverage being observed within the input time ranges

remove_neighbours()

Remove from the MOC instance the HEALPix cells located at its border.

The depth of the HEALPix cells removed is equal to the maximum depth of the MOC instance.

Returns:
mocMOC

self minus its HEALPix cells located at its border.

save(path, format='fits', overwrite=False, pre_v2=False, fold=0, fits_keywords=None)

Write the MOC to a file.

Format can be ‘fits’, ‘ascii’, or ‘json’, though the json format is not officially supported by the IVOA.

Parameters:
pathstr or pathlib.Path

The path to the file to save the MOC in.

formatstr, optional

The format in which the MOC is saved. Possible formats are “fits”, “ascii” or “json”. By default, format is set to “fits”.

overwritebool, optional

If the file already exists and you want to overwrite it, then set the overwrite keyword. Default to False.

fold: int

if >0, print ascii or json output with a maximum line width

fits_keywords: dict, optional

Additional keywords to add to the FITS header.

serialize(format='fits', optional_kw_dict=None, pre_v2=False)

Serialize the MOC into a specific format.

Possible formats are FITS, JSON and STRING

Parameters:
formatstr

‘fits’ by default. The other possible choice is ‘json’ or ‘str’.

optional_kw_dictdict

Optional keywords arguments added to the FITS header. Only used if format equals to ‘fits’.

Returns:
resultastropy.io.fits.HDUList or JSON dictionary

The result of the serialization.

symmetric_difference(another_moc, *args)

Symmetric difference (XOR) between the MOC instance and other MOCs.

Parameters:
another_mocMOC

The MOC used that will be substracted to self.

argsMOC

Other additional MOCs to perform the difference with.

Returns:
resultMOC or TimeMOC

The resulting MOC.

to_string(format='ascii', fold=0)

Write the MOC into a string.

Format can be ‘ascii’ or ‘json’, though the json format is not officially supported by the IVOA.

Parameters:
formatstr, optional

The format in which the MOC will be serialized before being saved. Possible formats are “ascii” or “json”. By default, format is set to “ascii”.

fold: int

if >0, print ascii or json output with a maximum line width

union(another_moc, *args)

Union between the MOC instance and other MOCs.

Parameters:
another_mocMOC

The MOC used for performing the union with self.

argsMOC

Other additional MOCs to perform the union with.

Returns:
resultMOC/TimeMOC

The resulting MOC.

property uniq_gen

Return a np.array of the generic uniq indices of the cell in the MOC.

Warning

This is not defined in the MOC standard and is not HEALPix scpecific.

Notes

  • It consists on the regular index with a sentinel bit placed at the immediate left of the index’s MSB. At a given depth, the sentinel bit is always put o the same bit.

  • Because the uniq HEALPix encoding is not adapted for non-HEALPIx indices.

property uniq_zorder

Return a np.array of the zorder uniq indices of the cell in the MOC.

Warning

This is not defined in the MOC standard and is not HEALPix specific.

Notes

  • It consists on a regular index shifted on the left so that indices at all level have the same MSB. Plus a sentinel bit placed at the immediate right of the LSB.

  • Because the uniq HEALPix encoding is not adapted for non-HEALPIx indices AND because the natural ordering of such indices follow the same order as the zorder indices (which is very useful for streaming processing, e.g. when dealing with multi-order maps)

write(path, format='fits', overwrite=False, optional_kw_dict=None, pre_v2=False)

Write the MOC to a file.

Format can be ‘fits’ or ‘json’, though only the fits format is officially supported by the IVOA.

Parameters:
pathstr

The path to the file to save the MOC in.

formatstr, optional

The format in which the MOC will be serialized before being saved. Possible formats are “fits” or “json”. By default, format is set to “fits”.

overwritebool, optional

If the file already exists and you want to overwrite it, then set the overwrite keyword. Default to False.

optional_kw_dictoptional

Optional keywords arguments added to the FITS header. Only used if format equals to ‘fits’.