Beispiel #1
0
 def __init__(
         self,
         GCName,  # i.e. Pal5
         basename="output",  # base name of each bin file
         increment=1,  # time step in 10s of millions of years
         current_time=0,  # first time step in the sequence
         max_time=500,  # this is actually today,
         # the number of time stamps to use for the center of mass orbit
     adjcent_COM_points=700,
         coordainte_sys='xy',  # what units are we going to plot
 ):
     self.GCName = GCName
     self.basename = basename
     self.increment = increment
     self.current_time = current_time
     self.max_time = max_time
     self.gc_frame = inputMW.ref_frame()
     self.adjcent_COM_points = adjcent_COM_points
     self.coordainte_sys = coordainte_sys
     self.folder_path = \
         "../../simulations/outputDATA4movies/" + GCName + "/"
     self.orbit_file = \
         "../../simulations/outputDATA/PII/Plummer/backwardorbits/orbit" + GCName + ".dat"
     self.set_file_name()
     self.set_center_of_mass_file()
 else:
     xlabel = "X (KPC)"
     ylabel = "Y (KPC)"
     my_x_coordinate = np.array(
         data_file[coordinate_system]["X"][criterian])
     my_y_coordinate = np.array(
         data_file[coordinate_system]["Y"][criterian])
     # pick limits by rounding up to the nearest 10
     extremes = [np.max(abs(my_x_coordinate)), np.max(abs(my_y_coordinate))]
     my_extreme = round(np.max(extremes) / 10) * 10
     xmin = -my_extreme
     xmax = my_extreme
     ymin = -my_extreme
     ymax = my_extreme
     # get the position in galacto-centric distance
     gc_frame = ref_frame()
     galactocentric = glob_center.transform_to(gc_frame)
     cluster_X = galactocentric.x
     cluster_Y = galactocentric.y
 # Get colorbar based on the unit selected
 my_cmap = "jet_r"
 strict_color_range = 0
 cbar_name = quantity_name
 # calculate or extract which quantity to use as color scale
 if quantity_name == "Lz":
     X = np.array(data_file['galactocentric']['X'][criterian])
     Y = np.array(data_file['galactocentric']['Y'][criterian])
     VX = np.array(data_file['galactocentric']['VX'][criterian])
     VY = np.array(data_file['galactocentric']['VY'][criterian])
     angular_momentum = X * VY - Y * VX
     my_quantity = np.array(angular_momentum)
Beispiel #3
0
def main(GCname):
    """ GOAL is to verify that we get sensical streams before and after... """

    """



    SET UP THE PARAMETERS



    """
    ### PARAMETERS TO CHANGE ####
    # ASSIGN MILKY WAY MODEL
    model = 'PII'
    modelshort = "GCGC"  # add this as another piece of information to add
    # PATH TO OBTAIN THE BACKWARD ORBITS of the GC CENTRE DE MASSE
    pathorbits = "/backwardorbitsGCGC/"
    backward = 'NO'
    pathstreams = "/streamsGCGC/"
    # LIST OF THE GCs. Current GC is omitted,
    fname_GClist = "GClist.txt"
    N = 1
    # ARE WE MAKING THE BIG TABLE WITH POTENTIAL PER TIME ?
    writeGCGC = 0
    # ASSIGN TOTAL NUMBER OF STEP FOR THE ORBIT INTEGRATION AND INTEGRATION TIME-STEP
    Nstep = 50000
    deltat = 0.001
    # ASSIGN PARAMETERS FOR MONTE-CARLO SIMULATIONS ON ERRORS
    Nsample = 10000
    n_trials = 1
    # ARE WE SAVING THE TIME STAMPS FOR THE MOVIE?
    isave = 100     # set to zero to not save the bin files !
    # PATH TO GC ORBITS
    path = '../outputDATA/' + model + pathorbits
    ierror = 0
    # INFO TO GET SUBHALOS
    pathSH = "../outputData/" + model + "/backwardorbitsOG/"
    # GALACTIC REFERENCE FRAME
    gc_frame = inputMW.ref_frame()
    # GET GALACTIC PARAMETERS
    MWparam = inputMW.MW(model)
    # INFORMATION ON GCs of DARKMATTER HALOS
    # must be initialized at zero for for orbits
    nhalos = 0
    nameSH = np.empty(0, dtype='c').T
    bgGCParams = np.empty(0)

    """


    OPEN THE INITIAL CONDITIONS FROM THE DATA FILES
        get the initial conditions of the target GC
        get initial confitions of the particles in the Target GC
        get the path information of the other GC/subhalos if they are being used


    """
    xGC, yGC, zGC, vxGC, vyGC, vzGC = inputGC.GCcoord(GCname, gc_frame, ierror)
    # GET THE INITAL COORDINATE FROM THE LAST LINE OF THE FILE
    with open(path + "orbit" + GCname + ".dat", 'r') as f:
        for line in f:
            pass
        last_line = line
    num = last_line.split()
    xGCini, yGCini, zGCini, vxGCini, vyGCini, vzGCini = \
        float(num[1]), float(num[2]), float(num[3]), \
        float(num[4]), float(num[5]), float(num[6])

    print("initial x,y,z,vx,vy,vz")
    print(xGCini, yGCini, zGCini)
    print(vxGCini, vyGCini, vzGCini)
    # GET THE INITIAL POSITIONS OF THE PARTICLES
    x0, y0, z0, vx0, vy0, vz0 = inputGC.Nbody(GCname)
    # PUT IN REFERENCE FRAME OF THE GALAXY
    x0 = x0 + xGCini
    y0 = y0 + yGCini
    z0 = z0 + zGCini
    vx0 = vx0 + vxGCini
    vy0 = vy0 + vyGCini
    vz0 = vz0 + vzGCini
    backward = "NO"
    N = len(x0)
    # Get the PARAMETERS OF THE SUBHALOS
    if not os.path.isfile(fname_GClist):
        GCparam = inputGC.Plummer(GCname)
        print(fname_GClist, "is empty. Using", nhalos, "dark matter subhalos")
    else:
        GCparam, bgGCParams, bgGCNames = manage_GC_data(
            GCname, fname_GClist, pathSH)
        nhalos = len(bgGCNames)
        res = max(bgGCNames, key=len)
        len_str = len(res)
        # this adds as many blank spaces to the right as necessary to have all elements in stringsSH as long as the longest one
        bgGCNames = [bgGCNames[i].ljust(len_str) for i in range(0, nhalos)]
        nameSH = np.array(bgGCNames, dtype='c').T
        print("USING", nhalos, "DARK MATTER HALOS")

    # MAKE FOLDER FOR SAVING THE MOVE
    if isave != 0:
        outdir = "../outputDATA4movies/" + model + "/" + modelshort + "/" + GCname
        if os.path.isdir(outdir):
            dircontents = os.listdir(outdir)
            if len(dircontents) > 0:
                print("")
                print("WARNING ! You might be over writing the movies for the film! ")
                print("The", outdir, "contains")
                print(dircontents)
                print("")
        else:
            os.makedirs(outdir)

    """



    CALCULATE THE ORBITS




    """
    start_time = time.time()
    print("starting integrale")
    integrate.orbits(x0, y0, z0, vx0, vy0, vz0, GCparam, MWparam, model, modelshort,
                     GCname, backward, pathorbits, deltat,
                     Nstep, pathSH, nameSH, bgGCParams, writeGCGC, isave)

    end_time = time.time()
    c_time = end_time - start_time
    minutes = np.floor(c_time / 60)
    seconds = c_time % 60
    print("COMPUTATION TIME: {:.0f} min {:.0f} s".format(minutes, seconds))

    """



        WRITE OUT THE STREAM FINAL COORDINATES




    """

    # get the final coordaintes of the particles
    xf = integrate.xp
    yf = integrate.yp
    zf = integrate.zp
    vxf = integrate.vxp
    vyf = integrate.vyp
    vzf = integrate.vzp
    tesc = integrate.tesc
    phiMW = integrate.phimw
    phiGC = integrate.phigc
    # GET OTHER COORDINATES
    c1 = coord.SkyCoord(x=xf * u.kpc, y=yf * u.kpc, z=zf * u.kpc, v_x=vxf * 10 *
                        u.km / u.s, v_y=vyf * 10 * u.km / u.s, v_z=vzf * 10 * u.km / u.s, frame=gc_frame)
    gc2 = c1.transform_to(coord.ICRS)
    # prepare RA and DEC
    ra = gc2.ra.value
    dec = gc2.dec.value
    D = gc2.distance.value
    pm_ra_cosdec = gc2.pm_ra_cosdec.value
    pm_dec = gc2.pm_dec.value
    RV = gc2.radial_velocity.value
    # prepare galactic longitude and latitude
    gc3 = gc2.transform_to('galactic')
    ll = gc3.l.value
    l = ll
    l[ll > 180] = l[ll > 180] - 360.
    b = gc3.b.value
    pm_l_cosb = gc3.pm_l_cosb.value
    pm_b = gc3.pm_b.value
    # SAVE OUTPUT DATA
    if (ierror == 0):
        path = '../outputData/' + model + pathstreams
        os.makedirs(path, exist_ok=True)
        hf = h5py.File(path + "/" + GCname + '.h5', 'w')
    # parameters
    EQ = hf.create_group('equatorial')
    EQ.create_dataset('RA', data=ra)
    EQ.create_dataset('DEC', data=dec)
    EQ.create_dataset('D', data=D)
    EQ.create_dataset('PMRA_COSDEC', data=pm_ra_cosdec)
    EQ.create_dataset('PMDEC', data=pm_dec)
    EQ.create_dataset('RV', data=RV)
    GAL = hf.create_group('galactic')
    GAL.create_dataset('LONG', data=l)
    GAL.create_dataset('LAT', data=b)
    GAL.create_dataset('PML_COSB', data=pm_l_cosb)
    GAL.create_dataset('PMB', data=pm_b)
    GALCEN = hf.create_group('galactocentric')
    GALCEN.create_dataset('X', data=xf)
    GALCEN.create_dataset('Y', data=yf)
    GALCEN.create_dataset('Z', data=zf)
    GALCEN.create_dataset('VX', data=vxf)
    GALCEN.create_dataset('VY', data=vyf)
    GALCEN.create_dataset('VZ', data=vzf)
    ENERGY = hf.create_group('energy')
    ENERGY.create_dataset('Tescape', data=tesc)
    ENERGY.create_dataset('phiMW', data=phiMW)
    ENERGY.create_dataset('phiGC', data=phiGC)
    # finish
    hf.close()
    integrate.deallocate()
    print("END")
