-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_data.py
More file actions
51 lines (42 loc) · 1.35 KB
/
generate_data.py
File metadata and controls
51 lines (42 loc) · 1.35 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import os
"""
This file is used to iterate over the data files obtained from the ZOS-API,
and is used to create a collection of values as a pandas dataframe
"""
cwd = os.getcwd()
path = os.path.join(cwd, 'data')
catlist = []
i = 0
category = []
data = pd.DataFrame()
for subdirs in os.listdir(path):
catlist.append(subdirs)
for cat in catlist:
for root, subdirs, files in os.walk(os.path.join(path, cat)):
for filename in files:
file_path = os.path.join(root, filename)
if filename == "zernike.csv":
extract = pd.read_csv(file_path, header = None, names = [root[root.rfind('/')+1:]])
extract = extract.T
data = data.append(extract)
category.append(i)
i=i+1
data['category'] = category
params = {'dx':0.0, 'dy':0.0, 'tx':0.0, 'ty':0.0}
df = data.assign(**params)
for index in df.index:
if index[:2] == 'dx':
df.at[index, 'dx'] = float(index[2:])
if index[:2] == 'dy':
df.at[index, 'dy'] = float(index[2:])
if index[:2] == 'tx':
df.at[index, 'tx'] = float(index[2:])
if index[:2] == 'ty':
df.at[index, 'ty'] = float(index[2:])
# print(data.shape)
# print(data.head())
# print(data['category'].unique())
df.to_csv(os.path.join(cwd, 'data.csv'))