Skip to content

Commit 748e030

Browse files
committed
Merge branch 'master' of https://github.com/ideasrule/pyTPCI
2 parents 66dda44 + 16da769 commit 748e030

File tree

6 files changed

+871
-353
lines changed

6 files changed

+871
-353
lines changed

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
pyTPCI is an improved version of The PLUTO-CLOUDY Interface, coupling together hydrodynamics code [PLUTO](https://plutocode.ph.unito.it/) and gas microphysics code [CLOUDY](https://gitlab.nublado.org/cloudy/cloudy).
2+
3+
## Setup
4+
1) After cloning the pyTPCI directory to your computer, copy the `wrapper` folder for **each instance of pyTPCI you wish to run**.
5+
2) Define the environment variable `PLUTO_DIR` and run `$PLUTO_DIR/setup.py` in your folder. Further customization of PLUTO takes place in `pluto_template.ini`.
6+
3) Run `make` and `make clean` in your folder to produce the PLUTO executable.
7+
4) Run `make` in `cloudy/source` to produce `cloudy.exe`.
8+
9+
pyTPCI runs PLUTO and then CLOUDY in alternating steps, transferring heating information between them with `write_heating_file`. In order to save computational power and improve speed,
10+
by default pyTPCI only calls CLOUDY if there is at least a 10% maximum fractional difference (`max_rel_diff`) in density or pressure between PLUTO files.
11+
12+
## Running pyTPCI
13+
1) Create a stellar spectrum at the planet's surface (semimajor axis), with columns of log10(frequency (Hz)) and log10(F_nu), spectral irradiance (ergs/(s cm^2 Hz)). At the end this also contains the band-integrated flux at the planet's surface, and the energy range in Rydbergs. See `spectra_example.ini`.
14+
2) Edit `tpci.py` to set the system parameters: the stellar spectrum file, the semimajor axis, planet radius and mass, stellar mass, initial temperature, and metallicity. Upon running, this will generate a CLOUDY `params.h` file and an input script ending in `.in`.
15+
3) Open `screen` and run `python tpci.py` to start at t=0 and use the default timestep dt=0.01. If restarting from a previous pyTPCI run, instead do `python tpci.py global_ind time timestep`, where `global_ind` is the number of the CLOUDY file you wish to start from.
16+
4) Monitor pyTPCI's progress by plotting PLUTO and CLOUDY files using `plot.py` and `cloudy_plot.py`.
17+
18+
## Plotting information
19+
- To plot one file, run `python plot.py global_ind` where `global_ind` is the number of the file, such as "54".
20+
- To plot multiple files, run `python plot.py start stop step`, where `start` and `stop` are the initial and final file numbers to plot, with a given `step`. Plotting files will automatically skip file names that do not exist.
21+
22+
## Logging and Docs information
23+
- pyTPCI run information is in `tpci_log.txt`.
24+
- PLUTO output logs for each PLUTO run are appended in `pluto_log.txt`
25+
- CLOUDY docs are in `cloudy/docs` and PLUTO docs are in `PLUTO/Doc`
26+
27+
## Troubleshooting and Common Errors
28+
- Is the path to the `spectra.ini` file correct?
29+
- Does `definitions.h` contain `#include params.h` at the top?
30+
- If CLOUDY crashes quickly, try using a smaller dt=0.001

hd209458/tpci.py

Lines changed: 0 additions & 258 deletions
This file was deleted.

scripts/cloudy_plot.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
import numpy as np
22
import matplotlib.pyplot as plt
33
import sys
4+
import os
45

5-
unit_length = 2.9 * 6.378136e8
6+
# replace with planet radius (Earth radii)
7+
unit_length = 12.54 * 6.378136e8
68

7-
for filename in sys.argv[1:]:
8-
depth, rho, n, mu, Te = np.loadtxt(filename, usecols=range(5), unpack=True)
9+
10+
# start, [stop, step]
11+
if len(sys.argv) == 2:
12+
start = str(sys.argv[1])
13+
files = ['cl_data.'+start.zfill(4)+'.over.tab']
14+
else:
15+
start, stop, step = int(sys.argv[1]), int(sys.argv[2]), int(sys.argv[3])
16+
file_nums = list(map(str, np.arange(start, stop+1, step)))
17+
files = []
18+
for i in range(len(file_nums)):
19+
fname = 'cl_data.'+file_nums[i].zfill(4)+'.over.tab'
20+
if os.path.exists(fname): # skip files that don't exist
21+
files.append(fname)
22+
23+
# oldest is purple, proceeds through rainbow to newest (red)
24+
colors = plt.cm.rainbow(np.linspace(0, 1, len(files)))
25+
26+
for i, file in enumerate(files):
27+
depth, rho, n, mu, Te = np.loadtxt(file, usecols=range(5), unpack=True)
928
cloudy_radii = 1 + (np.max(depth) - depth) / unit_length
10-
plt.plot(cloudy_radii, Te)
29+
plt.plot(cloudy_radii, Te, color=colors[i])
1130

1231
plt.show()

scripts/plot.py

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,49 @@
11
import numpy as np
22
import matplotlib.pyplot as plt
33
import sys
4+
import os
45

5-
for i, filename in enumerate(sys.argv[1:]):
6-
#if i % 2 != 1:
7-
# continue
6+
# PLUTO units
7+
UNIT_DENSITY = 1e-10
8+
UNIT_VELOCITY = 1e5
9+
UNIT_PRESSURE = UNIT_DENSITY * UNIT_VELOCITY**2
10+
11+
# start [stop, step]
12+
if len(sys.argv) == 2:
13+
start = str(sys.argv[1])
14+
files = ['data.'+start.zfill(4)+'.tab']
15+
else:
16+
start, stop, step = int(sys.argv[1]), int(sys.argv[2]), int(sys.argv[3])
17+
file_nums = list(map(str, np.arange(start, stop+1, step)))
18+
files = []
19+
for i in range(len(file_nums)):
20+
fname = 'data.'+file_nums[i].zfill(4)+'.tab'
21+
if os.path.exists(fname): # skip files that don't exist
22+
files.append(fname)
23+
24+
# oldest is purple, proceeds through rainbow to newest (red)
25+
colors = plt.cm.rainbow(np.linspace(0,1, len(files)))
26+
27+
for i, filename in enumerate(files):
828

929
r, rho, v, P = np.loadtxt(filename, usecols=(0,2,3,6), unpack=True)
10-
#r, rho, v = np.loadtxt(filename, usecols=(0,2,3), unpack=True)
1130
plt.figure(0)
12-
plt.loglog(r, rho)
31+
plt.loglog(r, rho*UNIT_DENSITY, color=colors[i])
32+
plt.ylabel("Density (g/cm3)")
1333
plt.title("rho")
1434

1535
plt.figure(1)
16-
plt.semilogx(r, v)
36+
plt.loglog(r, v, color=colors[i])
37+
plt.ylabel("Velocity (km/s)")
1738
plt.title("v")
1839

1940
plt.figure(2)
20-
plt.loglog(r, P)
41+
plt.loglog(r, P*UNIT_PRESSURE, color=colors[i])
42+
plt.ylabel("Pressure (g/(cm s^2))")
2143
plt.title("P")
2244

2345
plt.figure(3)
24-
plt.loglog(r, P*2.3*1.67e-24/(1.38e-16*rho*1e-10))
25-
plt.title("T?")
46+
plt.loglog(r, P*2.3*1.67e-24/(1.38e-16*rho*1e-10), color=colors[i])
47+
plt.title("Estimated Temperature (K)")
2648

2749
plt.show()

0 commit comments

Comments
 (0)