9def load_file_sequence(file_prefix,dimensions):
12 Load all files that start with file_prefix and merge them into one
17 filtered_files = glob.glob( file_prefix +
"*.csv" )
18 for filtered_file
in filtered_files:
20 new_dataset.parse(filtered_file,dimensions)
21 if new_dataset.valid
and result==
None:
23 elif new_dataset.valid:
24 result.append( new_dataset )
26 print(
"ERROR: file " + filtered_file +
" was not a valid Peano 4 particle database file" )
30def assert_ascending(data):
31 for i
in range(0,len(data)-1):
33 raise Exception(
"not in ascending order at position {}: {} vs {}".format(i,data[i],data[i+1]) )
39 Dataset object corresponding to one VTU snapshot
48 __Tree_Number_Identifier =
"tree_number"
49 __Tree_Local_Particle_Number_Identifier =
"particle_number"
55 colnames += [
"x",
"y" ]
57 colnames += [
"x",
"y",
"z" ]
63 read_header = open(filename,
"r" )
64 current_line = read_header.readline()
65 while "#" in current_line:
66 current_line = read_header.readline()
68 current_line = read_header.readline()
72 def parse(self,filename,dimensions):
74 print(
"-------------------------------------------------------")
75 print(
"parse file " + filename )
76 print(
"-------------------------------------------------------")
88 raise Exception(
"dimensions of datasets do not match")
90 raise Exception(
"number of data columns per particle do not match")
92 self.
data_ = pandas.concat([self.
data_, other_dataset.data_])
98 Particles are identified by integer tuples and not by a single
99 number. This operation returns a set of thes tuples.
105 def get_data(self,particle,column_number,clean_up=1e-3):
109 Tuple identifying a particular particle
112 Integer with the data column requested
114 Returns two lists: A lits of time stamps and a list of data entries
117 data_frame = pandas.DataFrame(self.
data_)
122 filtered_data = filtered_data.sort_values( by=
"t" )
124 result = list(filtered_data.t), list(filtered_data[
"Q{}".format(column_number)])
125 assert_ascending(result[0])
126 if clean_up!=0.0
and len(result[0])>2
and result[0][1]-result[0][0]<=clean_up:
127 result = result[0][1:],result[1][1:]
134 Pass in a particle identified by a two-tuple and return d+1 arrays.
135 The first result array is the timestamps, then we have d arrays with
136 the particle locations.
139 data_frame = pandas.DataFrame(self.
data_)
144 filtered_data = filtered_data.sort_values( by=
"t" )
147 return list(filtered_data.t), list(filtered_data[
"x"]), list(filtered_data[
"y"])
149 return list(filtered_data.t), list(filtered_data[
"x"]), list(filtered_data[
"y"]), list(filtered_data[
"z"])
Dataset object corresponding to one VTU snapshot.
str __Tree_Local_Particle_Number_Identifier
extract_particle_keys(self)
Particles are identified by integer tuples and not by a single number.
parse(self, filename, dimensions)
get_position(self, particle)
Pass in a particle identified by a two-tuple and return d+1 arrays.
str __Tree_Number_Identifier
get_data(self, particle, column_number, clean_up=1e-3)
particle: (Int,Int) Tuple identifying a particular particle
append(self, other_dataset)
_parse_number_of_entries(self, filename)