marta-marta commited on
Commit
3d5cee9
1 Parent(s): 484d52e

Found error in reading of output files. Need to edit how to output the files

Browse files
Data_Generation/Dataset_Generation_Functions.py CHANGED
@@ -71,43 +71,13 @@ def make_boxes(image_size, densities):
71
 
72
 
73
  ########################################################################################################################
74
- image_size = 9
75
- densities = [0.2, 0.4, 0.6, 0.8, 1]
76
- boxes = make_boxes(image_size, densities)
77
-
78
- box_arrays, box_density, basic_box_thickness, forward_slash_box_thickness, back_slash_box_thickness,hot_dog_box_thickness, hamburger_box_thickness\
79
- = list(zip(*boxes))[0], list(zip(*boxes))[1], list(zip(*boxes))[2], list(zip(*boxes))[3], list(zip(*boxes))[4], list(zip(*boxes))[5], list(zip(*boxes))[6]
80
- print(type(box_arrays[0]))
81
-
82
-
83
- class NumpyArrayEncoder(JSONEncoder):
84
- def default(self, obj):
85
- if isinstance(obj, np.ndarray):
86
- return obj.tolist()
87
- return JSONEncoder.default(self, obj)
88
-
89
-
90
- box_arrays = [json.dumps(x, cls=NumpyArrayEncoder) for x in box_arrays] # find argument for json dumps for numpy
91
-
92
- # Create a dataframe to convert the data to a csv file
93
- dataframe = (pd.DataFrame((box_arrays, box_density, basic_box_thickness, forward_slash_box_thickness, back_slash_box_thickness,hot_dog_box_thickness, hamburger_box_thickness)).T).astype(str)
94
-
95
- # Rename the columns to the desired outputs
96
- dataframe = dataframe.rename(columns={0: "Array", 1: "Density", 2:"Basic Box Thickness", 3:"Forward Slash Strut Thickness", 4:"Back Slash Strut Thickness", 5:"Vertical Strut Thickness", 6:"Horizontal Strut Thickness"})
97
-
98
- csv = dataframe.to_csv('2D_Lattice.csv')
99
-
100
-
101
  df = pd.read_csv('2D_Lattice.csv')
102
- # print(df)
103
- row = 0
104
  box = df.iloc[row, 1]
105
- print(box)
106
  array = np.array(json.loads(box))
107
- plt.imshow(array)
108
  plt.show()
109
-
110
- # import matplotlib.pyplot as plt
111
- # plt.imshow(np.array(box))
112
- # plt.show()
113
- # print(df)
 
71
 
72
 
73
  ########################################################################################################################
74
+ # How to read the files
75
+ '''
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  df = pd.read_csv('2D_Lattice.csv')
77
+ print(np.shape(df))
78
+ row = 1
79
  box = df.iloc[row, 1]
 
80
  array = np.array(json.loads(box))
81
+ plt.imshow(array, vmin=0, vmax=1)
82
  plt.show()
83
+ '''
 
 
 
 
app.py CHANGED
@@ -1,14 +1,15 @@
1
  import matplotlib.pyplot as plt
2
  import numpy as np
3
  import pandas as pd
4
-
 
5
  import streamlit as st
 
6
  from Data_Generation.Dataset_Generation_Functions import make_boxes
7
  from Data_Generation.Piecewise_Box_Functions import basic_box_array, forward_slash_array, combine_arrays, add_thickness
8
  ########################################################################################################################
9
  # User Inputs
10
  image_size = st.slider('Select a value for the image size', min_value=9, max_value=16)
11
- # st.write(x, 'squared is', x * x)
12
 
13
  density_selection = st.slider('Select a value for the number of equally spaced density values (0, 1]', min_value=1, max_value=10)
14
  ########################################################################################################################
@@ -19,27 +20,19 @@ densities = np.linspace(0, 1, num=density_selection+1)[1:]
19
  sample_basic_box = basic_box_array(image_size, 1)
20
  sample_forward_slash_box = forward_slash_array(image_size, 1)
21
  sample_combined = combine_arrays([sample_forward_slash_box, sample_basic_box])
22
- # print(sample_combined)
23
 
