[fitsbits] JSON to FITS bintable?

John K. Parejko parejkoj at uw.edu
Wed Jul 14 14:34:26 EDT 2021


I couldn’t quite get your json into an astropy.table, but this is almost what you need.

import pandas as pd
import astropy.table
data = pd.read_json('table.json', orient='values', typ='series’)
table = astropy.table.Table.from_pandas(data.to_frame()) <— this fails
table.write(’table.fits’)

You may be able to get it to work with the appropriate `pd.read_json` options. I’m not that familiar with pandas.

There’s an open astropy PR about this, but it stalled out and most recently folks there were moving towards ECSV.

https://github.com/astropy/astropy/issues/4604

John


> On 13Jul 2021, at 09:12, Seaman, Robert Lewis - (rseaman) via fitsbits <fitsbits at listmgr.nrao.edu> wrote:
> 
> Howdy,
>  
> Anybody have a viable JSON to bintable converter / library to recommend?
>  
> Format as below.
>  
> Rob
>  
>  
> {
>     "H": "20.3",
>     "Vmag": "21.8",
>     "arc": "48.40",
>     "caDist": null,
>     "dec": "-34",
>     "elong": "167",
>     "geocentricScore": "0",
>     "ieoScore": "0",
>     "lastRun": "2021-07-13 11:52",
>     "moid": "0.6",
>     "nObs": "7",
>     "neo1kmScore": "0",
>     "neoScore": "16",
>     "objectName": "P11hVaG",
>     "orbits": {
>         "count": "1000",
>         "data": [
>             [
>                 0,
>                 "2459406.890974739",
>                 "2.998598423946383E-01",
>                 "1.254932587424348E+00",
>                 "2459535.040736465",
>                 "3.1448800075530471E+02",
>                 "6.1192414581791162E+01",
>                 "1.1594628618305565E+01",
>                 "21.376293",
>                 "NULL",
>                 "NULL",
>                 "3.065249120E-01",
>                 "NULL",
>                 "1.000000000E+99",
>                 0
>             ],
>    . . .
>             [
>                 999,
>                 "2459406.890974739",
>                 "2.000304724974162E-01",
>                 "1.584871836255366E+00",
>                 "2459160.741920622",
>                 "3.1292408591618408E+02",
>                 "2.2731638231383295E+02",
>                 "1.7097327014467091E+01",
>                 "19.682230",
>                 "NULL",
>                 "NULL",
>                 "6.321307279E-01",
>                 "NULL",
>                 "1.000000000E+99",
>                 0
>             ]
>         ],
>         "fields": [
>             "idx",
>             "epoch",
>             "ec",
>             "qr",
>             "tp",
>             "om",
>             "w",
>             "inc",
>             "H",
>             "dca",
>             "tca",
>             "moid",
>             "vinf",
>             "geoEcc",
>             "impFlag"
>         ]
>     },
>     "phaScore": "0",
>     "ra": "19:44",
>     "rate": "0.9",
>     "rating": "0",
>     "rmsN": "0.58",
>     "signature": {
>         "source": "NASA/JPL Scout API",
>         "version": "1.2"
>     },
>     "tEphem": "2021-07-13 13:30",
>     "tisserandScore": "6",
>     "unc": "0.05",
>     "uncP1": "0.33",
>     "vInf": null
> }
>  
> _______________________________________________
> fitsbits mailing list
> fitsbits at listmgr.nrao.edu
> https://listmgr.nrao.edu/mailman/listinfo/fitsbits

--
*************************
John Parejko
parejkoj at uw.edu
Rubin Observatory, DIRAC Fellow
http://staff.washington.edu/parejkoj/
Department of Physics and Astronomy
University of Washington
Seattle, WA
**************************



















More information about the fitsbits mailing list