56
56
{
57
57
'property' : 'eneg' ,
58
58
'group' : None ,
59
- 'table_name' : 'eneg ' ,
59
+ 'table_name' : 'Energy ' ,
60
60
'description' : 'Electronegativity'
61
61
}
62
62
]
@@ -87,8 +87,8 @@ class ElementsDataInfo(pt.IsDescription):
87
87
source_key = pt .StringCol (30 , pos = 2 )
88
88
property_description = pt .StringCol (250 , pos = 3 )
89
89
reference = pt .StringCol (250 , pos = 4 )
90
- doi = pt .StringCol (150 , pos = 4 )
91
- notes = pt .StringCol (600 , pos = 5 )
90
+ doi = pt .StringCol (150 , pos = 5 )
91
+ notes = pt .StringCol (500 , pos = 6 )
92
92
93
93
94
94
def create_data_for_tables (hdf5_file , parent_folder , table_name , table_description , row_description , columns , row_data , sources_data , units_data ):
@@ -155,7 +155,7 @@ def read_elements_data_csv(elements_data_csv):
155
155
headers = [header .strip () for header in lines [0 ]] # first row as column headers
156
156
sources = [source .strip () for source in lines [1 ]] # second row as sources
157
157
units = [unit .strip () for unit in lines [2 ]] # third row as units
158
- data_rows = lines [3 :] # remaining rows as data
158
+ data_rows = lines [3 :] # remaining rows as data
159
159
160
160
# Process headers to make them unique
161
161
unique_headers = []
@@ -182,35 +182,43 @@ def read_elements_data_csv(elements_data_csv):
182
182
183
183
def read_data_info_csv (data_info_csv ):
184
184
"""
185
- Read and parse the data_info.csv file containing metadata.
185
+ Read and parse the data_info.csv file containing metadata.
186
186
187
- Args:
188
- data_info_csv: Path to the data_info.csv file.
189
-
190
- Returns:
191
- data_info: List of dictionaries containing metadata for each property.
192
- """
187
+ Args:
188
+ data_info_csv: Path to the data_info.csv file.
193
189
194
- # # Opens the csv file, filters out comment lines (starting with #) and empty lines.
190
+ Returns:
191
+ data_info: List of dictionaries containing metadata for each property.
192
+ """
193
+ # Opens the csv file, filters out comment lines (starting with #) and empty lines.
195
194
with open (data_info_csv , 'r' ) as f :
196
- reader = csv .reader (f )
197
195
lines = []
198
- for line in reader :
199
- if line and not line [0 ].startswith ('#' ):
200
- lines .append ([item .strip () for item in line ])
201
-
202
- # Get headers (first row)
203
- headers = [header .lstrip ('#' ).strip () for header in lines [0 ]]
204
- data_rows = lines [1 :]
205
-
206
- data_info = []
207
- for row in data_rows :
208
- data_info .append (dict (zip (headers , row )))
196
+ for line in f :
197
+ stripped = line .strip ()
198
+ if stripped and not stripped .startswith ('#' ):
199
+ lines .append (stripped )
200
+
201
+ # hardcode the headers
202
+ data_info_headers = [
203
+ 'Property key' ,
204
+ 'Property name' ,
205
+ 'Source key' ,
206
+ 'Property description' ,
207
+ 'Reference' ,
208
+ 'doi' ,
209
+ 'Notes'
210
+ ]
211
+
212
+ reader = csv .reader (lines )
213
+ data_rows = list (reader )
214
+
215
+ data_info = []
216
+ for row in data_rows :
217
+ data_info .append (dict (zip (data_info_headers , row )))
209
218
210
219
return data_info
211
220
212
221
213
-
214
222
def write_elements_data_to_hdf5 (data , unique_headers , sources_data , units_data ):
215
223
"""
216
224
Write element data to an HDF5 file.
@@ -304,12 +312,10 @@ def write_data_info_to_hdf5(data_info_list):
304
312
table_row ['doi' ] = row .get ('doi' , '' ).encode ('utf-8' )
305
313
table_row ['notes' ] = row .get ('Notes' , '' ).encode ('utf-8' )
306
314
table_row .append ()
307
-
308
315
property_info_table .flush ()
309
316
310
317
311
318
312
-
313
319
if __name__ == "__main__" :
314
320
# Read the elements data from the CSV file
315
321
data , unique_headers , sources_data , units_data = read_elements_data_csv (elements_data_csv )
0 commit comments