Skip to content

Instantly share code, notes, and snippets.

@Tehsurfer
Created January 17, 2019 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tehsurfer/ccc7f9dac52d9db76192201d54611534 to your computer and use it in GitHub Desktop.
Save Tehsurfer/ccc7f9dac52d9db76192201d54611534 to your computer and use it in GitHub Desktop.
Strains calculation (xyz comparing by index)
def getPortData(self, index):
"""
Add your code here that will return the appropriate objects for this step.
The index is the index of the port in the port list. If there is only one
provides port for this step then the index can be ignored.
:param index: Index of the port to return.
"""
# Data can be pasted here to send to other steps for testing, or grabbed from a file if we have larger data
ecgGrid = [[0.509204852009174, -0.5311370349544523, -0.0034167299250837833], ... ]
'''
Want to export in the form of 'time based node descriptions' in ecg step.
1. node_time_sequence = self._time_based_node_description['time_array']
so: export['time_array'] = [time1, time2,time3...]
2. node_locations = self._time_based_node_description['{0}'.format(node_identifier)]
so: export[{node_identifier}] = node_locations ([0,.5,.6],[0,.5,.7]...)
'''
ecg_dict = {}
ecg_dict['time_array'] = np.linspace(0,2).tolist()
for i, coords in enumerate(ecgGrid):
ecg_dict[str(i)] = []
for j, time in enumerate(ecg_dict['time_array']):
ecg_dict[str(i)].append([coords[0], coords[1] - (time/2 * i/len(ecgGrid)), coords[2]])
self._portData0 = ecg_dict
points = [ecg_dict['0'][0], ecg_dict['1'][0]]
points_dash = [ecg_dict['0'][1], ecg_dict['1'][1]]
strain = self.calculate_strain(points, points_dash)
strains = self.create_strain_arrays(self.convert_dict_to_array(ecg_dict))
return self._portData0 # ecg_grid_points
def convert_dict_to_array(self, dictionary):
array = []
for key in dictionary:
if key is not 'time_array':
array.append(dictionary[key])
return array
def create_strain_arrays(self, ecg_dict):
strains = []
for i, points_over_time in enumerate(ecg_dict[:-1]):
strains.append([])
for j, point in enumerate(points_over_time[:-1]):
points = [ecg_dict[i][j], ecg_dict[i+1][j]]
points_dash = [ecg_dict[i][j+1], ecg_dict[i+1][j+1]]
strains[i].append(self.calculate_strain(points, points_dash))
return strains
def calculate_strain(self, points, points_dash):
stress = [0, 0, 0]
for dimension, value in enumerate(points):
length1 = points_dash[1][dimension] - points_dash[0][dimension]
length0 = points[1][dimension] - points[0][dimension]
stress[dimension] = (length1 - length0) / length0
return stress
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment