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

Add update_curve and replace_curve_item methods to LASFile (fixes #478) #479

Merged
merged 5 commits into from
Aug 7, 2021

Conversation

kinverarity1
Copy link
Owner

See #478. This PR:

  • Adds LASFile.update_curve to allow updating of one or more CurveItem attributes from LASFile
  • Adds LASFile.replace_curve_item to allow replacement of a CurveItem from LASFile
  • Modifies LASFile.__setitem__ so that the behavior is more natural, see code session below.
>>> import lasio.examples
>>> las = lasio.examples.open("sample.las")
>>> las["ILD_MSM"] = 100 / las["ILD"]
>>> print(las.curves)
Mnemonic  Unit  Value  Description
--------  ----  -----  -----------
DEPT      M            1  DEPTH
DT        US/M         2  SONIC TRANSIT TIME
RHOB      K/M3         3  BULK DENSITY
NPHI      V/V          4   NEUTRON POROSITY
SFLU      OHMM         5  RXO RESISTIVITY
SFLA      OHMM         6  SHALLOW RESISTIVITY
ILM       OHMM         7  MEDIUM RESISTIVITY
ILD       OHMM         8  DEEP RESISTIVITY
ILD_MSM
>>> las["ILD_MSM"] = 1000 / las["ILD"]
>>> print(las.curves)
Mnemonic  Unit  Value  Description
--------  ----  -----  -----------
DEPT      M            1  DEPTH
DT        US/M         2  SONIC TRANSIT TIME
RHOB      K/M3         3  BULK DENSITY
NPHI      V/V          4   NEUTRON POROSITY
SFLU      OHMM         5  RXO RESISTIVITY
SFLA      OHMM         6  SHALLOW RESISTIVITY
ILM       OHMM         7  MEDIUM RESISTIVITY
ILD       OHMM         8  DEEP RESISTIVITY
ILD_MSM
>>> las["NPHI"] = lasio.CurveItem("NPHI", "%", "", "neutron porosity as %", data=(las["NPHI"] * 100))
>>> print(las.curves)
Mnemonic  Unit  Value  Description
--------  ----  -----  -----------
DEPT      M            1  DEPTH
DT        US/M         2  SONIC TRANSIT TIME
RHOB      K/M3         3  BULK DENSITY
NPHI      %            neutron porosity as %
SFLU      OHMM         5  RXO RESISTIVITY
SFLA      OHMM         6  SHALLOW RESISTIVITY
ILM       OHMM         7  MEDIUM RESISTIVITY
ILD       OHMM         8  DEEP RESISTIVITY
ILD_MSM
>>> las["NPHI"]
array([45., 45., 45.])

Copy link
Collaborator

@dcslagel dcslagel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes some things and is an improvement. Lets merge it. I do have one question for future consideration...

When def __setitem__(self, key, value): is run with a non-CurveItem key and value for an existing curve it looks like the existing curve will only update the data section (not unit, desc or value). If that is correct, could there be a case where the updated data should represented by a unit or in a different unit. Is this something rare or unlikely that it doesn’t need to be handled?

@kinverarity1
Copy link
Owner Author

@dcslagel unneeded I think - if someone is updating the data with a different unit, they'll need to either create a new CurveItem with correct new values and use that, or set the data and unit separately. Thanks for the review!

@kinverarity1 kinverarity1 merged commit 7767038 into master Aug 7, 2021
@kinverarity1 kinverarity1 deleted the replace-curve branch August 7, 2021 03:27
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 this pull request may close these issues.

2 participants