Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Fixed more bugs in encounter data processing
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Dec 7, 2022
1 parent 3145e09 commit f4fec1e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
8 changes: 4 additions & 4 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*
!.gitignore
!Basic_Simulation/*
!Fragmentation/*
!helio_gr_test/*
!whm_gr_test/*
!Basic_Simulation
!Fragmentation
!helio_gr_test
!whm_gr_test
6 changes: 3 additions & 3 deletions examples/Fragmentation/Fragmentation_Movie.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down Expand Up @@ -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)
41 changes: 23 additions & 18 deletions python/swiftest/swiftest/simulation_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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

Expand Down

0 comments on commit f4fec1e

Please sign in to comment.