From f4fec1e02d447399afe8c2ca560ef3315bac0b3a Mon Sep 17 00:00:00 2001 From: David A Minton Date: Wed, 7 Dec 2022 09:06:48 -0500 Subject: [PATCH] Fixed more bugs in encounter data processing --- examples/.gitignore | 8 ++-- examples/Fragmentation/Fragmentation_Movie.py | 6 +-- python/swiftest/swiftest/simulation_class.py | 41 +++++++++++-------- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/examples/.gitignore b/examples/.gitignore index 7c5c72692..ad990dfcb 100644 --- a/examples/.gitignore +++ b/examples/.gitignore @@ -1,6 +1,6 @@ * !.gitignore -!Basic_Simulation/* -!Fragmentation/* -!helio_gr_test/* -!whm_gr_test/* \ No newline at end of file +!Basic_Simulation +!Fragmentation +!helio_gr_test +!whm_gr_test \ No newline at end of file diff --git a/examples/Fragmentation/Fragmentation_Movie.py b/examples/Fragmentation/Fragmentation_Movie.py index 0bff9416a..fa1203a8e 100644 --- a/examples/Fragmentation/Fragmentation_Movie.py +++ b/examples/Fragmentation/Fragmentation_Movie.py @@ -40,8 +40,8 @@ movie_titles = dict(zip(available_movie_styles, movie_title_list)) # These initial conditions were generated by trial and error -pos_vectors = {"disruption_headon" : [np.array([1.0, -2.807993e-05, 0.0]), - np.array([1.0, 2.807993e-05 ,0.0])], +pos_vectors = {"disruption_headon" : [np.array([1.0, -5.0e-05, 0.0]), + np.array([1.0, 5.0e-05 ,0.0])], "supercatastrophic_off_axis": [np.array([1.0, -4.2e-05, 0.0]), np.array([1.0, 4.2e-05, 0.0])], "hitandrun" : [np.array([1.0, -2.0e-05, 0.0]), @@ -185,6 +185,6 @@ def data_stream(self, frame=0): minimum_fragment_gmass = 0.2 * body_Gmass[style][1] # Make the minimum fragment mass a fraction of the smallest body gmtiny = 0.99 * body_Gmass[style][1] # Make GMTINY just smaller than the smallest original body. This will prevent runaway collisional cascades sim.set_parameter(fragmentation=True, fragmentation_save="TRAJECTORY", gmtiny=gmtiny, minimum_fragment_gmass=minimum_fragment_gmass, verbose=False) - sim.run(dt=1e-4, tstop=2.0e-3, istep_out=1, dump_cadence=0) + sim.run(dt=1e-4, tstop=4.0e-3, istep_out=1, dump_cadence=0) anim = AnimatedScatter(sim,movie_filename,movie_titles[style],style,nskip=1) \ No newline at end of file diff --git a/python/swiftest/swiftest/simulation_class.py b/python/swiftest/swiftest/simulation_class.py index 9e18a8ff8..9b9bd02dc 100644 --- a/python/swiftest/swiftest/simulation_class.py +++ b/python/swiftest/swiftest/simulation_class.py @@ -17,6 +17,7 @@ from swiftest import __file__ as _pyfile import json import os +from glob import glob from pathlib import Path import datetime import xarray as xr @@ -2667,23 +2668,23 @@ def convert(self, param_file, newcodename="Swiftest", plname="pl.swiftest.in", t Parameters ---------- - param_file : string - File name of the input parameter file - newcodename : string - Name of the desired format (Swift/Swifter/Swiftest) - plname : string - File name of the massive body input file - tpname : string - File name of the test particle input file - cbname : string - File name of the central body input file - conversion_questions : dictronary - Dictionary of additional parameters required to convert between formats + param_file : string + File name of the input parameter file + newcodename : string + Name of the desired format (Swift/Swifter/Swiftest) + plname : string + File name of the massive body input file + tpname : string + File name of the test particle input file + cbname : string + File name of the central body input file + conversion_questions : dictronary + Dictionary of additional parameters required to convert between formats Returns ------- - oldparam : xarray dataset - The old parameter configuration. + oldparam : xarray dataset + The old parameter configuration. """ oldparam = self.param if self.codename == newcodename: @@ -2720,12 +2721,12 @@ def read_output_file(self,read_init_cond : bool = True): Parameters ---------- - read_init_cond : bool - Read in an initial conditions file along with the output file. Default is True + read_init_cond : bool + Read in an initial conditions file along with the output file. Default is True Returns ------- - self.data : xarray dataset + self.data : xarray dataset """ # Make a temporary copy of the parameter dictionary so we can supply the absolute path of the binary file @@ -2765,7 +2766,8 @@ def read_output_file(self,read_init_cond : bool = True): def read_encounter(self): if self.verbose: print("Reading encounter history file as .enc") - enc_files = self.simdir.glob("**/encounter_*.nc") + enc_files = glob(f"{self.simdir}{os.path.sep}encounter_*.nc") + enc_files.sort() # This is needed in order to pass the param argument down to the io.process_netcdf_input function def _preprocess(ds, param): @@ -2774,6 +2776,9 @@ def _preprocess(ds, param): self.enc = xr.open_mfdataset(enc_files,parallel=True,combine="nested",concat_dim="time",join="left",preprocess=partial_func,mask_and_scale=True) self.enc = io.process_netcdf_input(self.enc, self.param) + # Remove any overlapping time values + tgood,tid = np.unique(self.enc.time,return_index=True) + self.enc = self.enc.isel(time=tid) return