├── .gitignore
├── LICENSE
├── PointCloudObjectRetrieval.py
├── PointCloudSeismicInterpretation.py
├── README.md
├── assets
└── images
│ ├── geobody-detection.PNG
│ └── seismic-segmentation.gif
├── d2geo
├── LICENSE
├── README
└── attributes
│ ├── CompleTrace.py
│ ├── DipAzm.py
│ ├── EdgeDetection.py
│ ├── Frequency.py
│ ├── NoiseReduction.py
│ ├── SignalProcess.py
│ ├── __init__.py.txt
│ ├── io.py
│ └── util.py
├── environment.yml
├── notebooks
└── F3dataset-segmentation.ipynb
├── requirements.txt
└── utils.py
/.gitignore:
--------------------------------------------------------------------------------
1 | data/*
2 | outputs/*
3 | documents/*
4 |
5 | # Byte-compiled / optimized / DLL files
6 | __pycache__/
7 | *.py[cod]
8 | *$py.class
9 |
10 | # C extensions
11 | *.so
12 |
13 | # Distribution / packaging
14 | .Python
15 | build/
16 | develop-eggs/
17 | dist/
18 | downloads/
19 | eggs/
20 | .eggs/
21 | lib/
22 | lib64/
23 | parts/
24 | sdist/
25 | var/
26 | wheels/
27 | pip-wheel-metadata/
28 | share/python-wheels/
29 | *.egg-info/
30 | .installed.cfg
31 | *.egg
32 | MANIFEST
33 |
34 | # PyInstaller
35 | # Usually these files are written by a python script from a template
36 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
37 | *.manifest
38 | *.spec
39 |
40 | # Installer logs
41 | pip-log.txt
42 | pip-delete-this-directory.txt
43 |
44 | # Unit test / coverage reports
45 | htmlcov/
46 | .tox/
47 | .nox/
48 | .coverage
49 | .coverage.*
50 | .cache
51 | nosetests.xml
52 | coverage.xml
53 | *.cover
54 | *.py,cover
55 | .hypothesis/
56 | .pytest_cache/
57 |
58 | # Translations
59 | *.mo
60 | *.pot
61 |
62 | # Django stuff:
63 | *.log
64 | local_settings.py
65 | db.sqlite3
66 | db.sqlite3-journal
67 |
68 | # Flask stuff:
69 | instance/
70 | .webassets-cache
71 |
72 | # Scrapy stuff:
73 | .scrapy
74 |
75 | # Sphinx documentation
76 | docs/_build/
77 |
78 | # PyBuilder
79 | target/
80 |
81 | # Jupyter Notebook
82 | .ipynb_checkpoints
83 |
84 | # IPython
85 | profile_default/
86 | ipython_config.py
87 |
88 | # pyenv
89 | .python-version
90 |
91 | # pipenv
92 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
94 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
95 | # install all needed dependencies.
96 | #Pipfile.lock
97 |
98 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
99 | __pypackages__/
100 |
101 | # Celery stuff
102 | celerybeat-schedule
103 | celerybeat.pid
104 |
105 | # SageMath parsed files
106 | *.sage.py
107 |
108 | # Environments
109 | .env
110 | .venv
111 | env/
112 | venv/
113 | ENV/
114 | env.bak/
115 | venv.bak/
116 |
117 | # Spyder project settings
118 | .spyderproject
119 | .spyproject
120 |
121 | # Rope project settings
122 | .ropeproject
123 |
124 | # mkdocs documentation
125 | /site
126 |
127 | # mypy
128 | .mypy_cache/
129 | .dmypy.json
130 | dmypy.json
131 |
132 | # Pyre type checker
133 | .pyre/
134 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/PointCloudObjectRetrieval.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | maintainer:
5 | """
6 |
7 | import numpy as np
8 | from math import hypot, atan2
9 | import cv2
10 | from sklearn.neighbors import KDTree
11 | from datetime import datetime
12 | import pandas as pd
13 |
14 | class PointCloudObjectRetrieval():
15 | """
16 | Description
17 | -----------
18 | Characterise every object in a seismic point cloud
19 |
20 | Attributes:
21 | -----------
22 | point_cloud (np.array):
23 | semblance (np.array):
24 | labels_pointcloud (np.array or list):
25 |
26 | Methods:
27 | --------
28 | get_features: Extracts pandas dataFrame containing the features descriptives of every selected cluster
29 | """
30 | def __init__( self, point_cloud: np.array, semblance: np.array, labels_point_cloud: (np.array or list) ):
31 | """
32 | Description
33 | -----------
34 | Initiates the point cloud objects
35 |
36 | Args:
37 | -----
38 | point_cloud (np.array): point cloud coordinates (n, 4), first axis being the n points,
39 | second axis being the point coordinates and the amplitude reflectivity value (x, y, z, amp)
40 | semblance (np.array): semblance values of the point cloud
41 | labels_point_cloud (np.array or list): label values of the point cloud
42 | """
43 | self.point_cloud = point_cloud
44 | self.semblance = semblance
45 | self.labels_point_cloud = labels_point_cloud
46 |
47 | def get_features(self, selected_clusters: (np.array or list)):
48 | """
49 | Description
50 | -----------
51 | Extracts pandas dataFrame containing the features descriptives of every selected cluster
52 | Features: segmentID, n points, amplitude mean, semblance mean, Zeboudj distance,
53 | contour ratio, lambda1, lambda2, "lambda3", linearity,
54 | slope, planarity, orientation, rZHigh, rZLow
55 |
56 | Args:
57 | -----
58 | selected_clusters (np.array or list): list of cluster ids for which to perform the feature extraction
59 |
60 | Returns:
61 | --------
62 | pd.DataFrame: Each row represents a cluster of the segmented point cloud and each collumn
63 | represents the feature values
64 | """
65 | t0 = datetime.now()
66 | Features = []
67 | i=0
68 | for isegment in selected_clusters:
69 | i+=1
70 | print("({}/{})".format(i, len(selected_clusters)), end = "\r")
71 | Features.append([isegment] + extract_features(
72 | self.point_cloud[np.isin(self.labels_point_cloud, isegment)],
73 | self.semblance[np.isin(self.labels_point_cloud, isegment)]
74 | )
75 | )
76 | ## store it as a dataframe
77 | featureDF = pd.DataFrame(data=Features, columns=[
78 | "segmentID", "n points", "amplitude mean", "semblance mean", "Zeboudj distance",
79 | "contour ratio", "lambda1", "lambda2", "lambda3", "linearity",
80 | "slope", "planarity", "orientation", "rZHigh", "rZLow",
81 | ])
82 | featureDF.set_index('segmentID', inplace=True)
83 | featureDF=(featureDF-featureDF.mean())/featureDF.std()
84 | print('time: {}'.format(datetime.now()-t0))
85 | return featureDF
86 |
87 |
88 | #########
89 | ## functions
90 | #########
91 |
92 | def get_aspect_ratio(pcd: np.array):
93 | """
94 | Description
95 | -----------
96 | Gets the 3 eigen values, the linearity, the slope, the planarity and the orientation of of a point cloud object
97 |
98 | Args:
99 | pcd (np.array): a point cloud (n, 3)
100 |
101 | Returns:
102 | --------
103 | (list): [v1, v2, v3, linearity, slope, planarity, orientation] with vn being the n eigen value of the point cloud
104 | """
105 | pcd_sampling = np.random.choice(len(pcd),
106 | size=min(int(len(pcd)*0.5), 500), replace=False) #min([int(len(point_cloud)*0.2), 1000]), replace=False)
107 | eigvals, eigvecs = np.linalg.eig(np.cov(pcd[pcd_sampling].T))
108 | idx = eigvals.argsort()[::-1]
109 | eigvals = eigvals[idx]
110 | eigvecs = eigvecs[:,idx]
111 | orientation = atan2(eigvecs[0,1], eigvecs[0,0])
112 | return (
113 | [eigvals[0], eigvals[1], eigvals[2],
114 | (eigvals[0]-eigvals[1])/eigvals[0], eigvals[2]/eigvals[0], (eigvals[1]-eigvals[2])/eigvals[0], orientation]
115 | )
116 |
117 | def get_outline_ratio(pcd: np.array):
118 | """
119 | Description
120 | -----------
121 | Gets the outline ratio of a point cloud object
122 | The outline ratio is obtained by projection the 3D point cloud on a 2D plane,
123 | and computing its contour over its surface
124 |
125 | Retruns:
126 | --------
127 | float: the contour ratio
128 | """
129 | #convert 2d projection to image
130 | #shift X and Y coordinate to 0 origin
131 | X_shift = pcd[:,0]-min(pcd[:,0]); Y_shift = pcd[:,1]-min(pcd[:,1])
132 | X_shift = X_shift.astype(int, copy=False); Y_shift = Y_shift.astype(int, copy=False)
133 | Img = np.zeros((max(X_shift)+1, max(Y_shift)+1))
134 | Img[X_shift, Y_shift] = 255
135 | Img=Img.astype('uint8')
136 | Imgblur = cv2.blur(Img, (10, 10))
137 | _, Imgthresh = cv2.threshold(Imgblur, 50, 255, cv2.THRESH_BINARY)
138 | imct, _ = cv2.findContours(Imgthresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
139 | length = 0
140 | for contour in imct:
141 | length += sum(hypot(x1 - x2, y1 - y2) for (x1, y1), (x2, y2) in zip(contour[:,0, :], contour[1:,0, :]))
142 | surface = Imgthresh.sum()/255
143 | return (length/surface)
144 |
145 | def get_zeboudj_distance(pcd: np.array, distance: float = 2.5):
146 | """
147 | Description
148 | -----------
149 | Gets the Zeboudj distance of the spatial distribution of amplitude of a point cloud object
150 |
151 | Returns
152 | -------
153 | """
154 | #sample large point cloud to save processing time although keeping a good approximate
155 | pcd_sampling = np.random.choice(len(pcd), size=min(int(len(pcd)*0.5), 10000), replace=False)
156 | cl_sample = pcd[pcd_sampling]
157 | #build kdtree for each cluster
158 | tree = KDTree(cl_sample[:,:3])
159 | #loop over every point within the cluster to compute color distances with its neighbourhood
160 | L_neighbors_idxs = tree.query_radius(cl_sample[:,:3], r=distance)
161 | CI = 0
162 | for ipoint, neighbors_idxs in enumerate (L_neighbors_idxs):
163 | if len(neighbors_idxs) > 0:
164 | Dist_neighbs = np.zeros(len(neighbors_idxs))
165 | for ineighb, neighb in enumerate (neighbors_idxs):
166 | Dist_neighbs[ineighb] = cl_sample[:,3][ipoint] - cl_sample[:,3][neighb]
167 | CI += Dist_neighbs.max()
168 | CI = CI/len(cl_sample)
169 | return (CI)
170 |
171 | def get_depth_distribution(pcd: np.array):
172 | """
173 | Description
174 | -----------
175 | Gets the distribution of points of a point cloud object in the vertical axis
176 |
177 | Returns:
178 | --------
179 | (list): [p1, p2] p1 proportion under one forth of the depth, p2 proportion above three fourth of the depth
180 | """
181 | zmin = np.percentile(pcd[:,2], 2)
182 | zmax = np.percentile(pcd[:,2], 98)
183 | r_zlow = len(pcd[pcd[:,2]zmax-(zmax-zmin)/4])/len(pcd) #proportion_over_three_fourth
185 | return([r_zlow, r_zhigh])
186 |
187 | def extract_features(pcd: np.array, semblance: np.array):
188 | """
189 | Description
190 | -----------
191 | Extracts all features of a point cloud object
192 |
193 | Returns:
194 | --------
195 | (list): [n_points, amp_mean, semblance_mean, zeboudj_distance, outline_ratio, v1, v2, v3, linearity,
196 | slope, planarity, orientation, p1, p2]
197 | """
198 | n_points = len(pcd)
199 | amp_mean = pcd[:,3].mean()
200 | semb_mean = semblance.mean()
201 | zeboudj_2_5 = get_zeboudj_distance(pcd, distance=2.5)
202 | # zeboudj_3_5 = get_zeboudj_distance(pcd, distance=3.5)
203 | outline_ratio = get_outline_ratio(pcd[:,:2])
204 | aspect_ratios = get_aspect_ratio(pcd[:,:3])
205 | r_z = get_depth_distribution(pcd[:,:3])
206 | return ([n_points]+[amp_mean]+[semb_mean]+[zeboudj_2_5]+[outline_ratio]+aspect_ratios+r_z)
207 |
208 |
--------------------------------------------------------------------------------
/PointCloudSeismicInterpretation.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | maintainer:
5 | """
6 |
7 | import numpy as np
8 | import pandas as pd
9 | from scipy.signal import argrelextrema
10 | from datetime import datetime
11 | from sklearn.cluster import DBSCAN
12 | import dask.array as da
13 | import dask
14 |
15 | from d2geo.attributes.EdgeDetection import EdgeDetection
16 | from d2geo.attributes.util import compute_chunk_size
17 | from utils import *
18 |
19 |
20 | class PointCloudSeismicInterpretation():
21 | """
22 | Description
23 | -----------
24 | Create Point Cloud Seismic dataframe from a 3D seismic cube
25 | The point cloud is extracted by local extrema extraction in the trace direction,
26 | filter on semblance and filter on amplitude
27 |
28 | Attributes:
29 | -----------
30 | seismic_array (np.array): 3D seismic cube as a 3D numpy array with amplitude reflectivity values
31 | point_cloud (np.array): point cloud attribute as a 2D array with shape (n, 3) with n being the number
32 | of points and the second axis being the coordinates of the points (x, y, z)
33 | amplitude_point_cloud (np.array): amplitude reflectivity values of the points of the point cloud
34 | semblance_array (np.array): 3D semblance cube computed from the 3D seismic
35 | semblance_point_cloud (np.array): semblance values of the points of the point cloud
36 | ampv95p (float): approximate of the 95-th percentile of the seismic amplitude
37 |
38 | Methods:
39 | ---------
40 | load_seismic_array: Loads the 3D seismic cube
41 | extrema_extraction: Extracts the point cloud from the seismic with local extrema in the trace direction
42 | extrema_extraction_dask: Extracts the point cloud from the seismic with local extrema in the trace direction
43 | - multiprocessing with dask
44 | filter_point_cloud_with_semblance: Computes the semblance cube and filters the point cloud based on semblance cut-off
45 | filter_point_cloud_with_amplitude: Filters the point cloud based on amplitude cut-off
46 | DBSCAN_segmentation_sklearn: segments the point cloud based on DBSCAN clustering - sklearn implementation
47 |
48 | """
49 | def __init__( self, seismic_array, ampv95p=None ):
50 | self.load_seismic_array(seismic_array, ampv95p=ampv95p)
51 |
52 | def load_seismic_array(self, seismic_array, ampv95p=None):
53 | """
54 | Description
55 | -----------
56 | Loads the 3D seismic cube, computes 95th amplitude quartile and the intialise the point cloud objects
57 |
58 | Args:
59 | seismic_array (np.array): 3D seismic cube as a 3D numpy array with amplitude reflectivity values
60 | ampv95p (float or None): the 95-th percentile of the seismic amplitude
61 | - if not None prevents from having to compute it
62 | """
63 | self.seismic_array = seismic_array
64 | if not ampv95p:
65 | self.ampv95p = np.percentile(self.seismic_array[self.seismic_array.shape[0]//2:self.seismic_array.shape[0]//2+100,
66 | self.seismic_array.shape[1]//2:self.seismic_array.shape[1]//2+100,
67 | : ], 95) # compute the 99th percentile of amplitude to scale
68 | else:
69 | self.ampv95p = ampv95p
70 | self.point_cloud = np.array([])
71 | self.amplitude_point_cloud = np.array([])
72 | self.semblance_array = np.array([])
73 | self.semblance_point_cloud = np.array([])
74 |
75 | def extrema_extraction(self, extrema_type=np.greater):
76 | """
77 | Description
78 | -----------
79 | Extract extrema in the trace direction (3rd dimension) of a 3D array
80 | Creates a point cloud attribute (numpy.array) of shape [n_extrema, 3]
81 | Each row of the point cloud being [x,, y, z] of the each extrema
82 | Amplitude values are normalized and stored in a amplitude point cloud attribute
83 |
84 | Args:
85 | -----
86 | extrema_type (callable, default np.greater): np.greater or np.less, the type of extrema to extract (maxima or minima)
87 | """
88 | t0 = datetime.now()
89 | (nx, ny, nz) = self.seismic_array.shape
90 | Lx = []
91 | Ly = []
92 | Lz = []
93 | for i in range (nx):
94 | for j in range (ny):
95 | maxima = argrelextrema(self.seismic_array[i, j], extrema_type)[0]
96 | Lx.extend([i]*len(maxima))
97 | Ly.extend([j]*len(maxima))
98 | Lz.extend(maxima)
99 | self.point_cloud = np.zeros((len(Lx), 3), dtype='int32')
100 | self.point_cloud[:, 0] = Lx
101 | self.point_cloud[:, 1] = Ly
102 | self.point_cloud[:, 2] = Lz
103 | self.amplitude_point_cloud = NormalizeData(self.seismic_array[Lx, Ly, Lz], thr=self.ampv95p, type='positive')
104 | self.semblance_point_cloud = np.array([])
105 | print('Point cloud created - {} points - time to execute: {}'.format(self.point_cloud.shape[0], datetime.now()-t0))
106 |
107 | def extrema_extraction_dask(self, extrema_type=np.greater):
108 | """
109 | Description
110 | -----------
111 | Extract extrema in the trace direction (3rd dimension) of a 3D array
112 | Creates a point cloud attribute (numpy.array) of shape [n_extrema, 3]
113 | Each row of the point cloud being [x,, y, z] of the each extrema
114 | Amplitude values are normalized and stored in a amplitude point cloud attribute
115 | Dask multiprocessing implementation
116 |
117 | Args:
118 | -----
119 | extrema_type (callable, default np.greater): np.greater or np.less, the type of extrema to extract (maxima or minima)
120 | """
121 | t0 = datetime.now()
122 | (xChunkSize, yChunkSize, zChunkSize) = compute_chunk_size(self.seismic_array.shape,
123 | self.seismic_array.dtype.itemsize,
124 | kernel=(1, 1, self.seismic_array.shape[2]),
125 | preview=None)
126 | seis_ilBlock_dask_trace = da.from_array(self.seismic_array, chunks=(xChunkSize, yChunkSize, self.seismic_array.shape[2]))
127 | blocks = seis_ilBlock_dask_trace.to_delayed()#.ravel()
128 | results = []
129 | for ixb, xb in enumerate(blocks):
130 | results.extend([da.from_delayed(get_point_cloud_chunks(yb[0], ixb*xChunkSize, iyb*xChunkSize, extrema_type), shape=(3, np.nan), dtype=np.int64)
131 | for iyb, yb in enumerate(xb)])
132 | arr = da.concatenate(results, axis=1, allow_unknown_chunksizes=True)
133 | self.point_cloud = arr.compute()
134 | self.point_cloud = self.point_cloud.T
135 | print('point cloud shape {}'.format(self.point_cloud.shape))
136 | self.amplitude_point_cloud = NormalizeData(
137 | self.point_cloud[:,3], thr=self.ampv95p, type='positive'
138 | )
139 | self.point_cloud = self.point_cloud[:,:3]
140 | self.semblance_point_cloud = np.array([])
141 | print('Point cloud created - {} points - time to execute: {}'.format(self.point_cloud.shape[0], datetime.now()-t0))
142 |
143 | def filter_point_cloud_with_semblance(self, kernel=(3, 3, 9), thr=0.9, in_place=True):
144 | """
145 | Description
146 | -----------
147 | Computes the semblance cube and filters the point cloud based on semblance cut-off
148 |
149 | Args:
150 | -----
151 | kernel (tuple, default (3, 3, 9)): tuple of int (x, y, z) the dimension of the 3D kernel applied to compute semblance
152 | thr (float, default 0.9): semblance threshold, float between 0 and 1
153 | in_place (bool, default True): If True, perform operation in-place.
154 | """
155 | if self.point_cloud.size == 0:
156 | print('Point cloud not computed - extracting extrema first')
157 | self.extrema_extraction()
158 | return()
159 |
160 | if self.semblance_array.size == 0:
161 | t0 = datetime.now()
162 | daSemblance = EdgeDetection().semblance(darray=self.seismic_array, kernel=kernel) #Dask instance of the semblance
163 | self.semblance_array = daSemblance.compute()
164 | self.semblance_point_cloud = np.array([])
165 | print('Semblance attribute computed - time to execute: {}'.format(datetime.now()-t0))
166 | if self.semblance_point_cloud.size == 0:
167 | t0 = datetime.now()
168 | self.semblance_point_cloud = self.semblance_array[self.point_cloud[:, 0], self.point_cloud[:, 1], self.point_cloud[:, 2]]
169 | print('Semblance point cloud extracted - time to execute: {}'.format(datetime.now()-t0))
170 | t0 = datetime.now()
171 | if in_place:
172 | mask = self.semblance_point_cloud > thr
173 | self.point_cloud = self.point_cloud[mask]
174 | self.amplitude_point_cloud = self.amplitude_point_cloud[mask]
175 | self.semblance_point_cloud = self.semblance_point_cloud[mask]
176 | print('Applied semblance filter in place - {} points - time to execute: {}'.format(self.point_cloud.shape[0], datetime.now()-t0))
177 | else:
178 | return (self.point_cloud[ self.semblance_point_cloud > thr])
179 |
180 | def filter_point_cloud_with_amplitude(self, thr=0.25, in_place=True):
181 | """
182 | Description
183 | -----------
184 | Filters the point cloud based on amplitude cut-off
185 |
186 | Args:
187 | -----
188 | thr (float, default 0.25): amplitude threshold, float between 0 and 1
189 | in_place (bool, default True): If True, perform operation in-place.
190 | """
191 | if self.point_cloud.size == 0:
192 | print('Point cloud not computed - extract extrema first')
193 | t0 = datetime.now()
194 | if in_place:
195 | mask = self.amplitude_point_cloud > thr
196 | self.point_cloud = self.point_cloud[mask]
197 | self.semblance_point_cloud = self.semblance_point_cloud[mask]
198 | self.amplitude_point_cloud = self.amplitude_point_cloud[mask]
199 | print('Applied amplitude filter in place - {} points - time to execute: {}'.format(self.point_cloud.shape[0], datetime.now()-t0))
200 | else:
201 | return (self.point_cloud[ self.amplitude_point_cloud > thr ])
202 |
203 | def DBSCAN_segmentation_sklearn(self, eps=2, min_samples=8, z_factor=1):
204 | """
205 | Description
206 | -----------
207 | Segments the point cloud based on DBSCAN clustering - sklearn implementation
208 |
209 | Args:
210 | -----
211 | eps (float, default 2): epsilon distance parameter to DBSCAN
212 | min_samples (int, default 8): minimum number of points parameter to DBSCAN
213 | z_factor (int, default 1): vertical exageration to apply to the seismic point cloud
214 | """
215 | t0=datetime.now()
216 | point_cloud_to_compute = self.point_cloud.copy()
217 | point_cloud_to_compute[:, 2] = self.point_cloud[:, 2]*z_factor
218 | print('vertical exageration applied')
219 | clustering = DBSCAN(eps=eps, min_samples=min_samples, algorithm='ball_tree', n_jobs=-1).fit(point_cloud_to_compute)
220 | self.labels = clustering.labels_
221 | print('seismic segmented - {} clusters - time {}'.format( self.labels.max()+1, datetime.now()-t0 ))
222 |
223 | ######
224 | # Functions
225 | ######
226 |
227 | def NormalizeData(data: np.array, thr: float, type='positive'):
228 | """
229 | Description
230 | -----------
231 | Normalize data between [0, thr] if positive and [-thr, 0] if negative
232 |
233 | Args:
234 | -----
235 | data (np.array):
236 | thr (float): threshold to ceil the data
237 |
238 | Returns:
239 | --------
240 | np.array: data normalized
241 | """
242 | if type == 'positive':
243 | data[data < 0] = 0.
244 | data[data > thr] = thr
245 | return (data / thr)
246 | elif type == 'negative':
247 | data[data > 0] = 0.
248 | data[data < -thr] = -thr
249 | return (data/ thr)
250 | else:
251 | print('Unrecognized type, expected "positive" or "negative", got {}'.format(type))
252 | return None
253 |
254 | @dask.delayed
255 | def get_point_cloud_chunks(seismic, xchunk, ychunk, extrema_type=np.greater):
256 | """
257 | Description
258 | -----------
259 | Extract extrema of a 1D signal - dask delayed implementation
260 |
261 | Args:
262 | -----
263 | seismic (np.array):
264 | xchunk (int):
265 | ychunk (int):
266 | extrema_type (callable, default np.greater): np.greater or np.less, the type of extrema to extract (maxima or minima)
267 |
268 | Returns:
269 | --------
270 | np.array: point cloud of extrema from data, shape (3, n): first axis being the coordinates,
271 | second axis being the n extrema points
272 | """
273 | (nx, ny, nz) = seismic.shape
274 | Lx = []
275 | Ly = []
276 | Lz = []
277 | Lamp = []
278 | for i in range (nx):
279 | for j in range (ny):
280 | maxima = argrelextrema(seismic[i,j], extrema_type)[0]
281 | Lx.extend([xchunk + i]*len(maxima))
282 | Ly.extend([ychunk + j]*len(maxima))
283 | Lz.extend(maxima)
284 | Lamp.extend(seismic[i,j,maxima])
285 | point_cloud = np.zeros((4, len(Lx),), dtype='int32')
286 | point_cloud[0, :] = Lx
287 | point_cloud[1, :] = Ly
288 | point_cloud[2, :] = Lz
289 | point_cloud[3, :] = Lamp
290 | return(point_cloud)
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # pyseismic: seismic segmentation and geobody detection in 3D seismic
2 |
3 | Workflow to automatically segment 3D seismic reflection data into objects and detect and extract geobodies.
4 |
5 | ## Usage
6 |
7 | For seismic segmentation
8 |
9 | ```python
10 | import open3d as o3d
11 | from pyntcloud import PyntCloud
12 |
13 | from PointCloudSeismicInterpretation import PointCloudSeismicInterpretation
14 |
15 | #first load your 3D seismic
16 | #seismic_data is your 3D seismic data loaded as a numpy array
17 |
18 | #initiate seismic data object
19 | pointCloudInterpretor = PointCloudSeismicInterpretation(seismic_array=seismic_data)
20 |
21 | #extract a point cloud of trace extrema from the seismic
22 | pointCloudInterpretor.extrema_extraction_dask()
23 |
24 | #compute semblance attribute and filter points based on a semblance cut-off value
25 | pointCloudInterpretor.filter_point_cloud_with_semblance(kernel=(3,3,9), thr=0.85, in_place=True)
26 |
27 | #filter points based on an amplitude cut-off value
28 | pointCloudInterpretor.filter_point_cloud_with_amplitude(thr=0.20, in_place=True)
29 |
30 | #create an open3D point cloud object and segment the point cloud with DBSCAN
31 | pcd_pyntcloud = PyntCloud(pd.DataFrame(data={'x':pointCloudInterpretor.point_cloud.T[0],
32 | 'y':pointCloudInterpretor.point_cloud.T[1],
33 | 'z':pointCloudInterpretor.point_cloud.T[2],
34 | 'amplitude':pointCloudInterpretor.amplitude_point_cloud})[:])
35 | pcd_o3d = pcd_pyntcloud.to_instance("open3d", mesh=False)
36 | with o3d.utility.VerbosityContextManager(o3d.utility.VerbosityLevel.Debug) as cm:
37 | labels = np.array(
38 | pcd_o3d.cluster_dbscan(eps=2, min_points=8, print_progress=True))
39 | ```
40 |
41 | For geobody detection in a segmented seismic
42 |
43 | ```python
44 | from lshashpy3 import LSHash
45 | from PointCloudObjectRetrieval import PointCloudObjectRetrieval
46 |
47 | #merge seismic point cloud and amplitude point cloud in an numpy array ([n_points, 4])
48 | pcd = np.zeros((len(pointCloudInterpretor.point_cloud),4))
49 | pcd[:,:3] = pointCloudInterpretor.point_cloud[:,:]
50 | pcd[:,3]= pointCloudInterpretor.amplitude_point_cloud
51 | #initiate feature extraction object
52 | FeatureExtractor = PointCloudObjectRetrieval(
53 | pcd,
54 | pointCloudInterpretor.semblance_point_cloud,
55 | labels
56 | )
57 |
58 | #extract features for each point cloud object
59 | standardized_featureDF = FeatureExtractor.get_features(selected_clusters)
60 |
61 | #contruct lsh tables
62 | feature_dict = dict(zip(standardized_featureDF.index, standardized_featureDF[selected_features].values))
63 | k = 7 # hash size
64 | L = 20 # number of tables
65 | d = len(selected_features) #2048 # Dimension of Feature vector
66 | lsh = LSHash(hash_size=k, input_dim=d, num_hashtables=L)
67 | for ID, vec in notebook.tqdm(feature_dict.items()):
68 | lsh.index(vec.flatten(), extra_data=ID)
69 |
70 | #query similar geobodies to a specific geobody example previously identified
71 | n_items = 10 #number of similar geobodies
72 | feature_example = feature_dict[0].flatten() #features of the geobody example
73 | #replace 0 by the id of the identified example
74 | response = lsh_variable.query(feature_example, num_results=n_items, distance_func='hamming')
75 | ```
76 |
77 | ## Notebook demo
78 |
79 | For a more complete demo run the the file notebooks/F3dataset-segmentation.ipynb
80 |
81 | It gives a complete example of seismic segmentation of the open-source F3-dataset (https://terranubis.com/datainfo/F3-Demo-2020) and geobody detection.
82 |
83 | #### Point cloud seismic segmentation of F3 seismic data
84 | 
85 |
86 | #### Geobody detection - elongated geobodies - in the F3 seismic data (150-closest objects)
87 |
88 |
--------------------------------------------------------------------------------
/assets/images/geobody-detection.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GeoDataScienceUQ/pyseismic/d8200e1181b6a4ec2719cba6b9ec25a1a5c33469/assets/images/geobody-detection.PNG
--------------------------------------------------------------------------------
/assets/images/seismic-segmentation.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GeoDataScienceUQ/pyseismic/d8200e1181b6a4ec2719cba6b9ec25a1a5c33469/assets/images/seismic-segmentation.gif
--------------------------------------------------------------------------------
/d2geo/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/d2geo/README:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GeoDataScienceUQ/pyseismic/d8200e1181b6a4ec2719cba6b9ec25a1a5c33469/d2geo/README
--------------------------------------------------------------------------------
/d2geo/attributes/CompleTrace.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Complex Trace Attributes for Seismic Data
4 |
5 | @author: Braden Fitz-Gerald
6 | @email: braden.fitzgerald@gmail.com
7 |
8 | """
9 |
10 | # Import Libraries
11 | import dask.array as da
12 | import numpy as np
13 | import util
14 | from SignalProcess import SignalProcess as sp
15 |
16 |
17 | class ComplexAttributes():
18 | """
19 | Description
20 | -----------
21 | Class object containing methods for computing complex trace attributes
22 | from 3D seismic data.
23 |
24 | Methods
25 | -------
26 | create_array
27 | envelope
28 | instantaneous_phase
29 | cosine_instantaneous_phase
30 | relative_amplitude_change
31 | instantaneous_frequency
32 | instantaneous_bandwidth
33 | dominant_frequency
34 | frequency_change
35 | sweetness
36 | quality_factor
37 | response_phase
38 | response_frequency
39 | response_amplitude
40 | apparent_polarity
41 | """
42 |
43 | def create_array(self, darray, kernel=None, preview=None):
44 | """
45 | Description
46 | -----------
47 | Convert input to Dask Array with ideal chunk size as necessary. Perform
48 | necessary ghosting as needed for opertations utilizing windowed functions.
49 |
50 | Parameters
51 | ----------
52 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
53 |
54 | Keywork Arguments
55 | -----------------
56 | kernel : tuple (len 3), operator size
57 | preview : str, enables or disables preview mode and specifies direction
58 | Acceptable inputs are (None, 'inline', 'xline', 'z')
59 | Optimizes chunk size in different orientations to facilitate rapid
60 | screening of algorithm output
61 |
62 | Returns
63 | -------
64 | darray : Dask Array
65 | chunk_init : tuple (len 3), chunk size before ghosting. Used in select cases
66 | """
67 |
68 | # Compute chunk size and convert if not a Dask Array
69 | if not isinstance(darray, da.core.Array):
70 | chunk_size = util.compute_chunk_size(darray.shape,
71 | darray.dtype.itemsize,
72 | kernel=kernel,
73 | preview=preview)
74 | darray = da.from_array(darray, chunks=chunk_size)
75 | chunks_init = darray.chunks
76 |
77 | else:
78 | chunks_init = darray.chunks
79 |
80 | # Ghost Dask Array if operation specifies a kernel
81 | if kernel != None:
82 | hw = tuple(np.array(kernel) // 2)
83 | darray = da.ghost.ghost(darray, depth=hw, boundary='reflect')
84 |
85 | return(darray, chunks_init)
86 |
87 |
88 | def envelope(self, darray, preview=None):
89 | """
90 | Description
91 | -----------
92 | Compute the Envelope of the input data
93 |
94 | Parameters
95 | ----------
96 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
97 |
98 | Keywork Arguments
99 | -----------------
100 | preview : str, enables or disables preview mode and specifies direction
101 | Acceptable inputs are (None, 'inline', 'xline', 'z')
102 | Optimizes chunk size in different orientations to facilitate rapid
103 | screening of algorithm output
104 |
105 | Returns
106 | -------
107 | result : Dask Array
108 | """
109 |
110 | kernel = (1,1,25)
111 | darray, chunks_init = self.create_array(darray, kernel, preview=preview)
112 | analytical_trace = darray.map_blocks(util.hilbert, dtype=darray.dtype)
113 | result = da.absolute(analytical_trace)
114 | result = util.trim_dask_array(result, kernel)
115 |
116 | return(result)
117 |
118 |
119 |
120 | def instantaneous_phase(self, darray, preview=None):
121 | """
122 | Description
123 | -----------
124 | Compute the Instantaneous Phase of the input data
125 |
126 | Parameters
127 | ----------
128 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
129 |
130 | Keywork Arguments
131 | -----------------
132 | preview : str, enables or disables preview mode and specifies direction
133 | Acceptable inputs are (None, 'inline', 'xline', 'z')
134 | Optimizes chunk size in different orientations to facilitate rapid
135 | screening of algorithm output
136 |
137 | Returns
138 | -------
139 | result : Dask Array
140 | """
141 |
142 | kernel = (1,1,25)
143 | darray, chunks_init = self.create_array(darray, kernel, preview=preview)
144 | analytical_trace = darray.map_blocks(util.hilbert, dtype=darray.dtype)
145 | result = da.rad2deg(da.angle(analytical_trace))
146 | result = util.trim_dask_array(result, kernel)
147 |
148 | return(result)
149 |
150 |
151 | def cosine_instantaneous_phase(self, darray, preview=None):
152 | """
153 | Description
154 | -----------
155 | Compute the Cose of Instantaneous Phase of the input data
156 |
157 | Parameters
158 | ----------
159 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
160 |
161 | Keywork Arguments
162 | -----------------
163 | preview : str, enables or disables preview mode and specifies direction
164 | Acceptable inputs are (None, 'inline', 'xline', 'z')
165 | Optimizes chunk size in different orientations to facilitate rapid
166 | screening of algorithm output
167 |
168 | Returns
169 | -------
170 | result : Dask Array
171 | """
172 |
173 | darray, chunks_init = self.create_array(darray, preview=preview)
174 | phase = self.instantaneous_phase(darray)
175 | result = da.rad2deg(da.angle(phase))
176 |
177 | return(result)
178 |
179 |
180 |
181 | def relative_amplitude_change(self, darray, preview=None):
182 | """
183 | Description
184 | -----------
185 | Compute the Relative Amplitude Change of the input data
186 |
187 | Parameters
188 | ----------
189 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
190 |
191 | Keywork Arguments
192 | -----------------
193 | preview : str, enables or disables preview mode and specifies direction
194 | Acceptable inputs are (None, 'inline', 'xline', 'z')
195 | Optimizes chunk size in different orientations to facilitate rapid
196 | screening of algorithm output
197 |
198 | Returns
199 | -------
200 | result : Dask Array
201 | """
202 |
203 | darray, chunks_init = self.create_array(darray, preview=preview)
204 | env = self.envelope(darray)
205 | env_prime = sp().first_derivative(env, axis=-1)
206 | result = env_prime / env
207 | result = da.clip(result, -1, 1)
208 |
209 | return(result)
210 |
211 |
212 |
213 | def amplitude_acceleration(self, darray, preview=None):
214 | """
215 | Description
216 | -----------
217 | Compute the Amplitude Acceleration of the input data
218 |
219 | Parameters
220 | ----------
221 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
222 |
223 | Keywork Arguments
224 | -----------------
225 | preview : str, enables or disables preview mode and specifies direction
226 | Acceptable inputs are (None, 'inline', 'xline', 'z')
227 | Optimizes chunk size in different orientations to facilitate rapid
228 | screening of algorithm output
229 |
230 | Returns
231 | -------
232 | result : Dask Array
233 | """
234 |
235 | darray, chunks_init = self.create_array(darray, preview=preview)
236 | rac = self.relative_amplitude_change(darray)
237 | result = sp().first_derivative(rac, axis=-1)
238 |
239 | return(result)
240 |
241 |
242 |
243 | def instantaneous_frequency(self, darray, sample_rate=4, preview=None):
244 | """
245 | Description
246 | -----------
247 | Compute the Instantaneous Frequency of the input data
248 |
249 | Parameters
250 | ----------
251 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
252 |
253 | Keywork Arguments
254 | -----------------
255 | sample_rate : Number, sample rate in milliseconds (ms)
256 | preview : str, enables or disables preview mode and specifies direction
257 | Acceptable inputs are (None, 'inline', 'xline', 'z')
258 | Optimizes chunk size in different orientations to facilitate rapid
259 | screening of algorithm output
260 |
261 | Returns
262 | -------
263 | result : Dask Array
264 | """
265 |
266 | darray, chunks_init = self.create_array(darray, preview=preview)
267 |
268 | fs = 1000 / sample_rate
269 | phase = self.instantaneous_phase(darray)
270 | phase = da.deg2rad(phase)
271 | phase = phase.map_blocks(np.unwrap, dtype=darray.dtype)
272 | phase_prime = sp().first_derivative(phase, axis=-1)
273 | result = da.absolute((phase_prime / (2.0 * np.pi) * fs))
274 |
275 | return(result)
276 |
277 |
278 | def instantaneous_bandwidth(self, darray, preview=None):
279 | """
280 | Description
281 | -----------
282 | Compute the Instantaneous Bandwidth of the input data
283 |
284 | Parameters
285 | ----------
286 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
287 |
288 | Keywork Arguments
289 | -----------------
290 | preview : str, enables or disables preview mode and specifies direction
291 | Acceptable inputs are (None, 'inline', 'xline', 'z')
292 | Optimizes chunk size in different orientations to facilitate rapid
293 | screening of algorithm output
294 |
295 | Returns
296 | -------
297 | result : Dask Array
298 | """
299 |
300 | darray, chunks_init = self.create_array(darray, preview=preview)
301 | rac = self.relative_amplitude_change(darray)
302 | result = da.absolute(rac) / (2.0 * np.pi)
303 |
304 | return(result)
305 |
306 |
307 | def dominant_frequency(self, darray, sample_rate=4, preview=None):
308 | """
309 | Description
310 | -----------
311 | Compute the Dominant Frequency of the input data
312 |
313 | Parameters
314 | ----------
315 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
316 |
317 | Keywork Arguments
318 | -----------------
319 | sample_rate : Number, sample rate in milliseconds (ms)
320 | preview : str, enables or disables preview mode and specifies direction
321 | Acceptable inputs are (None, 'inline', 'xline', 'z')
322 | Optimizes chunk size in different orientations to facilitate rapid
323 | screening of algorithm output
324 |
325 | Returns
326 | -------
327 | result : Dask Array
328 | """
329 |
330 | darray, chunks_init = self.create_array(darray, preview=preview)
331 | inst_freq = self.instantaneous_frequency(darray, sample_rate)
332 | inst_band = self.instantaneous_bandwidth(darray)
333 | result = da.hypot(inst_freq, inst_band)
334 |
335 | return(result)
336 |
337 |
338 | def frequency_change(self, darray, sample_rate=4, preview=None):
339 | """
340 | Description
341 | -----------
342 | Compute the Frequency Change of the input data
343 |
344 | Parameters
345 | ----------
346 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
347 |
348 | Keywork Arguments
349 | -----------------
350 | sample_rate : Number, sample rate in milliseconds (ms)
351 | preview : str, enables or disables preview mode and specifies direction
352 | Acceptable inputs are (None, 'inline', 'xline', 'z')
353 | Optimizes chunk size in different orientations to facilitate rapid
354 | screening of algorithm output
355 |
356 | Returns
357 | -------
358 | result : Dask Array
359 | """
360 |
361 | darray, chunks_init = self.create_array(darray, preview=preview)
362 | inst_freq = self.instantaneous_frequency(darray, sample_rate)
363 | result = sp().first_derivative(inst_freq, axis=-1)
364 |
365 | return(result)
366 |
367 |
368 | def sweetness(self, darray, sample_rate=4, preview=None):
369 | """
370 | Description
371 | -----------
372 | Compute the Sweetness of the input data
373 |
374 | Parameters
375 | ----------
376 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
377 |
378 | Keywork Arguments
379 | -----------------
380 | sample_rate : Number, sample rate in milliseconds (ms)
381 | preview : str, enables or disables preview mode and specifies direction
382 | Acceptable inputs are (None, 'inline', 'xline', 'z')
383 | Optimizes chunk size in different orientations to facilitate rapid
384 | screening of algorithm output
385 |
386 | Returns
387 | -------
388 | result : Dask Array
389 | """
390 |
391 | def func(chunk):
392 | chunk[chunk < 5] = 5
393 | return(chunk)
394 |
395 | darray, chunks_init = self.create_array(darray, preview=preview)
396 | inst_freq = self.instantaneous_frequency(darray, sample_rate)
397 | inst_freq = inst_freq.map_blocks(func, dtype=darray.dtype)
398 | env = self.envelope(darray)
399 |
400 | result = env / inst_freq
401 |
402 | return(result)
403 |
404 |
405 | def quality_factor(self, darray, sample_rate=4, preview=None):
406 | """
407 | Description
408 | -----------
409 | Compute the Quality Factor of the input data
410 |
411 | Parameters
412 | ----------
413 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
414 |
415 | Keywork Arguments
416 | -----------------
417 | sample_rate : Number, sample rate in milliseconds (ms)
418 | preview : str, enables or disables preview mode and specifies direction
419 | Acceptable inputs are (None, 'inline', 'xline', 'z')
420 | Optimizes chunk size in different orientations to facilitate rapid
421 | screening of algorithm output
422 |
423 | Returns
424 | -------
425 | result : Dask Array
426 | """
427 |
428 | darray, chunks_init = self.create_array(darray, preview=preview)
429 |
430 | inst_freq = self.instantaneous_frequency(darray, sample_rate)
431 | rac = self.relative_amplitude_change(darray)
432 |
433 | result = (np.pi * inst_freq) / rac
434 |
435 | return(result)
436 |
437 |
438 | def response_phase(self, darray, preview=None):
439 | """
440 | Description
441 | -----------
442 | Compute the Response Phase of the input data
443 |
444 | Parameters
445 | ----------
446 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
447 |
448 | Keywork Arguments
449 | -----------------
450 | preview : str, enables or disables preview mode and specifies direction
451 | Acceptable inputs are (None, 'inline', 'xline', 'z')
452 | Optimizes chunk size in different orientations to facilitate rapid
453 | screening of algorithm output
454 |
455 | Returns
456 | -------
457 | result : Dask Array
458 | """
459 |
460 | def operation(chunk1, chunk2, chunk3):
461 |
462 | out = np.zeros(chunk1.shape)
463 | for i,j in np.ndindex(out.shape[:-1]):
464 |
465 | ints = np.unique(chunk3[i, j, :])
466 |
467 | for ii in ints:
468 |
469 | idx = np.where(chunk3[i, j, :] == ii)[0]
470 | peak = idx[chunk1[i, j, idx].argmax()]
471 | out[i, j, idx] = chunk2[i, j, peak]
472 |
473 | return(out)
474 |
475 | darray, chunks_init = self.create_array(darray, preview=preview)
476 | env = self.envelope(darray)
477 | phase = self.instantaneous_phase(darray)
478 | troughs = env.map_blocks(util.local_events, comparator=np.less,
479 | dtype=darray.dtype)
480 | troughs = troughs.cumsum(axis=-1)
481 | result = da.map_blocks(operation, env, phase, troughs, dtype=darray.dtype)
482 | result[da.isnan(result)] = 0
483 |
484 |
485 | return(result)
486 |
487 |
488 | def response_frequency(self, darray, sample_rate=4, preview=None):
489 | """
490 | Description
491 | -----------
492 | Compute the Response Frequency of the input data
493 |
494 | Parameters
495 | ----------
496 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
497 |
498 | Keywork Arguments
499 | -----------------
500 | sample_rate : Number, sample rate in milliseconds (ms)
501 | preview : str, enables or disables preview mode and specifies direction
502 | Acceptable inputs are (None, 'inline', 'xline', 'z')
503 | Optimizes chunk size in different orientations to facilitate rapid
504 | screening of algorithm output
505 |
506 | Returns
507 | -------
508 | result : Dask Array
509 | """
510 |
511 | def operation(chunk1, chunk2, chunk3):
512 |
513 | out = np.zeros(chunk1.shape)
514 | for i,j in np.ndindex(out.shape[:-1]):
515 |
516 | ints = np.unique(chunk3[i, j, :])
517 |
518 | for ii in ints:
519 |
520 | idx = np.where(chunk3[i, j, :] == ii)[0]
521 | peak = idx[chunk1[i, j, idx].argmax()]
522 | out[i, j, idx] = chunk2[i, j, peak]
523 |
524 | return(out)
525 |
526 | darray, chunks_init = self.create_array(darray, preview=preview)
527 | env = self.envelope(darray)
528 | inst_freq = self.instantaneous_frequency(darray, sample_rate)
529 | troughs = env.map_blocks(util.local_events, comparator=np.less,
530 | dtype=darray.dtype)
531 | troughs = troughs.cumsum(axis=-1)
532 | result = da.map_blocks(operation, env, inst_freq, troughs, dtype=darray.dtype)
533 | result[da.isnan(result)] = 0
534 |
535 | return(result)
536 |
537 |
538 | def response_amplitude(self, darray, preview=None):
539 | """
540 | Description
541 | -----------
542 | Compute the Response Amplitude of the input data
543 |
544 | Parameters
545 | ----------
546 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
547 |
548 | Keywork Arguments
549 | -----------------
550 | preview : str, enables or disables preview mode and specifies direction
551 | Acceptable inputs are (None, 'inline', 'xline', 'z')
552 | Optimizes chunk size in different orientations to facilitate rapid
553 | screening of algorithm output
554 |
555 | Returns
556 | -------
557 | result : Dask Array
558 | """
559 |
560 | def operation(chunk1, chunk2, chunk3):
561 |
562 | out = np.zeros(chunk1.shape)
563 | for i,j in np.ndindex(out.shape[:-1]):
564 |
565 | ints = np.unique(chunk3[i, j, :])
566 |
567 | for ii in ints:
568 |
569 | idx = np.where(chunk3[i, j, :] == ii)[0]
570 | peak = idx[chunk1[i, j, idx].argmax()]
571 | out[i, j, idx] = chunk2[i, j, peak]
572 |
573 | return(out)
574 |
575 | darray, chunks_init = self.create_array(darray, preview=preview)
576 | env = self.envelope(darray)
577 | troughs = env.map_blocks(util.local_events, comparator=np.less,
578 | dtype=darray.dtype)
579 | troughs = troughs.cumsum(axis=-1)
580 | result = da.map_blocks(operation, env, darray, troughs, dtype=darray.dtype)
581 | result[da.isnan(result)] = 0
582 |
583 | return(result)
584 |
585 |
586 | def apparent_polarity(self, darray, preview=None):
587 | """
588 | Description
589 | -----------
590 | Compute the Apparent Polarity of the input data
591 |
592 | Parameters
593 | ----------
594 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
595 |
596 | Keywork Arguments
597 | -----------------
598 | preview : str, enables or disables preview mode and specifies direction
599 | Acceptable inputs are (None, 'inline', 'xline', 'z')
600 | Optimizes chunk size in different orientations to facilitate rapid
601 | screening of algorithm output
602 |
603 | Returns
604 | -------
605 | result : Dask Array
606 | """
607 | def operation(chunk1, chunk2, chunk3):
608 |
609 | out = np.zeros(chunk1.shape)
610 | for i,j in np.ndindex(out.shape[:-1]):
611 |
612 | ints = np.unique(chunk3[i, j, :])
613 |
614 | for ii in ints:
615 |
616 | idx = np.where(chunk3[i, j, :] == ii)[0]
617 | peak = idx[chunk1[i, j, idx].argmax()]
618 | out[i, j, idx] = chunk1[i, j, peak] * np.sign(chunk2[i, j, peak])
619 |
620 | return(out)
621 |
622 | darray, chunks_init = self.create_array(darray, preview=preview)
623 | env = self.envelope(darray)
624 | troughs = env.map_blocks(util.local_events, comparator=np.less,
625 | dtype=darray.dtype)
626 | troughs = troughs.cumsum(axis=-1)
627 | result = da.map_blocks(operation, env, darray, troughs, dtype=darray.dtype)
628 | result[da.isnan(result)] = 0
629 |
630 | return(result)
--------------------------------------------------------------------------------
/d2geo/attributes/DipAzm.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Dip & Azimuth Calculations for Seismic Data
4 |
5 | @author: Braden Fitz-Gerald
6 | @email: braden.fitzgerald@gmail.com
7 |
8 | """
9 |
10 | # Import Libraries
11 | import numpy as np
12 | import dask.array as da
13 | from scipy import ndimage as ndi
14 | import util
15 | from SignalProcess import SignalProcess as sp
16 |
17 |
18 | class DipAzm():
19 | """
20 | Description
21 | -----------
22 | Class object containing methods for computing dip & azimuth attributes
23 | from 3D seismic data.
24 |
25 | Methods
26 | -------
27 | create_array
28 | gradient_dips
29 | gradient_structure_tensor
30 | gst_2D_dips
31 | gst_3D_dip
32 | gst_3D_azm
33 | """
34 |
35 | def create_array(self, darray, kernel=None, preview=None):
36 | """
37 | Description
38 | -----------
39 | Convert input to Dask Array with ideal chunk size as necessary. Perform
40 | necessary ghosting as needed for opertations utilizing windowed functions.
41 |
42 | Parameters
43 | ----------
44 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
45 |
46 | Keywork Arguments
47 | -----------------
48 | kernel : tuple (len 3), operator size
49 | preview : str, enables or disables preview mode and specifies direction
50 | Acceptable inputs are (None, 'inline', 'xline', 'z')
51 | Optimizes chunk size in different orientations to facilitate rapid
52 | screening of algorithm output
53 |
54 | Returns
55 | -------
56 | darray : Dask Array
57 | chunk_init : tuple (len 3), chunk size before ghosting. Used in select cases
58 | """
59 |
60 | if not isinstance(darray, da.core.Array):
61 | chunk_size = util.compute_chunk_size(darray.shape,
62 | darray.dtype.itemsize,
63 | kernel=kernel,
64 | preview=preview)
65 | darray = da.from_array(darray, chunks=chunk_size)
66 | chunks_init = darray.chunks
67 |
68 | else:
69 | chunks_init = darray.chunks
70 |
71 | if kernel != None:
72 | hw = tuple(np.array(kernel) // 2)
73 | darray = da.ghost.ghost(darray, depth=hw, boundary='reflect')
74 |
75 | return(darray, chunks_init)
76 |
77 |
78 | def gradient_dips(self, darray, dip_factor=10, kernel=(3,3,3), preview=None):
79 | """
80 | Description
81 | -----------
82 | Compute Inline and Crossline Dip from the Inline, Crossline, & Z Gradients
83 |
84 | Parameters
85 | ----------
86 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
87 |
88 | Keywork Arguments
89 | -----------------
90 | dip_factor : Number, scalar for dip values
91 | kernel : tuple (len 3), operator size
92 | preview : str, enables or disables preview mode and specifies direction
93 | Acceptable inputs are (None, 'inline', 'xline', 'z')
94 | Optimizes chunk size in different orientations to facilitate rapid
95 | screening of algorithm output
96 |
97 | Returns
98 | -------
99 | il_dip : Dask Array, Inline Dips
100 | xl_dip : Dask Array, Crossline Dips
101 | """
102 |
103 | # Generate Dask Array as necessary
104 | darray, chunks_init = self.create_array(darray, kernel=None, preview=preview)
105 |
106 | # Compute I, J, K gradients
107 | gi = sp().first_derivative(darray, axis=0)
108 | gj = sp().first_derivative(darray, axis=1)
109 | gk = sp().first_derivative(darray, axis=2)
110 |
111 | # Compute dips
112 | il_dip = -(gi / gk) * dip_factor
113 | xl_dip = -(gj / gk) * dip_factor
114 |
115 | il_dip[da.isnan(il_dip)] = 0
116 | xl_dip[da.isnan(xl_dip)] = 0
117 |
118 | # Perform smoothing as specified
119 | if kernel != None:
120 | hw = tuple(np.array(kernel) // 2)
121 | il_dip = il_dip.map_overlap(ndi.median_filter, depth=hw, boundary='reflect',
122 | dtype=darray.dtype, size=kernel)
123 | xl_dip = xl_dip.map_overlap(ndi.median_filter, depth=hw, boundary='reflect',
124 | dtype=darray.dtype, size=kernel)
125 |
126 | return(il_dip, xl_dip)
127 |
128 |
129 | def gradient_structure_tensor(self, darray, kernel, preview=None):
130 | """
131 | Description
132 | -----------
133 | Convience function to compute the Inner Product of Gradients
134 |
135 | Parameters
136 | ----------
137 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
138 | kernel : tuple (len 3), operator size
139 |
140 | Keywork Arguments
141 | -----------------
142 | preview : str, enables or disables preview mode and specifies direction
143 | Acceptable inputs are (None, 'inline', 'xline', 'z')
144 | Optimizes chunk size in different orientations to facilitate rapid
145 | screening of algorithm output
146 |
147 | Returns
148 | -------
149 | gi2, gj2, gk2, gigj, gigk, gjgk : Dask Array
150 | """
151 |
152 | # Generate Dask Array as necessary
153 | darray, chunks_init = self.create_array(darray, kernel, preview=preview)
154 |
155 | # Compute I, J, K gradients
156 | gi = sp().first_derivative(darray, axis=0)
157 | gj = sp().first_derivative(darray, axis=1)
158 | gk = sp().first_derivative(darray, axis=2)
159 | gi = util.trim_dask_array(gi, kernel)
160 | gj = util.trim_dask_array(gj, kernel)
161 | gk = util.trim_dask_array(gk, kernel)
162 |
163 | # Compute Inner Product of Gradients
164 | hw = tuple(np.array(kernel) // 2)
165 | gi2 = (gi * gi).map_overlap(ndi.uniform_filter, depth=hw, boundary='reflect',
166 | dtype=darray.dtype, size=kernel)
167 | gj2 = (gj * gj).map_overlap(ndi.uniform_filter, depth=hw, boundary='reflect',
168 | dtype=darray.dtype, size=kernel)
169 | gk2 = (gk * gk).map_overlap(ndi.uniform_filter, depth=hw, boundary='reflect',
170 | dtype=darray.dtype, size=kernel)
171 | gigj = (gi * gj).map_overlap(ndi.uniform_filter, depth=hw, boundary='reflect',
172 | dtype=darray.dtype, size=kernel)
173 | gigk = (gi * gk).map_overlap(ndi.uniform_filter, depth=hw, boundary='reflect',
174 | dtype=darray.dtype, size=kernel)
175 | gjgk = (gj * gk).map_overlap(ndi.uniform_filter, depth=hw, boundary='reflect',
176 | dtype=darray.dtype, size=kernel)
177 |
178 | return(gi2, gj2, gk2, gigj, gigk, gjgk)
179 |
180 |
181 | def gst_2D_dips(self, darray, dip_factor=10, kernel=(3,3,3), preview=None):
182 | """
183 | Description
184 | -----------
185 | Compute Inline and Crossline Dip from the Gradient Structure Tensor
186 |
187 | Parameters
188 | ----------
189 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
190 |
191 | Keywork Arguments
192 | -----------------
193 | dip_factor : Number, scalar for dip values
194 | kernel : tuple (len 3), operator size
195 | preview : str, enables or disables preview mode and specifies direction
196 | Acceptable inputs are (None, 'inline', 'xline', 'z')
197 | Optimizes chunk size in different orientations to facilitate rapid
198 | screening of algorithm output
199 |
200 | Returns
201 | -------
202 | il_dip : Dask Array, Inline Dips
203 | xl_dip : Dask Array, Crossline Dips
204 | """
205 |
206 | # Compute dips from Eigenvectors of GST
207 | def operation(gi2, gj2, gk2, gigj, gigk, gjgk, axis):
208 | np.seterr(all='ignore')
209 |
210 | shape = gi2.shape
211 |
212 | gst = np.array([[gi2, gigj, gigk],
213 | [gigj, gj2, gjgk],
214 | [gigk, gjgk, gk2]])
215 |
216 | gst = np.moveaxis(gst, [0,1], [-2,-1])
217 | gst = gst.reshape((-1, 3, 3))
218 |
219 | evals, evecs = np.linalg.eigh(gst)
220 | ndx = evals.argsort()
221 | evecs = evecs[np.arange(0,gst.shape[0],1),:,ndx[:,2]]
222 |
223 | out = -evecs[:, axis] / evecs[:, 2]
224 | out = out.reshape(shape)
225 |
226 | return(out)
227 |
228 | # Compute Inner Product of Gradients and Dips
229 | gi2, gj2, gk2, gigj, gigk, gjgk = self.gradient_structure_tensor(darray, kernel,
230 | preview=preview)
231 | il_dip = da.map_blocks(operation, gi2, gj2, gk2, gigj, gigk, gjgk, axis=0,
232 | dtype=darray.dtype)
233 | xl_dip = da.map_blocks(operation, gi2, gj2, gk2, gigj, gigk, gjgk, axis=1,
234 | dtype=darray.dtype)
235 |
236 | il_dip *= dip_factor
237 | xl_dip *= dip_factor
238 | il_dip[da.isnan(il_dip)] = 0
239 | xl_dip[da.isnan(xl_dip)] = 0
240 |
241 | return(il_dip, xl_dip)
242 |
243 |
244 | def gst_3D_dip(self, darray, dip_factor=10, kernel=(3,3,3), preview=None):
245 | """
246 | Description
247 | -----------
248 | Compute 3D Dip from the Gradient Structure Tensor
249 |
250 | Parameters
251 | ----------
252 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
253 |
254 | Keywork Arguments
255 | -----------------
256 | dip_factor : Number, scalar for dip values
257 | kernel : tuple (len 3), operator size
258 | preview : str, enables or disables preview mode and specifies direction
259 | Acceptable inputs are (None, 'inline', 'xline', 'z')
260 | Optimizes chunk size in different orientations to facilitate rapid
261 | screening of algorithm output
262 |
263 | Returns
264 | -------
265 | result : Dask Array, dip in degrees
266 | """
267 |
268 | # Function to compute 3D dip from GST
269 | def operation(gi2, gj2, gk2, gigj, gigk, gjgk, axis):
270 | np.seterr(all='ignore')
271 |
272 | shape = gi2.shape
273 |
274 | gst = np.array([[gi2, gigj, gigk],
275 | [gigj, gj2, gjgk],
276 | [gigk, gjgk, gk2]])
277 |
278 | gst = np.moveaxis(gst, [0,1], [-2,-1])
279 | gst = gst.reshape((-1, 3, 3))
280 |
281 | evals, evecs = np.linalg.eigh(gst)
282 | ndx = evals.argsort()
283 | evecs = evecs[np.arange(0,gst.shape[0],1),:,ndx[:,2]]
284 |
285 | norm_factor = np.linalg.norm(evecs, axis = -1)
286 | evecs[:, 0] /= norm_factor
287 | evecs[:, 1] /= norm_factor
288 | evecs[:, 2] /= norm_factor
289 |
290 | evecs[evecs[:, 2] < 0] *= np.sign(evecs[evecs[:, 2] < 0])
291 |
292 | dip = np.dot(evecs, np.array([0,0,1]))
293 | dip = np.arccos(dip)
294 | dip = dip.reshape(shape)
295 |
296 | dip = np.rad2deg(dip)# - 90
297 |
298 | return(dip)
299 |
300 | # Compute Inner Product of Gradients and Dips
301 | gi2, gj2, gk2, gigj, gigk, gjgk = self.gradient_structure_tensor(darray, kernel,
302 | preview=preview)
303 | result = da.map_blocks(operation, gi2, gj2, gk2, gigj, gigk, gjgk, axis=0,
304 | dtype=darray.dtype)
305 | result[da.isnan(result)] = 0
306 |
307 | return(result)
308 |
309 |
310 | def gst_3D_azm(self, darray, dip_factor=10, kernel=(3,3,3), preview=None):
311 | """
312 | Description
313 | -----------
314 | Compute 3D Azimuth from the Gradient Structure Tensor
315 |
316 | Parameters
317 | ----------
318 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
319 |
320 | Keywork Arguments
321 | -----------------
322 | dip_factor : Number, scalar for dip values
323 | kernel : tuple (len 3), operator size
324 | preview : str, enables or disables preview mode and specifies direction
325 | Acceptable inputs are (None, 'inline', 'xline', 'z')
326 | Optimizes chunk size in different orientations to facilitate rapid
327 | screening of algorithm output
328 |
329 | Returns
330 | -------
331 | result : Dask Array, azimuth in degrees
332 | """
333 |
334 | # Function to compute 3D azimuth from GST
335 | def operation(gi2, gj2, gk2, gigj, gigk, gjgk, axis):
336 | np.seterr(all='ignore')
337 |
338 | shape = gi2.shape
339 |
340 | gst = np.array([[gi2, gigj, gigk],
341 | [gigj, gj2, gjgk],
342 | [gigk, gjgk, gk2]])
343 |
344 | gst = np.moveaxis(gst, [0,1], [-2,-1])
345 | gst = gst.reshape((-1, 3, 3))
346 |
347 | evals, evecs = np.linalg.eigh(gst)
348 | ndx = evals.argsort()
349 | evecs = evecs[np.arange(0,gst.shape[0],1),:,ndx[:,2]]
350 |
351 | norm_factor = np.linalg.norm(evecs, axis = -1)
352 | evecs[:, 0] /= norm_factor
353 | evecs[:, 1] /= norm_factor
354 | evecs[:, 2] /= norm_factor
355 |
356 | evecs[evecs[:, 2] < 0] *= np.sign(evecs[evecs[:, 2] < 0])
357 |
358 | azm = np.arctan2(evecs[:, 0], evecs[:, 1])
359 | azm = azm.reshape(shape)
360 | azm = np.rad2deg(azm)
361 | azm[azm < 0] += 360
362 |
363 | return(azm)
364 |
365 | # Compute Inner Product of Gradients and Azimuth
366 | gi2, gj2, gk2, gigj, gigk, gjgk = self.gradient_structure_tensor(darray, kernel,
367 | preview=preview)
368 | result = da.map_blocks(operation, gi2, gj2, gk2, gigj, gigk, gjgk, axis=0,
369 | dtype=darray.dtype)
370 | result[da.isnan(result)] = 0
371 |
372 | return(result)
373 |
--------------------------------------------------------------------------------
/d2geo/attributes/EdgeDetection.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Edge Detection Attributes for Seismic Data
4 |
5 | @author: Braden Fitz-Gerald
6 | @email: braden.fitzgerald@gmail.com
7 |
8 | """
9 |
10 | # Import Libraries
11 |
12 | import dask.array as da
13 | import numpy as np
14 | from scipy import ndimage as ndi
15 | import util
16 | from SignalProcess import SignalProcess as sp
17 |
18 |
19 |
20 | class EdgeDetection():
21 | """
22 | Description
23 | -----------
24 | Class object containing methods for computing edge attributes
25 | from 3D seismic data.
26 |
27 | Methods
28 | -------
29 | create_array
30 | semblance
31 | eig_complex
32 | gradient_structure_tensor
33 | chaos
34 | volume_curvature
35 | """
36 |
37 | def create_array(self, darray, kernel, preview):
38 | """
39 | Description
40 | -----------
41 | Convert input to Dask Array with ideal chunk size as necessary. Perform
42 | necessary ghosting as needed for opertations utilizing windowed functions.
43 |
44 | Parameters
45 | ----------
46 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
47 |
48 | Keywork Arguments
49 | -----------------
50 | kernel : tuple (len 3), operator size
51 | preview : str, enables or disables preview mode and specifies direction
52 | Acceptable inputs are (None, 'inline', 'xline', 'z')
53 | Optimizes chunk size in different orientations to facilitate rapid
54 | screening of algorithm output
55 |
56 | Returns
57 | -------
58 | darray : Dask Array
59 | chunk_init : tuple (len 3), chunk size before ghosting. Used in select cases
60 | """
61 |
62 | # Compute chunk size and convert if not a Dask Array
63 | if not isinstance(darray, da.core.Array):
64 | chunk_size = util.compute_chunk_size(darray.shape,
65 | darray.dtype.itemsize,
66 | kernel=kernel,
67 | preview=preview)
68 | darray = da.from_array(darray, chunks=chunk_size)
69 | chunks_init = darray.chunks
70 |
71 | else:
72 | chunks_init = darray.chunks
73 |
74 | # Ghost Dask Array if operation specifies a kernel
75 | if kernel != None:
76 | hw = tuple(np.array(kernel) // 2)
77 | darray = da.overlap.overlap(darray, depth=hw, boundary='reflect')
78 |
79 | return(darray, chunks_init)
80 |
81 |
82 | def semblance(self, darray, kernel=(3,3,9), preview=None):
83 | """
84 | Description
85 | -----------
86 | Compute multi-trace semblance from 3D seismic
87 |
88 | Parameters
89 | ----------
90 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
91 |
92 | Keywork Arguments
93 | -----------------
94 | kernel : tuple (len 3), operator size
95 | preview : str, enables or disables preview mode and specifies direction
96 | Acceptable inputs are (None, 'inline', 'xline', 'z')
97 | Optimizes chunk size in different orientations to facilitate rapid
98 | screening of algorithm output
99 |
100 | Returns
101 | -------
102 | result : Dask Array
103 | """
104 |
105 | # Function to extract patches and perform algorithm
106 | def operation(chunk, kernel):
107 | np.seterr(all='ignore')
108 | x = util.extract_patches(chunk, kernel)
109 | s1 = np.sum(x, axis=(-3,-2)) ** 2
110 | s2 = np.sum(x ** 2, axis=(-3,-2))
111 | sembl = s1.sum(axis = -1) / s2.sum(axis = -1)
112 | sembl /= kernel[0] * kernel[1]
113 | return(sembl)
114 |
115 | # Generate Dask Array as necessary and perform algorithm
116 | darray, chunks_init = self.create_array(darray, kernel, preview)
117 | result = darray.map_blocks(operation, kernel=kernel, dtype=darray.dtype, chunks=chunks_init)
118 | result[da.isnan(result)] = 0
119 |
120 | return(result)
121 |
122 |
123 |
124 | def gradient_structure_tensor(self, darray, kernel=(3,3,9), preview=None):
125 | """
126 | Description
127 | -----------
128 | Compute discontinuity from eigenvalues of gradient structure tensor
129 |
130 | Parameters
131 | ----------
132 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
133 |
134 | Keywork Arguments
135 | -----------------
136 | kernel : tuple (len 3), operator size
137 | preview : str, enables or disables preview mode and specifies direction
138 | Acceptable inputs are (None, 'inline', 'xline', 'z')
139 | Optimizes chunk size in different orientations to facilitate rapid
140 | screening of algorithm output
141 |
142 | Returns
143 | -------
144 | result : Dask Array
145 | """
146 |
147 | # Function to extract patches and perform algorithm
148 | def operation(gi2, gj2, gk2, gigj, gigk, gjgk):
149 | np.seterr(all='ignore')
150 |
151 | chunk_shape = gi2.shape
152 |
153 | gst = np.array([[gi2, gigj, gigk],
154 | [gigj, gj2, gjgk],
155 | [gigk, gjgk, gk2]])
156 |
157 | gst = np.moveaxis(gst, [0,1], [-2,-1])
158 | gst = gst.reshape((-1, 3, 3))
159 |
160 | eigs = np.sorgst(np.linalg.eigvalsh(gst))
161 | e1 = eigs[:, 2].reshape(chunk_shape)
162 | e2 = eigs[:, 1].reshape(chunk_shape)
163 | e3 = eigs[:, 0].reshape(chunk_shape)
164 |
165 | # Compute cvals from Eigenvalues
166 | cline = (e2 - e3) / (e2 + e3)
167 | cplane = (e1 - e2) / (e1 + e2)
168 | cfault = cline * (1 - cplane)
169 |
170 | return(cfault)
171 |
172 | # Generate Dask Array as necessary
173 | darray, chunks_init = self.create_array(darray, kernel, preview)
174 |
175 | # Compute I, J, K gradients
176 | gi = sp().first_derivative(darray, axis=0)
177 | gj = sp().first_derivative(darray, axis=1)
178 | gk = sp().first_derivative(darray, axis=2)
179 |
180 | # Compute the Inner Product of the Gradients
181 | gi2 = (gi * gi).map_blocks(ndi.uniform_filter, size=kernel, dtype=darray.dtype)
182 | gj2 = (gj * gj).map_blocks(ndi.uniform_filter, size=kernel, dtype=darray.dtype)
183 | gk2 = (gk * gk).map_blocks(ndi.uniform_filter, size=kernel, dtype=darray.dtype)
184 | gigj = (gi * gj).map_blocks(ndi.uniform_filter, size=kernel, dtype=darray.dtype)
185 | gigk = (gi * gk).map_blocks(ndi.uniform_filter, size=kernel, dtype=darray.dtype)
186 | gjgk = (gj * gk).map_blocks(ndi.uniform_filter, size=kernel, dtype=darray.dtype)
187 |
188 | result = da.map_blocks(operation, gi2, gj2, gk2, gigj, gigk, gjgk,
189 | dtype=darray.dtype)
190 | result = util.trim_dask_array(result, kernel)
191 | result[da.isnan(result)] = 0
192 |
193 | return(result)
194 |
195 |
196 | def eig_complex(self, darray, kernel=(3,3,9), preview=None):
197 | """
198 | Description
199 | -----------
200 | Compute multi-trace semblance from 3D seismic incorporating the
201 | analytic trace
202 |
203 | Parameters
204 | ----------
205 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
206 |
207 | Keywork Arguments
208 | -----------------
209 | kernel : tuple (len 3), operator size
210 | preview : str, enables or disables preview mode and specifies direction
211 | Acceptable inputs are (None, 'inline', 'xline', 'z')
212 | Optimizes chunk size in different orientations to facilitate rapid
213 | screening of algorithm output
214 |
215 | Returns
216 | -------
217 | result : Dask Array
218 | """
219 |
220 | # Function to compute the COV
221 | def cov(x, ki, kj, kk):
222 | x = x.reshape((ki * kj, kk))
223 | x = np.hstack([x.real, x.imag])
224 | return(x.dot(x.T))
225 |
226 | # Function to extract patches and perform algorithm
227 | def operation(chunk, kernel):
228 | np.seterr(all='ignore')
229 | ki, kj, kk = kernel
230 | patches = util.extract_patches(chunk, kernel)
231 |
232 | out_data = []
233 | for i in range(0, patches.shape[0]):
234 | traces = patches[i]
235 | traces = traces.reshape(-1, ki * kj * kk)
236 | cov = np.apply_along_axis(cov, 1, traces, ki, kj, kk)
237 | vals = np.linalg.eigvals(cov)
238 | vals = np.abs(vals.max(axis=1) / vals.sum(axis=1))
239 |
240 | out_data.append(vals)
241 |
242 | out_data = np.asarray(out_data).reshape(patches.shape[:3])
243 |
244 | return(out_data)
245 |
246 | # Generate Dask Array as necessary and perform algorithm
247 | darray, chunks_init = self.create_array(darray, kernel, preview)
248 | hilbert = darray.map_blocks(util.hilbert, dtype=darray.dtype)
249 | result = hilbert.map_blocks(operation, kernel=kernel, dtype=darray.dtype)
250 | result = util.trim_dask_array(result, kernel)
251 | result[da.isnan(result)] = 0
252 |
253 | return(result)
254 |
255 |
256 | def chaos(self, darray, kernel=(3,3,9), preview=None):
257 | """
258 | Description
259 | -----------
260 | Compute multi-trace chaos from 3D seismic
261 |
262 | Parameters
263 | ----------
264 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
265 |
266 | Keywork Arguments
267 | -----------------
268 | kernel : tuple (len 3), operator size
269 | preview : str, enables or disables preview mode and specifies direction
270 | Acceptable inputs are (None, 'inline', 'xline', 'z')
271 | Optimizes chunk size in different orientations to facilitate rapid
272 | screening of algorithm output
273 |
274 | Returns
275 | -------
276 | result : Dask Array
277 | """
278 |
279 | # Function to extract patches and perform algorithm
280 | def operation(gi2, gj2, gk2, gigj, gigk, gjgk):
281 | np.seterr(all='ignore')
282 |
283 | chunk_shape = gi2.shape
284 |
285 | gst = np.array([[gi2, gigj, gigk],
286 | [gigj, gj2, gjgk],
287 | [gigk, gjgk, gk2]])
288 |
289 | gst = np.moveaxis(gst, [0,1], [-2,-1])
290 | gst = gst.reshape((-1, 3, 3))
291 |
292 | eigs = np.sort(np.linalg.eigvalsh(gst))
293 | e1 = eigs[:, 2].reshape(chunk_shape)
294 | e2 = eigs[:, 1].reshape(chunk_shape)
295 | e3 = eigs[:, 0].reshape(chunk_shape)
296 |
297 | out = (2 * e2) / (e1 + e3)
298 |
299 | return(out)
300 |
301 | # Generate Dask Array as necessary
302 | darray, chunks_init = self.create_array(darray, kernel, preview)
303 |
304 | # Compute I, J, K gradients
305 | gi = sp().first_derivative(darray, axis=0)
306 | gj = sp().first_derivative(darray, axis=1)
307 | gk = sp().first_derivative(darray, axis=2)
308 |
309 | # Compute the Inner Product of the Gradients
310 | gi2 = (gi * gi).map_blocks(ndi.uniform_filter, size=kernel, dtype=darray.dtype)
311 | gj2 = (gj * gj).map_blocks(ndi.uniform_filter, size=kernel, dtype=darray.dtype)
312 | gk2 = (gk * gk).map_blocks(ndi.uniform_filter, size=kernel, dtype=darray.dtype)
313 | gigj = (gi * gj).map_blocks(ndi.uniform_filter, size=kernel, dtype=darray.dtype)
314 | gigk = (gi * gk).map_blocks(ndi.uniform_filter, size=kernel, dtype=darray.dtype)
315 | gjgk = (gj * gk).map_blocks(ndi.uniform_filter, size=kernel, dtype=darray.dtype)
316 |
317 | result = da.map_blocks(operation, gi2, gj2, gk2, gigj, gigk, gjgk,
318 | dtype=darray.dtype)
319 | result = util.trim_dask_array(result, kernel)
320 | result[da.isnan(result)] = 0
321 |
322 | return(result)
323 |
324 |
325 | def volume_curvature(self, darray_il, darray_xl, dip_factor=10, kernel=(3,3,3),
326 | preview=None):
327 | """
328 | Description
329 | -----------
330 | Compute volume curvature attributes from 3D seismic dips
331 |
332 | Parameters
333 | ----------
334 | darray_il : Array-like, Inline dip - acceptable inputs include
335 | Numpy, HDF5, or Dask Arrays
336 | darray_xl : Array-like, Crossline dip - acceptable inputs include
337 | Numpy, HDF5, or Dask Arrays
338 |
339 | Keywork Arguments
340 | -----------------
341 | dip_factor : Number, scalar for dip values
342 | kernel : tuple (len 3), operator size
343 | preview : str, enables or disables preview mode and specifies direction
344 | Acceptable inputs are (None, 'inline', 'xline', 'z')
345 | Optimizes chunk size in different orientations to facilitate rapid
346 | screening of algorithm output
347 |
348 | Returns
349 | -------
350 | H, K, Kmax, Kmin, KMPos, KMNeg : Dask Array, {H : 'Mean Curvature',
351 | K : 'Gaussian Curvature',
352 | Kmax : 'Max Curvature',
353 | Kmin : 'Min Curvature',
354 | KMPos : Most Positive Curvature,
355 | KMNeg : Most Negative Curvature}
356 | """
357 |
358 | np.seterr(all='ignore')
359 |
360 | # Generate Dask Array as necessary
361 | darray_il, chunks_init = self.create_array(darray_il, kernel, preview=preview)
362 | darray_xl, chunks_init = self.create_array(darray_xl, kernel, preview=preview)
363 |
364 | u = -darray_il / dip_factor
365 | v = -darray_xl / dip_factor
366 | w = da.ones_like(u, chunks=u.chunks)
367 |
368 | # Compute Gradients
369 | ux = sp().first_derivative(u, axis=0)
370 | uy = sp().first_derivative(u, axis=1)
371 | uz = sp().first_derivative(u, axis=2)
372 | vx = sp().first_derivative(v, axis=0)
373 | vy = sp().first_derivative(v, axis=1)
374 | vz = sp().first_derivative(v, axis=2)
375 |
376 | # Smooth Gradients
377 | ux = ux.map_blocks(ndi.uniform_filter, size=kernel, dtype=ux.dtype)
378 | uy = uy.map_blocks(ndi.uniform_filter, size=kernel, dtype=ux.dtype)
379 | uz = uz.map_blocks(ndi.uniform_filter, size=kernel, dtype=ux.dtype)
380 | vx = vx.map_blocks(ndi.uniform_filter, size=kernel, dtype=ux.dtype)
381 | vy = vy.map_blocks(ndi.uniform_filter, size=kernel, dtype=ux.dtype)
382 | vz = vz.map_blocks(ndi.uniform_filter, size=kernel, dtype=ux.dtype)
383 |
384 | u = util.trim_dask_array(u, kernel)
385 | v = util.trim_dask_array(v, kernel)
386 | w = util.trim_dask_array(w, kernel)
387 | ux = util.trim_dask_array(ux, kernel)
388 | uy = util.trim_dask_array(uy, kernel)
389 | uz = util.trim_dask_array(uz, kernel)
390 | vx = util.trim_dask_array(vx, kernel)
391 | vy = util.trim_dask_array(vy, kernel)
392 | vz = util.trim_dask_array(vz, kernel)
393 |
394 | wx = da.zeros_like(ux, chunks=ux.chunks, dtype=ux.dtype)
395 | wy = da.zeros_like(ux, chunks=ux.chunks, dtype=ux.dtype)
396 | wz = da.zeros_like(ux, chunks=ux.chunks, dtype=ux.dtype)
397 |
398 | uv = u * v
399 | vw = v * w
400 | u2 = u * u
401 | v2 = v * v
402 | w2 = w * w
403 | u2pv2 = u2 + v2
404 | v2pw2 = v2 + w2
405 | s = da.sqrt(u2pv2 + w2)
406 |
407 | # Measures of surfaces
408 | E = da.ones_like(u, chunks=u.chunks, dtype=u.dtype)
409 | F = -(u * w) / (da.sqrt(u2pv2) * da.sqrt(v2pw2))
410 | G = da.ones_like(u, chunks=u.chunks, dtype=u.dtype)
411 | D = -(-uv * vx+u2 * vy + v2 * ux - uv * uy) / (u2pv2 * s)
412 | Di = -(vw * (uy + vx) - 2 * u * w * vy - v2 * (uz + wx) + uv * (vz + wy)) / (2 * da.sqrt(u2pv2) * da.sqrt(v2pw2) * s)
413 | Dii = -(-vw * wy + v2 * wz + w2 * vy - vw * vz) / (v2pw2 *s)
414 | H = (E * Dii - 2 * F *Di + G * D) / (2 * (E * G - F * F))
415 | K = (D * Dii - Di * Di) / (E * G - F * F)
416 | Kmin = H - da.sqrt(H * H - K)
417 | Kmax = H + da.sqrt(H * H - K)
418 |
419 | H[da.isnan(H)] = 0
420 | K[da.isnan(K)] = 0
421 | Kmax[da.isnan(Kmax)] = 0
422 | Kmin[da.isnan(Kmin)] = 0
423 |
424 | KMPos = da.maximum(Kmax, Kmin)
425 | KMNeg = da.minimum(Kmax, Kmin)
426 |
427 | return(H, K, Kmax, Kmin, KMPos, KMNeg)
428 |
--------------------------------------------------------------------------------
/d2geo/attributes/Frequency.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Frequency attributes for Seismic data
4 |
5 | @author: Braden Fitz-Gerald
6 | @email: braden.fitzgerald@gmail.com
7 |
8 | """
9 |
10 | # Import Libraries
11 | import dask.array as da
12 | import numpy as np
13 | from scipy import signal
14 | import util
15 |
16 |
17 |
18 | class Frequency():
19 | """
20 | Description
21 | -----------
22 | Class object containing methods for performing frequency filtering
23 |
24 | Methods
25 | -------
26 | create_array
27 | lowpass_filter
28 | highpass_filter
29 | bandpass_filter
30 | cwt_ricker
31 | cwt_ormsby
32 | """
33 |
34 | def create_array(self, darray, kernel, preview):
35 | """
36 | Description
37 | -----------
38 | Convert input to Dask Array with ideal chunk size as necessary. Perform
39 | necessary ghosting as needed for opertations utilizing windowed functions.
40 |
41 | Parameters
42 | ----------
43 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
44 |
45 | Keywork Arguments
46 | -----------------
47 | kernel : tuple (len 3), operator size
48 | preview : str, enables or disables preview mode and specifies direction
49 | Acceptable inputs are (None, 'inline', 'xline', 'z')
50 | Optimizes chunk size in different orientations to facilitate rapid
51 | screening of algorithm output
52 |
53 | Returns
54 | -------
55 | darray : Dask Array
56 | chunk_init : tuple (len 3), chunk size before ghosting. Used in select cases
57 | """
58 |
59 | # Compute chunk size and convert if not a Dask Array
60 | if not isinstance(darray, da.core.Array):
61 | chunk_size = util.compute_chunk_size(darray.shape,
62 | darray.dtype.itemsize,
63 | kernel=kernel,
64 | preview=preview)
65 | darray = da.from_array(darray, chunks=chunk_size)
66 | chunks_init = darray.chunks
67 |
68 | else:
69 | chunks_init = darray.chunks
70 |
71 | # Ghost Dask Array if operation specifies a kernel
72 | if kernel != None:
73 | hw = tuple(np.array(kernel) // 2)
74 | darray = da.ghost.ghost(darray, depth=hw, boundary='reflect')
75 |
76 | return(darray, chunks_init)
77 |
78 |
79 | def lowpass_filter(self, darray, freq, sample_rate=4, preview=None):
80 | """
81 | Description
82 | -----------
83 | Perform low pass filtering of 3D seismic data
84 |
85 | Parameters
86 | ----------
87 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
88 | freq : Number (Hz), frequency cutoff used in filter
89 |
90 | Keywork Arguments
91 | -----------------
92 | sample_rate : Number, sample rate in milliseconds (ms)
93 | preview : str, enables or disables preview mode and specifies direction
94 | Acceptable inputs are (None, 'inline', 'xline', 'z')
95 | Optimizes chunk size in different orientations to facilitate rapid
96 | screening of algorithm output
97 |
98 | Returns
99 | -------
100 | result : Dask Array
101 | """
102 |
103 | # Filtering Function
104 | def filt(chunk, B, A):
105 |
106 | out = signal.filtfilt(B, A, x=chunk)
107 |
108 | return(out)
109 |
110 | # Generate Dask Array as necessary and perform algorithm
111 | darray, chunks_init = self.create_array(darray, kernel=None,
112 | preview=preview)
113 | fs = 1000 / sample_rate
114 | nyq = fs * 0.5
115 | B, A = signal.butter(6, freq/nyq, btype='lowpass', analog=False)
116 | result = darray.map_blocks(filt, B, A, dtype=darray.dtype)
117 |
118 | return(result)
119 |
120 | def highpass_filter(self, darray, freq, sample_rate=4, preview=None):
121 | """
122 | Description
123 | -----------
124 | Perform high pass filtering of 3D seismic data
125 |
126 | Parameters
127 | ----------
128 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
129 | freq : Number (Hz), frequency cutoff used in filter
130 |
131 | Keywork Arguments
132 | -----------------
133 | sample_rate : Number, sample rate in milliseconds (ms)
134 | preview : str, enables or disables preview mode and specifies direction
135 | Acceptable inputs are (None, 'inline', 'xline', 'z')
136 | Optimizes chunk size in different orientations to facilitate rapid
137 | screening of algorithm output
138 |
139 | Returns
140 | -------
141 | result : Dask Array
142 | """
143 |
144 | # Filtering Function
145 | def filt(chunk, B, A):
146 |
147 | out = signal.filtfilt(B, A, x=chunk)
148 |
149 | return(out)
150 |
151 | # Generate Dask Array as necessary and perform algorithm
152 | darray, chunks_init = self.create_array(darray, kernel=None,
153 | preview=preview)
154 | fs = 1000 / sample_rate
155 | nyq = fs * 0.5
156 | B, A = signal.butter(6, freq/nyq, btype='highpass', analog=False)
157 | result = darray.map_blocks(filt, B, A, dtype=darray.dtype)
158 |
159 | return(result)
160 |
161 |
162 | def bandpass_filter(self, darray, freq_lp, freq_hp, sample_rate=4, preview=None):
163 | """
164 | Description
165 | -----------
166 | Perform bandpass filtering of 3D seismic data
167 |
168 | Parameters
169 | ----------
170 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
171 | freq_lp : Number (Hz), frequency cutoff used in low pass filter
172 | freq_hp : Number (Hz), frequency cutoff used in high pass filter
173 |
174 | Keywork Arguments
175 | -----------------
176 | sample_rate : Number, sample rate in milliseconds (ms)
177 | preview : str, enables or disables preview mode and specifies direction
178 | Acceptable inputs are (None, 'inline', 'xline', 'z')
179 | Optimizes chunk size in different orientations to facilitate rapid
180 | screening of algorithm output
181 |
182 | Returns
183 | -------
184 | result : Dask Array
185 | """
186 |
187 | # Filtering Function
188 | def filt(chunk, B, A):
189 |
190 | out = signal.filtfilt(B, A, x=chunk)
191 |
192 | return(out)
193 |
194 | # Generate Dask Array as necessary and perform algorithm
195 | darray, chunks_init = self.create_array(darray, kernel=None,
196 | preview=preview)
197 | fs = 1000 / sample_rate
198 | nyq = fs * 0.5
199 | B, A = signal.butter(6, (freq_lp/nyq, freq_hp/nyq), btype='bandpass', analog=False)
200 | result = darray.map_blocks(filt, B, A, dtype=darray.dtype)
201 |
202 | return(result)
203 |
204 |
205 | def cwt_ricker(self, darray, freq, sample_rate=4, preview=None):
206 | """
207 | Description
208 | -----------
209 | Perform Continuous Wavelet Transform using Ricker Wavelet
210 |
211 | Parameters
212 | ----------
213 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
214 | freq : Number (Hz), frequency defining Ricker Wavelet
215 |
216 | Keywork Arguments
217 | -----------------
218 | sample_rate : Number, sample rate in milliseconds (ms)
219 | preview : str, enables or disables preview mode and specifies direction
220 | Acceptable inputs are (None, 'inline', 'xline', 'z')
221 | Optimizes chunk size in different orientations to facilitate rapid
222 | screening of algorithm output
223 |
224 | Returns
225 | -------
226 | result : Dask Array
227 | """
228 |
229 | # Generate wavelet of specified frequency
230 | def wavelet(freq, sample_rate):
231 |
232 | sr = sample_rate / 1000
233 | t = np.arange(-0.512 / 2, 0.512 / 2, sr)
234 | out = (1 - (2 * (np.pi * freq * t) ** 2)) * np.exp(-(np.pi * freq * t) ** 2)
235 |
236 | return(out)
237 |
238 | # Convolve wavelet with trace
239 | def convolve(chunk, w):
240 |
241 | out = np.zeros(chunk.shape)
242 |
243 | for i,j in np.ndindex(chunk.shape[:-1]):
244 | out[i, j] = signal.fftconvolve(chunk[i, j], w, mode='same')
245 |
246 | return(out)
247 |
248 | # Generate Dask Array as necessary and perform algorithm
249 | darray, chunks_init = self.create_array(darray, kernel=None,
250 | preview=preview)
251 | w = wavelet(freq, sample_rate)
252 | result = darray.map_blocks(convolve, w=w, dtype=darray.dtype)
253 |
254 | return(result)
255 |
256 |
257 | def cwt_ormsby(self, darray, freqs, sample_rate=4, preview=None):
258 | """
259 | Description
260 | -----------
261 | Perform Continuous Wavelet Transform using Ormsby Wavelet
262 |
263 | Parameters
264 | ----------
265 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
266 | freq : tuple (len 4), frequency cutoff used in filter
267 |
268 | Keywork Arguments
269 | -----------------
270 | sample_rate : Number, sample rate in milliseconds (ms)
271 | preview : str, enables or disables preview mode and specifies direction
272 | Acceptable inputs are (None, 'inline', 'xline', 'z')
273 | Optimizes chunk size in different orientations to facilitate rapid
274 | screening of algorithm output
275 |
276 | Returns
277 | -------
278 | result : Dask Array
279 | """
280 | # Generate wavelet of specified frequencyies
281 | def wavelet(freqs, sample_rate):
282 |
283 | f1, f2, f3, f4 = freqs
284 | sr = sample_rate / 1000
285 | t = np.arange(-0.512 / 2, 0.512 / 2, sr)
286 |
287 | term1 = (((np.pi * f4) ** 2) / ((np.pi * f4) - (np.pi * f3))) * np.sinc(np.pi * f4 * t) ** 2
288 | term2 = (((np.pi * f3) ** 2) / ((np.pi * f4) - (np.pi * f3))) * np.sinc(np.pi * f3 * t) ** 2
289 | term3 = (((np.pi * f2) ** 2) / ((np.pi * f2) - (np.pi * f1))) * np.sinc(np.pi * f2 * t) ** 2
290 | term4 = (((np.pi * f1) ** 2) / ((np.pi * f2) - (np.pi * f1))) * np.sinc(np.pi * f1 * t) ** 2
291 |
292 | out = (term1 - term2) - (term3 - term4)
293 |
294 | return(out)
295 |
296 | # Convolve wavelet with trace
297 | def convolve(chunk, w):
298 |
299 | out = np.zeros(chunk.shape)
300 |
301 | for i,j in np.ndindex(chunk.shape[:-1]):
302 | out[i, j] = signal.fftconvolve(chunk[i, j], w, mode='same')
303 |
304 | return(out)
305 |
306 | # Generate Dask Array as necessary and perform algorithm
307 | darray, chunks_init = self.create_array(darray, kernel=None,
308 | preview=preview)
309 | w = wavelet(freqs, sample_rate)
310 | result = darray.map_blocks(convolve, w=w, dtype=darray.dtype)
311 |
312 | return(result)
--------------------------------------------------------------------------------
/d2geo/attributes/NoiseReduction.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Noise Reduction attributes for Seismic Data
4 |
5 | @author: Braden Fitz-Gerald
6 | @email: braden.fitzgerald@gmail.com
7 |
8 | """
9 |
10 | # Import Libraries
11 | import dask.array as da
12 | import numpy as np
13 | from scipy import ndimage as ndi
14 | import util
15 |
16 |
17 |
18 | class NoiseReduction():
19 | """
20 | Description
21 | -----------
22 | Class object containing methods for reducing noise in 3D seismic
23 |
24 | Methods
25 | -------
26 | create_array
27 | gaussian
28 | median
29 | convolution
30 | """
31 |
32 | def create_array(self, darray, kernel, preview):
33 | """
34 | Description
35 | -----------
36 | Convert input to Dask Array with ideal chunk size as necessary. Perform
37 | necessary ghosting as needed for opertations utilizing windowed functions.
38 |
39 | Parameters
40 | ----------
41 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
42 |
43 | Keywork Arguments
44 | -----------------
45 | kernel : tuple (len 3), operator size
46 | preview : str, enables or disables preview mode and specifies direction
47 | Acceptable inputs are (None, 'inline', 'xline', 'z')
48 | Optimizes chunk size in different orientations to facilitate rapid
49 | screening of algorithm output
50 |
51 | Returns
52 | -------
53 | darray : Dask Array
54 | chunk_init : tuple (len 3), chunk size before ghosting. Used in select cases
55 | """
56 |
57 | # Compute chunk size and convert if not a Dask Array
58 | if not isinstance(darray, da.core.Array):
59 | chunk_size = util.compute_chunk_size(darray.shape,
60 | darray.dtype.itemsize,
61 | kernel=kernel,
62 | preview=preview)
63 | darray = da.from_array(darray, chunks=chunk_size)
64 | chunks_init = darray.chunks
65 |
66 | else:
67 | chunks_init = darray.chunks
68 |
69 | # Ghost Dask Array if operation specifies a kernel
70 | if kernel != None:
71 | hw = tuple(np.array(kernel) // 2)
72 | darray = da.ghost.ghost(darray, depth=hw, boundary='reflect')
73 |
74 | return(darray, chunks_init)
75 |
76 |
77 | def gaussian(self, darray, sigmas=(1, 1, 1), preview=None):
78 | """
79 | Description
80 | -----------
81 | Perform gaussian smoothing of input seismic
82 |
83 | Parameters
84 | ----------
85 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
86 |
87 | Keywork Arguments
88 | -----------------
89 | sigmas : tuple (len 3), smoothing parameters in I, J, K
90 | preview : str, enables or disables preview mode and specifies direction
91 | Acceptable inputs are (None, 'inline', 'xline', 'z')
92 | Optimizes chunk size in different orientations to facilitate rapid
93 | screening of algorithm output
94 |
95 | Returns
96 | -------
97 | result : Dask Array
98 | """
99 |
100 | # Generate Dask Array as necessary and perform algorithm
101 | kernel = tuple((np.array(sigmas) * 2.5).astype(int))
102 | darray, chunks_init = self.create_array(darray, kernel, preview=preview)
103 | result = darray.map_blocks(ndi.gaussian_filter, sigma=sigmas, dtype=darray.dtype)
104 | result = util.trim_dask_array(result, kernel)
105 | result[da.isnan(result)] = 0
106 |
107 | return(result)
108 |
109 |
110 | def median(self, darray, kernel=(3, 3, 3), preview=None):
111 | """
112 | Description
113 | -----------
114 | Perform median smoothing of input seismic data
115 |
116 | Parameters
117 | ----------
118 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
119 |
120 | Keywork Arguments
121 | -----------------
122 | kernel : tuple (len 3), operator size in I, J, K
123 | preview : str, enables or disables preview mode and specifies direction
124 | Acceptable inputs are (None, 'inline', 'xline', 'z')
125 | Optimizes chunk size in different orientations to facilitate rapid
126 | screening of algorithm output
127 |
128 | Returns
129 | -------
130 | result : Dask Array
131 | """
132 |
133 | # Generate Dask Array as necessary and perform algorithm
134 | darray, chunks_init = self.create_array(darray, kernel, preview=preview)
135 | result = darray.map_blocks(ndi.median_filter, size=kernel, dtype=darray.dtype)
136 | result = util.trim_dask_array(result, kernel)
137 | result[da.isnan(result)] = 0
138 |
139 | return(result)
140 |
141 | def convolution(self, darray, kernel=(3, 3, 3), preview=None):
142 | """
143 | Description
144 | -----------
145 | Perform convolution smoothing of input seismic data
146 |
147 | Parameters
148 | ----------
149 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
150 |
151 | Keywork Arguments
152 | -----------------
153 | kernel : tuple (len 3), operator size in I, J, K
154 | preview : str, enables or disables preview mode and specifies direction
155 | Acceptable inputs are (None, 'inline', 'xline', 'z')
156 | Optimizes chunk size in different orientations to facilitate rapid
157 | screening of algorithm output
158 |
159 | Returns
160 | -------
161 | result : Dask Array
162 | """
163 |
164 | # Generate Dask Array as necessary and perform algorithm
165 | darray, chunks_init = self.create_array(darray, kernel, preview=preview)
166 | result = darray.map_blocks(ndi.uniform_filter, size=kernel, dtype=darray.dtype)
167 | result = util.trim_dask_array(result, kernel)
168 | result[da.isnan(result)] = 0
169 |
170 | return(result)
171 |
172 |
--------------------------------------------------------------------------------
/d2geo/attributes/SignalProcess.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Various signal processing attributes for Seismic Data
4 |
5 | @author: Braden Fitz-Gerald
6 | @email: braden.fitzgerald@gmail.com
7 |
8 | """
9 |
10 | # Import Libraries
11 | import dask.array as da
12 | import numpy as np
13 | from scipy import ndimage as ndi
14 | from scipy import signal
15 | import util
16 |
17 |
18 |
19 | class SignalProcess():
20 | """
21 | Description
22 | -----------
23 | Class object containing methods for performing various Signal Processing
24 | algorithms
25 |
26 | Methods
27 | -------
28 | create_array
29 | first_derivative
30 | second_derivative
31 | histogram_equalization
32 | time_gain
33 | rescale_amplitude_range
34 | rms
35 | trace_agc
36 | gradient_magnitude
37 | reflection_intensity
38 | phase_rotation
39 | """
40 |
41 | def create_array(self, darray, kernel, preview):
42 | """
43 | Description
44 | -----------
45 | Convert input to Dask Array with ideal chunk size as necessary. Perform
46 | necessary ghosting as needed for opertations utilizing windowed functions.
47 |
48 | Parameters
49 | ----------
50 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
51 |
52 | Keywork Arguments
53 | -----------------
54 | kernel : tuple (len 3), operator size
55 | preview : str, enables or disables preview mode and specifies direction
56 | Acceptable inputs are (None, 'inline', 'xline', 'z')
57 | Optimizes chunk size in different orientations to facilitate rapid
58 | screening of algorithm output
59 |
60 | Returns
61 | -------
62 | darray : Dask Array
63 | chunk_init : tuple (len 3), chunk size before ghosting. Used in select cases
64 | """
65 |
66 | # Compute chunk size and convert if not a Dask Array
67 | if not isinstance(darray, da.core.Array):
68 | chunk_size = util.compute_chunk_size(darray.shape,
69 | darray.dtype.itemsize,
70 | kernel=kernel,
71 | preview=preview)
72 | darray = da.from_array(darray, chunks=chunk_size)
73 | chunks_init = darray.chunks
74 |
75 | else:
76 | chunks_init = darray.chunks
77 |
78 | # Ghost Dask Array if operation specifies a kernel
79 | if kernel != None:
80 | hw = tuple(np.array(kernel) // 2)
81 | darray = da.ghost.ghost(darray, depth=hw, boundary='reflect')
82 |
83 | return(darray, chunks_init)
84 |
85 |
86 | def first_derivative(self, darray, axis=-1, preview=None):
87 | """
88 | Description
89 | -----------
90 | Compute first derivative of seismic data in specified direction
91 |
92 | Parameters
93 | ----------
94 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
95 |
96 | Keywork Arguments
97 | -----------------
98 | axis : Number, axis dimension
99 | preview : str, enables or disables preview mode and specifies direction
100 | Acceptable inputs are (None, 'inline', 'xline', 'z')
101 | Optimizes chunk size in different orientations to facilitate rapid
102 | screening of algorithm output
103 |
104 | Returns
105 | -------
106 | result : Dask Array
107 | """
108 |
109 | kernel = (3,3,3)
110 | axes = [ax for ax in range(darray.ndim) if ax != axis]
111 | darray, chunks_init = self.create_array(darray, kernel, preview=preview)
112 | result0 = darray.map_blocks(ndi.correlate1d, weights=[-0.5, 0, 0.5],
113 | axis=axis, dtype=darray.dtype)
114 | result1 = result0.map_blocks(ndi.correlate1d, weights=[0.178947,0.642105,0.178947],
115 | axis=axes[0], dtype=darray.dtype)
116 | result2 = result1.map_blocks(ndi.correlate1d, weights=[0.178947,0.642105,0.178947],
117 | axis=axes[1], dtype=darray.dtype)
118 | result = util.trim_dask_array(result2, kernel)
119 |
120 | return(result)
121 |
122 |
123 | def second_derivative(self, darray, axis=-1, preview=None):
124 | """
125 | Description
126 | -----------
127 | Compute second derivative of seismic data in specified direction
128 |
129 | Parameters
130 | ----------
131 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
132 |
133 | Keywork Arguments
134 | -----------------
135 | axis : Number, axis dimension
136 | preview : str, enables or disables preview mode and specifies direction
137 | Acceptable inputs are (None, 'inline', 'xline', 'z')
138 | Optimizes chunk size in different orientations to facilitate rapid
139 | screening of algorithm output
140 |
141 | Returns
142 | -------
143 | result : Dask Array
144 | """
145 |
146 | kernel = (5,5,5)
147 | axes = [ax for ax in range(darray.ndim) if ax != axis]
148 | darray, chunks_init = self.create_array(darray, kernel, preview=preview)
149 | result0 = darray.map_blocks(ndi.correlate1d, weights=[0.232905, 0.002668, -0.471147, 0.002668, 0.232905],
150 | axis=axis, dtype=darray.dtype)
151 | result1 = result0.map_blocks(ndi.correlate1d, weights=[0.030320, 0.249724, 0.439911, 0.249724, 0.030320],
152 | axis=axes[0], dtype=darray.dtype)
153 | result2 = result1.map_blocks(ndi.correlate1d, weights=[0.030320, 0.249724, 0.439911, 0.249724, 0.030320],
154 | axis=axes[1], dtype=darray.dtype)
155 | result = util.trim_dask_array(result2, kernel)
156 |
157 | return(result)
158 |
159 |
160 | def histogram_equalization(self, darray, preview=None):
161 | """
162 | Description
163 | -----------
164 | Perform histogram equalization of seismic data
165 |
166 | Parameters
167 | ----------
168 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
169 |
170 | Keywork Arguments
171 | -----------------
172 | preview : str, enables or disables preview mode and specifies direction
173 | Acceptable inputs are (None, 'inline', 'xline', 'z')
174 | Optimizes chunk size in different orientations to facilitate rapid
175 | screening of algorithm output
176 |
177 | Returns
178 | -------
179 | result : Dask Array
180 | """
181 |
182 | # Function to interpolate seismic to new scaling
183 | def interp(chunk, cdf, bins):
184 |
185 | out = np.interp(chunk.ravel(), bins, cdf)
186 |
187 | return(out.reshape(chunk.shape))
188 |
189 | darray, chunks_init = self.create_array(darray, preview=preview)
190 | hist, bins = da.histogram(darray, bins=np.linspace(darray.min(), darray.max(),
191 | 256, dtype=darray.dtype))
192 | cdf = hist.cumsum(axis=-1)
193 | cdf = cdf / cdf[-1]
194 | bins = (bins[:-1] + bins[1:]) / 2
195 |
196 | result = darray.map_blocks(interp, cdf=cdf, bins=bins, dtype=darray.dtype)
197 |
198 | return(result)
199 |
200 |
201 | def time_gain(self, darray, gain_val=1.5, preview=None):
202 | """
203 | Description
204 | -----------
205 | Gain the amplitudes in the Z/K dimension
206 |
207 | Parameters
208 | ----------
209 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
210 |
211 | Keywork Arguments
212 | -----------------
213 | gain_val : Float, exponential value
214 | preview : str, enables or disables preview mode and specifies direction
215 | Acceptable inputs are (None, 'inline', 'xline', 'z')
216 | Optimizes chunk size in different orientations to facilitate rapid
217 | screening of algorithm output
218 |
219 | Returns
220 | -------
221 | result : Dask Array
222 | """
223 |
224 | darray, chunks_init = self.create_array(darray, preview=preview)
225 | z_ind = da.ones(darray.shape, chunks=darray.chunks).cumsum(axis=-1)
226 | gain = (1 + z_ind) ** gain_val
227 |
228 | result = darray * gain
229 |
230 | return(result)
231 |
232 |
233 |
234 | def rescale_amplitude_range(self, darray, min_val, max_val, preview=None):
235 | """
236 | Description
237 | -----------
238 | Clip the seismic data to specified values
239 |
240 | Parameters
241 | ----------
242 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
243 | min_val : Number, min clip value
244 | max_val : Numer, max clip value
245 |
246 | Keywork Arguments
247 | -----------------
248 | preview : str, enables or disables preview mode and specifies direction
249 | Acceptable inputs are (None, 'inline', 'xline', 'z')
250 | Optimizes chunk size in different orientations to facilitate rapid
251 | screening of algorithm output
252 |
253 | Returns
254 | -------
255 | result : Dask Array
256 | """
257 |
258 | darray, chunks_init = self.create_array(darray, preview=preview)
259 | result = da.clip(darray, min_val, max_val)
260 |
261 | return(result)
262 |
263 |
264 | def rms(self, darray, kernel=(1,1,9), preview=None):
265 | """
266 | Description
267 | -----------
268 | Compute the Root Mean Squared (RMS) value within a specified window
269 |
270 | Parameters
271 | ----------
272 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
273 |
274 | Keywork Arguments
275 | -----------------
276 | kernel : tuple (len 3), operator size
277 | preview : str, enables or disables preview mode and specifies direction
278 | Acceptable inputs are (None, 'inline', 'xline', 'z')
279 | Optimizes chunk size in different orientations to facilitate rapid
280 | screening of algorithm output
281 |
282 | Returns
283 | -------
284 | result : Dask Array
285 | """
286 |
287 | # Function to extract patches and perform algorithm
288 | def operation(chunk, kernel):
289 | x = util.extract_patches(chunk, kernel)
290 | out = np.sqrt(np.mean(x ** 2, axis=(-3, -2, -1)))
291 |
292 | return(out)
293 |
294 | darray, chunks_init = self.create_array(darray, kernel, preview=preview)
295 | result = darray.map_blocks(operation, kernel=kernel, dtype=darray.dtype, chunks=darray.chunks)
296 | result = util.trim_dask_array(result, kernel)
297 | result[da.isnan(result)] = 0
298 |
299 | return(result)
300 |
301 |
302 | def trace_agc(self, darray, kernel=(1,1,9), preview=None):
303 | """
304 | Description
305 | -----------
306 | Apply an adaptive trace gain to input seismic
307 |
308 | Parameters
309 | ----------
310 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
311 |
312 | Keywork Arguments
313 | -----------------
314 | kernel : tuple (len 3), operator size
315 | preview : str, enables or disables preview mode and specifies direction
316 | Acceptable inputs are (None, 'inline', 'xline', 'z')
317 | Optimizes chunk size in different orientations to facilitate rapid
318 | screening of algorithm output
319 |
320 | Returns
321 | -------
322 | result : Dask Array
323 | """
324 |
325 | darray, chunks_init = self.create_array(darray, kernel, preview=preview)
326 | rms = self.rms(darray, kernel)
327 | rms_max = rms.max()
328 | result = darray * (1.5 - (rms / rms_max))
329 | result[da.isnan(result)] = 0
330 |
331 | return(result)
332 |
333 |
334 | def gradient_magnitude(self, darray, sigmas=(1,1,1), preview=None):
335 | """
336 | Description
337 | -----------
338 | Compute the 3D Gradient Magnitude using a Gaussian Operator
339 |
340 | Parameters
341 | ----------
342 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
343 |
344 | Keywork Arguments
345 | -----------------
346 | sigmas : tuple (len 3), gaussian operator in I, J, K
347 | preview : str, enables or disables preview mode and specifies direction
348 | Acceptable inputs are (None, 'inline', 'xline', 'z')
349 | Optimizes chunk size in different orientations to facilitate rapid
350 | screening of algorithm output
351 |
352 | Returns
353 | -------
354 | result : Dask Array
355 | """
356 |
357 | kernel = tuple(2 * (4 * np.array(sigmas) + 0.5).astype(int) + 1)
358 | darray, chunks_init = self.create_array(darray, kernel, preview=preview)
359 | result = darray.map_blocks(ndi.gaussian_gradient_magnitude, sigma=sigmas, dtype=darray.dtype)
360 | result = util.trim_dask_array(result, kernel)
361 | result[da.isnan(result)] = 0
362 |
363 | return(result)
364 |
365 |
366 | def reflection_intensity(self, darray, kernel=(1,1,9), preview=None):
367 | """
368 | Description
369 | -----------
370 | Compute reflection intensity by integrating the trace over a specified window
371 |
372 | Parameters
373 | ----------
374 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
375 |
376 | Keywork Arguments
377 | -----------------
378 | kernel : tuple (len 3), operator size
379 | preview : str, enables or disables preview mode and specifies direction
380 | Acceptable inputs are (None, 'inline', 'xline', 'z')
381 | Optimizes chunk size in different orientations to facilitate rapid
382 | screening of algorithm output
383 |
384 | Returns
385 | -------
386 | result : Dask Array
387 | """
388 |
389 | # Function to extract patches and perform algorithm
390 | def operation(chunk, kernel):
391 | x = util.extract_patches(chunk, (1, 1, kernel[-1]))
392 | out = np.trapz(x).reshape(x.shape[:3])
393 |
394 | return(out)
395 |
396 | darray, chunks_init = self.create_array(darray, kernel, preview=preview)
397 | result = darray.map_blocks(operation, kernel=kernel, dtype=darray.dtype, chunks=chunks_init)
398 | result[da.isnan(result)] = 0
399 |
400 | return(result)
401 |
402 |
403 | def phase_rotation(self, darray, rotation, preview=None):
404 | """
405 | Description
406 | -----------
407 | Rotate the phase of the seismic data by a specified angle
408 |
409 | Parameters
410 | ----------
411 | darray : Array-like, acceptable inputs include Numpy, HDF5, or Dask Arrays
412 | rotation : Number (degrees), angle of rotation
413 |
414 | Keywork Arguments
415 | -----------------
416 | preview : str, enables or disables preview mode and specifies direction
417 | Acceptable inputs are (None, 'inline', 'xline', 'z')
418 | Optimizes chunk size in different orientations to facilitate rapid
419 | screening of algorithm output
420 |
421 | Returns
422 | -------
423 | result : Dask Array
424 | """
425 |
426 | phi = np.deg2rad(rotation)
427 | kernel = (1,1,25)
428 | darray, chunks_init = self.create_array(darray, kernel, preview=preview)
429 | analytical_trace = darray.map_blocks(signal.hilbert, dtype=darray.dtype)
430 | result = analytical_trace.real * da.cos(phi) - analytical_trace.imag * da.sin(phi)
431 | result = util.trim_dask_array(result, kernel)
432 | result[da.isnan(result)] = 0
433 |
434 | return(result)
--------------------------------------------------------------------------------
/d2geo/attributes/__init__.py.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GeoDataScienceUQ/pyseismic/d8200e1181b6a4ec2719cba6b9ec25a1a5c33469/d2geo/attributes/__init__.py.txt
--------------------------------------------------------------------------------
/d2geo/attributes/io.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Utilities for reading seismic data from SEGY and converting to usable format.
4 |
5 | @author: Braden Fitz-Gerald
6 | @email: braden.fitzgerald@gmail.com
7 |
8 | """
9 |
10 | # Import Libraries
11 | import dask.array as da
12 | import numpy as np
13 | import segyio
14 | import h5py
15 | from shutil import copyfile as cf
16 |
17 |
18 | def segy_read(segy_path, out_path, out_name):
19 |
20 | def write(chunk, segy_file, dset):
21 | for i in chunk:
22 | dset[i[0], i[1], :] = segy_file.trace.raw[i[2]]
23 |
24 | return(chunk)
25 |
26 | segy_file = segyio.open(segy_path)
27 | trace_inlines = segy_file.attributes(segyio.TraceField.INLINE_3D)[:]
28 | trace_xlines = segy_file.attributes(segyio.TraceField.CROSSLINE_3D)[:]
29 |
30 | trace_inlines_unique = np.unique(trace_inlines)
31 | trace_xlines_unique = np.unique(trace_xlines)
32 |
33 | num_inline = trace_inlines_unique.size
34 | num_xline = trace_xlines_unique.size
35 | num_zsamples = len(segy_file.samples)
36 |
37 | min_inline = trace_inlines_unique.min()
38 | min_xline = trace_xlines_unique.min()
39 | min_zsample = segy_file.samples.min()
40 |
41 | max_inline = trace_inlines_unique.max()
42 | max_xline = trace_xlines_unique.max()
43 | max_zsample = segy_file.samples.max()
44 |
45 | inc_inline = int((max_inline - min_inline) / num_inline)
46 | inc_xline = int((max_xline - min_xline) / num_xline)
47 | inc_zsample = segy_file.bin[segyio.BinField.Interval] / 1000
48 |
49 | shape = (trace_inlines_unique.size, trace_xlines_unique.size, num_zsamples)
50 | ti_idx = trace_inlines - trace_inlines.min()
51 | tx_idx = trace_xlines - trace_xlines.min()
52 | idx = np.arange(ti_idx.size)
53 | coords = np.dstack((ti_idx, tx_idx, idx))[0]
54 | coords = da.from_array(coords, chunks=(25, 3))
55 |
56 | with h5py.File(out_path, 'w') as f:
57 |
58 | dset = f.create_dataset(out_name, shape=shape)
59 |
60 | dset.attrs['dims'] = shape
61 |
62 | dset.attrs['inc_inline'] = inc_inline
63 | dset.attrs['inc_xline'] = inc_xline
64 | dset.attrs['inc_zsample'] = inc_zsample
65 |
66 | dset.attrs['min_inline'] = min_inline
67 | dset.attrs['min_xline'] = min_xline
68 | dset.attrs['min_zsample'] = min_zsample
69 |
70 | dset.attrs['max_inline'] = max_inline
71 | dset.attrs['max_xline'] = max_xline
72 | dset.attrs['max_zsample'] = max_zsample
73 |
74 | coords.map_blocks(write, segy_file, dset, dtype=np.float32).compute()
75 |
76 |
77 |
78 | def segy_write(in_data, template_segy, out_file):
79 |
80 | cf(template_segy, out_file)
81 |
82 | with segyio.open(out_file, 'r+') as f:
83 |
84 | for i in range(in_data.shape[0]):
85 | try:
86 | il = f.ilines[i]
87 | f.iline[il] = in_data[i]
88 |
89 | except Exception:
90 | continue
--------------------------------------------------------------------------------
/d2geo/attributes/util.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Utilities for working with seismic and computing volume attributes.
4 |
5 | @author: Braden Fitz-Gerald
6 | @email: braden.fitzgerald@gmail.com
7 |
8 | """
9 |
10 | # Import Libraries
11 | import dask.array as da
12 | import numpy as np
13 | import h5py
14 | import psutil
15 |
16 |
17 | def compute_chunk_size(shape, byte_size, kernel=None, preview=None):
18 | """
19 | Description
20 | -----------
21 | Compute ideal block size for Dask Array given specific information about
22 | the computer being used, the input data, kernel size, and whether or not
23 | this operation is is 'preview' mode.
24 |
25 | Parameters
26 | ----------
27 | shape : tuple (len 3), shape of seismic data
28 | byte_size : int, byte size of seismic data dtype
29 |
30 | Keywork Arguments
31 | -----------------
32 | kernel : tuple (len 3), operator size
33 | preview : str, enables or disables preview mode and specifies direction
34 | Acceptable inputs are (None, 'inline', 'xline', 'z')
35 | Optimizes chunk size in different orientations to facilitate rapid
36 | screening of algorithm output
37 |
38 | Returns
39 | -------
40 | chunk_size : tuple (len 3), optimal chunk size
41 | """
42 |
43 | # Evaluate kernel
44 | if kernel == None:
45 | kernel = (1,1,1)
46 | ki, kj, kk = kernel
47 | else:
48 | ki, kj, kk = kernel
49 |
50 | # Identify acceptable chunk sizes
51 | i_s = np.arange(ki, shape[0])
52 | j_s = np.arange(kj, shape[1])
53 | k_s = np.arange(kk, shape[2])
54 |
55 | modi = shape[0] % i_s
56 | modj = shape[1] % j_s
57 | modk = shape[2] % k_s
58 |
59 | kki = i_s[(modi >= ki) | (modi == 0)]
60 | kkj = j_s[(modj >= kj) | (modj == 0)]
61 | kkk = k_s[(modk >= kk) | (modk == 0)]
62 |
63 | # Compute Machine Specific information
64 | mem = psutil.virtual_memory().available
65 | cpus = psutil.cpu_count()
66 | byte_size = byte_size
67 | M = ((mem / (cpus * byte_size)) / (ki * kj * kk)) * 0.75
68 |
69 | # Compute chunk size if preview mode is disabled
70 | if preview == None:
71 | # M *= 0.3
72 | Mij = kki * kkj.reshape(-1,1) * shape[2]
73 | Mij[Mij > M] = -1
74 | Mij = Mij.diagonal()
75 |
76 | chunks = [kki[Mij.argmax()], kkj[Mij.argmax()], shape[2]]
77 |
78 | # Compute chunk size if preview mode is enabled
79 | else:
80 | kki = kki.min()
81 | kkj = kkj.min()
82 | kkk = kkk.min()
83 |
84 | if preview == 'inline':
85 | if (kki * shape[1] * shape[2]) < M:
86 | chunks = [kki, shape[1], shape[2]]
87 |
88 | else:
89 | j_s = np.arange(kkj, shape[1])
90 | modj = shape[1] % j_s
91 | kkj = j_s[(modj >= kj) | (modj == 0)]
92 | Mj = j_s * kki * shape[2]
93 | Mj = Mj[Mj < M]
94 | chunks = [kki, Mj.argmax(), shape[2]]
95 |
96 | elif preview == 'xline':
97 | if (kkj * shape[0] * shape[2]) < M:
98 | chunks = [shape[0], kkj, shape[2]]
99 |
100 | else:
101 | i_s = np.arange(kki, shape[0])
102 | modi = shape[0] % i_s
103 | kki = i_s[(modi >= ki) | (modi == 0)]
104 | Mi = i_s * kkj * shape[2]
105 | Mi = Mi[Mi < M]
106 | chunks = [Mi.argmax(), kkj, shape[2]]
107 |
108 | else:
109 | if (kkk * shape[0] * shape[1]) < M:
110 | chunks = [shape[0], shape[2], kk]
111 |
112 | else:
113 | j_s = np.arange(kkj, shape[1])
114 | modj = shape[1] % j_s
115 | kkj = j_s[(modj >= kj) | (modj == 0)]
116 | Mj = j_s * kkk * shape[0]
117 | Mj = Mj[Mj < M]
118 | chunks = [shape[0], Mj.argmax(), kkk]
119 |
120 | return(tuple(chunks))
121 |
122 |
123 |
124 | def trim_dask_array(in_data, kernel):
125 | """
126 | Description
127 | -----------
128 | Trim resuling Dask Array given a specified kernel size
129 |
130 | Parameters
131 | ----------
132 | in_data : Dask Array
133 | kernel : tuple (len 3), operator size
134 |
135 | Returns
136 | -------
137 | out : Dask Array
138 | """
139 |
140 | # Compute half windows and assign to dict
141 | hw = tuple(np.array(kernel) // 2)
142 | axes = {0 : hw[0], 1 : hw[1], 2: hw[2]}
143 |
144 | return(da.ghost.trim_internal(in_data, axes=axes))
145 |
146 |
147 |
148 | def available_volumes(file_path):
149 | """
150 | Description
151 | -----------
152 | Convience function to evaluate what volumes exist and what their names are
153 |
154 | Parameters
155 | ----------
156 | file_path : str, path to file
157 |
158 | Returns
159 | -------
160 | vols : list, array of volume names in file
161 | """
162 |
163 | # Iterate through HDF5 file and output dataset names
164 | with h5py.File(file_path) as f:
165 | vols = [i for i in f]
166 |
167 | return(vols)
168 |
169 |
170 |
171 | def read(file_path):
172 | """
173 | Description
174 | -----------
175 | Convience function to read file and create a pointer to data on disk
176 |
177 | Parameters
178 | ----------
179 | file_path : str, path to file
180 |
181 | Returns
182 | -------
183 | data : HDF5 dataset, pointer to data on disk
184 | """
185 |
186 | data = h5py.File(file_path)['data']
187 |
188 | return(data)
189 |
190 |
191 |
192 | def save(out_data, out_file):
193 | """
194 | Description
195 | -----------
196 | Convience function to read file and create a pointer to data on disk
197 |
198 | Parameters
199 | ----------
200 | out_data : Dask Array, data to be saved to disk
201 | out_file : str, path to file to save to
202 | """
203 |
204 | # Save to disk if object is Dask Array
205 | try:
206 | out_data.to_hdf5(out_file, 'data')
207 | except Exception:
208 | raise Exception('Object is not a Dask Array')
209 |
210 |
211 |
212 | def convert_dtype(in_data, min_val, max_val, to_dtype):
213 | """
214 | Description
215 | -----------
216 | Convience function to read file and create a pointer to data on disk
217 |
218 | Parameters
219 | ----------
220 | in_data : Dask Array, data to convert
221 | min_val : number, lower clip
222 | max_val : number, upper clip
223 | to_dtype : NumPy dtype
224 | Acceptable formats include (np.int8, np.float16, np.float32)
225 |
226 | Returns
227 | -------
228 | out : Dask Array, converted data
229 | """
230 |
231 | # Check if data is already in correct format
232 | if in_data.dtype == to_dtype:
233 | return(in_data)
234 |
235 |
236 | else:
237 |
238 | in_data = da.clip(in_data, min_val, max_val)
239 | if to_dtype == np.int8:
240 | in_data = ((in_data - min_val) / (max_val - min_val))
241 | dtype = np.iinfo(np.int8)
242 | in_data *= dtype.max - dtype.min
243 | in_data -= dtype.min
244 | out = in_data.astype(np.int8)
245 |
246 | elif to_dtype == np.float16:
247 | out = in_data.astype(np.float16)
248 |
249 | elif to_dtype == np.int32:
250 | out = in_data.astype(np.float32)
251 |
252 | else:
253 | raise Exception('Not a valid dtype')
254 |
255 | return(out)
256 |
257 |
258 |
259 | def extract_patches(in_data, kernel):
260 | """
261 | Description
262 | -----------
263 | Reshape in_data into a collection of patches defined by kernel
264 |
265 | Parameters
266 | ----------
267 | in_data : Dask Array, data to convert
268 | kernel : tuple (len 3), operator size
269 |
270 | Returns
271 | -------
272 | out : Numpy Array, has shape (in_data.shape[0], in_data.shape[1],
273 | in_data.shape[2], kernel[0], kernel[1], kernel[2])
274 | """
275 |
276 | strides = in_data.strides + in_data.strides
277 | shape = (np.array(in_data.shape) - np.array(kernel)) + 1
278 | shape = tuple(list(shape) + list(kernel))
279 |
280 | patches = np.lib.stride_tricks.as_strided(in_data,
281 | shape=shape,
282 | strides=strides)
283 | return(patches)
284 |
285 |
286 |
287 | def local_events(in_data, comparator):
288 | """
289 | Description
290 | -----------
291 | Find local peaks or troughs depending on comparator used
292 |
293 | Parameters
294 | ----------
295 | in_data : Dask Array, data to convert
296 | comparator : function, defines truth between neighboring elements
297 |
298 | Returns
299 | -------
300 | out : Numpy Array
301 | """
302 |
303 | idx = np.arange(0, in_data.shape[-1])
304 | trace = in_data.take(idx, axis=-1, mode='clip')
305 | plus = in_data.take(idx + 1, axis=-1, mode='clip')
306 | minus = in_data.take(idx - 1, axis=-1, mode='clip')
307 |
308 | result = np.ones(in_data.shape, dtype=np.bool)
309 |
310 | result &= comparator(trace, plus)
311 | result &= comparator(trace, minus)
312 |
313 | return(result)
314 |
315 |
316 |
317 | def hilbert(in_data):
318 | """
319 | Description
320 | -----------
321 | Perform Hilbert Transform on input data
322 |
323 | Parameters
324 | ----------
325 | in_data : Dask Array, data to convert
326 |
327 | Returns
328 | -------
329 | out : Numpy Array
330 | """
331 |
332 | N = in_data.shape[-1]
333 |
334 | Xf = np.fft.fftpack.fft(in_data, n=N, axis=-1)
335 |
336 | h = np.zeros(N)
337 | if N % 2 == 0:
338 | h[0] = h[N // 2] = 1
339 | h[1:N // 2] = 2
340 | else:
341 | h[0] = 1
342 | h[1:(N + 1) // 2] = 2
343 |
344 | if in_data.ndim > 1:
345 | ind = [np.newaxis] * in_data.ndim
346 | ind[-1] = slice(None)
347 | h = h[ind]
348 | x = np.fft.fftpack.ifft(Xf * h, axis=-1)
349 | return x
--------------------------------------------------------------------------------
/environment.yml:
--------------------------------------------------------------------------------
1 | name: seismicpy
2 | channels:
3 | - defaults
4 | dependencies:
5 | - ca-certificates=2024.7.2=haa95532_0
6 | - libffi=3.4.4=hd77b12b_1
7 | - openssl=3.0.14=h827c3e9_0
8 | - pip=24.0=py38haa95532_0
9 | - python=3.8.19=h1aa4202_0
10 | - setuptools=69.5.1=py38haa95532_0
11 | - sqlite=3.45.3=h2bbff1b_0
12 | - vc=14.2=h2eaa2aa_4
13 | - vs2015_runtime=14.29.30133=h43f2093_4
14 | - wheel=0.43.0=py38haa95532_0
15 | - pip:
16 | - dask==2021.11.1
17 | - numpy==1.24.4
18 | - open3d==0.13.0
19 | - opencv-python-headless==4.5.4.60
20 | - pandas==2.0.3
21 | - pyntcloud==0.1.5
22 | - scikit-image==0.18.1
23 | - scikit-learn==1.1.3
24 | - scipy==1.10.1
25 | - segysak==0.3.3
26 | - lshashpy3==0.0.9
27 | - matplotlib==3.7.5
28 | - h5py==3.8.0
29 | - xarray==2023.1.0
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | dask
2 | opencv-python-headless
3 | pandas
4 | pyntcloud
5 | scikit-image
6 | scikit-learn
7 | scipy
8 | segysak
9 | lshashpy3
10 | matplotlib
11 | h5py==3.8.0
12 | xarray==2023.1.0
13 | numpy==1.24.4
14 | open3d==0.13.0
--------------------------------------------------------------------------------
/utils.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | maintainer:
5 | """
6 |
7 | import pickle
8 | import sys
9 |
10 | def to_pickle(obj, file):
11 | with open(file, 'wb') as handle:
12 | pickle.dump(obj, handle, protocol=pickle.HIGHEST_PROTOCOL)
13 |
14 | # Adapted from https://stackoverflow.com/questions/3173320/text-progress-bar-in-the-console/14879561
15 | # Print iterations progress
16 | def printProgressBar (iteration, total, prefix = 'Progress: ', suffix = 'Complete', decimals = 1, bar_length=100):
17 | """
18 | Call in a loop to create terminal progress bar
19 | @params:
20 | iteration - Required : current iteration (Int)
21 | total - Required : total iterations (Int)
22 | prefix - Optional : prefix string (Str)
23 | suffix - Optional : suffix string (Str)
24 | decimals - Optional : positive number of decimals in percent complete (Int)
25 | bar_length - Optional : character length of bar (Int)
26 | """
27 | str_format = "{0:." + str(decimals) + "f}"
28 | percents = str_format.format(100 * (iteration / float(total)))
29 | filled_length = int(round(bar_length * iteration / float(total)))
30 | bar = '█' * filled_length + '-' * (bar_length - filled_length)
31 |
32 | # print('\r%s |%s| %s%% %s' % (prefix, bar, percents, suffix), end = '\r'),
33 | # if iteration == total:
34 | # print()
35 |
36 | sys.stdout.write('\r%s |%s| %s%s %s' % (prefix, bar, percents, '%', suffix)),
37 | if iteration == total:
38 | sys.stdout.write('\n')
39 | sys.stdout.flush()
40 |
41 | def write_pcd_to_ASCII(pcd, cdp_x, cdp_y, twt, file_path):
42 | with open(file_path, 'w') as the_file:
43 | #convert point from cube coordinates to point referenced coordinates
44 | the_file.write("CDP_X CDP_Y TWT\n")
45 | for (x, y, z) in pcd:
46 | # the_file.write("INLINE : {} XLINE : {} {} {} {}\n".format(
47 | # int(iline[x]), int(xline[y]), float(cdp_x[x, y]), float(cdp_y[x, y]), int(twt[z])))
48 | the_file.write("{} {} {}\n".format(
49 | float(cdp_x[x, y]), float(cdp_y[x, y]), int(twt[z])))
--------------------------------------------------------------------------------