{"id":17358303,"url":"https://github.com/yymao/generic-catalog-reader","last_synced_at":"2025-04-15T00:29:52.306Z","repository":{"id":55541954,"uuid":"95732024","full_name":"yymao/generic-catalog-reader","owner":"yymao","description":"A common reader interface for accessing generic catalogs","archived":false,"fork":false,"pushed_at":"2023-08-14T23:01:11.000Z","size":739,"stargazers_count":7,"open_issues_count":1,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T02:14:49.561Z","etag":null,"topics":["abstract-class","catalog-api","data-access","python","reader"],"latest_commit_sha":null,"homepage":"https://yymao.github.io/generic-catalog-reader/index.html","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yymao.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-06-29T02:48:50.000Z","updated_at":"2024-02-26T18:19:12.000Z","dependencies_parsed_at":"2022-08-15T02:50:47.410Z","dependency_job_id":"7c8a6327-4dfa-4b22-a51d-c3b0e1264039","html_url":"https://github.com/yymao/generic-catalog-reader","commit_stats":{"total_commits":128,"total_committers":4,"mean_commits":32.0,"dds":0.0625,"last_synced_commit":"2b4731c879264a2b203b45e9a03bc2de7270a846"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yymao%2Fgeneric-catalog-reader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yymao%2Fgeneric-catalog-reader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yymao%2Fgeneric-catalog-reader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yymao%2Fgeneric-catalog-reader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yymao","download_url":"https://codeload.github.com/yymao/generic-catalog-reader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248983685,"owners_count":21193621,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abstract-class","catalog-api","data-access","python","reader"],"created_at":"2024-10-15T19:05:02.986Z","updated_at":"2025-04-15T00:29:52.272Z","avatar_url":"https://github.com/yymao.png","language":"Python","readme":"# Generic Catalog Reader (GCR)\n[![Conda Version](https://img.shields.io/conda/vn/conda-forge/gcr.svg)](https://anaconda.org/conda-forge/gcr)\n[![PyPIVversion](https://img.shields.io/pypi/v/GCR.svg)](https://pypi.python.org/pypi/GCR)\n\nA ready-to-use, abstract base class for creating a common reader interface that accesses generic table-like catalogs. \n\nThis project was started in response to the need of the [DESCQA](https://github.com/LSSTDESC/descqa) framework. It is now used in the [LSST DESC GCR Catalogs](https://github.com/LSSTDESC/gcr-catalogs). \n\n## Installation\n\nYou can install `GCR` from conda-forge:\n\n```bash\nconda install gcr --channel conda-forge\n```\n\nOr from PyPI:\n\n```bash\npip install GCR\n```\n\n## Concept\n\nThe reader should specify: (1) how to translate (assemble) requested quantities from the native quantities; and (2) how to access native quantities from the underlying data format. \n\n![Concept](https://i.imgur.com/eBR6kof.png)\n\n\n## Usage\n\nYou can [find API documentation here](https://yymao.github.io/generic-catalog-reader/). However, looking at some [real examples](https://github.com/LSSTDESC/gcr-catalogs/tree/master/GCRCatalogs) is probably more useful. \n\nBasically, you will subclass `GCR.BaseGenericCatalog` and then set the member dict `_quantity_modifiers` inside `_subclass_init`, and implement the member methods `_generate_native_quantity_list` and `_iter_native_dataset`. Here's an minimal example. \n\n```python\nimport h5py\nimport GCR\n\nclass YourCatalogReader(GCR.BaseGenericCatalog):\n    \n    def _subclass_init(self, **kwargs):\n        self._file = kwargs['filename']\n        \n        self._quantity_modifiers = {\n            'galaxy_id' :    'galaxyID',\n            'ra':            (lambda x: x/3600.0, 'ra'),\n            'dec':           (lambda x: x/3600.0, 'dec'),\n            'is_central':    (lambda x, y: x == y, 'haloId', 'parentHaloId'),\n        }\n        \n    def _generate_native_quantity_list(self):\n        \"\"\"\n        Must return an iterable of all native quantity names.\n        \"\"\"\n        with h5py.File(self._file, 'r') as fh:\n            return fh.keys()\n        \n    def _iter_native_dataset(self, native_filters=None):\n        \"\"\"\n        Must be a generator.\n        Must yield a callable, *native_quantity_getter*.\n        This function must iterate over subsets of rows, not columns!\n        Below are specifications of *native_quantity_getter*\n        ---\n        Must take a single argument of a native quantity name.\n        Should assume the argument is valid.\n        Must return a numpy 1d array.\n        \"\"\"\n        assert not native_filters, '*native_filters* is not supported'\n        with h5py.File(self._file, 'r') as fh:\n            def native_quantity_getter(native_quantity):\n                return fh[native_quantity].value\n            yield native_quantity_getter\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyymao%2Fgeneric-catalog-reader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyymao%2Fgeneric-catalog-reader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyymao%2Fgeneric-catalog-reader/lists"}