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

Unnamed df index is not handled by lasio in LASFile.set_data_from_df #463

Open
eucalypt1 opened this issue Apr 30, 2021 · 8 comments
Open

Comments

@eucalypt1
Copy link

Thank you for updata 2.9

I have been using Python3 and the lasio 2.8 library to create special purpose lasfiles
I added data curves and used las_data.set_data(new_df) prior to overwriting an existing lasfile using new_las.write(new_File, version=2.0)

The saved las file shows the old data section in the ~Other section (blows me away)
1257.3 17.4 -9999.25 7 9 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25
1257.4 17.5 -9999.25 7 9 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25
1257.5 17.6 -9999.25 7 9 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25
1257.6 17.7 -9999.25 7 9 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25
1257.7 17.8 -9999.25 7 9 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25
1257.8 17.9 -9999.25 7 9 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25
1257.9 18.0 -9999.25 7 9 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25
1258.0 18.1 -9999.25 7 9 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25
1258.1 18.2 -9999.25 7 9 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25
1258.2 18.3 -9999.25 7 9 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25
~ASCII -----------------------------------------------------

and the updated data in the ~ASCII section. The file counts 47 curves over a relatively small depth intervalL
~ASCII -----------------------------------------------------
1240.00000 0.10000 -9999.25 3.00000 1.00000 1.00000 415.00000 91.82000 3.44500 0.00000 23.01950 0.00000 0.00000 0.00000 3.00000 3.50000 4.00000 0.00000 18.00000 22.00000 71.50000 2.58000 2.00000 -9999.25 23.01950 29.51950 51.51950 71.42130 27.51950 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 1.00000 1240.08000 0.10000 40.10000 -9999.25000 0.63000 0.18900 2660.00000 2160.00000 0.13700 0.35100 FD0001
1240.10000 0.20000 -9999.25 3.00000 1.00000 -9999.25 15.00000 78.00000 3.68040 0.00000 23.01950 0.00000 0.00000 0.00000 3.00000 3.50000 4.00000 0.00000 18.00000 22.00000 71.50000 2.58000 2.00000 -9999.25 23.01950 29.51950 51.51950 71.42130 27.51950 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 -9999.25 1.00000 1240.18000 0.12000 7.17000 1.83000 0.12000 0.16700 2700.00000 2250.00000 0.00100 0.42600 FD0002
1240.20000 0.30000 1.00000 3.00000 1.00000 11.00000 4.00000 91.82000 3.44500 0.00000 23.01950 0.00000 0.00000 0.00000 1.00000 3.50000 4.00000 0.00000 18.00000 22.00000 73.50000 2.58000 2.00000 -9999.25 23.01950 27.51950 49.51950 71.42130 27.51950 -9999.25 22.00000 27.51950 -9999.25 -9999.25 -9999.25 1.00000 1240.30000 0.25000 57.10000 56.10000 16.70000 0.18100 2680.00000 2190.00000 0.15700 0.27700 FD0003
1240.30000 0.40000 -9999.25 3.00000 1.00000 -9999.25 4.00000 91.00000 3.45800 0.00000 23.01950 0.00000 0.00000 0.00000 1.00000 3.50000 4.00000 0.00000 18.00000 22.00000 73.50000 2.58000 2.00000 -9999.25 23.01950 27.51950 49.51950 71.42130 27.51950 -9999.25 22.00000 27.51950 -9999.25 -9999.25 -9999.25 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000
1240.40000 0.50000 -9999.25 3.00000 1.00000 -9999.25 -9999.25 91.00000 3.45800 0.00000 23.01950 0.00000 0.00000 0.00000 1.00000 3.50000 4.00000 0.00000 18.00000 22.00000 73.50000 2.58000 2.00000 -9999.25 23.01950 27.51950 49.51950 71.42130 27.51950 -9999.25 22.00000 27.51950 -9999.25 -9999.25 -9999.25 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000
1240.50000 0.60000 -9999.25 3.00000 1.00000 -9999.25 4.00000 91.00000 3.45800 0.00000 23.01950 0.00000 0.00000 0.00000 1.00000 3.50000 4.00000 0.00000 18.00000 22.00000 73.50000 2.58000 2.00000 -9999.25 23.01950 27.51950 49.51950 71.42130 27.51950 -9999.25 22.00000 22.91560 -9999.25 -9999.25 -9999.25 1.00000 1240.55000 0.25000 45.70000 41.20000 4.68000 0.20100 2660.00000 2120.00000 0.12400 0.34500 FD0004
1240.60000 0.70000 -9999.25 3.00000 1.00000 -9999.25 430.00000 91.00000 3.45800 0.00000 23.01950 0.00000 0.00000 0.00000 1.00000 3.50000 4.00000 0.00000 18.00000 22.00000 73.50000 2.58000 2.00000 -9999.25 23.01950 27.51950 49.51950 71.42130 27.51950 -9999.25 22.00000 18.31170 -9999.25 -9999.25 -9999.25 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000
1240.70000 0.80000 -9999.25 3.00000 3.00000 -9999.25 -9999.25 15.00000 6.05890 0.00000 0.00000 0.00000 0.00000 0.00000 1.00000 0.00000 4.00000 0.00000 18.00000 22.00000 77.00000 2.58000 2.00000 -9999.25 0.00000 1.00000 23.00000 78.00000 4.50000 -9999.25 28.08000 13.70780 -9999.25 -9999.25 -9999.25 1.00000 1240.80000 0.35000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 DE0000
1240.80000 0.90000 -9999.25 3.00000 3.00000 -9999.25 -9999.25 15.00000 6.05890 0.00000 0.00000 0.00000 0.00000 0.00000 1.00000 0.00000 4.00000 0.00000 18.00000 22.00000 77.00000 2.58000 2.00000 -9999.25 0.00000 1.00000 23.00000 78.00000 4.50000 -9999.25 33.40000 9.10390 -9999.25 -9999.25 -9999.25 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000
1240.90000 1.00000 -9999.25 3.00000 3.00000 33.00000 110122.00000 15.00000 6.05890 0.00000 0.00000 0.00000 0.00000 0.00000 1.00000 0.00000 4.00000 80.00000 18.00000 52.40000 47.40000 2.58000 2.00000 -9999.25 0.00000 0.20000 52.60000 47.60000 4.50000 -9999.25 33.40000 9.10000 -9999.25 -9999.25 -9999.25 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000
1241.00000 1.10000 -9999.25 3.00000 3.00000 33.00000 1101.00000 15.00000 6.05890 0.00000 0.00000 0.00000 0.00000 0.00000 1.00000 0.00000 4.00000 70.00000 18.00000 48.60000 51.10000 2.58000 2.00000 -9999.25 0.00000 0.30000 48.90000 51.40000 4.50000 -9999.25 32.80000 13.70000 -9999.25 -9999.25 -9999.25 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000 -9999.25000
1241.10000 1.20000 -9999.25 3.00000 1.00000 -9999.25 3204.00000 91.00000 3.45800 0.00000

