Changeset 1618

Show
Ignore:
Timestamp:
02/11/10 11:47:43 (6 months ago)
Author:
mturk
Message:

Bug fixes from trunk and instinfo command.

Location:
branches/yt-1.6/yt
Files:
11 modified

Legend:

Unmodified
Added
Removed
  • branches/yt-1.6/yt/commands.py

    r1539 r1618  
    2828from yt.recipes import _fix_pf 
    2929import yt.cmdln as cmdln 
    30 import optparse, os, os.path, math, sys 
     30import optparse, os, os.path, math, sys, time, subprocess 
    3131 
    3232_common_options = dict( 
     
    206206    return arg_iterate 
    207207 
     208def _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 
     215def _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 
     221def _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 
     243def _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 
     276def _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 
    208289class YTCommands(cmdln.Cmdln): 
    209290    name="yt" 
     
    220301        """ 
    221302        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." 
    222334 
    223335    @add_cmd_options(['outputfn','bn','thresh','dm_only','skip']) 
  • branches/yt-1.6/yt/extensions/HaloMassFcn.py

    r1596 r1618  
    179179        mylog.info("Reading halo masses from %s" % self.halo_file) 
    180180        f = open(self.halo_file,'r') 
    181         line = f.readline() # burn the top header line. 
    182181        line = f.readline() 
     182        while line[0] == '#': 
     183            line = f.readline() 
    183184        self.haloes = [] 
    184185        while line: 
     
    204205            if i == (self.num_sigma_bins - 3): break 
    205206 
    206         self.dis = dis / self.pf['CosmologyComovingBoxSize']**3.0 
     207        self.dis = dis  / self.pf['CosmologyComovingBoxSize']**3.0 * self.hubble0**3.0 
    207208 
    208209    def sigmaM(self): 
  • branches/yt-1.6/yt/extensions/volume_rendering/software_sampler.py

    r1579 r1618  
    2929 
    3030def 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): 
    3234    center = na.array(center, dtype='float64') 
    3335 
     
    7375    hit = 0 
    7476    tnow = time.time() 
    75     every = na.ceil(len(partitioned_grids) / 100.0) 
    7677 
    7778    vp = VectorPlane(vectors, norm_vec, back_center, 
     
    8687     
    8788    tfp = TransferFunctionProxy(tf) 
     89    tfp.ns = nsamples 
    8890 
    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 
    9095    for i,g in enumerate(partitioned_grids[ind]): 
    91         if (i % every) == 0:  
    92             pbar.update(i) 
     96        pbar.update(total_cells) 
    9397        pos = g.cast_plane(tfp, vp) 
     98        total_cells += na.prod(g.my_data.shape) 
    9499    pbar.finish() 
    95100 
  • branches/yt-1.6/yt/lagos/EnzoDefs.py

    r1555 r1618  
    8686                  'pc'    : 1e6, 
    8787                  'au'    : 2.063e11, 
    88                   'rsun'  : 2.2167e13, 
     88                  'rsun'  : 4.43664e13, 
    8989                  'cm'    : 3.0857e24, 
    9090                  'miles' : 1.917e19} 
  • branches/yt-1.6/yt/lagos/EnzoFields.py

    r1560 r1618  
    343343          projection_conversion="1") 
    344344 
     345def _IsStarParticle(field, data): 
     346    is_star = (data['creation_time'] > 0).astype('float64') 
     347    return is_star 
     348add_field('IsStarParticle', function=_IsStarParticle, 
     349          particle_type = True) 
     350 
    345351# 
    346352# Now we do overrides for 2D fields 
  • branches/yt-1.6/yt/lagos/HDF5LightReader.c

    r1603 r1618  
    3434 
    3535#include "numpy/ndarrayobject.h" 
     36 
     37#ifndef npy_float128 
     38#define npy_float128 npy_longdouble 
     39#endif 
    3640 
    3741 
  • branches/yt-1.6/yt/lagos/HierarchyType.py

    r1603 r1618  
    250250 
    251251        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] 
    253256 
    254257    def _close_data_file(self): 
  • branches/yt-1.6/yt/lagos/parallelHOP/parallelHOP.py

    r1563 r1618  
    105105                # max_padding, which is more likely the case with load-balancing 
    106106                # 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])) 
    113113                d = na.sqrt(dx*dx + dy*dy + dz*dz) 
    114114                if d <= self.max_padding: 
     
    13751375        if calc: 
    13761376            com = self.CoM[subchain] 
    1377             rad = na.abs(com - loc) 
     1377            rad = na.fabs(com - loc) 
    13781378            dist = (na.minimum(rad, self.period - rad)**2.).sum(axis=1) 
    13791379            dist = dist[sort] 
  • branches/yt-1.6/yt/lagos/Profiles.py

    r1533 r1618  
    167167                # in the way. 
    168168                if field in self.pf.field_info \ 
    169                     and self.pf.field_info[field].particle_type \ 
    170                     and not 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) 
    172172                else: 
    173173                    pointI = self._data_source._get_point_indices(source) 
  • branches/yt-1.6/yt/_amr_utils/FixedInterpolator.c

    r1579 r1618  
    9898      normval += grad[i]*grad[i]; 
    9999    } 
    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    } 
    104108} 
  • branches/yt-1.6/yt/_amr_utils/VolumeIntegrator.pyx

    r1579 r1618  
    4646 
    4747cdef 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 
    4951 
    5052cdef inline np.float64_t fclip(np.float64_t f, 
     
    7678    cdef np.float64_t *vs[4] 
    7779    cdef int nbins 
    78     cdef np.float64_t dbin 
     80    cdef public int ns 
     81    cdef np.float64_t dbin, idbin 
    7982    cdef np.float64_t light_color[3] 
    8083    cdef np.float64_t light_dir[3] 
     
    9699        self.nbins = tf_obj.nbins 
    97100        self.dbin = (self.x_bounds[1] - self.x_bounds[0])/self.nbins 
     101        self.idbin = 1.0/self.dbin 
    98102        self.light_color[0] = tf_obj.light_color[0] 
    99103        self.light_color[1] = tf_obj.light_color[1] 
     
    108112        self.use_light = tf_obj.use_light 
    109113 
     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) 
    110130    cdef void eval_transfer(self, np.float64_t dt, np.float64_t dv, 
    111131                                    np.float64_t *rgba, np.float64_t *grad): 
    112132        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)  
    117135        # get source alpha first 
    118136        # 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/dy 
    122         bv = self.vs[3][bin_id] # This is x0 
    123         dy = self.vs[3][bin_id+1]-bv # dy 
    124         dd = dv-(self.x_bounds[0] + bin_id * dx) # x - x0 
    125             # This is our final value for transfer function on the entering face 
    126         tf = bv+dd*(dy/dx)  
    127         ta = tf  # Store the source alpha 
    128137        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] 
    148148 
    149149cdef class VectorPlane: 
     
    181181        self.pdy = (self.bounds[3] - self.bounds[2])/self.nv 
    182182 
     183    @cython.boundscheck(False) 
     184    @cython.wraparound(False) 
    183185    cdef void get_start_stop(self, np.float64_t *ex, int *rv): 
    184186        # Extrema need to be re-centered 
    185187        cdef np.float64_t cx, cy 
     188        cdef int i 
    186189        cx = cy = 0.0 
    187190        for i in range(3): 
     
    215218    cdef np.float64_t right_edge[3] 
    216219    cdef np.float64_t dds[3] 
     220    cdef np.float64_t idds[3] 
    217221    cdef public np.float64_t min_dds 
    218     cdef int ns 
    219222    cdef int dims[3] 
    220223 
     
    235238            self.dims[i] = dims[i] 
    236239            self.dds[i] = (self.right_edge[i] - self.left_edge[i])/dims[i] 
     240            self.idds[i] = 1.0/self.dds[i] 
    237241        self.my_data = data 
    238242        self.data = <np.float64_t*> data.data 
     
    245249        # like http://courses.csusm.edu/cs697exz/ray_box.htm 
    246250        cdef int vi, vj, hit, i, ni, nj, nn 
    247         self.ns = 5 #* (1 + <int> log2(self.dds[0] / self.min_dds)) 
    248251        cdef int iter[4] 
    249252        cdef np.float64_t v_pos[3], v_dir[3], rgba[4], extrema[4] 
     
    295298        cdef np.float64_t intersect_t = 1.0 
    296299        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 
    298301        cdef np.float64_t tr, tl, temp_x, temp_y, dv 
    299302        for i in range(3): 
     
    329332            cur_ind[i] = <int> floor((intersect[i] + 
    330333                                      step[i]*1e-8*self.dds[i] - 
    331                                       self.left_edge[i])/self.dds[i]) 
     334                                      self.left_edge[i])*self.idds[i]) 
    332335            tmax[i] = (((cur_ind[i]+step[i])*self.dds[i])+ 
    333336                        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. 
    334340            if cur_ind[i] == self.dims[i] and step[i] < 0: 
    335341                cur_ind[i] = self.dims[i] - 1 
     
    355361            if tmax[0] < tmax[1]: 
    356362                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, 
    358365                                       rgba, tf) 
    359366                    cur_ind[0] += step[0] 
    360                     dt = fmin(tmax[0], 1.0) - enter_t 
    361367                    enter_t = tmax[0] 
    362368                    tmax[0] += tdelta[0] 
    363369                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, 
    365372                                       rgba, tf) 
    366373                    cur_ind[2] += step[2] 
    367                     dt = fmin(tmax[2], 1.0) - enter_t 
    368374                    enter_t = tmax[2] 
    369375                    tmax[2] += tdelta[2] 
    370376            else: 
    371377                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, 
    373380                                       rgba, tf) 
    374381                    cur_ind[1] += step[1] 
    375                     dt = fmin(tmax[1], 1.0) - enter_t 
    376382                    enter_t = tmax[1] 
    377383                    tmax[1] += tdelta[1] 
    378384                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, 
    380387                                       rgba, tf) 
    381388                    cur_ind[2] += step[2] 
    382                     dt = fmin(tmax[2], 1.0) - enter_t 
    383389                    enter_t = tmax[2] 
    384390                    tmax[2] += tdelta[2] 
     
    386392        return hit 
    387393 
     394    @cython.boundscheck(False) 
     395    @cython.wraparound(False) 
    388396    cdef void sample_values(self, 
    389397                            np.float64_t v_pos[3], 
     
    395403                            TransferFunctionProxy tf): 
    396404        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 
    398407        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):  
    402415            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] 
    405417            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 
    406420            if tf.use_light == 1: 
    407421                eval_gradient(self.dims, ci, dp, self.data, grad)