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

Commit

Permalink
Browse files Browse the repository at this point in the history
Major restructuring of the swiftest Python module. Now with OOP!
  • Loading branch information
daminton committed Jun 25, 2021
1 parent a0398de commit 33cbac8
Show file tree
Hide file tree
Showing 15 changed files with 353 additions and 311 deletions.
File renamed without changes.
32 changes: 0 additions & 32 deletions python/.ipynb_checkpoints/swiftestreader-checkpoint.py

This file was deleted.

3 changes: 3 additions & 0 deletions python/swiftest/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions python/swiftest/swiftest/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from swiftest.constants import *
from swiftest.simulation_class import Simulation
15 changes: 15 additions & 0 deletions python/swiftest/swiftest/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import numpy as np
import astropy.constants as const

# Constants in SI units
GC = np.longdouble(const.G.value)
AU2M = np.longdouble(const.au.value)
GMSunSI = np.longdouble(const.GM_sun.value)
MSun = np.longdouble(const.M_sun.value)
RSun = np.longdouble(const.R_sun.value)
JD2S = 86400
YR2S = np.longdouble(365.25 * JD2S)
einsteinC = np.longdouble(299792458.0)
# Solar oblatenes values: From Mecheri et al. (2004), using Corbard (b) 2002 values (Table II)
J2Sun = np.longdouble(2.198e-7)
J4Sun = np.longdouble(-4.805e-9)
47 changes: 47 additions & 0 deletions python/swiftest/swiftest/simulation_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from swiftest import swiftestio
class Simulation:
"""
This is a class that define the basic Swift/Swifter/Swiftest simulation object
"""
def __init__(self, param_file_name, codename="Swiftest"):
self.read_param(param_file_name, codename)
return

def read_param(self, param_file_name, codename="Swiftest"):
if codename == "Swiftest":
self.param = swiftestio.read_swiftest_param(param_file_name)
self.codename = "Swiftest"
elif codename == "Swifter":
self.param = swiftestio.read_swifter_param(param_file_name)
self.codename = "Swifter"
elif codename == "Swift":
self.param = swiftestio.read_swift_param(param_file_name)
self.codename = "Swift"
else:
print(f'{codename} is not a recognized code name. Valid options are "Swiftest", "Swifter", or "Swift".')
self.codename = "Unknown"
return

def write_param(self, param_file_name):
# Check to see if the parameter type matches the output type. If not, we need to convert
codename = self.param['VERSION'].split()[1]
if codename == "Swifter" or codename == "Swiftest":
swiftestio.write_labeled_param(self.param, param_file_name)
elif codename == "Swift":
swiftestio.write_swift_param(self.param, param_file_name)
else:
print('Cannot process unknown code type. Call the read_param method with a valid code name. Valid options are "Swiftest", "Swifter", or "Swift".')
return

def bin2xr(self):
if self.codename == "Swiftest":
self.ds = swiftestio.swiftest2xr(self.param)
elif self.codename == "Swifter":
self.ds = swiftestio.swifter2xr(self.param)
elif self.codename == "Swift":
print("Reading Swift simulation data is not implemented yet")
else:
print('Cannot process unknown code type. Call the read_param method with a valid code name. Valid options are "Swiftest", "Swifter", or "Swift".')
return


Loading

0 comments on commit 33cbac8

Please sign in to comment.