teamtomo / starfile

STAR file I/O in Python
https://teamtomo.org/starfile/
BSD 3-Clause "New" or "Revised" License
44 stars 19 forks source link

float formatting when writing STAR files #1

Closed bingwang14 closed 4 years ago

bingwang14 commented 4 years ago

Hi,

Thank you for sharing the module. But I met a problem when using it. Here is the specific issue. When I write a pandas dataframe to a star file with starfile.new() function, it changes the decimal place for all data. The data in dataframe is 6 decimal places(%0.6f), while in the output star file, it is 5 decimal places(%0.5f). For example, 3374.201417 is changed to 3374.20142. Is there any way to avoid that?

Thanks, Bing

alisterburt commented 4 years ago

Hi Bing,

Thanks for letting me know. I've uploaded an updated version (0.1.3) to PyPi which will allow you to pass keyword arguments when writing new star files. Actually writing the loop style data blocks is delegated to pandas DataFrame.to_csv(), any keyword arguments you pass to starfile.new() will now be passed through to the DataFrame.to_csv() call. Keyword arguments for that are listed at https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_csv.html

I've left the default at %.5f (to avoid large files when doing mathematical operations on euler angles for instance), to achieve what you want you could now write the following

starfile.new(df, 'test.star', float_format='%.6f')

Hope that helps, let me know if you feel like this default behaviour isn't correct

bingwang14 commented 4 years ago

Hi,

Thank you so much. It works well.

Regards, Bing


From: alisterburt notifications@github.com Sent: Monday, September 28, 2020 6:14 AM To: alisterburt/starfile starfile@noreply.github.com Cc: Bing Wang bwang@fsu.edu; Author author@noreply.github.com Subject: Re: [alisterburt/starfile] starfile.new (#1)

Hi Bing,

Thanks for letting me know. I've uploaded an updated version (0.1.3) to PyPi which will allow you to pass keyword arguments when writing new star files. Actually writing the loop style data blocks is delegated to pandas DataFrame.to_csv(), any keyword arguments you pass to starfile.new() will now be passed through to the DataFrame.to_csv() call. Keyword arguments for that are listed at https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_csv.htmlhttps://urldefense.com/v3/__https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_csv.html__;!!PhOWcWs!mZgXfxfZufik_sYsE6s4_dDKWsM4uWmatwMYwwU_OHl4o74f8b3rxKA-75fjMA$

I've left the default at %.5f (to avoid large files when doing mathematical operations on euler angles for instance), to achieve what you want you could now write the following

starfile.new(df, 'test.star', float_format='%.6f')

Hope that helps, let me know if you feel like this default behaviour isn't correct

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https://github.com/alisterburt/starfile/issues/1*issuecomment-699915925__;Iw!!PhOWcWs!mZgXfxfZufik_sYsE6s4_dDKWsM4uWmatwMYwwU_OHl4o74f8b3rxKC4LsDdhQ$, or unsubscribehttps://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/ALZ6W3734UCROWVGFN5JYNDSIBOXHANCNFSM4R3DAGBQ__;!!PhOWcWs!mZgXfxfZufik_sYsE6s4_dDKWsM4uWmatwMYwwU_OHl4o74f8b3rxKCgl1uhuQ$.