0

I would appreciate some advice on how to parse a file. I have a file generated by another party, and it is a dump of data. I would prefer to use python to parse the file, but if a C based method would be easier I would use that. The file is ascii text, in the form:

Sequence { 
 Target ManualDump
 Camera xxxx
 Timestamp "20170623133425"
 ID NULL
 FrameSize.x 512
 FrameSize.y 512
 Frames 
[ { 
 SequenceNumber 0
 frameStart "23/06/2017 13:32:29.707459"
 Stars 
[ 
 ] } { 
 SequenceNumber 1
 frameStart "23/06/2017 13:32:34.767027"
 Stars 
[ { 
 Catalog "YYYYY" 
 Index 13016559
 Name NULL 
} { 
 Catalog "YYYYY" 
 Index 13016572
 Name NULL 
} 
 ] } { 
 SequenceNumber 2
 frameStart "23/06/2017 13:32:39.826595"
 Stars 
[ { 
 Catalog "YYYYY" 
 Index 13016559
 Name NULL 
} { 
 Catalog "YYYYY" 
 Index 13016572
 Name NULL 
} 
 ] }
] }

I have definitions of Sequence, Frames, Stars, etc, for example a Frame is:

Frame
{
    SequenceNumber INTEGER
    FrameStart STRING                                            
    FrameStop STRING                                             
    FieldDerotationDegrees FLOAT                                 
    BoresightDegrees STRUCTURE TelescopeCoord                    
    BoresightSkyPos STRUCTURE SkyCoord                           
    Stars ARRAY STRUCTURE Star                                   
    BoresightCoord STRUCTURE PixelCoord                          
}

I've trimmed some details to fit, but I don't think I'm deleted anything important.

I can probably cobble up a had written parser to parse this file, but I was wondering if someone could recommend a package/tool that seems meant for the job.

Thank you.

4
  • 1
    Given this isn't in a common format, I suspect you'll have to roll your own. You could try converting it to JSON or the like, but that will probably be at least as much work. Commented Jul 17, 2017 at 21:41
  • Can you ask the third party to provide the data in a common format such as JSON or YAML? Commented Jul 17, 2017 at 21:51
  • I think since you have the definitions, using json.loads() would be best. Then pass the resulting dictionary to the __init__ as kwargs and build the instance accordingly. Commented Jul 17, 2017 at 21:51
  • @JohnGordon I can ask, but I have severe doubts they will change their infrastructure based on my request Commented Jul 18, 2017 at 14:24

1 Answer 1

1

This looks a natural candidate for pyparsing

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.