24
  sample_density = np.array([sample_combined * density_value for density_value in densities])
25
-
26
- # copy = sample_combined
27
  sample_thickness = []
28
- # test = add_thickness(copy, 2)
29
- # sample_thickness.append(test)
30
- # print(sample_thickness)
31
  for i in [1, 2, 3, 4]:
32
  copy = sample_combined
33
- # print(i)
34
  test = add_thickness(copy, i)
35
- # print(test)
36
  sample_thickness.append(test)
37
- # print(sample_thickness)
38
  ########################################################################################################################
39
  # Output Example Shapes
40
  st.write("Click 'Generate Samples' to show some density values that would exist in your dataset:")
41
 
42
-
43
  # Show samples of various density values
44
 
45
  if st.button('Generate Samples'): # Generate the samples
@@ -52,6 +45,7 @@ if st.button('Generate Samples'): # Generate the samples
52
  plt.tick_params(left=False, labelleft=False)
53
  plt.title("Density: " + str(round(densities[i], 4)), fontsize=6)
54
  plt.figure(1)
 
55
  # cax = plt.axes([0.85, 0.1, 0.075, 0.8])
56
  # plt.colorbar(cax=cax, shrink=0.1)
57
  st.pyplot(plt.figure(1))
@@ -65,6 +59,7 @@ if st.button('Generate Samples'): # Generate the samples
65
  plt.tick_params(left=False, labelleft=False)
66
  plt.title("Thickness: " + str(i+1), fontsize=6)
67
  plt.figure(2)
 
68
  # cax = plt.axes([0.85, 0.1, 0.075, 0.8])
69
  # plt.colorbar(cax=cax, shrink=0.1)
70
  st.pyplot(plt.figure(2))
@@ -72,19 +67,34 @@ if st.button('Generate Samples'): # Generate the samples
72
  ########################################################################################################################
73
  # Output Entire Dataset
74
  st.write("Click 'Generate Dataset' to generate the dataset based on the conditions set previously:")
75
- if st.button('Generate Dataset'): # Generate the samples
76
- boxes = make_boxes(image_size, densities)
 
77
  box_arrays, box_density, basic_box_thickness, forward_slash_box_thickness, back_slash_box_thickness,hot_dog_box_thickness, hamburger_box_thickness\
78
  = list(zip(*boxes))[0], list(zip(*boxes))[1], list(zip(*boxes))[2], list(zip(*boxes))[3], list(zip(*boxes))[4], list(zip(*boxes))[5], list(zip(*boxes))[6]
79
 
 
 
 
 
 
 
 
 
 
80
  # Create a dataframe to convert the data to a csv file
81
- dataframe = (pd.DataFrame((box_arrays, box_density, basic_box_thickness, forward_slash_box_thickness, back_slash_box_thickness,hot_dog_box_thickness, hamburger_box_thickness)).T).astype(str)
 
82
 
83
  # Rename the columns to the desired outputs
84
- dataframe = dataframe.rename(columns={0: "Array", 1: "Density", 2:"Basic Box Thickness", 3:"Forward Slash Strut Thickness", 4:"Back Slash Strut Thickness", 5:"Vertical Strut Thickness", 6:"Horizontal Strut Thickness"})
 
 
85
 
 
86
  csv = dataframe.to_csv()
87
- st.write("Here is what the generated data looks like (double click on the 'Array' cells to view the full array):")
88
- st.write(dataframe) # Display the data generated
 
89
  st.write("Click 'Download' to download a CSV file of the dataset:")
90
- st.download_button("Download Dataset", csv, file_name='2D_Lattice.csv')
 
1
  import matplotlib.pyplot as plt
2
  import numpy as np
3
  import pandas as pd
4
+ import json
5
+ from json import JSONEncoder
6
  import streamlit as st
7
+
8
  from Data_Generation.Dataset_Generation_Functions import make_boxes
9
  from Data_Generation.Piecewise_Box_Functions import basic_box_array, forward_slash_array, combine_arrays, add_thickness
10
  ########################################################################################################################
11
  # User Inputs
12
  image_size = st.slider('Select a value for the image size', min_value=9, max_value=16)
 
13
 
