This repository was archived by the owner on Aug 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Major restructuring of the swiftest Python module. Now with OOP!
- Loading branch information
Showing
15 changed files
with
353 additions
and
311 deletions.
There are no files selected for viewing
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| from swiftest.constants import * | ||
| from swiftest.simulation_class import Simulation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
|
|
Oops, something went wrong.