@@ -135,85 +135,6 @@ def _create_vol(self, obs_u, obs_v, obs_l, xyz, **kwargs):
135
135
self ._vvol = vvol
136
136
self ._lvol = lvol
137
137
138
- def _resample_distance_strategy (self ):
139
- from scipy .spatial import cKDTree
140
-
141
- u , v , l = self .u , self .v , self .l
142
- um , vm , lm = np .meshgrid (u , v , l , indexing = 'ij' )
143
- uvl = np .array ([um .ravel (), vm .ravel (), lm .ravel ()]).T
144
- x , y , z = self ._xvol (uvl ), self ._yvol (uvl ), self ._zvol (uvl )
145
- xyz = np .asarray ([x , y , z ], dtype = 'float32' ).T
146
- tree = cKDTree (xyz )
147
-
148
- distance_dictionary = {}
149
- distances = []
150
- N = xyz .shape [0 ]
151
- min_distance , min_index = 1.0e9 , - 1
152
- for n in range (N ):
153
- d , i = tree .query (xyz [n ], k = 2 )
154
- d , i = d [- 1 ], i [- 1 ]
155
- distance_dictionary [tuple (xyz [n ])] = [d , n , i ]
156
- distances .append (d )
157
- if d < min_distance :
158
- min_distance , min_index = d , (n , i )
159
-
160
- f = open ('distances_curv.txt' , 'w' )
161
- for distance in distances :
162
- f .write (str (distance ) + '\n ' )
163
- f .close ()
164
-
165
- f = open ('add_points.txt' , 'w' )
166
- for n in range (N ):
167
- ndistance , self_index , neighbor_index = distance_dictionary [tuple (xyz [n ])]
168
- nearest_neighbor = xyz [neighbor_index ]
169
- rel = old_div (np .abs (ndistance - min_distance ), min_distance )
170
- points_to_add = 2 ** (rel + 2 )
171
- distance_dictionary [tuple (xyz [n ])].append (points_to_add )
172
- f .write (str (int (points_to_add )) + '\n ' )
173
- f .close ()
174
-
175
- def sample_from_sphere (R , xyz ):
176
- phi = np .random .uniform (0 , 2. * np .pi )
177
- costheta = np .random .uniform (- 1 , 1 )
178
- u = np .random .uniform (0 , 1 )
179
- theta = np .arccos (costheta )
180
- r = sphere_radius * (u ** (1. / 3. ))
181
- xnew , ynew , znew = xyz [0 ] + r * np .sin (theta ) * np .cos (phi ), xyz [1 ] + r * np .sin (theta ) * np .sin (phi ), xyz [
182
- 2 ] + r * np .cos (theta )
183
-
184
- xyz_new = np .asarray ([xnew , ynew , znew ], dtype = 'float32' ).reshape (1 , 3 )
185
- u , v , l = self ._uvol (xyz_new ), self ._vvol (xyz_new ), self ._lvol (xyz_new )
186
- u , v , l = u [0 ], v [0 ], l [0 ]
187
- if (u < np .min (self .u ) or u > np .max (self .u )):
188
- return None , None
189
- if (v < np .min (self .v ) or v > np .max (self .v )):
190
- return None , None
191
- if (l < np .min (self .l ) or l > np .max (self .l )):
192
- return None , None
193
- return xyz_new , np .array ([u , v , l ], dtype = 'float32' ).reshape (1 , 3 )
194
-
195
- for xyz_key in list (distance_dictionary .keys ()):
196
- ndistance , _ , _ , points_to_add = distance_dictionary [xyz_key ]
197
-
198
- sphere_centroid , sphere_radius = xyz_key , ndistance / 2.
199
- for i in range (int (points_to_add )):
200
- xyz_new = None
201
- while xyz_new is None :
202
- xyz_new , uvl_new = sample_from_sphere (sphere_radius , sphere_centroid )
203
- xyz = np .concatenate ((xyz , xyz_new ))
204
- uvl = np .concatenate ((uvl , uvl_new ))
205
-
206
- f = open ('distance_curv_added.txt' , 'w' )
207
- tree_added = cKDTree (xyz )
208
-
209
- N2 = xyz .shape [0 ]
210
- for n in range (N2 ):
211
- d , i = tree_added .query (xyz [n ], k = 2 )
212
- d , i = d [- 1 ], i [- 1 ]
213
- f .write (str (d ) + '\n ' )
214
- f .close ()
215
- return xyz , uvl
216
-
217
138
def _resample_uv (self , ures , vres ):
218
139
"""Helper function to re-sample to u and v parameters
219
140
at the specified resolution
0 commit comments