Skip to content

Commit

Permalink
Moved double_exp distn into "distributions.py"
Browse files Browse the repository at this point in the history
  • Loading branch information
samb8s committed May 8, 2014
1 parent 0a080a6 commit 6493991
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 8 additions & 0 deletions lib/python/distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,12 @@ def draw1d(dist):
if rand_num <= c:
return i

def draw_double_sided_exp(scale, origin=0.0):
"""Exponential distribution around origin, with scale height scale."""
if scale == 0.0:
return origin

rn = random.random()
sign = random.choice([-1.0, 1.0])

return origin + sign * scale * math.log(rn)
8 changes: 4 additions & 4 deletions lib/python/evolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,9 @@ def birthVelocity( pulsar, pop):
pulsar.vy = random.gauss(mean, sigma)
pulsar.vz = random.gauss(mean, sigma)
elif bvM == 'exp':
pulsar.vx = go._double_sided_exp(sigma, origin = mean)
pulsar.vy = go._double_sided_exp(sigma, origin = mean)
pulsar.vz = go._double_sided_exp(sigma, origin = mean)
pulsar.vx = dists.draw_double_sided_exp(sigma, origin = mean)
pulsar.vy = dists.draw_double_sided_exp(sigma, origin = mean)
pulsar.vz = dists.draw_double_sided_exp(sigma, origin = mean)
else:
raise EvolveException('Invalid velocity model selected')

Expand All @@ -350,7 +350,7 @@ def galacticDistribute(pulsar, pop):
y = -20. + random.random()*40.

# calculate z and r0
z = go._double_sided_exp(pop.zscale)
z = dists.draw_double_sided_exp(pop.zscale)
pulsar.galCoords = (x, y, z)
pulsar.r0 = math.sqrt(x**2 + y**2)

Expand Down

0 comments on commit 6493991

Please sign in to comment.