POSYDON-code / POSYDON

POSYDON is a next-generation single and binary-star population synthesis code incorporating full stellar structure and evolution modeling with the use of MESA.
BSD 3-Clause "New" or "Revised" License
25 stars 19 forks source link

Add functions to read initial values from file #299

Closed mkruckow closed 1 month ago

mkruckow commented 1 month ago

Add the functionality to be able to read the initial binary values from a given file.

ZAMS_values.csv content:

M_1,M_2,P_orb,e,w1,phi1,theta1,s1_natal_kick_array_3 10.0,10.0,10.0,0.0,0.0,0.0,0.0,0.0 10.0,10.0,100.0,0.0,1.0,0.0,0.0,0.0 10.0,10.0,1000.0,0.0,10.0,0.0,0.0,0.0 20.0,10.0,10.0,0.0,10.0,0.785398163,0.0,0.0 20.0,10.0,100.0,0.0,10.0,1.570796327,0.0,0.0 20.0,10.0,1000.0,0.0,10.0,2.35619449,0.0,0.0 40.0,10.0,10.0,0.0,10.0,3.141592654,0.0,0.0 40.0,10.0,100.0,0.0,10.0,0.785398163,0.785398163,0.0 40.0,10.0,1000.0,0.0,10.0,1.570796327,0.785398163,0.0 20.0,20.0,10.0,0.0,10.0,2.35619449,0.785398163,0.0 20.0,20.0,100.0,0.0,10.0,3.141592654,0.785398163,0.0 20.0,20.0,1000.0,0.0,10.0,0.785398163,0.785398163,0.785398163 40.0,20.0,10.0,0.0,10.0,1.570796327,0.785398163,0.785398163 40.0,20.0,100.0,0.0,10.0,2.35619449,0.785398163,0.785398163 40.0,20.0,1000.0,0.0,10.0,3.141592654,0.785398163,0.785398163 40.0,40.0,10.0,0.0,10.0,4.712388981,0.785398163,0.785398163 40.0,40.0,100.0,0.0,10.0,4.712388981,0.785398163,1.570796327 40.0,40.0,1000.0,0.0,10.0,4.712388981,0.785398163,4.712388981

astroJeff commented 1 month ago

To clean up the input string options, can we use either .lower() or .casefold(), see SO link: https://stackoverflow.com/questions/319426/how-do-i-do-a-case-insensitive-string-comparison

mkruckow commented 1 month ago

To clean up the input string options, can we use either .lower() or .casefold(), see SO link: https://stackoverflow.com/questions/319426/how-do-i-do-a-case-insensitive-string-comparison

I have made the change to use those functions to shorten the lists. Should we get an own function, which removes dashes, underscores and spaces to shorten it even more?

maxbriel commented 1 month ago

A bit late to this PR, but this functionality is already there in the binarypopulation.py, where you can read and evolve binaries from an hdf5 file. That function is not optimised for reading the binaries from the file, but works correctly in evolving the binaries using custom initial ZAMS value.

I'm not sure what the added benefit of two frameworks for the same thing is. Is it possible to combine the two in some way or is there additional functionality here that is missing in the other?

mkruckow commented 1 month ago

A bit late to this PR, but this functionality is already there in the binarypopulation.py, where you can read and evolve binaries from an hdf5 file. That function is not optimised for reading the binaries from the file, but works correctly in evolving the binaries using custom initial ZAMS value.

I'm not sure what the added benefit of two frameworks for the same thing is. Is it possible to combine the two in some way or is there additional functionality here that is missing in the other?

The from_hdf function is aimed to read in from an existing population file. Usually, you'd even use it to read in the evolution not just ZAMS values. Any hdf5 file read by this function needs to be formatted in the POSYDON way, hence having all columns named as POSYDON would name them. Additionally, I'm not sure whether it will work well, if the load is specified in the population_params.ini (surely the default version doesn't include value, which you'd need to change). Using the from_hdf at least requires a two step process from a user.

So, additional functionality here is:

Additional functionality of from_hdf:

mkruckow commented 1 month ago

@maxbriel, maybe we can add the option to switch to the from_hdf in case the given file has an h5 file extension in an new PR?