kinverarity1 / aseg_gdf2

Python code to help read ASEG GDF2 packages
https://pypi.org/project/aseg-gdf2/
MIT License
9 stars 2 forks source link

Write formatted .dat file from .dfn #17

Open bminsley opened 4 years ago

bminsley commented 4 years ago

Hi Kent- this is a nice package! Wondering if you have any tools for writing a formatted .dat file using the formatting specified in a .dfn. I've read an existing .dat/.dfn into a dataframe, and done some manipulation to the values. Now I want to write a new .dat file (exact same columns) using the precision specified in the .dfn - have you done this sort of thing?

kinverarity1 commented 4 years ago

Hey, thanks for trying it out. I haven't done that before but I think it is fairly straightforward. I've put up a simple notebook using the current release of aseg_gdf2, showing how you could write a dat file with a modified DataFrame here:

https://github.com/kinverarity1/aseg_gdf2/blob/issue17-write/notebooks/Issue%2017%20-%20write%20dat%20file.ipynb

You'll need to run pip install fortranformat first.

bminsley commented 4 years ago

Hi Kent-

thanks for that formatted writing solution- works great. Another related question- it appears that on reading a .dat/.dfn file, the default is to parse out columns using whitespace. We have one file where, unfortunately, the values from one column fill up the entire column width for that entry, so that there is not a whitespace between it and the previous column. It is something that we will fix by adding width to that field, but it would also be nice if the issue could be avoided by reading the fixed-width values defined in the .dfn file. It seems that 'fixed-width' is an option on import, but we were not able to get it to work without errors and can only seem to use import with 'whitespace'. Any suggestions on how to do this are welcome

thanks again Burke


Burke J. Minsley Research Geophysicist https://profile.usgs.gov/bminsley

Geology, Geophysics, and Geochemistry Science Center U.S. Geological Survey MS 964 - Denver Federal Center Bldg. 20, B2133 Denver, CO 80225 303 236 5718 bminsley@usgs.govmailto:bminsley@usgs.gov


From: Kent Inverarity notifications@github.com Sent: Saturday, February 1, 2020 10:39 PM To: kinverarity1/aseg_gdf2 aseg_gdf2@noreply.github.com Cc: Minsley, Burke J bminsley@usgs.gov; Author author@noreply.github.com Subject: [EXTERNAL] Re: [kinverarity1/aseg_gdf2] Write formatted .dat file from .dfn (#17)

Hey, thanks for trying it out. I haven't done that before but I think it is fairly straightforward. I've put a simple notebook using the current release of aseg_gdf2, showing how you could write a dat file with a modified DataFrame here:

https://github.com/kinverarity1/aseg_gdf2/blob/issue17-write/notebooks/Issue%2017%20-%20write%20dat%20file.ipynb

You'll need to run pip install fortranformat first.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/kinverarity1/aseg_gdf2/issues/17?email_source=notifications&email_token=ABB6ELIVP4XXQCNM577LMTTRAZMBNA5CNFSM4KOMQ2Q2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKROORQ#issuecomment-581101382, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABB6ELKYJQPBWKCP3X5I3ZTRAZMBNANCNFSM4KOMQ2QQ.

kinverarity1 commented 4 years ago

No worries - might be a bug I think, I haven't tested that much since it was written. It is certainly supposed to work using the dfn widths though.

Would you be able to send the dfn and a short sample from the dat file? I think you can upload them to the GitHub issue.

kinverarity1 commented 4 years ago

I'll leave this issue of writing a new dataframe open. It'd be good to have the code from the above notebook turned into a function in aseg_gdf2.