f = FortranFile(namefile, 'r')
x = f.read_reals(dtype='float32')
y = f.read_reals(dtype='float32')
z = f.read_reals(dtype='float32')
vx = f.read_reals(dtype='float32')
vy = f.read_reals(dtype='float32')
vz = f.read_reals(dtype='float32')
f.close()

print(len(x))

plt.figure()
plt.scatter(x, y)
plt.show()

gc_frame = inputMW.ref_frame()

c1 = coord.SkyCoord(x=x * u.kpc,
                    y=y * u.kpc,
                    z=z * u.kpc,
                    v_x=vx * 10 * u.km / u.s,
                    v_y=vy * 10 * u.km / u.s,
                    v_z=vz * 10 * u.km / u.s,
                    frame=gc_frame)
gc2 = c1.transform_to(coord.ICRS)

ra = gc2.ra.value
dec = gc2.dec.value
D = gc2.distance.value
pm_ra_cosdec = gc2.pm_ra_cosdec.value
pm_dec = gc2.pm_dec.value
Beispiel #5
0
def main(GCname):
    """ Integrate backward in time """
    """ 
    
    
    SET THE PARAMETERS AND PATH INFORMATION 
    
    
    """
    model = 'PII'
    modelshort = model
    # SET OUTPUT PATH OF WHERE TO SAVE THE BACKWARDORBITS
    pathorbits = "/backwardorbitsGCGC/"
    backward = 'YES'
    # GET THE POTENTIAL OF THE INTERACTIONS OF EACH GCGC
    writeGCGC = "YES"
    # LIST OF THE GCs. Current GC is omitted,
    fname_GClist = "GClist.txt"
    N = 1
    # ASSIGN TOTAL NUMBER OF STEP FOR THE ORBIT INTEGRATION AND INTEGRATION TIME-STEP
    Nstep = 50000
    deltat = 0.001
    # ASSIGN PARAMETERS FOR MONTE-CARLO SIMULATIONS ON ERRORS
    Nsample = 10000
    n_trials = 1
    # PATH TO GC ORBITS
    path = '../outputDATA/' + model + pathorbits
    ierror = 0
    # INFO TO GET SUBHALOS
    pathSH = "../outputData/" + model + "/backwardorbitsOG/"
    # GALACTIC REFERENCE FRAME
    gc_frame = inputMW.ref_frame()
    # GET GALACTIC PARAMETERS
    MWparam = inputMW.MW(modelshort)
    # GET THE GC initial conditions
    xGC, yGC, zGC, vxGC, vyGC, vzGC = inputGC.GCcoord(GCname, gc_frame, ierror)

    # the parameters of each
    if not os.path.isfile(fname_GClist):
        GCparam = inputGC.Plummer(GCname)
        nhalos = 0
        len_str = 2
        nameSH = np.empty(0, dtype='c').T
        bgGCParams = np.empty(0)
        print(fname_GClist, "is empty. Using", nhalos, "dark matter subhalos")
    else:
        GCparam, bgGCParams, bgGCNames = manage_GC_data(
            GCname, fname_GClist, pathSH)
        nhalos = len(bgGCNames)
        res = max(bgGCNames, key=len)
        len_str = len(res)
        # this adds as many blank spaces to the right as necessary to have all elements in stringsSH as long as the longest one
        bgGCNames = [bgGCNames[i].ljust(len_str) for i in range(0, nhalos)]
        nameSH = np.array(bgGCNames, dtype='c').T

    os.makedirs(path, exist_ok=True)

    integrate.orbits(xGC, yGC, zGC, vxGC, vyGC, vzGC, GCparam, MWparam, model,
                     modelshort, GCname, backward, pathorbits, deltat,
                     int(Nstep), pathSH, nameSH, bgGCParams, writeGCGC)

    # orbits(x,y,z,vx,vy,vz,GCparam,MWparam,
    # model,modelshort,GCname,backward,pathorbits,deltat,
    # Nstep,N,Nhalos,len_str,pathSH,nameSH)
    # No need to #DEFINE N don't need to be passed from python,
    # though they need to be declared in fortran
    #  But since the arrays are being passed from python, we don't need this variable that declares size
    # same thing with NHalos, since it is impiled with nameSH
    # no need to pass len_str either

    # I don't think we need this code below ?
    xGCini = integrate.xp
    yGCini = integrate.yp
    zGCini = integrate.zp
    vxGCini = integrate.vxp
    vyGCini = integrate.vyp
    vzGCini = integrate.vzp