sampotter / fluxpy

Fast thermal modeling and radiosity in Python.
11 stars 5 forks source link

crater shape/orientation with spice #4

Closed steo85it closed 3 years ago

steo85it commented 3 years ago

While making experiments with your libraries at the Moon's south pole, I noticed a (possible) issue when using lsp_spice. This should be the interior of a crater (see elevation map of the region below), with a smaller crater within it even projecting a shadow of its own (which is clearly not the expected behavior...). image

I think that this could be due to the fact of being in the southern hemisphere and the transformation to cartesian, which the code ending up "confusing" a crater for a hill.

image

(above is the elevation from the Moon mean radius, while below is Z ~ signed distance from the Moon center)

image

You can check it by setting

i0, i1 = 2425, 2663  # 600, 700
j0, j1 = 1912, 2172  # 650, 725

as indexes to select a region from the whole south_pole grd "LDEM_80S_150M_adjusted.grd" in lsp_make_shape_model and running the lsp_shape.py example for the 6-Sep-2021. Since the region is a bit large, you can maybe subsample the map a bit by adding

IJ = IJ[::3]
V = np.array([x.ravel(), y.ravel(), z.ravel()]).T
V = V[::3]

to lsp_make_shape_model.py.

I tested several solutions/options:

Any hint here would be appreciated! :)

sampotter commented 3 years ago

OK, had a chance to start looking at this. We may need to go back and forth a bit to figure out what's going on.

From your post, it looks like there's some confusion (probably mine :^) ) about how to set sun_dirs.

My assumption is the following:

In the MATLAB SPICE script Erwan sent me, he did this using trigonometry, which I just translated directly. But the result is the same as normalizing. I verified that this is the case, and made the simplification (see my latest commits, in particular 84712bf7e31bd8ff4d210ced09b71e972fae4d0f).

Is my understanding of this correct? Let's get this squared away first...

steo85it commented 3 years ago

Great, thanks! This looks correct and, at least in the Moon case, it should be ok also if we are/our target is on the surface of the Moon instead of at its center of mass (distance_Sun_Moon >> R_Moon). And your simplification looks good, too (in principle, the second element of spkpos output should be the source to target norm and could be directly used, even though sometimes small additional/unwanted corrections could be included).

sampotter commented 3 years ago

Ah, I think I figured it out. I was passing the arguments to TrimeshShadeModel in lsp_spice.py. See the change in 83ce63f7bc6ece3ded71effaa0efbdf5c937307a. I'm testing this now to see if it fixes things, but I'm pretty sure it should.

In TrimeshShadeModel's constructor, if you just pass in V and F (which is what I was effectively doing), you compute N automatically by normalizing the cross product of two edges in each triangle indexed by F. This ends up with upside down normals at the LSP. Since I had the argument order wrong, the face normals were being computed automatically, resulting in the behavior that you observed.

steo85it commented 3 years ago

Ah, that would make sense! I was indeed playing with N arrays too, but never checked the order... let me check that out! Great job if it works!

steo85it commented 3 years ago

It works for me now, thanks!!