API#
Utilities#
- class lib.utility.ByteReader(line: bytes)#
Bases:
object
A utility class to read from binary files where each data field corresponds to a byte range in a line.
- get(begin: int, end: int, d_type: ~typing.Callable[[bytes], ~lib.utility.T | str] = <function ByteReader.<lambda>>) T | str #
Get data from the byte-range
begin
toend
and convert it withd_type
.- Parameters:
begin – beginning of the data range
end – end of the data range
d_type – A function that takes a bytestring and converts it to some type
T
, defaults to decoding as utf-8 string.
- class lib.utility.DownloadData(url: str, filename: str | None = None, _path: str = '')#
Bases:
object
Holds information about downloadable data. Usually the user supplies
filename
andurl
and the path is then supplied programatically bydownload()
orlib.catalogfactory.Factory.download_cached()
.- open(*args, **kwargs)#
Open the downloaded file (if it exists).
Corresponds to the built-in
io.open()
with the first argument presupplied.
- property path: str#
The path to the downloaded file.
- Raises:
RuntimeError – when the file does not exist (both at assignment and at retrieval)
- lib.utility.download(download_dir: str, download_data: Iterable[DownloadData])#
Downloads a file from
DownloadData.url
for each member ofdownload_data
and saves it in thedownload_dir
.This function also sets
DownloadData.path
to the downloaded file.
Catalog Base Class#
The basic plumbing and template for creating custom catalogs.
- class lib.catalogfactory.Factory(cache_dir: str, data_dir: str)#
Bases:
object
The base class for all catalogs.
- Parameters:
cache_dir – the path to the cache directory
data_dir – the path to the data directory
Each catalog subclasses this class. The class variable
meta
is overwritten by a catalog to specify catalog metadata.Because of caching, the modifications to the state of the class instance is not persistent. Therefore the
_state
, which is persisted by pickling should be used.These methods are commonly overwritten:
The method
__post_init__()
may be overwritten to perform initialization as an alternative to the constructor.The method
get_data()
may be overwritten to acquire the catalog data.The method
load_objects()
may be overwritten to retrieve objects from the catalog data.The method
get_dublicates()
may be overwritten to identify dublicates between catalogs.
To overwrite those methods is less common:
The method
is_fresh()
may be overwritten to customize the detection of an outdated cache.
- property _download_dir#
Path to the download directory for the catalog.
- _in_cache_dir(path: str) str #
Transforms a path relative to the cache directory to an absolute path.
- _in_download_dir(path: str) str #
Transforms a path relative to the download directory to an absolute path.
- _make_catalog_object(*args, **kwargs)#
Constructs a
lib.catalogsdb.CatalogObject
with the fieldcatalog
prebound to the current catalog. All other arguments are passed through to the constructor.
- _state#
Storage for persistend state. Is being synced to disk.
- property dirname: str#
The filename for the generated catalog. (without extension) Used to label the cache directory.
- download_cached(*download_data: DownloadData)#
Download a file and cache it. Uses
is_fresh()
.
- get_data() None #
This method can be overwritten to download catalog data into
_download_dir()
.
- get_dublicates(query_fn: Callable[[str | int, str | None, int], List[CatalogObject]], catalogs: Dict[int, Catalog]) Iterator[Set[Tuple[int, bytes]]] #
Returns an iterator of sets of catalog-id and object hash pairs. Those sets signify the dublicate objects. The catalog database can be queried by the query_fn which is basically
lib.catalogsdb.CatalogsDB.retrieve_objects()
.catalogs
is a dict of catalog id and meta information.
- is_fresh(path: str) bool #
Returns wether the file under
path
is to considered fresh to be loaded from cache.The standard implementation checks if the file’s m-time is more or as recent as the m-time of the module file.
- load_objects() Iterator[CatalogObject] #
A generator that yields
lib.catalogsdb.CatalogObject
to be inserted into the catalog database.Should use
_make_catalog_object()
for convenience.
Catalogsdb Interface#
Code to create and manipulate a kstars catalog database.
- class lib.catalogsdb.CATALOGS#
Bases:
SimpleNamespace
An Enumeration of hardcoded catalog names.
- all_objects = 'all_catalogs'#
- master = 'master'#
- class lib.catalogsdb.Catalog(id: int, name: str, precedence: float = 0, author: str = '', source: str = '', description: str = '', version: int = 0, mut: bool = True, enabled: bool = True, colors: ~typing.Dict[str, str] = <factory>, image: str | None = None, license: str = '', maintainer: str = '', timestamp: ~datetime.datetime = datetime.datetime(2024, 5, 2, 14, 36, 46, 616567))#
Bases:
object
Catalog Metadata.
- colors: Dict[str, str]#
The color that the catalog’s objects are being rendered in as a dict of the form:
{ 'default': '#[hex rgb color code for default color]', '[color scheme file name]': '#[hex rgb color code]' }
The default color is used when the color for a specific color scheme is not specified.
- id: int#
The numeric and unique id of the catalog. Should be chosen greater that the biggest previusly given id.
- image: str | None = None#
The path of the preview image of the catalog relative to the data directory.
- precedence: float = 0#
The precedence of the catalog. If an dublicate object exists in another catalog with a higher precedence, it will shadow an object from this catalog. Should be between 0 and 1.
- class lib.catalogsdb.CatalogObject(trixel: int = 0, hash: bytes = b'', oid: bytes = b'', type: int | ~pykstars.ObjectType = <property object>, ra: float = 0, dec: float = 0, magnitude: float | None = None, name: str = '', long_name: str = '', catalog_identifier: str = '', major_axis: float | None = None, minor_axis: float | None = None, position_angle: float | None = None, flux: float | None = None, catalog: int = 0)#
Bases:
object
A DSO in the catalog. Just a simple container. No magic!
- Parameters:
id – oid of the object
oid – oid of the object
typed – Type of object
ra – Right Ascension
dec – Declination
magnitude – magnitude (brightness)
name – Primary name
long_name – Long name (common name)
catalog_identifier – a catalog specific identifier
catalog – catalog id
major_axis – major axis (arcminutes)
minor_axis – minor axis (arcminutes)
position_angle – position angle (degrees)
flux – integrated flux (optional)
- class lib.catalogsdb.CatalogsDB(db_filename: str, htmesh_level: int = 3)#
Bases:
object
A utility to manipulate a catalog db in the kstars format.
Wraps and augments the kstars python bindings and is usually not required for catalog packaging.
- property filename#
Returns the filename of the underlying db.
- insert_object(obj: CatalogObject) None #
Insert an object into a catalog. Regenerates its
hash
,trixel
and also itsoid
if it is empty.
- insert_objects(objs: Iterator[CatalogObject]) None #
Insert objects into a catalog. Regenerates their
hash
,trixel
and also theiroid
if it is empty.
- process_dupes(dupes: Set[Tuple[int, bytes]], precedence_ordered: List[int])#
Set the object ids of the object to the same value deterministically.
- retrieve_objects(catalog: str | int, query: str | None = None, limit: int = -1) List[CatalogObject] #
Retrieve objects from the
catalog
(either id or table name).query
is inserted as WHERE clause verbatim. The result list size is limited tolimit
.To search all catalogs, use
lib.catalogsdb.CATALOGS.all_objects
first argument.
- lib.catalogsdb.partition(lst: Sequence[T], key_fn: Callable[[T], KeyType]) Dict[KeyType, List[T]] #
Partition
lst
by the key determined bykey
.
- lib.catalogsdb.raise_if_not_successful(success: Tuple[bool, str]) None #
Raise a runtime error if the first entry of
success
isFalse
.
- lib.catalogsdb.strip_None(dct: MutableMapping[Any, Any]) MutableMapping[Any, Any] #
Strip any entries with
None
values fromdct
.
Thin bindings for KStars to facilitate trixel indexation from python.
- class pykstars.DBManager#
Bases:
pybind11_object
- compile_master_catalog(self: pykstars.DBManager) bool #
- dump_catalog(self: pykstars.DBManager, catalog_id: int, file_path: QString) Tuple[bool, QString] #
- import_catalog(self: pykstars.DBManager, file_path: QString, overwrite: bool) Tuple[bool, QString] #
- register_catalog(self: pykstars.DBManager, catalog: dict) Tuple[bool, QString] #
- remove_catalog(self: pykstars.DBManager, catalog_id: int) Tuple[bool, QString] #
- update_catalog_meta(self: pykstars.DBManager, catalog: dict) Tuple[bool, QString] #
- update_catalog_views(self: pykstars.DBManager) bool #
- class pykstars.Indexer#
Bases:
pybind11_object
- get_trixel(self: pykstars.Indexer, ra: float, dec: float, convert_epoch: bool = False) int #
Calculates the trixel number from the right ascention and the declination. The epoch of coordinates is assumed to be J2000.
If the epoch is B1950, convert_epoch has to be set to True.
- property level#
Sets the level of the HTMesh/SkyMesh used to index points.
- class pykstars.ObjectType#
Bases:
pybind11_object
The types of CatalogObjects
Members:
STAR
CATALOG_STAR
PLANET
OPEN_CLUSTER
GLOBULAR_CLUSTER
GASEOUS_NEBULA
PLANETARY_NEBULA
SUPERNOVA_REMNANT
GALAXY
COMET
ASTEROID
CONSTELLATION
MOON
ASTERISM
GALAXY_CLUSTER
DARK_NEBULA
QUASAR
MULT_STAR
RADIO_SOURCE
SATELLITE
SUPERNOVA
NUMBER_OF_KNOWN_TYPES
TYPE_UNKNOWN
- ASTERISM = <ObjectType.ASTERISM: 13>#
- ASTEROID = <ObjectType.ASTEROID: 10>#
- CATALOG_STAR = <ObjectType.CATALOG_STAR: 1>#
- COMET = <ObjectType.COMET: 9>#
- CONSTELLATION = <ObjectType.CONSTELLATION: 11>#
- DARK_NEBULA = <ObjectType.DARK_NEBULA: 15>#
- GALAXY = <ObjectType.GALAXY: 8>#
- GALAXY_CLUSTER = <ObjectType.GALAXY_CLUSTER: 14>#
- GASEOUS_NEBULA = <ObjectType.GASEOUS_NEBULA: 5>#
- GLOBULAR_CLUSTER = <ObjectType.GLOBULAR_CLUSTER: 4>#
- MOON = <ObjectType.MOON: 12>#
- MULT_STAR = <ObjectType.MULT_STAR: 17>#
- NUMBER_OF_KNOWN_TYPES = <ObjectType.NUMBER_OF_KNOWN_TYPES: 21>#
- OPEN_CLUSTER = <ObjectType.OPEN_CLUSTER: 3>#
- PLANET = <ObjectType.PLANET: 2>#
- PLANETARY_NEBULA = <ObjectType.PLANETARY_NEBULA: 6>#
- QUASAR = <ObjectType.QUASAR: 16>#
- RADIO_SOURCE = <ObjectType.RADIO_SOURCE: 18>#
- SATELLITE = <ObjectType.SATELLITE: 19>#
- STAR = <ObjectType.STAR: 0>#
- SUPERNOVA = <ObjectType.SUPERNOVA: 20>#
- SUPERNOVA_REMNANT = <ObjectType.SUPERNOVA_REMNANT: 7>#
- TYPE_UNKNOWN = <ObjectType.TYPE_UNKNOWN: 255>#
- property name#
- property value#