Commit f77c4073 authored by Valentin Buck's avatar Valentin Buck

Added displacement to ADCP Reader

parent b620010c
Pipeline #8313 passed with stage
in 49 minutes and 57 seconds
...@@ -43,12 +43,14 @@ class PythonWinADCPReader(VTKPythonAlgorithmBase): ...@@ -43,12 +43,14 @@ class PythonWinADCPReader(VTKPythonAlgorithmBase):
self._utm_zone_letter = None self._utm_zone_letter = None
self._pos_depth = 0 self._pos_depth = 0
self._looks_down = True self._looks_down = True
self._displace_points = True
self._displacement_vectors = []
def _get_raw_data(self, requested_time): def _get_raw_data(self, requested_time):
if self._data is not None: if self._data is not None:
if requested_time is not None: if requested_time is not None:
print("Requested time " + str(requested_time)) print("Requested time " + str(requested_time))
return next(x for x in self._data['frames'] if x['timestamp'] / 1000 == requested_time) return next(x for x in self._data['frames'] if x['timestamp'] == requested_time)
else: else:
print("Requested item at cursor, currently at " + str(self._cursor)) print("Requested item at cursor, currently at " + str(self._cursor))
data = self._data['frames'][self._cursor] data = self._data['frames'][self._cursor]
...@@ -58,9 +60,12 @@ class PythonWinADCPReader(VTKPythonAlgorithmBase): ...@@ -58,9 +60,12 @@ class PythonWinADCPReader(VTKPythonAlgorithmBase):
raise RuntimeError("No filename specified") raise RuntimeError("No filename specified")
else: else:
self._data = pylibwinadcp.load(self._filename) self._data = pylibwinadcp.load(self._filename)
self._timesteps = [x['timestamp'] / 1000 for x in self._data['frames']] self._timesteps = [x['timestamp'] for x in self._data['frames']]
bin_zero = self._data['frames'][0]['bins'][0] bin_zero = self._data['frames'][0]['bins'][0]
self._bins = len(self._data['frames'][0]['bins']) self._bins = len(self._data['frames'][0]['bins'])
self._displacement_vectors = []
for i in range(self._bins):
self._displacement_vectors.append((0,0))
#for entry in bin_zero: #for entry in bin_zero:
# print("NAME: " + entry['name']) # print("NAME: " + entry['name'])
...@@ -97,6 +102,12 @@ class PythonWinADCPReader(VTKPythonAlgorithmBase): ...@@ -97,6 +102,12 @@ class PythonWinADCPReader(VTKPythonAlgorithmBase):
self._looks_down = direction == 1 self._looks_down = direction == 1
self.Modified() self.Modified()
@smproperty.intvector(name="Displace Points", default_values=1)
@smdomain.xml('<BooleanDomain name="bool"/>')
def SetPositionDirection(self, direction):
self._looks_down = direction == 1
self.Modified()
def _get_timesteps(self): def _get_timesteps(self):
self._get_raw_data(None) self._get_raw_data(None)
return self._timesteps if self._timesteps is not None else None return self._timesteps if self._timesteps is not None else None
...@@ -161,6 +172,8 @@ class PythonWinADCPReader(VTKPythonAlgorithmBase): ...@@ -161,6 +172,8 @@ class PythonWinADCPReader(VTKPythonAlgorithmBase):
y = np.repeat(y_pos,self._bins) y = np.repeat(y_pos,self._bins)
z = np.zeros(self._bins) z = np.zeros(self._bins)
for i in range(self._bins): for i in range(self._bins):
x[i] += self._displacement_vectors[i][0]
y[i] += self._displacement_vectors[i][1]
z[i] = self._pos_depth + ((z_zero + (i * z_offset)) * (-1.0 if self._looks_down else 1.0)) z[i] = self._pos_depth + ((z_zero + (i * z_offset)) * (-1.0 if self._looks_down else 1.0))
coordinates = algs.make_vector(x,y,z) coordinates = algs.make_vector(x,y,z)
...@@ -186,9 +199,28 @@ class PythonWinADCPReader(VTKPythonAlgorithmBase): ...@@ -186,9 +199,28 @@ class PythonWinADCPReader(VTKPythonAlgorithmBase):
else: else:
print("Unexpected bin name: " + str(name)) print("Unexpected bin name: " + str(name))
displacement = np.zeros((self._bins,3))
tdiff = 0
if data_time in self._timesteps:
time_index = self._timesteps.index(data_time)
if time_index > 0:
tdiff = (data_time - self._timesteps[time_index - 1]) #Timesteps are in seconds
for i in range(self._bins):
prev = self._displacement_vectors[i]
offset = (directions[i][0] * ((magnitudes[i] / 1000) * tdiff), directions[i][1] * ((magnitudes[i] / 1000) * tdiff)) # Magnitude needs to divided by 1000 because it's in mm/s not m/s
displacement[i] = [offset[0], offset[1],0]
self._displacement_vectors[i] = (prev[0] + offset[0], prev[1] + offset[1])
print(repr(self._displacement_vectors))
output.SetPoints(points) output.SetPoints(points)
output.PointData.append(magnitudes, "Magnitude") output.PointData.append(magnitudes, "Magnitude (mm/s)")
output.PointData.append(directions, "Direction") output.PointData.append(directions, "Direction (°)")
output.PointData.append(displacement, "Displacement (m)")
pointIds = vtkIdList() pointIds = vtkIdList()
pointIds.SetNumberOfIds(self._bins) pointIds.SetNumberOfIds(self._bins)
......
...@@ -81,7 +81,7 @@ pub fn read_file(filename: &str)-> Result<WinADCPFile,Box<dyn Error>>{ ...@@ -81,7 +81,7 @@ pub fn read_file(filename: &str)-> Result<WinADCPFile,Box<dyn Error>>{
let timestr = format!("{} {}", raw_date, raw_time); let timestr = format!("{} {}", raw_date, raw_time);
let date = NaiveDateTime::parse_from_str(&timestr, "%y/%m/%d %T%.f"); let date = NaiveDateTime::parse_from_str(&timestr, "%y/%m/%d %T%.f");
header.first_ensemble_datetime = date.unwrap()/*_or_else(|_| NaiveDateTime::from_timestamp(0, 0))*/.timestamp_millis(); header.first_ensemble_datetime = date.unwrap()/*_or_else(|_| NaiveDateTime::from_timestamp(0, 0))*/.timestamp();
input.read_line(&mut temp)?; input.read_line(&mut temp)?;
let splitpos = temp.find("= \"").unwrap_or(0); let splitpos = temp.find("= \"").unwrap_or(0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment