Skip to content

Export PTR to timeline segments

Benoit Seignovert requested to merge export-ptr-to-segments into main

Implement PTR timeline export for JUICE Segment Harmonization Tool (a.k.a the JUICE timeline tool).

It is possible to export a PTR file, PTR string or PointingRequestMessage object into CSV and JSON files compatible with the pointing tool. You can do it programmatically:

>>> from ptr import read_ptr, export_timeline

>>> ptr = read_ptr('example.ptx')

>>> export_timeline('example.csv', ptr)

or in the terminal (CLI):

ptr2seg --help

usage: ptr2seg [-h] [-o FILENAME] [--json] [--subgroup SUBGROUP]
               [--source SOURCE] [--crema CREMA] [--timeline TIMELINE]
               ptr

Convert PTR to segmentation file.

positional arguments:
  ptr                   PTR/PTX input file.

options:
  -h, --help            show this help message and exit
  -o FILENAME, --output FILENAME
                        Custom output filename (default: PTR filename).
  --json                Export as JSON (default CSV if not provided).
  --subgroup SUBGROUP   Subgroup field (default: `<EMPTY>`).
  --source SOURCE       Source field (default: `GENERIC`).
  --crema CREMA         Trajectory crema keyword in JSON export (default:
                        `CREMA_5_0`).
  --timeline TIMELINE   Timeline keyword in JSON export (default: `LOCAL`).
ptr2seg --json example.ptx

Closes #5 (closed).

Other improvements:

  • Add iso() formater (with milliseconds precision, if needed):
>>> iso('2032-01-01')
'2032-01-01T00:00:00Z'

>>> iso(datetime(2032, 1, 2, 3, 4, 5, 6_000))
'2032-01-02T03:04:05.006Z'
  • Fix microseconds representation (closes #8 (closed)) in TimeElement elements:
>>> StartTime('2032-09-24T18:03:23.999')
<startTime> 2032-09-24T18:03:23.999 </startTime>

>>> EndTime('2032-09-24T18:03:23.666666')  # Rounded
<endTime> 2032-09-24T18:03:23.667 </endTime>
  • Improve WithDatetimeWindow.set_window error message:
>>> ElementWindow('window', '2032-07-02', '2032-07-01')  # start > end
ValueError: `<startTime> 2032-07-01T00:00:00 </startTime>` shall be before `<endTime> 2032-07-01T00:00:00 </endTime>`.
  • Add parser on metadata comments properties.

Note

Due to cyclic import error, it was not possible to implement PRM export function, like suggested in #5 (closed):

ptr.export('ptr.[csv|json]')

The recommended way to export a PointingRequestMessage object is with the export_timeline() function like shown above.

Edited by Benoit Seignovert

Merge request reports