Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delete_curve issue #315

Closed
hflesche opened this issue Apr 16, 2020 · 4 comments · Fixed by #325
Closed

delete_curve issue #315

hflesche opened this issue Apr 16, 2020 · 4 comments · Fixed by #325

Comments

@hflesche
Copy link

hflesche commented Apr 16, 2020

If you loop through curves in a las-file to delete some of them, the result is not correct unless you start from the last curve and move forwards. Let's say we have a las object with curves DEPTH, BS, CALI, RHOB, DT and DTS. The following code will skip CALI when BS curve is deleted:

keep_curves = ['DEPTH', 'DT', 'DTS']
for curve in las_file.curves:
    if curve.mnemonic not in keep_curves:
        las_file.delete_curve(curve.mnemonic)

whereas if the list of curves is reversed, the correct ones are deleted:

use_curves = ['DEPT', 'DT', 'DTS']
for curve in reversed(las_file.curves):
    if curve.mnemonic not in keep_curves:
        las_file.delete_curve(curve.mnemonic)
@kinverarity1
Copy link
Owner

Thanks @hflesche, I will have a look at this tomorrow.

@kinverarity1
Copy link
Owner

I have a feeling this is always likely to fail, e.g. https://stackoverflow.com/a/2897058/596328

Out of curiosity, does adding a slice to obtain a copy (see below) work for you?

keep_curves = ['DEPTH''DT''DTS']
for curve in las_file.curves[:]:
    if curve.mnemonic not in keep_curves:
        las_file.delete_curve(curve.mnemonic)

@hflesche
Copy link
Author

Yes, that works. Another option that also works is this:

for curve_name in las_file.keys():
    if curve_name not in keep_curves:
        las_file.delete_curve(curve_name)

According to the link that you sent, this may not be an issue for delete_curve, it is more of a Python issue. A warning could perhaps be added to the docs, but it is not really a bug.

@kinverarity1
Copy link
Owner

kinverarity1 commented Apr 16, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants