esheldon / pymangle

Simple code to read mangle masks, calculate ids and weights, and generate random points
14 stars 15 forks source link

Error when reading shortened polygon descriptions #7

Closed pmelchior closed 5 years ago

pmelchior commented 5 years ago

A full polygon description would read something like

polygon 18 ( 4 caps, 1 weight, 0 pixel, 0.042198885297204 str):

but there are shortened versions around there like

polygon 1 ( 4 caps, 1 weight ):

According to the Mangle manual, anything other than caps is optional:

The polygon specification also optionally includes the weight assigned to the polygon, the pixel in which the polygon is contained, and the area of the polygon in steradians. If these are not specified, the polygon will be assigned a default weight of 1 and a default pixel of 0.

However, when I try to read a file with shortened description, I get this error: Failed to read expected string in polygon: 'weight,' got 'weight'failed to read polygon 0

Can the reader be made more forgiving to tolerate these shortened descriptions, given that the optional parts are well meant to be, well, optional?

erykoff commented 5 years ago

So pymangle only works with mangle files that have the pixels associated with them, so you need to run that mangle task first which adds the pixel and area.

erykoff commented 5 years ago

Hmm, the description of the code says it works without pixelization but I don't know if that's ever been tested! Certainly not how I thought the code was supposed to be run.

esheldon commented 5 years ago

the code does work without pixelization

esheldon commented 5 years ago

This change will be straightforward but annoying to implement, because string operations in C are annoying :)

esheldon commented 5 years ago

Note, however, that this means the polygons will not have an associated area.

I think this is OK for all the operations we currently support. New features would require knowing the area, in particular if we started supporting creation of masks. I looked into how the area is calculated in the original code and it would be extremely difficult to port that old fortran code.