Changeset 1618
- Timestamp:
- 02/11/10 11:47:43 (6 months ago)
- Location:
- branches/yt-1.6/yt
- Files:
-
- 11 modified
-
commands.py (modified) (3 diffs)
-
extensions/HaloMassFcn.py (modified) (2 diffs)
-
extensions/volume_rendering/software_sampler.py (modified) (3 diffs)
-
lagos/EnzoDefs.py (modified) (1 diff)
-
lagos/EnzoFields.py (modified) (1 diff)
-
lagos/HDF5LightReader.c (modified) (1 diff)
-
lagos/HierarchyType.py (modified) (1 diff)
-
lagos/parallelHOP/parallelHOP.py (modified) (2 diffs)
-
lagos/Profiles.py (modified) (1 diff)
-
_amr_utils/FixedInterpolator.c (modified) (1 diff)
-
_amr_utils/VolumeIntegrator.pyx (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/yt-1.6/yt/commands.py
r1539 r1618 28 28 from yt.recipes import _fix_pf 29 29 import yt.cmdln as cmdln 30 import optparse, os, os.path, math, sys 30 import optparse, os, os.path, math, sys, time, subprocess 31 31 32 32 _common_options = dict( … … 206 206 return arg_iterate 207 207 208 def _get_vcs_type(path): 209 if os.path.exists(os.path.join(path, ".hg")): 210 return "hg" 211 if os.path.exists(os.path.join(path, ".svn")): 212 return "svn" 213 return None 214 215 def _get_svn_version(path): 216 p = subprocess.Popen(["svn", "info", path], stdout = subprocess.PIPE, 217 stderr = subprocess.STDOUT) 218 stdout, stderr = p.communicate() 219 return stdout 220 221 def _update_svn(path): 222 f = open(os.path.join(path, "yt_updater.log"), "a") 223 f.write("\n\nUPDATE PROCESS: %s\n\n" % (time.asctime())) 224 p = subprocess.Popen(["svn", "up", path], stdout = subprocess.PIPE, 225 stderr = subprocess.STDOUT) 226 stdout, stderr = p.communicate() 227 f.write(stdout) 228 f.write("\n\n") 229 if p.returncode: 230 print "BROKEN: See %s" % (os.path.join(path, "yt_updater.log")) 231 sys.exit(1) 232 f.write("Rebuilding modules\n\n") 233 p = subprocess.Popen([sys.executable, "setup.py", "build_ext", "-i"], cwd=path, 234 stdout = subprocess.PIPE, stderr = subprocess.STDOUT) 235 stdout, stderr = p.communicate() 236 f.write(stdout) 237 f.write("\n\n") 238 if p.returncode: 239 print "BROKEN: See %s" % (os.path.join(path, "yt_updater.log")) 240 sys.exit(1) 241 f.write("Successful!\n") 242 243 def _update_hg(path): 244 from mercurial import hg, ui, commands 245 f = open(os.path.join(path, "yt_updater.log"), "a") 246 u = ui.ui() 247 u.pushbuffer() 248 config_fn = os.path.join(path, ".hg", "hgrc") 249 print "Reading configuration from ", config_fn 250 u.readconfig(config_fn) 251 repo = hg.repository(u, path) 252 commands.pull(u, repo) 253 f.write(u.popbuffer()) 254 f.write("\n\n") 255 u.pushbuffer() 256 commands.identify(u, repo) 257 if "+" in u.popbuffer(): 258 print "Can't rebuild modules by myself." 259 print "You will have to do this yourself. Here's a sample commands:" 260 print 261 print " $ cd %s" % (path) 262 print " $ hg up" 263 print " $ %s setup.py develop" % (sys.executable) 264 sys.exit(1) 265 f.write("Rebuilding modules\n\n") 266 p = subprocess.Popen([sys.executable, "setup.py", "build_ext", "-i"], cwd=path, 267 stdout = subprocess.PIPE, stderr = subprocess.STDOUT) 268 stdout, stderr = p.communicate() 269 f.write(stdout) 270 f.write("\n\n") 271 if p.returncode: 272 print "BROKEN: See %s" % (os.path.join(path, "yt_updater.log")) 273 sys.exit(1) 274 f.write("Successful!\n") 275 276 def _get_hg_version(path): 277 from mercurial import hg, ui, commands 278 u = ui.ui() 279 u.pushbuffer() 280 repo = hg.repository(u, path) 281 commands.identify(u, repo) 282 return u.popbuffer() 283 284 _vcs_identifier = dict(svn = _get_svn_version, 285 hg = _get_hg_version) 286 _vcs_updater = dict(svn = _update_svn, 287 hg = _update_hg) 288 208 289 class YTCommands(cmdln.Cmdln): 209 290 name="yt" … … 220 301 """ 221 302 self.cmdloop() 303 304 @cmdln.option("-u", "--update-source", action="store_true", 305 default = False, 306 help="Update the yt installation, if able") 307 def do_instinfo(self, subcmd, opts): 308 """ 309 ${cmd_name}: Get some information about the yt installation 310 311 ${cmd_usage} 312 ${cmd_option_list} 313 """ 314 import pkg_resources 315 yt_provider = pkg_resources.get_provider("yt") 316 path = os.path.dirname(yt_provider.module_path) 317 print 318 print "yt module located at:" 319 print " %s" % (path) 320 if "site-packages" not in path: 321 vc_type = _get_vcs_type(path) 322 vstring = _vcs_identifier[vc_type](path) 323 print 324 print "The current version of the code is:" 325 print 326 print "---" 327 print vstring 328 print "---" 329 print 330 print "This installation CAN be automatically updated." 331 if opts.update_source: 332 _vcs_updater[vc_type](path) 333 print "Updated successfully." 222 334 223 335 @add_cmd_options(['outputfn','bn','thresh','dm_only','skip']) -
branches/yt-1.6/yt/extensions/HaloMassFcn.py
r1596 r1618 179 179 mylog.info("Reading halo masses from %s" % self.halo_file) 180 180 f = open(self.halo_file,'r') 181 line = f.readline() # burn the top header line.182 181 line = f.readline() 182 while line[0] == '#': 183 line = f.readline() 183 184 self.haloes = [] 184 185 while line: … … 204 205 if i == (self.num_sigma_bins - 3): break 205 206 206 self.dis = dis / self.pf['CosmologyComovingBoxSize']**3.0207 self.dis = dis / self.pf['CosmologyComovingBoxSize']**3.0 * self.hubble0**3.0 207 208 208 209 def sigmaM(self): -
branches/yt-1.6/yt/extensions/volume_rendering/software_sampler.py
r1579 r1618 29 29 30 30 def direct_ray_cast(pf, L, center, W, Nvec, tf, 31 partitioned_grids = None, field = 'Density', log_field = True, whole_box=False): 31 partitioned_grids = None, field = 'Density', 32 log_field = True, whole_box=False, 33 nsamples = 5): 32 34 center = na.array(center, dtype='float64') 33 35 … … 73 75 hit = 0 74 76 tnow = time.time() 75 every = na.ceil(len(partitioned_grids) / 100.0)76 77 77 78 vp = VectorPlane(vectors, norm_vec, back_center, … … 86 87 87 88 tfp = TransferFunctionProxy(tf) 89 tfp.ns = nsamples 88 90 89 pbar = get_pbar("Ray casting ", len(partitioned_grids)) 91 92 total_cells = sum(na.prod(g.my_data.shape) for g in partitioned_grids) 93 pbar = get_pbar("Ray casting ", total_cells) 94 total_cells = 0 90 95 for i,g in enumerate(partitioned_grids[ind]): 91 if (i % every) == 0: 92 pbar.update(i) 96 pbar.update(total_cells) 93 97 pos = g.cast_plane(tfp, vp) 98 total_cells += na.prod(g.my_data.shape) 94 99 pbar.finish() 95 100 -
branches/yt-1.6/yt/lagos/EnzoDefs.py
r1555 r1618 86 86 'pc' : 1e6, 87 87 'au' : 2.063e11, 88 'rsun' : 2.2167e13,88 'rsun' : 4.43664e13, 89 89 'cm' : 3.0857e24, 90 90 'miles' : 1.917e19} -
branches/yt-1.6/yt/lagos/EnzoFields.py
r1560 r1618 343 343 projection_conversion="1") 344 344 345 def _IsStarParticle(field, data): 346 is_star = (data['creation_time'] > 0).astype('float64') 347 return is_star 348 add_field('IsStarParticle', function=_IsStarParticle, 349 particle_type = True) 350 345 351 # 346 352 # Now we do overrides for 2D fields -
branches/yt-1.6/yt/lagos/HDF5LightReader.c
r1603 r1618 34 34 35 35 #include "numpy/ndarrayobject.h" 36 37 #ifndef npy_float128 38 #define npy_float128 npy_longdouble 39 #endif 36 40 37 41 -
branches/yt-1.6/yt/lagos/HierarchyType.py
r1603 r1618 250 250 251 251 full_name = "%s/%s" % (node, name) 252 return self._data_file[full_name][:] 252 try: 253 return self._data_file[full_name][:] 254 except TypeError: 255 return self._data_file[full_name] 253 256 254 257 def _close_data_file(self): -
branches/yt-1.6/yt/lagos/parallelHOP/parallelHOP.py
r1563 r1618 105 105 # max_padding, which is more likely the case with load-balancing 106 106 # turned on. 107 dx = na.min( na.abs(my_vertex[0] - vertex[0]), \108 self.period[0] - na. abs(my_vertex[0] - vertex[0]))109 dy = na.min( na.abs(my_vertex[1] - vertex[1]), \110 self.period[1] - na. abs(my_vertex[1] - vertex[1]))111 dz = na.min( na.abs(my_vertex[2] - vertex[2]), \112 self.period[2] - na. abs(my_vertex[2] - vertex[2]))107 dx = min( na.fabs(my_vertex[0] - vertex[0]), \ 108 self.period[0] - na.fabs(my_vertex[0] - vertex[0])) 109 dy = min( na.fabs(my_vertex[1] - vertex[1]), \ 110 self.period[1] - na.fabs(my_vertex[1] - vertex[1])) 111 dz = min( na.fabs(my_vertex[2] - vertex[2]), \ 112 self.period[2] - na.fabs(my_vertex[2] - vertex[2])) 113 113 d = na.sqrt(dx*dx + dy*dy + dz*dz) 114 114 if d <= self.max_padding: … … 1375 1375 if calc: 1376 1376 com = self.CoM[subchain] 1377 rad = na. abs(com - loc)1377 rad = na.fabs(com - loc) 1378 1378 dist = (na.minimum(rad, self.period - rad)**2.).sum(axis=1) 1379 1379 dist = dist[sort] -
branches/yt-1.6/yt/lagos/Profiles.py
r1533 r1618 167 167 # in the way. 168 168 if field in self.pf.field_info \ 169 and self.pf.field_info[field].particle_type \170 andnot self._data_source._is_fully_enclosed(source):171 pointI = self._data_source._get_particle_indices(source)169 and self.pf.field_info[field].particle_type: 170 if not self._data_source._is_fully_enclosed(source): 171 pointI = self._data_source._get_particle_indices(source) 172 172 else: 173 173 pointI = self._data_source._get_point_indices(source) -
branches/yt-1.6/yt/_amr_utils/FixedInterpolator.c
r1579 r1618 98 98 normval += grad[i]*grad[i]; 99 99 } 100 normval = sqrt(normval); 101 for (i = 0; i < 3; i++) grad[i] /= -normval; 102 //fprintf(stderr, "Normval: %0.3lf %0.3lf %0.3lf %0.3lf\n", 103 // normval, grad[0], grad[1], grad[2]); 100 if (normval != 0.0){ 101 normval = sqrt(normval); 102 for (i = 0; i < 3; i++) grad[i] /= -normval; 103 //fprintf(stderr, "Normval: %0.3lf %0.3lf %0.3lf %0.3lf\n", 104 // normval, grad[0], grad[1], grad[2]); 105 }else{ 106 grad[0]=grad[1]=grad[2]=0.0; 107 } 104 108 } -
branches/yt-1.6/yt/_amr_utils/VolumeIntegrator.pyx
r1579 r1618 46 46 47 47 cdef inline int iclip(int i, int a, int b): 48 return imin(imax(i, a), b) 48 if i < a: return a 49 if i > b: return b 50 return i 49 51 50 52 cdef inline np.float64_t fclip(np.float64_t f, … … 76 78 cdef np.float64_t *vs[4] 77 79 cdef int nbins 78 cdef np.float64_t dbin 80 cdef public int ns 81 cdef np.float64_t dbin, idbin 79 82 cdef np.float64_t light_color[3] 80 83 cdef np.float64_t light_dir[3] … … 96 99 self.nbins = tf_obj.nbins 97 100 self.dbin = (self.x_bounds[1] - self.x_bounds[0])/self.nbins 101 self.idbin = 1.0/self.dbin 98 102 self.light_color[0] = tf_obj.light_color[0] 99 103 self.light_color[1] = tf_obj.light_color[1] … … 108 112 self.use_light = tf_obj.use_light 109 113 114 @cython.boundscheck(False) 115 @cython.wraparound(False) 116 cdef void interpolate(self, np.float64_t dv, np.float64_t *trgba): 117 cdef int bin_id, channel 118 cdef np.float64_t bv, dy, dd, tf 119 bin_id = <int> ((dv - self.x_bounds[0]) * self.idbin) 120 # Recall that linear interpolation is y0 + (x-x0) * dx/dy 121 dd = dv-(self.x_bounds[0] + bin_id * self.dbin) # x - x0 122 for channel in range(4): 123 bv = self.vs[channel][bin_id] # This is x0 124 dy = self.vs[channel][bin_id+1]-bv # dy 125 # This is our final value for transfer function on the entering face 126 trgba[channel] = bv+dd*dy*self.idbin 127 128 @cython.boundscheck(False) 129 @cython.wraparound(False) 110 130 cdef void eval_transfer(self, np.float64_t dt, np.float64_t dv, 111 131 np.float64_t *rgba, np.float64_t *grad): 112 132 cdef int i 113 cdef int bin_id 114 cdef np.float64_t tf, trgba[4], bv, dx, dy, dd, ta, dot_prod 115 dx = self.dbin 116 133 cdef np.float64_t ta, tf, trgba[4], dot_prod 134 self.interpolate(dv, trgba) 117 135 # get source alpha first 118 136 # First locate our points 119 bin_id = iclip(<int> floor((dv - self.x_bounds[0]) / dx),120 0, self.nbins-2)121 # Recall that linear interpolation is y0 + (x-x0) * dx/dy122 bv = self.vs[3][bin_id] # This is x0123 dy = self.vs[3][bin_id+1]-bv # dy124 dd = dv-(self.x_bounds[0] + bin_id * dx) # x - x0125 # This is our final value for transfer function on the entering face126 tf = bv+dd*(dy/dx)127 ta = tf # Store the source alpha128 137 dot_prod = 0.0 129 for i in range(3): 130 dot_prod += self.light_dir[i] * grad[i] 131 #print dot_prod, grad[0], grad[1], grad[2] 132 dot_prod = fmax(0.0, dot_prod) 133 for i in range(3): 134 # Recall that linear interpolation is y0 + (x-x0) * dx/dy 135 bv = self.vs[i][bin_id] # This is x0 136 dy = self.vs[i][bin_id+1]-bv # dy 137 dd = dv-(self.x_bounds[0] + bin_id * dx) # x - x0 138 # This is our final value for transfer function on the entering face 139 tf = bv+dd*(dy/dx) + dot_prod * self.light_color[i] 140 # alpha blending 141 rgba[i] += (1. - rgba[3])*ta*tf*dt 142 #update alpha 143 rgba[3] += (1. - rgba[3])*ta*dt 144 # We should really do some alpha blending. 145 # Front to back blending is defined as: 146 # dst.rgb = dst.rgb + (1 - dst.a) * src.a * src.rgb 147 # dst.a = dst.a + (1 - dst.a) * src.a 138 if self.use_light: 139 for i in range(3): 140 dot_prod += self.light_dir[i] * grad[i] 141 dot_prod = fmax(0.0, dot_prod) 142 for i in range(3): 143 trgba[i] += dot_prod*self.light_color[i] 144 # alpha blending 145 ta = (1.0 - rgba[3])*dt*trgba[3] 146 for i in range(4): 147 rgba[i] += ta*trgba[i] 148 148 149 149 cdef class VectorPlane: … … 181 181 self.pdy = (self.bounds[3] - self.bounds[2])/self.nv 182 182 183 @cython.boundscheck(False) 184 @cython.wraparound(False) 183 185 cdef void get_start_stop(self, np.float64_t *ex, int *rv): 184 186 # Extrema need to be re-centered 185 187 cdef np.float64_t cx, cy 188 cdef int i 186 189 cx = cy = 0.0 187 190 for i in range(3): … … 215 218 cdef np.float64_t right_edge[3] 216 219 cdef np.float64_t dds[3] 220 cdef np.float64_t idds[3] 217 221 cdef public np.float64_t min_dds 218 cdef int ns219 222 cdef int dims[3] 220 223 … … 235 238 self.dims[i] = dims[i] 236 239 self.dds[i] = (self.right_edge[i] - self.left_edge[i])/dims[i] 240 self.idds[i] = 1.0/self.dds[i] 237 241 self.my_data = data 238 242 self.data = <np.float64_t*> data.data … … 245 249 # like http://courses.csusm.edu/cs697exz/ray_box.htm 246 250 cdef int vi, vj, hit, i, ni, nj, nn 247 self.ns = 5 #* (1 + <int> log2(self.dds[0] / self.min_dds))248 251 cdef int iter[4] 249 252 cdef np.float64_t v_pos[3], v_dir[3], rgba[4], extrema[4] … … 295 298 cdef np.float64_t intersect_t = 1.0 296 299 cdef np.float64_t intersect[3], tmax[3], tdelta[3] 297 cdef np.float64_t enter_t, dist, alpha, dt 300 cdef np.float64_t enter_t, dist, alpha, dt, exit_t 298 301 cdef np.float64_t tr, tl, temp_x, temp_y, dv 299 302 for i in range(3): … … 329 332 cur_ind[i] = <int> floor((intersect[i] + 330 333 step[i]*1e-8*self.dds[i] - 331 self.left_edge[i]) /self.dds[i])334 self.left_edge[i])*self.idds[i]) 332 335 tmax[i] = (((cur_ind[i]+step[i])*self.dds[i])+ 333 336 self.left_edge[i]-v_pos[i])/v_dir[i] 337 # This deals with the asymmetry in having our indices refer to the 338 # left edge of a cell, but the right edge of the brick being one 339 # extra zone out. 334 340 if cur_ind[i] == self.dims[i] and step[i] < 0: 335 341 cur_ind[i] = self.dims[i] - 1 … … 355 361 if tmax[0] < tmax[1]: 356 362 if tmax[0] < tmax[2]: 357 self.sample_values(v_pos, v_dir, enter_t, tmax[0], cur_ind, 363 exit_t = fmin(tmax[0], 1.0) 364 self.sample_values(v_pos, v_dir, enter_t, exit_t, cur_ind, 358 365 rgba, tf) 359 366 cur_ind[0] += step[0] 360 dt = fmin(tmax[0], 1.0) - enter_t361 367 enter_t = tmax[0] 362 368 tmax[0] += tdelta[0] 363 369 else: 364 self.sample_values(v_pos, v_dir, enter_t, tmax[2], cur_ind, 370 exit_t = fmin(tmax[2], 1.0) 371 self.sample_values(v_pos, v_dir, enter_t, exit_t, cur_ind, 365 372 rgba, tf) 366 373 cur_ind[2] += step[2] 367 dt = fmin(tmax[2], 1.0) - enter_t368 374 enter_t = tmax[2] 369 375 tmax[2] += tdelta[2] 370 376 else: 371 377 if tmax[1] < tmax[2]: 372 self.sample_values(v_pos, v_dir, enter_t, tmax[1], cur_ind, 378 exit_t = fmin(tmax[1], 1.0) 379 self.sample_values(v_pos, v_dir, enter_t, exit_t, cur_ind, 373 380 rgba, tf) 374 381 cur_ind[1] += step[1] 375 dt = fmin(tmax[1], 1.0) - enter_t376 382 enter_t = tmax[1] 377 383 tmax[1] += tdelta[1] 378 384 else: 379 self.sample_values(v_pos, v_dir, enter_t, tmax[2], cur_ind, 385 exit_t = fmin(tmax[2], 1.0) 386 self.sample_values(v_pos, v_dir, enter_t, exit_t, cur_ind, 380 387 rgba, tf) 381 388 cur_ind[2] += step[2] 382 dt = fmin(tmax[2], 1.0) - enter_t383 389 enter_t = tmax[2] 384 390 tmax[2] += tdelta[2] … … 386 392 return hit 387 393 394 @cython.boundscheck(False) 395 @cython.wraparound(False) 388 396 cdef void sample_values(self, 389 397 np.float64_t v_pos[3], … … 395 403 TransferFunctionProxy tf): 396 404 cdef np.float64_t cp[3], dp[3], temp, dt, t, dv 397 cdef np.float64_t grad[3] 405 cdef np.float64_t grad[3], ds[3] 406 grad[0] = grad[1] = grad[2] = 0.0 398 407 cdef int dti, i 399 dt = (exit_t - enter_t) / (self.ns-1) # five samples, so divide by four 400 for dti in range(self.ns - 1): 401 t = enter_t + dt * dti 408 dt = (exit_t - enter_t) / (tf.ns) # 4 samples should be dt=0.25 409 for i in range(3): 410 temp = ci[i] * self.dds[i] + self.left_edge[i] 411 dp[i] = (enter_t + 0.5 * dt) * v_dir[i] + v_pos[i] - temp 412 dp[i] *= self.idds[i] 413 ds[i] = v_dir[i] * self.idds[i] * dt 414 for dti in range(tf.ns): 402 415 for i in range(3): 403 cp[i] = v_pos[i] + t * v_dir[i] 404 dp[i] = fclip(fmod(cp[i], self.dds[i])/self.dds[i], 0, 1.0) 416 dp[i] += ds[i] 405 417 dv = trilinear_interpolate(self.dims, ci, dp, self.data) 418 if not ((dv > tf.x_bounds[0]) and (dv < tf.x_bounds[1])): 419 continue 406 420 if tf.use_light == 1: 407 421 eval_gradient(self.dims, ci, dp, self.data, grad)
