brandon-rhodes / python-sgp4

Python version of the SGP4 satellite position library
MIT License
376 stars 88 forks source link

TypeError: bad argument type for built-in operation #105

Closed jawhster closed 2 years ago

jawhster commented 2 years ago

Hello all! Anyone come across this error before when executing omm.initialize(sat,fields). I'm using Python3.6. Thank you very much for your help.

` from sgp4 import omm from sgp4.api import Satrec

sat = Satrec()

with open('omm-week.csv') as f: fields = next(omm.parse_csv(f))`

omm.initialize(sat, fields)

`--------------------------------------------------------------------------- TypeError Traceback (most recent call last)

in ----> 1 omm.initialize(sat, fields) ~/.local/lib/python3.6/site-packages/sgp4/omm.py in initialize(sat, fields) 27 28 def initialize(sat, fields): ---> 29 sat.classification = fields['CLASSIFICATION_TYPE'] 30 sat.intldesg = fields['OBJECT_ID'][2:].replace('-', '') 31 sat.ephtype = int(fields['EPHEMERIS_TYPE']) TypeError: bad argument type for built-in operation`
jawhster commented 2 years ago

fields is OrderedDict([('CLASSIFICATION_TYPE', 'UNCLASSIFIED'), ('OBJECT_ID', '2019-059A'), ('EPHEMERIS_TYPE', 'SGP'), ('ELEMENT_SET_NO', '999'), ('REV_AT_EPOCH', '7995'), ('EPOCH', '1616415835953'), ('ARG_OF_PERICENTER', '93.243'), ('BSTAR', '1.6948e-05'), ('ECCENTRICITY', '0.0001644'), ('INCLINATION', '98.5191'), ('MEAN_ANOMALY', '266.8937'), ('MEAN_MOTION_DDOT', '0.0'), ('MEAN_MOTION_DOT', '5e-08'), ('MEAN_MOTION', '14.35316656'), ('RA_OF_ASC_NODE', '160.7115'), ('NORAD_CAT_ID', '44528')])

sat is <sgp4.wrapper.Satrec at 0x55c74404a460>

jawhster commented 2 years ago

I think it is because of the fields that have been transformed, e.g. EPHEMERIS_TYPE now str instead of int index. Will try to convert back to original without transformations applied

brandon-rhodes commented 2 years ago

Could you share the first few lines of the omm-week.csv file? Without that, it's not possible to run your code locally to try reproducing the problem. I'm not sure what the error message means, since the line that the arrow points at looks very simple, just a dictionary key lookup and an assignment to a object attribute. Let us know if you learn more!

jawhster commented 2 years ago

Thanks for reply. The value for classification_type was Unclassified instead of just U which was causing the error there. Also needed to fix values for ephemeris_type and epoch into their expected formats. Error message is a bit broad because from C API based on some stack overflow searching. Thank you

brandon-rhodes commented 2 years ago

Oh! sat.classification is a single character down at the C language level, isn't it?

    {"classification", T_CHAR, O(classification), 0,
     "Usually U=Unclassified, C=Classified, or S=Secret."},

And I guess the Python 3.6 error message for "you're trying to assign a >1 character string to a C char" is a terrible one that doesn't tell you what went wrong! I wonder if a more recent Python would do better, since they've been working hard on making better error messages? Or I wonder if there's something we could do on our end to improve the error message?