14
  density_selection = st.slider('Select a value for the number of equally spaced density values (0, 1]', min_value=1, max_value=10)
15
  ########################################################################################################################
 
20
  sample_basic_box = basic_box_array(image_size, 1)
21
  sample_forward_slash_box = forward_slash_array(image_size, 1)
22
  sample_combined = combine_arrays([sample_forward_slash_box, sample_basic_box])
 
23
 
24
  sample_density = np.array([sample_combined * density_value for density_value in densities])
 
 
25
  sample_thickness = []
26
+
 
 
27
  for i in [1, 2, 3, 4]:
28
  copy = sample_combined
 
29
  test = add_thickness(copy, i)
 
30
  sample_thickness.append(test)
31
+
32
  ########################################################################################################################
33
  # Output Example Shapes
34
  st.write("Click 'Generate Samples' to show some density values that would exist in your dataset:")
35
 
 
36
  # Show samples of various density values
37
 
38
  if st.button('Generate Samples'): # Generate the samples
 
45
  plt.tick_params(left=False, labelleft=False)
46
  plt.title("Density: " + str(round(densities[i], 4)), fontsize=6)
47
  plt.figure(1)
48
+ # These settings can be used to display a colorbar
49
  # cax = plt.axes([0.85, 0.1, 0.075, 0.8])
50
  # plt.colorbar(cax=cax, shrink=0.1)
51
  st.pyplot(plt.figure(1))
 
59
  plt.tick_params(left=False, labelleft=False)
60
  plt.title("Thickness: " + str(i+1), fontsize=6)
61
  plt.figure(2)
62
+ # These settings can be used to display a colorbar
63
  # cax = plt.axes([0.85, 0.1, 0.075, 0.8])
64
  # plt.colorbar(cax=cax, shrink=0.1)
65
  st.pyplot(plt.figure(2))
 
67
  ########################################################################################################################
68
  # Output Entire Dataset
69
  st.write("Click 'Generate Dataset' to generate the dataset based on the conditions set previously:")
70
+ if st.button('Generate Dataset'): # Generate the dataset
71
+ boxes = make_boxes(image_size, densities) # Create all of the data points
72
+ # Unpack all of the data
73
  box_arrays, box_density, basic_box_thickness, forward_slash_box_thickness, back_slash_box_thickness,hot_dog_box_thickness, hamburger_box_thickness\
74
  = list(zip(*boxes))[0], list(zip(*boxes))[1], list(zip(*boxes))[2], list(zip(*boxes))[3], list(zip(*boxes))[4], list(zip(*boxes))[5], list(zip(*boxes))[6]
75
 
76
+ class NumpyArrayEncoder(JSONEncoder):
77
+ def default(self, obj):
78
+ if isinstance(obj, np.ndarray):
79
+ return obj.tolist()
80
+ return JSONEncoder.default(self, obj)
81
+
82
+ # Save the arrays in a JSON format so they can be read
83
+ box_arrays = [json.dumps(x, cls=NumpyArrayEncoder) for x in box_arrays] # find argument for json dumps for numpy
84
+
85
  # Create a dataframe to convert the data to a csv file
86
+ dataframe = (pd.DataFrame((box_arrays, box_density, basic_box_thickness, forward_slash_box_thickness,
87
+ back_slash_box_thickness, hot_dog_box_thickness, hamburger_box_thickness)).T).astype(str)
88
 
89
  # Rename the columns to the desired outputs
90
+ dataframe = dataframe.rename(
91
+ columns={0: "Array", 1: "Density", 2: "Basic Box Thickness", 3: "Forward Slash Strut Thickness",
92
+ 4: "Back Slash Strut Thickness", 5: "Vertical Strut Thickness", 6: "Horizontal Strut Thickness"})
93
 
94
+ # Convert the dataframe to CSV
95
  csv = dataframe.to_csv()
96
+
97
+ st.write("Here is what a portion of the generated data looks like (double click on the 'Array' cells to view the full array):")
98
+ st.write(dataframe.iloc[:100,:]) # Display the data generated
99
  st.write("Click 'Download' to download a CSV file of the dataset:")
100
+ st.download_button("Download Dataset", csv, file_name='2D_Lattice.csv') # Provide download for user