forked from Cisneros-Galaxy/RCFM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataAid.py
34 lines (27 loc) · 1.06 KB
/
DataAid.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from os import listdir
# Goes into the specified folder for Galaxies and returns
# all files in the specified relative folder
def getFiles(dirRelPath):
return [x for x in listdir(dirRelPath) if x[0] != '.']
# Given a line of data from a file, convert each string value
# (which are sepperated by tabs) to floats
def dataLineToValues(line):
stringValues = line.split("\t")
floatValues = list(map(lambda x: float(x), stringValues))
return floatValues
# Returns all the galaxy data in the given folder
def GetGalaxyData(galaxiesDirRelPath):
files = getFiles(galaxiesDirRelPath)
# Dictionary "galaxy name"->[list of data points]
data = {}
for fileName in files:
file = open(galaxiesDirRelPath + fileName, "r")
# Convert the file string to an array of each line
lines = file.read().splitlines()
# Cut off the first 3 lines which are just comments
dataLines = lines[3:]
# Convert each line to a list of data points
parsedLines = list(map(dataLineToValues, dataLines))
data[fileName[:-4]] = parsedLines
file.close()
return data