What do I do wrong for the old data to show up in the ~other section --- or is it a bug?

And although the ~ASCII section data is complete, I am unsure how to control the width of the data columns, especially when NULLs are involved. I have tried rounding the values before saving them but the results are all over the place. Any suggestions?

@eucalypt1 eucalypt1 added the bug label Apr 30, 2021
@dcslagel
Copy link
Collaborator

dcslagel commented May 1, 2021

Hi @eucalypt1 ,

Is it correct that there are 3 issues as follows:

  1. The previous (old) data section shouldn't be added to the ~Other section.
  2. NULL values should use the same number format as other numbers in the ~ASCII section.
  3. How to change the number format in the ~ASCII section

THanks!,
DC

@eucalypt1
Copy link
Author

eucalypt1 commented May 1, 2021 via email

@dcslagel
Copy link
Collaborator

dcslagel commented May 1, 2021

For How to change the number format in the ~ASCII section, there are 2 parameters that can be passed into to the write function: fmt and column_fmt. These use python's string formatting language.

This a good quick tutorial that covers the string-to-numbers formatting:
https://www.python-course.eu/python3_formatted_output.php

Here is an example usage. The

las.write("example.las", fmt='%.2f', column_fmt={0: '%.3f'},  version=2.0)

There default settings are:

    fmt="%.5f",
    column_fmt=None,

Excerpt from the documentation on the write() function:

        fmt (str): Python string formatting operator for numeric data to be
            used.
        column_fmt (dict or None): use this to set a different format string
            for specific columns from the data ndarray. E.g. to use ``'%.3f'``
            for the depth column and ``'%.2f'`` for all the other columns,
            you would use ``fmt='%.2f', column_fmt={0: '%.3f'}``.

@eucalypt1
Copy link
Author

eucalypt1 commented May 1, 2021 via email

@eucalypt1
Copy link
Author

eucalypt1 commented May 2, 2021 via email

@kinverarity1
Copy link
Owner

Hi @eucalypt1 thanks for raising these issues. Apologies on my behalf for the documentation, it is not that easy to find relevant information!

I'm unclear on how the problem arose with data being written to the ~Other section, although it sounds like you have resolved that. If you are able to post a minimal working example, I'll have a look for you.

Also, would you be able to reply (or edit previous comments) by using a web browser (#463), rather than replying through your email client? It's quite difficult to understand your messages because the email client is unfortunately modifying them.

@eucalypt1
Copy link
Author

eucalypt1 commented May 4, 2021

Sorry, about the gabblecook when trying to show some code in my emails. I didn't realize it all showed up here on github. I am such a Newby!

Anyway, it seems that with your input I resolved the formatting issue. When trying to write a resampling function, I got similar problems when writing lasfiles. I created a dataframe of curves that I then updated in the lasfile using lasfile.set_data(df). I ran into a similar exception as showed up in my special application lasfile function discussed above. The exeption message states that it couldn't use the 'strip' attribute. (Sorry I lost the screenshot of the error message), which happened in the Lasio Library) Below is the resampling code now 'corrected'.

It turned out that Lasio doesn't 'like' an un-named depth index in the dataframe. I had to specifically state: las_df.index.name='DEPT' With that my problems have dissappeared. So now everything is running hanky dory.

#create new dept index
dpt=cstart
mdpt=[] #Create empty new depth curve
while (dpt <= cstop):
mdpt.append(dpt)
dpt +=cstep
dpt=round(dpt,1)

#create new dataframe
las_df=pd.DataFrame(index=mdpt,columns=df.columns)
las_df.index.name='DEPT'

The NaN issue seems to be taken care of as follows:

#update las_data for las_df
mynull=round(las_data.well.NULL.value,2)
las_df.fillna(mynull)
las_data.set_data(las_df)

Thank you for your help. Much appreciated

@kinverarity1
Copy link
Owner

Thanks for the update @eucalypt1

Note to myself: set_data_from_df should handle the case where the df index is unnamed.

@kinverarity1 kinverarity1 changed the title Dataframe issue and formatting issue Blank df index not handled by lasio Jun 30, 2021
@kinverarity1 kinverarity1 changed the title Blank df index not handled by lasio Unnamed df index is not handled by lasio in LASFile.set_data_from_df Apr 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants