riogroup / SORA

MIT License
15 stars 12 forks source link

Error trying to define Body using model.obj files to fit chords #83

Open andres-baquero opened 1 year ago

andres-baquero commented 1 year ago

Hi. I'm trying to fit an occultation chord to 3D shape model for Tombecka asteroid, but I'm getting this error "ValueError: could not convert string to float: " with the model.obj file. I'm using the code used in the example: https://sora.readthedocs.io/en/latest/examples/shape3d.html

import requests response = requests.get("https://3d-asteroids.space/data/asteroids/models/t/1013_Tombecka_2357.obj") open("Tombecka_Durech_48k_poly.obj", "wb").write(response.content)

from sora import Body tombecka = Body(name="Tombecka", shape="Tombecka_Durech_48k_poly.obj", ephem="horizons")

SORA version: 0.3 Obtaining data for Tombecka from SBDB

ValueErrorTraceback (most recent call last)

in 1 from sora import Body ----> 2 tombecka = Body(name="Tombecka", shape="Tombecka_Durech_48k_poly.obj", ephem="horizons") 3 # Now, we include the texture in the shape of Phoebe 4 #phoebe.shape.texture = "Phoebe_Grayscale.jpg" /fefs/aswg/workspace/andres.baquero/miniconda3/envs/lst-dev-073/lib/python3.7/site-packages/sora/body/core.py in __init__(self, name, database, **kwargs) 137 self.spectral_type['Tholen']['value'] = kwargs.pop('tholen') 138 for key in kwargs: --> 139 setattr(self, key, kwargs[key]) 140 self._shared_with['ephem']['search_name'] = self._search_name 141 self._shared_with['ephem']['id_type'] = self._id_type /fefs/aswg/workspace/andres.baquero/miniconda3/envs/lst-dev-073/lib/python3.7/site-packages/sora/body/meta.py in shape(self, value) 396 self._shape = value 397 elif isinstance(value, str): --> 398 self._shape = Shape3D(value) 399 else: 400 value = np.array(value, ndmin=1, dtype=np.float) /fefs/aswg/workspace/andres.baquero/miniconda3/envs/lst-dev-073/lib/python3.7/site-packages/sora/body/shape/core.py in __init__(self, obj_file, texture, scale) 30 def __init__(self, obj_file, texture=None, scale=1) -> None: 31 super(Shape3D, self).__init__() ---> 32 vertices, faces = read_obj_file(obj_file) 33 self.name = obj_file 34 self._vertices = CartesianRepresentation(*vertices.T, unit=u.km) /fefs/aswg/workspace/andres.baquero/miniconda3/envs/lst-dev-073/lib/python3.7/site-packages/sora/body/shape/utils.py in read_obj_file(filename) 36 faces.append([i.split('/')[0] for i in values]) 37 ---> 38 vertices = np.array(vertices, dtype='float') 39 faces = np.array(faces, dtype='int32') 40 return vertices, faces ValueError: could not convert string to float: The same occur when I'm tried to used a model for Krylov asteroid obtained from: https://astro.troja.mff.cuni.cz/projects/damit/asteroid_models/view/3153
altairgomes commented 1 year ago

Dear @andres-baquero This issue is fixed and will be soon published on SORA v0.3.1. The error arises from the way SORA is reading the OBJ file. It expects only one space between numbers.

It follows a code snippet that can convert your OBJ file to one that SORA can read in v0.3.0.

def convert(input_file, output_file):
    with open(input_file, 'r') as f:
        lines = f.readlines()
    with open(output_file, 'w') as f:
        for l in lines:
            f.write(' '.join(l.split()) + '\n')

convert('Tombecka.obj', 'Tombecka_2.obj')