Example #1
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri May 18 13:48:50 2018

@author: php17cs
"""

import numpy as np
from function_file import read_in_any_datafiles, velocity_elements, plots_legend

#reads in the .dat files from an inputfile list
dflist, dname, nlines = read_in_any_datafiles('file.txt')

#calculates the velocity (distance travelled/snapshot length
dflist = velocity_elements(dflist, dname, nlines)

#creates the legend for for plots of single simulations
legend = plots_legend(dname)

j = 50
velocity = 'PM-velxy'

dflist_mean = np.empty(1000)

for line in range(1000):
    dflist_sumlist = []
    for n in range(nlines):
        dflist_sumlist.append(
            (dflist[n].loc[j].sort_values(velocity)[velocity]).iloc[line])
    dflist_mean[line] = (np.mean(dflist_sumlist))
# this code calculates and plots the cumulative PM and 3D velocity for all snaps in all simulations that are read in from an input text file

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

from matplotlib.ticker import AutoMinorLocator
from function_file import read_in_any_datafiles, velocity_elements, energy_stars, stars_in_outside_2HMR

dflist, dname, nlines = read_in_any_datafiles(
    'file_evolved.txt')  #this reads in the .dat files from an inputfile list

#the functions below are not used for the simulations with stellar evolustion, as issue with Fortran concerning loss of stars in simulations is not yet solved
#dflist = energy_stars(dflist,dname,nlines)       #this calculates the energy of each star in each snapshot an simulation and adds this in a column
#dflist = velocity_elements(dflist,dname,nlines)  #this calculates the velocity by using the distance travelled between each snapshot and divides it by snapshot length - this is an alternative to the provided velocities from the simulation
#dflist = stars_in_outside_2HMR(dflist,dname,nlines)  # this calculates the half-mass radius based on centre of density corrected locations and then adds a column identifying if the stars are inside or outside 2*HMR

#%%

# This creates the filename for including the intial conditions by using filename[0]

filename = []

for fname in dname:  # to allow the filename of the simulations to dictate the labels

    if fname[21] == 'E':
        if fname[17] == 'X':
            legendtitle = (
                '%s_sim_%s.%s_%s.%s_%spc_E_1000' %
                (nlines, fname[7], fname[8], fname[22], fname[23], fname[12]))
        elif fname[17] == '5':