Page MenuHomec4science

gget_massin
No OneTemporary

File Metadata

Created
Mon, Jul 1, 06:34

gget_massin

#!/usr/bin/env python
'''
Get the mass contained in a specific radius
Yves Revaz
Thu Feb 23 14:06:51 CET 2006
'''
from numarray import *
from Nbody import *
import string
import sys
import os
from libjeans import *
from Nbody.libutil import histogram
from optparse import OptionParser
from Gtools import *
def parse_options():
usage = "usage: %prog [options] file"
parser = OptionParser(usage=usage)
parser = add_units_options(parser)
parser.add_option("-t",
action="store",
dest="ftype",
type="string",
default = None,
help="type of the file",
metavar=" TYPE")
parser.add_option("--cgs",
action="store_true",
dest="cgs",
default = 0,
help="invert into cgs units")
parser.add_option("--rmax",
action="store",
dest="rmax",
type="float",
default=0,
help="max radius")
(options, args) = parser.parse_args()
if len(args) == 0:
print "you must specify a filename"
sys.exit(0)
files = args
return files,options
#############################
# graph
#############################
# get options
files,options = parse_options()
rmax = options.rmax
cgs = options.cgs
ftype = options.ftype
if cgs:
units = get_units_options(options)
# read files
for file in files:
nbody = Nbody(file,ftype=ftype)
nbody.hdcenter()
r = nbody.rxyz()
mass = nbody.mass
if cgs:
mass = Mass2cgs(mass,units)
r = Length2cgs(r,units)
c = (r<rmax)
mass = compress(c,mass)
mtot = sum(mass)
print mtot

Event Timeline