Skip to content

Commit

Permalink
Merge pull request #29 from jeonggyukim/delete-whitespaces
Browse files Browse the repository at this point in the history
Delete whitespaces
  • Loading branch information
jeonggyukim authored Jan 12, 2024
2 parents cad40d4 + 35bde5d commit 31475ec
Show file tree
Hide file tree
Showing 122 changed files with 1,204 additions and 1,204 deletions.
1 change: 0 additions & 1 deletion pyathena/classic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@
from .vtk_reader import *
from .create_pickle import *
from .plot_tools.movie import display_movie, make_movie

23 changes: 11 additions & 12 deletions pyathena/classic/add_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ def decorate(func):
return decorate

def add_fields(ds, IXN=3,
kappa_dust=500.0*yu.cm**2/yu.g,
kappa_dust=500.0*yu.cm**2/yu.g,
sigma_ph=3.0e-18*yu.cm**2,
muH=1.4272,
y=0.0,
units='LT'):
"""
Function to add derived fields to yt dataset.
Parameters
----------
ds: yt dataset
Expand All @@ -35,7 +35,7 @@ def add_fields(ds, IXN=3,
Contribution to electron density from all heavy elements
ne = (1 - xn + y)*nH
"""

# Set code units
if units == 'LT':
lunit = yu.pc
Expand All @@ -49,13 +49,13 @@ def add_fields(ds, IXN=3,
lunit = yu.cm
tunit = yu.s
munit = yu.g

vunit = lunit/tunit
Eunit = munit/(lunit*tunit**2) # energy density
Funit = (Eunit*lunit/tunit).in_cgs() # flux

field_xn = "specific_scalar[{0:d}]".format(IXN)

# Number density of H, HI and H neutral fraction
def _nH(field, data):
return data["density"]/(muH*phyc.mass_hydrogen_cgs)
Expand All @@ -68,7 +68,7 @@ def _xn(field, data):
take_log=False, display_name=r'$x_{\rm n}$')
def _nHI(field, data):
return data[("athena","xn")]*data[("athena","nH")]
ds.add_field(("athena","nHI"), sampling_type="cell",
ds.add_field(("athena","nHI"), sampling_type="cell",
function=_nHI,units="cm**-3", take_log=True,
display_name=r'$n_{\rm HI}$')

Expand All @@ -92,11 +92,11 @@ def _Temperature(field, data):
ds.add_field("Temperature", sampling_type="cell",
function=_Temperature, units="K", take_log=True,
display_name=r'$T$')

def _density_ion(field, data):
return (1.0 - data[("athena",field_xn)])*data[("athena","density")]
ds.add_field(("athena","density_ion"), sampling_type="cell",
function=_density_ion, units="g*cm**-3", take_log=True,
function=_density_ion, units="g*cm**-3", take_log=True,
display_name=r'$\rho_{\rm i}$')
def _density_neu(field, data):
return data[("athena", field_xn)]*data[("athena", "density")]
Expand All @@ -121,7 +121,7 @@ def _G0prime0(field, data):
ds.add_field("G0prime0", sampling_type="cell",
function=_G0prime0, units="dimensionless", take_log=True,
display_name=r'$G_{0,{\rm EUV}}^{\prime}$')

def _Erad1(field, data):
return data[("athena","rad_energy_density1")]*Eunit
ds.add_field(("gas","Erad1"), sampling_type="cell",
Expand All @@ -134,15 +134,15 @@ def _Jrad1(field, data):
display_name=r'$J_{\rm FUV}$')
def _G0prime1(field, data):
return data["Jrad1"]/(2.1e-4*yu.erg/yu.cm**2/yu.s/yu.sr)
ds.add_field("G0prime1", sampling_type="cell",
ds.add_field("G0prime1", sampling_type="cell",
function=_G0prime1, units="dimensionless", take_log=True,
display_name=r'$G_{0,{\rm FUV}}^{\prime}$')

# absorption coefficient per unit length
@static_vars(kappa_dust=kappa_dust)
def _chi_nion(field, data):
return _chi_nion.kappa_dust*data["density"]
ds.add_field("chi_nion", sampling_type="cell",
ds.add_field("chi_nion", sampling_type="cell",
function=_chi_nion, units="1/cm", take_log=True,
display_name=r'$\chi_{\rm FUV}$')

Expand All @@ -160,4 +160,3 @@ def _chi_ion(field, data):
ds.coordinates.x_axis['y'] = 0
ds.coordinates.y_axis[1] = 2
ds.coordinates.y_axis['y'] = 2

48 changes: 24 additions & 24 deletions pyathena/classic/ath_hst.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ def get_volume(filename):
line=file.readline()
file.close()

match=re.search('-?\d(\.\d+|)[Ee][+\-]\d\d',line)
match=re.search(r'-?\d(\.\d+|)[Ee][+\-]\d\d',line)

return eval(match.group(0))

def get_varlist(filename,snfile=False):

base=os.path.basename(filename)
split=re.split('\.',base)
split=re.split(r'\.',base)
ext=split[-1]
file=open(filename,'r')

Expand All @@ -38,12 +38,12 @@ def get_varlist(filename,snfile=False):
file.close()

if not snfile:
varlist=re.split("\[\d+]\=|\n",header)
for i in range(len(varlist)): varlist[i]=re.sub("\s|\W","",varlist[i])
varlist=re.split(r"\[\d+]\=|\n",header)
for i in range(len(varlist)): varlist[i]=re.sub(r"\s|\W","",varlist[i])
varlist=varlist[1:-1]
else:
varlist=re.split("\,",header[1:])
for i in range(len(varlist)): varlist[i]=re.sub("\s|\W","",varlist[i])
varlist=re.split(r"\,",header[1:])
for i in range(len(varlist)): varlist[i]=re.sub(r"\s|\W","",varlist[i])

return varlist

Expand All @@ -56,18 +56,18 @@ def read_w_pandas(filename,silent=False,snfile=False,write=True):
if test_pickle(filename):
hst = pd.read_pickle(filename+'.p')
if not silent: print("Reading a history file:" + filename+'.p')
else:
hst = pd.read_table(filename,skiprows=nheader,names=varlist,sep='\s*',comment='#')
else:
hst = pd.read_table(filename,skiprows=nheader,names=varlist,sep=r'\s*',comment='#')
if not silent: print("Reading a history file:" + filename)
hst.to_pickle(filename+'.p')
hst.to_pickle(filename+'.p')

return hst

def read(filename,sortable_key=False,silent=False):

if not silent: print("Reading a history file:" + filename)
base=os.path.basename(filename)
split=re.split('\.',base)
split=re.split(r'\.',base)
ext=split[-1]
file=open(filename,'r')
lines=file.readlines()
Expand All @@ -78,32 +78,32 @@ def read(filename,sortable_key=False,silent=False):
header = lines[1]

if ext == 'hst':
match=re.search('-?\d(\.\d+|)[Ee][+\-]\d\d',lines[0])
match=re.search(r'-?\d(\.\d+|)[Ee][+\-]\d\d',lines[0])
data['vol']=eval(match.group(0))

if header[0] != "#":
split=re.findall('[+\-]?\d\.?\d*[Ee][+\-]\d\d?',header)
split=re.findall(r'[+\-]?\d\.?\d*[Ee][+\-]\d\d?',header)
nvar=len(split)
varlist=[]
for i in range(nvar):
varlist.append('var%d' % i)
else:
varlist=re.split("\[\d+]\=|\n",header)
for i in range(len(varlist)): varlist[i]=re.sub("\s|\W","",varlist[i])
varlist=re.split(r"\[\d+]\=|\n",header)
for i in range(len(varlist)): varlist[i]=re.sub(r"\s|\W","",varlist[i])
varlist=varlist[1:-1]
nvar=len(varlist)

if sortable_key:
for i in range(nvar):
for i in range(nvar):
head= '%02d' % (i+1)
varlist[i] = head+varlist[i]
varlist[i] = head+varlist[i]

for var in varlist:
data[var] = []

for line in lines:
if ext == 'hst':
split=re.findall('[+\-]?\d\.?\d*[Ee][+\-]\d\d?',line)
split=re.findall(r'[+\-]?\d\.?\d*[Ee][+\-]\d\d?',line)
elif ext == 'sn':
split=line.split()
if nvar == len(split):
Expand All @@ -118,7 +118,7 @@ def readsn(filename,sortable_key=False,silent=False):

if not silent: print("Reading a sn file:" + filename)
base=os.path.basename(filename)
split=re.split('\.',base)
split=re.split(r'\.',base)
ext=split[-1]
file=open(filename,'r')
lines=file.readlines()
Expand All @@ -129,26 +129,26 @@ def readsn(filename,sortable_key=False,silent=False):
header = lines[0]

if header[0] != "#":
split=re.findall('[+\-]?\d\.?\d*[Ee][+\-]\d\d?',header)
split=re.findall(r'[+\-]?\d\.?\d*[Ee][+\-]\d\d?',header)
nvar=len(split)
varlist=[]
for i in range(nvar):
varlist.append('var')
else:
varlist=re.split("\,",header[1:])
for i in range(len(varlist)): varlist[i]=re.sub("\s|\W","",varlist[i])
varlist=re.split(r"\,",header[1:])
for i in range(len(varlist)): varlist[i]=re.sub(r"\s|\W","",varlist[i])
nvar=len(varlist)

if sortable_key:
for i in range(nvar):
for i in range(nvar):
head= '%02d' % (i+1)
varlist[i] = head+varlist[i]
varlist[i] = head+varlist[i]

for var in varlist:
data[var] = []

for line in lines[1:]:
split=re.split('\s*',line[:-1])
split=re.split(r'\s*',line[:-1])
if nvar == len(split):
for var, value in zip(varlist, split):
data[var].append(eval(value))
Expand Down
90 changes: 45 additions & 45 deletions pyathena/classic/cooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,58 @@
import numpy as np

class coolftn(object):
def __init__(self):
self.cool=cool
self.heat=heat
self.temp=temp
self.T1=T1
def __init__(self):
self.cool=cool
self.heat=heat
self.temp=temp
self.T1=T1

self.Tmin=self.T1.min()
self.Tmax=self.T1.max()
self.dT=np.log10(self.T1[1]/self.T1[0])
self.nT=len(self.T1)
self.Tmin=self.T1.min()
self.Tmax=self.T1.max()
self.dT=np.log10(self.T1[1]/self.T1[0])
self.nT=len(self.T1)

def get_Tidx(self,T):
if type(T)==np.ndarray:
Tidx=np.log10(T/self.Tmin)/self.dT
Tidx[np.where(T<self.Tmin)]=0
Tidx[np.where(T>=self.Tmax)]=self.nT-2
return Tidx.astype(int)
else:
if T < self.Tmin: return 0
if T >= self.Tmax: return self.nT-2
Tidx=np.log10(T/self.Tmin)/self.dT
return int(Tidx)
def get_Tidx(self,T):
if type(T)==np.ndarray:
Tidx=np.log10(T/self.Tmin)/self.dT
Tidx[np.where(T<self.Tmin)]=0
Tidx[np.where(T>=self.Tmax)]=self.nT-2
return Tidx.astype(int)
else:
if T < self.Tmin: return 0
if T >= self.Tmax: return self.nT-2
Tidx=np.log10(T/self.Tmin)/self.dT
return int(Tidx)

def get_temp(self,T1):
T1idx=self.get_Tidx(T1)
Ti=self.temp[T1idx]
Tip1=self.temp[T1idx+1]
T1i=self.T1[T1idx]
T1ip1=self.T1[T1idx+1]
T=Ti+(Tip1-Ti)*(T1-T1i)/(T1ip1-T1i)
def get_temp(self,T1):
T1idx=self.get_Tidx(T1)
Ti=self.temp[T1idx]
Tip1=self.temp[T1idx+1]
T1i=self.T1[T1idx]
T1ip1=self.T1[T1idx+1]
T=Ti+(Tip1-Ti)*(T1-T1i)/(T1ip1-T1i)

return T
return T

def get_cool(self,T1):
T1idx=self.get_Tidx(T1)
Li=self.cool[T1idx]
Lip1=self.cool[T1idx+1]
T1i=self.T1[T1idx]
T1ip1=self.T1[T1idx+1]
L=Li+(Lip1-Li)*(T1-T1i)/(T1ip1-T1i)
def get_cool(self,T1):
T1idx=self.get_Tidx(T1)
Li=self.cool[T1idx]
Lip1=self.cool[T1idx+1]
T1i=self.T1[T1idx]
T1ip1=self.T1[T1idx+1]
L=Li+(Lip1-Li)*(T1-T1i)/(T1ip1-T1i)

return L

def get_heat(self,T1):
T1idx=self.get_Tidx(T1)
Gi=self.heat[T1idx]
Gip1=self.heat[T1idx+1]
T1i=self.T1[T1idx]
T1ip1=self.T1[T1idx+1]
G=Gi+(Gip1-Gi)*(T1-T1i)/(T1ip1-T1i)
return L

return G
def get_heat(self,T1):
T1idx=self.get_Tidx(T1)
Gi=self.heat[T1idx]
Gip1=self.heat[T1idx+1]
T1i=self.T1[T1idx]
T1ip1=self.T1[T1idx+1]
G=Gi+(Gip1-Gi)*(T1-T1i)/(T1ip1-T1i)

return G

cool=np.array([ 8.27861336e-31, 9.84438083e-31, 1.16632763e-30,
1.37686216e-30, 1.61969658e-30, 1.89882491e-30,
Expand Down
Loading

0 comments on commit 31475ec

Please sign in to comment.