Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
andres-baquero opened this issue May 18, 2023 · 1 comment
Open
Assignees
Labels
bug Something isn't working effort_low Probably easy to solve
Milestone

Comments

@andres-baquero
Copy link

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
Copy link
Collaborator

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')

@altairgomes altairgomes self-assigned this Jun 14, 2023
@altairgomes altairgomes added bug Something isn't working effort_low Probably easy to solve labels Jun 14, 2023
@altairgomes altairgomes added this to the 0.3.1 milestone Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working effort_low Probably easy to solve
Projects
None yet
Development

No branches or pull requests

2 participants