Skip to content

Cleaning: evove_forward needs refactoring

There : https://gitlab.aip.de/lketzer/platypos/-/blob/master/platypos_package/Planet_class_LoFo14.py#L188

The issue with this function is that it is a mixture of solving stuff and writing output (and inputs?).

So the name of the method does not tell what it actually does. This function should be just:

# call mass_planet_RK4_forward_LO14 to start the integration
            t, M, R, Lx = mass_planet_RK4_forward_LO14(
                                        epsilon=epsilon,
                                        K_on=K_on,
                                        beta_on=beta_on,
                                        planet_object=self,
                                        initial_step_size=initial_step_size,
                                        t_final=t_final,
                                        track_dict=evo_track_dict
                                        )

or something like that. All the rest should go into gen_planet_id, prepare_folder, write_results_to_file ...

Another issue I see is that you are using DataFrame like:

df = pd.DataFrame({"Time": t, "Mass": M, "Radius": R, "Lx": Lx})
df.to_csv(path_for_saving+self.planet_id+".txt", index=None)

That is fine, even though you could create the DataFrame inside the mass_planet_RK4_forward_LO14 method.

But why not using the same mechanism later? instead of:

# create another file, which contains the final parameters only
            if os.path.exists(path_for_saving+\
                              self.planet_id+"_final.txt"):
                pass
            else:
                p = open(path_for_saving+self.planet_id+"_final.txt", "w")
                # get index of last valid entry in the radius array and access
                # its value
                index_of_last_entry = df["Radius"][df["Radius"].notna()].index[-1]
                R_final = df["Radius"].loc[index_of_last_entry]
                index_of_last_entry = df["Mass"][df["Mass"].notna()].index[-1]
                M_final = df["Mass"].loc[index_of_last_entry]
                f_env_final = ((M_final-self.core_mass)/M_final)*100  # %
                planet_params = "a,core_mass,fenv,mass,radius,metallicity,track\n"\
                                + str(self.distance) + "," + str(self.core_mass)\
                                + "," + str(f_env_final) + "," + str(M_final)\
                                + "," + str(R_final) + "," + self.metallicity\
                                + "," + self.planet_id
                p.write(planet_params)
                p.close()

Here you are actually doing what df.to_csv() does but by hand. That is less efficient and wordy. and must not index_of_last_entry be the same for radius and mass ?