fetoflow 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
fetoflow-0.1.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,31 @@
1
+ Metadata-Version: 2.4
2
+ Name: fetoflow
3
+ Version: 0.1.0
4
+ Summary: A Python library for fetoplacental vasculature modelling.
5
+ Author: Jordan Blennerhassett, Jude Beullens
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/VirtualPregnancy/fetoflow
8
+ Project-URL: Source, https://github.com/VirtualPregnancy/fetoflow
9
+ Keywords: blood flow,placenta,network,hemodynamics,feto-placental
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3 :: Only
15
+ Classifier: Topic :: Scientific/Engineering
16
+ Requires-Python: >=3.8
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: numpy>=1.20
20
+ Requires-Dist: scipy>=1.7
21
+ Requires-Dist: pandas>=1.3
22
+ Requires-Dist: networkx>=2.6
23
+ Provides-Extra: dev
24
+ Requires-Dist: pytest>=6.0; extra == "dev"
25
+ Dynamic: license-file
26
+
27
+ # FetoFlow
28
+
29
+ This is a Python Library developed by Jordan Blennerhassett and Jude Beullens under the guidance of Alys Clark and Sahan Jayatissa for use in computational modelling of fetoplacental vascular networks.
30
+
31
+ **Documentation:** https://virtualpregnancy.github.io/fetoflow/
@@ -0,0 +1,5 @@
1
+ # FetoFlow
2
+
3
+ This is a Python Library developed by Jordan Blennerhassett and Jude Beullens under the guidance of Alys Clark and Sahan Jayatissa for use in computational modelling of fetoplacental vascular networks.
4
+
5
+ **Documentation:** https://virtualpregnancy.github.io/fetoflow/
@@ -0,0 +1,43 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+
4
+ [project]
5
+ name = "fetoflow"
6
+ version = "0.1.0"
7
+ description = "A Python library for fetoplacental vasculature modelling."
8
+ readme = "README.md"
9
+ requires-python = ">=3.8"
10
+ license = { text = "Apache-2.0" }
11
+ authors = [
12
+ { name = "Jordan Blennerhassett" },
13
+ { name = "Jude Beullens" }
14
+ ]
15
+ keywords = ["blood flow", "placenta", "network", "hemodynamics", "feto-placental"]
16
+ classifiers = [
17
+ "Development Status :: 4 - Beta",
18
+ "Intended Audience :: Science/Research",
19
+ "License :: OSI Approved :: Apache Software License",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3 :: Only",
22
+ "Topic :: Scientific/Engineering",
23
+ ]
24
+
25
+ dependencies = [
26
+ "numpy>=1.20",
27
+ "scipy>=1.7",
28
+ "pandas>=1.3",
29
+ "networkx>=2.6",
30
+ ]
31
+
32
+ [project.urls]
33
+ Homepage = "https://github.com/VirtualPregnancy/fetoflow"
34
+ Source = "https://github.com/VirtualPregnancy/fetoflow"
35
+
36
+ [project.optional-dependencies]
37
+ dev = ["pytest>=6.0"]
38
+
39
+ [tool.setuptools]
40
+ package-dir = {"" = "src"}
41
+
42
+ [tool.setuptools.packages.find]
43
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,33 @@
1
+ from .geometry_utils import (
2
+ create_geometry,
3
+ calcLength,
4
+ create_anastomosis,
5
+ create_venous_mesh,
6
+ calculate_branching_angles
7
+ )
8
+ from .bc_utils import generate_boundary_conditions
9
+ from .matrix_builder import create_matrices, create_small_matrices
10
+ from .resistance_utils import (
11
+ calculate_capillary_equivalent_resistance,
12
+ calculate_resistance,
13
+ calculate_convolute_resistance,
14
+ calculate_viscosity_factor_from_radius
15
+ )
16
+ from .file_parsing_utils import read_nodes, read_elements, define_fields_from_files
17
+ from .helper_functions import (
18
+ getRadii,
19
+ getEdgeData,
20
+ getNode,
21
+ getNumVessels,
22
+ getRadius,
23
+ getVesselLength,
24
+ )
25
+ from .pressure_flow_utils import (
26
+ pressures_and_flows,
27
+ )
28
+ from.solve_utils import(
29
+ solve_small_system,
30
+ solve_system,
31
+ update_small_matrix,
32
+ iterative_solve_small
33
+ )
@@ -0,0 +1,107 @@
1
+ from warnings import warn
2
+ def generate_boundary_conditions(inlet_pressure=None, inlet_flow=None, outlet_pressure=None):
3
+ # TODO: IF ONLY INLET FLOW, SET OUTLET PRESSURE TO 0 AND WE LOOK AT THE PRESSURE DROP. THEN NOTE THIS SOMEWHERE.
4
+ if inlet_pressure and inlet_flow:
5
+ raise TypeError(f"Cannot have both an inlet pressure and inlet flow defined. Inlet pressure: {inlet_pressure}Inlet Flow: {inlet_flow}")
6
+ elif inlet_pressure is None and inlet_flow is None:
7
+ raise TypeError("No inlet boundary condition defined. Must define one of inlet_pressure or inlet flow for a valid boundary condition.")
8
+ bcs = {}
9
+
10
+ if outlet_pressure is None and inlet_flow is None:
11
+ raise TypeError(
12
+ "No valid outlet pressure for boundary condition. "
13
+ "Currently Reprosim does not support outlet flow boundary conditions and must have a defined outlet pressure."
14
+ )
15
+ elif outlet_pressure is None and inlet_flow is not None:
16
+ warn("No outlet pressure defined with flow inlet. Setting outlet pressure to 0.")
17
+
18
+
19
+ # Outlet Pressure
20
+ if outlet_pressure:
21
+ if not (isinstance(outlet_pressure, int) or isinstance(outlet_pressure, float)):
22
+ raise TypeError(f"Outlet pressure type '{type(outlet_pressure)}' is not valid. Valid types include float or int.")
23
+ elif not outlet_pressure >= 0:
24
+ raise ValueError(f"Outlet pressure value of '{outlet_pressure}' is not valid. Must be greater than or equal to 0.")
25
+
26
+ bcs["outlet"] = {"pressure": outlet_pressure}
27
+
28
+ # TODO Add outlet flows potentially?
29
+
30
+ # Inlet Pressure
31
+ if inlet_pressure:
32
+ if not (isinstance(inlet_pressure, int) or isinstance(inlet_pressure, float) or isinstance(inlet_pressure, dict)):
33
+ raise TypeError(
34
+ f"Inlet pressure type '{type(inlet_pressure)}' is not valid. Valid types include float or int for single inputs and dict for multiple inputs."
35
+ )
36
+ elif isinstance(inlet_pressure, int) or isinstance(inlet_pressure, float):
37
+ if not inlet_pressure > 0:
38
+ raise ValueError(f"Invalid inlet pressure of '{inlet_pressure}' Pa. Must be greater than 0.")
39
+ bcs["inlet"] = {"pressure": inlet_pressure}
40
+ elif isinstance(inlet_pressure, dict):
41
+ inlet_pressures = {}
42
+ for key, value in inlet_pressure.items():
43
+ if not isinstance(key, int) or not key > 0:
44
+ raise ValueError(f"Invalid Node Id {key} for multiple inlet pressures. Must be a positive integer.")
45
+ if not (isinstance(value, float) or isinstance(value, int)) or not value > 0:
46
+ raise ValueError(f"Invalid inlet pressure for node {key} of '{inlet_pressure}' Pa. Must be greater than 0.")
47
+ # Fix indexing here (1-based for IPNODE and IPELEM to 0 based for NetworkX)
48
+ # TODO: Update this if we change input file types.
49
+ inlet_pressures[key - 1] = value
50
+ bcs["inlet"] = {"pressure": inlet_pressures}
51
+
52
+ # Inlet flow
53
+ if inlet_flow:
54
+ if not (isinstance(inlet_flow, int) or isinstance(inlet_flow, float) or isinstance(inlet_flow, dict)):
55
+ raise TypeError(
56
+ f"Inlet flow type '{type(inlet_flow)}' is not valid. Valid types include float or int for single inputs and dict for multiple inputs."
57
+ )
58
+ elif isinstance(inlet_flow, int) or isinstance(inlet_flow, float):
59
+ if not inlet_flow > 0:
60
+ raise ValueError(f"Invalid inlet flow of '{inlet_flow}' Pa. Must be greater than 0.")
61
+ bcs["inlet"] = {"flow": inlet_flow}
62
+ elif isinstance(inlet_flow, dict):
63
+ inlet_flows = {}
64
+ for key, value in inlet_flow.items():
65
+ if not isinstance(key, int) or not key > 0:
66
+ raise ValueError(f"Invalid Element Id {key} for multiple inlet flows. Must be a positive integer.")
67
+ if not (isinstance(value, float) or isinstance(value, int)) or not value > 0:
68
+ raise ValueError(f"Invalid inlet flow for element {key} of '{inlet_flow}'. Must be greater than 0.")
69
+ # Fix indexing here (1-based for IPNODE and IPELEM to 0 based for NetworkX)
70
+ # TODO: Update this if we change input file types.
71
+ inlet_flows[key - 1] = value
72
+ bcs["inlet"] = {"flow": inlet_flows}
73
+
74
+ return bcs
75
+
76
+
77
+ """
78
+ # TODO: Some form that allows:
79
+ - inlet type
80
+ - inlet BC's
81
+
82
+ - multiple inlet BC's either flow or pressure (for now say that can only do same type cause otherwise this is hell)
83
+ - if multiple inlet BC's:
84
+ - must provide the inlet ID's they are referring to. MATCH THESE ID's with Placentagen.
85
+ NOTE: THIS MEANS WE HAVE TO UPDATE INDEXING SLIGHTLY TO MATCH, AS IPELEM FILES HAVE 1-BASED INDEXING AND NETWORKX HAS 0 BASED INDEXING
86
+
87
+
88
+
89
+ - outlet pressure.
90
+ - defaults to setting this outlet pressure at all outlet nodes (this makes the most sense to me, can be changed later)
91
+
92
+
93
+
94
+ function inputs:
95
+
96
+ inlet_pressure - value or dict[node_id, pressure]
97
+ inlet_flow - value or dict [edge_id, flow]
98
+ outlet_pressure - value
99
+
100
+
101
+
102
+ function output:
103
+
104
+ bcs: dict[inlet/outlet, dict[pressure/flow, value or dict[node/element_id, pressure/flow]]]
105
+ (if pressure must be node in inner dict, if flow must be element.)
106
+
107
+ """
@@ -0,0 +1,77 @@
1
+ def read_nodes(filename):
2
+ if not isinstance(filename,str):
3
+ raise(TypeError("File name should be a string!"))
4
+ if not filename[-7:] == ".ipnode":
5
+ raise(TypeError("This function expects a .ipnode file."))
6
+ with open(filename, "r") as f:
7
+ lines = f.readlines()
8
+ nodes = {}
9
+ numVars = int(lines[4].split()[-1])
10
+ baseStep = numVars + 2
11
+ i = 4 + 2 * numVars + 2
12
+ while i < len(lines):
13
+ node_id = int(lines[i].split()[-1])
14
+ nversions = int(lines[i + 1].split()[-1])
15
+ i_step = baseStep + nversions * numVars + (nversions * numVars if nversions > 1 else 0)
16
+ c_step = numVars * nversions - 1
17
+ coords = []
18
+ for c in range(1 + nversions, i_step, c_step):
19
+ coord = lines[i + c].split()[-1]
20
+ coords.append(float(coord))
21
+ nodes[node_id - 1] = coords # 0-based indexing for the networkX geometry.
22
+ i += i_step
23
+ return nodes
24
+
25
+
26
+ def read_elements(filename):
27
+ if not isinstance(filename,str):
28
+ raise(TypeError("File name should be a string!"))
29
+ if not filename[-7:] == ".ipelem":
30
+ raise(TypeError("This function expects a .ipelem file."))
31
+
32
+ with open(filename, "r") as f:
33
+ lines = f.readlines()
34
+ elems = []
35
+ i = 5
36
+ while i < len(lines):
37
+ intraElementStep = 5
38
+ nodes = tuple(int(x) - 1 for x in lines[i + intraElementStep].split()[-2:]) # Translate to 0-based indexing.
39
+ elems.append(nodes)
40
+ while len(lines[i].split()) != 0:
41
+ i += 1
42
+ if i + 1 == len(lines):
43
+ return elems
44
+ i += 1
45
+ return elems
46
+
47
+
48
+ def define_fields_from_files(files: dict[str]):
49
+ """
50
+ Defines field(s) as specified in ipfield file(s).
51
+ """
52
+ if not isinstance(files, dict):
53
+ raise (TypeError("files must be a dictionary in the format files[field_name] = filename"))
54
+ fields = {}
55
+ for field in files.keys():
56
+ file_name = files[field]
57
+ if not file_name[-7:] == ".ipfiel":
58
+ ext_start = -(str.__reversed__(file_name).find(".") + 1)
59
+ if ext_start is not None:
60
+ raise(TypeError(f"This function expects a .ipfiel file, got {file_name[ext_start:]}"))
61
+ else:
62
+ raise(TypeError(f"This function expects a .ipfiel file. No file extension found."))
63
+ with open(file_name, "r") as f:
64
+ i = 7 # ignore metadata
65
+ lines = f.readlines()
66
+ max_digits = len(lines[3][lines[3].find(":") + 1 :].strip())
67
+ currentField = {}
68
+ while i < len(lines):
69
+ j = i + 2
70
+ id = (
71
+ int(lines[i][-max_digits-1:].strip()) - 1
72
+ ) # assuming for now these correspond to element ids, -1 to 0 based
73
+ val = float(lines[j][lines[j].find(":")+1:].strip())
74
+ currentField[id] = val
75
+ i += 4
76
+ fields[field] = currentField
77
+ return fields