Skip to content

Add json serialization format for tables in ska_api - #33

Merged
javierggt merged 4 commits into
mainfrom
table-meta
Sep 10, 2026
Merged

javierggt merged 4 commits into
mainfrom
table-meta

Conversation

@javierggt

@javierggt javierggt commented Mar 27, 2026

Copy link
Copy Markdown
Collaborator

Description

This adds a json serialization format for tables in ska_api. The current implementation in master accepts two values for table_format (rows, columns) when returning astropy tables in ska_api methods. Both of these completely ignore the meta data in the table. This PR fixes that by adding a third choice (json) that includes it. An example output is shown in the functional test below.

This PR is rebased on top of #36 so the running kadi-test can be used to check that one too.

Interface impacts

No impact on existing interface. This PR adds an argument to methods that return astropy tables.

Testing

This PR also adds a test for the new format choice.

Unit tests

Two tests fail, and they already fail in the main branch:

  • kadi_apps/tests/test_astromon.py::test_obsid
  • kadi_apps/tests/test_astromon.py::test_regions
  • Mac
(ska3-flight-web) ~/SAO/git/kadi-apps table-meta $ git rev-parse HEAD
34058c115e0eba47a4a16e3ab460e3b3b16acfe2
(ska3-flight-web) ~/SAO/git/kadi-apps table-meta $ pytest kadi_apps
================================================== test session starts ==================================================
platform darwin -- Python 3.13.11, pytest-9.0.2, pluggy-1.6.0
rootdir: /Users/javierg/SAO/git
configfile: pytest.ini
plugins: anyio-4.12.1, timeout-2.4.0, dash-4.1.0
collected 28 items                                                                                                      

kadi_apps/tests/test_astromon.py ....                                                                             [ 14%]
kadi_apps/tests/test_auth.py .......                                                                              [ 39%]
kadi_apps/tests/test_django_cleanup.py .                                                                          [ 42%]
kadi_apps/tests/test_ska_api.py ................                                                                  [100%]

=================================================== warnings summary ====================================================
../../../miniforge3/envs/ska3-flight-web/lib/python3.13/site-packages/setuptools_scm/git.py:427
kadi-apps/kadi_apps/tests/test_django_cleanup.py::test_django_connection_closed_after_request
  /Users/javierg/miniforge3/envs/ska3-flight-web/lib/python3.13/site-packages/setuptools_scm/git.py:427: UserWarning: git archive did not support describe output
    warnings.warn("git archive did not support describe output")

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
============================================ 28 passed, 2 warnings in 17.30s ============================================

Independent check of unit tests by Jean

  • OSX
(ska3-latest) flame:kadi-apps jean$ pytest
============================================================== test session starts ==============================================================
platform darwin -- Python 3.13.11, pytest-9.0.2, pluggy-1.6.0
rootdir: /Users/jean/git
configfile: pytest.ini
plugins: anyio-4.12.1, timeout-2.4.0, dash-4.4.1
collected 28 items                                                                                                                              

kadi_apps/tests/test_astromon.py ....                                                                                                     [ 14%]
kadi_apps/tests/test_auth.py .......                                                                                                      [ 39%]
kadi_apps/tests/test_django_cleanup.py .                                                                                                  [ 42%]
kadi_apps/tests/test_ska_api.py ................                                                                                          [100%]

=============================================================== warnings summary ================================================================
kadi-apps/kadi_apps/tests/test_django_cleanup.py::test_django_connection_closed_after_request
  /Users/jean/miniforge3/envs/ska3-latest/lib/python3.13/site-packages/setuptools_scm/git.py:427: UserWarning: git archive did not support describe output
    warnings.warn("git archive did not support describe output")

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
======================================================== 28 passed, 1 warning in 22.33s =========================================================
(ska3-latest) flame:kadi-apps jean$ git rev-parse HEAD
34058c115e0eba47a4a16e3ab460e3b3b16acfe2

Functional tests

I set up a kadi-apps server in kadi-test and did the following. This is no a necessary test, because the unit test does the same, but still. Note the meta key:

import requests
starcat_date = "2026:083:18:43:00.208"
ska_api_url = "https://kadi-test.cfa.harvard.edu/api/ska_api"
url = f"{ska_api_url}/kadi/commands/get_starcats?{starcat_date=}&table_format=full"
req = requests.get(url)
req.json()
Out[1]: 
[{'meta': {'acqs': {'meta': {'t_ccd_acq': -20.0},
    'class_name': 'AcqTable',
    'full_name': 'proseco.acq.AcqTable',
    'columns': {}},
   'guides': {'meta': {'t_ccd_guide': -20.0},
    'class_name': 'GuideTable',
    'full_name': 'proseco.guide.GuideTable',
    'columns': {}},
   'obsid': 31041,
   'att': [0.052608906151, -0.964772971511, -0.074231229153, 0.246850442686],
   'date': '2026:083:18:43:00.208',
   'duration': 23929.74899995327,
   'detector': 'ACIS-S',
   'sim_offset': 4,
   't_ccd_guide': -20.0,
   't_ccd_acq': -20.0},
  'class_name': 'ACATable',
  'full_name': 'proseco.catalog.ACATable',
  'columns': {'slot': [0, 1, 2, 3, 4, 5, 6, 7, 0, 1],
   'idx': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
   'id': [2,
    4,
    5,
    261112008,
    260977968,
    261097656,
    261101336,
    261110376,
    260976784,
    261112608],
   'type': ['FID',
    'FID',
    'FID',
    'BOT',
    'BOT',
    'BOT',
    'BOT',
    'BOT',
    'ACQ',
    'ACQ'],
   'sz': ['8x8',
    '8x8',
    '8x8',
    '8x8',
    '8x8',
    '8x8',
    '8x8',
    '8x8',
    '8x8',
    '8x8'],
   'mag': [7.0,
    7.0,
    7.0,
    8.810208320617676,
    8.968791007995605,
    9.13710880279541,
    9.305754661560059,
    9.709272384643555,
    9.915582656860352,
    10.789575576782227],
   'maxmag': [8.0,
    8.0,
    8.0,
    10.3125,
    10.46875,
    10.640625,
    10.8125,
    11.0,
    11.203125,
    11.203125],
   'yang': [-760.829403193583,
    2152.6831217751305,
    -1813.935621020117,
    1950.0956342233915,
    2180.601840172675,
    517.8143301014,
    1515.9892904727205,
    -985.4919554210975,
    1609.4518274948591,
    -2247.3856582967437],
   'zang': [-1742.710664487318,
    166.00807861444784,
    159.5455777373639,
    -154.56692211725203,
    1827.201790723327,
    1865.6642507982788,
    -1111.691919972395,
    -1254.9419256662368,
    2306.1454982499286,
    -1543.5356248222818],
   'dim': [1, 1, 1, 28, 28, 28, 28, 28, 8, 8],
   'res': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
   'halfw': [25, 25, 25, 160, 160, 160, 160, 160, 60, 60]}}]

@javierggt
javierggt changed the base branch from main to fix-stale-events-db August 26, 2026 14:20
@javierggt
javierggt requested a review from jeanconn August 26, 2026 15:19
Base automatically changed from fix-stale-events-db to main September 9, 2026 17:33
@jeanconn

jeanconn commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

This looks good to me, but me and Codex note that it doesn't look to go all the way:

  • Failed: np.bool_, np.int8/16, all tested unsigned integers, and np.float16.
  • Also failed: Astropy Quantity and Time metadata.
  • Confirmed HTTP failure: get_cmds(..., table_format=full) returns 500 (CommandTable issues) - strict_encode=false converts the weak reference to an unstable string containing a memory address, so it is not a real solution.

@jeanconn jeanconn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there are some outstanding issues with json serialization but this PR moves things in the right direction.

@javierggt
javierggt merged commit 2bf3061 into main Sep 10, 2026
@javierggt
javierggt deleted the table-meta branch September 10, 2026 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants