Commit 7c2ce85a authored by Shuai Feng's avatar Shuai Feng
Browse files

fix PEP8 bugs

parent 1128112c
Pipeline #7131 failed with stage
in 0 seconds
......@@ -22,13 +22,12 @@ class config():
dpix : float, optional
Pixel size in the spatial direction, by default 0.2arcsec
"""
def __init__(self, wave_min=3500.0, wave_max=10000.0,
def __init__(self, wave_min=3500.0, wave_max=10000.0,
dlam=2.0, inst_fwhm=0.1,
nx=30, ny=30, dpix=0.2):
self.dlam = dlam
self.wave = np.arange(wave_min, wave_max, dlam)
self.wave_min = wave_min
self.inst_fwhm = inst_fwhm
self.nx = nx
self.ny = ny
......
......@@ -9,86 +9,78 @@ class Cube3D():
Class of 3-dimentional spectral cube
"""
def __init__(self, config, stellar_map=None, gas_map=None):
self.config = config
self.nx = config.nx
self.ny = config.ny
self.dpix = config.dpix
self.fov_x = config.fov_x
self.fov_y = config.fov_y
self.wave = config.wave
self.nz = len(self.wave)
self.wave0 = np.min(self.wave)
self.inst_fwhm = config.inst_fwhm
self.flux = np.zeros((self.nx, self.ny, self.nz))
self.stellar_map = stellar_map
self.gas_map = gas_map
def make_cube(self, stellar_tem=None, hii_tem=None):
for i in range(self.nx):
for j in range(self.ny):
if self.stellar_map is not None:
ss = StellarContinuum(self.config, stellar_tem, mag=self.stellar_map.mag[i, j],
age=self.stellar_map.age[i, j], feh=self.stellar_map.feh[i, j],
vel=self.stellar_map.vel[i, j], vdisp=self.stellar_map.vdisp[i, j],
ss = StellarContinuum(self.config, stellar_tem, mag=self.stellar_map.mag[i, j],
age=self.stellar_map.age[i, j], feh=self.stellar_map.feh[i, j],
vel=self.stellar_map.vel[i, j], vdisp=self.stellar_map.vdisp[i, j],
ebv=self.stellar_map.ebv[i, j])
if self.gas_map is not None:
gg = HII_Region(self.config, hii_tem, halpha=self.gas_map.halpha[i, j],
logz=self.gas_map.zh[i, j], vel=self.gas_map.vel[i, j],
gg = HII_Region(self.config, hii_tem, halpha=self.gas_map.halpha[i, j],
logz=self.gas_map.zh[i, j], vel=self.gas_map.vel[i, j],
vdisp=self.gas_map.vdisp[i, j], ebv=self.gas_map.ebv[i, j])
self.flux[i, j, :] = ss.flux + gg.flux
else:
self.flux[i, j, :] = ss.flux
def wcs_info(self):
# wcs = fits.Header()
wcs_dict = {'CTYPE1': 'WAVE ',
'CUNIT1': 'Angstrom',
'CDELT1': self.config.dlam,
'CRPIX1': 1,
'CRVAL1': np.min(self.wave),
'CTYPE2': 'RA---TAN',
'CUNIT2': 'deg',
'CDELT2': self.dpix / 3600.,
'CRPIX2': np.round(self.ny / 2.),
'CRVAL2': 0.5,
'CTYPE3': 'DEC--TAN',
'CUNIT3': 'deg',
'CDELT3': self.dpix / 3600.,
'CRPIX3': np.round(self.nx / 2.),
'CRVAL3': 1,
wcs_dict = {'CTYPE1': 'WAVE ',
'CUNIT1': 'Angstrom',
'CDELT1': self.config.dlam,
'CRPIX1': 1,
'CRVAL1': np.min(self.wave),
'CTYPE2': 'RA---TAN',
'CUNIT2': 'deg',
'CDELT2': self.dpix / 3600.,
'CRPIX2': np.round(self.ny / 2.),
'CRVAL2': 0.5,
'CTYPE3': 'DEC--TAN',
'CUNIT3': 'deg',
'CDELT3': self.dpix / 3600.,
'CRPIX3': np.round(self.nx / 2.),
'CRVAL3': 1,
'BUNIT': '10**(-17)*erg/s/cm**2/Angstrom'}
input_wcs = astropy.wcs.WCS(wcs_dict)
self.wcs_header = input_wcs.to_header()
def insert_spec(self, spec, dx=0, dy=0):
x0 = np.int(np.round(self.config.nx / 2.))
y0 = np.int(np.round(self.config.ny / 2.))
self.flux[x0 + dx, y0 + dy, :] = self.flux[x0 + dx, y0 + dy, :] + spec.flux
def savefits(self, filename, path='./'):
def savefits(self, filename, path='./'):
hdr = fits.Header()
hdr['FILETYPE'] = 'SCICUBE'
hdr['CODE'] = 'CSST-IFS-GEHONG'
hdr['VERSION'] = '0.0.1'
hdr['OBJECT'] = 'NGC1234'
hdr['RA'] = 0.0
hdr['DEC'] = 0.0
hdu0 = fits.PrimaryHDU(header=hdr)
self.wcs_info()
hdr = self.wcs_header
hdu1 = fits.ImageHDU(self.flux, header=hdr)
# Output
hdulist = fits.HDUList([hdu0, hdu1])
hdulist.writeto(path + filename, overwrite=True)
\ No newline at end of file
hdulist.writeto(path + filename, overwrite=True)
......@@ -49,23 +49,23 @@ def Sersic2D(x, y, mag=12.0, r_eff=1.0, n=2.0, ellip=0.5,
x_min = -(x - x_0) * sin_theta + (y - y_0) * cos_theta
z = (abs(x_maj / a) ** 2 + abs(x_min / b) ** 2) ** (1 / 2)
profile = np.exp(-bn * (z ** (1 / n) - 1))
# Normalization
integral = a * b * 2 * np.pi * n * np.exp(bn) / (bn ** (2 * n)) * sp.gamma(2 * n)
prof_norm = profile / integral * pixelscale
# Calibration
total_flux = 10. ** ((22.5 - mag) * 0.4)
sb_mag = 22.5 - 2.5 * np.log10(prof_norm * total_flux / pixelscale)
return sb_mag
def VelMap2D(x, y, vmax=200.0, rt=1.0, ellip=0.5,
def VelMap2D(x, y, vmax=200.0, rt=1.0, ellip=0.5,
theta=0.0, x_0=0.0, y_0=0.0):
"""
VelMap2D: Caculate the velocity at given spatial position base on the rotating disk model.
The rotation curve is adpot as the tanh model.
VelMap2D: Caculate the velocity at given spatial position base on the rotating disk model.
The rotation curve is adpot as the tanh model.
Parameters
----------
......@@ -102,15 +102,15 @@ def VelMap2D(x, y, vmax=200.0, rt=1.0, ellip=0.5,
x_min = -(x - x_0) * sin_theta + (y - y_0) * cos_theta
z = (abs(x_maj / a) ** 2 + abs(x_min / b) ** 2) ** (1 / 2)
profile = vmax * np.tanh(z) * ((x_maj / a) / z)
return profile
def GradMap2D(x, y, a0=10.0, r_eff=1.0, gred=-1.0, ellip=0.5,
def GradMap2D(x, y, a0=10.0, r_eff=1.0, gred=-1.0, ellip=0.5,
theta=0.0, x_0=0.0, y_0=0.0):
"""
GradMap2D: Caculate the intensity at given spatial position base on the disk model.
The radial profile is adpot as the gradient model.
GradMap2D: Caculate the intensity at given spatial position base on the disk model.
The radial profile is adpot as the gradient model.
Parameters
----------
......@@ -149,7 +149,7 @@ def GradMap2D(x, y, a0=10.0, r_eff=1.0, gred=-1.0, ellip=0.5,
x_min = -(x - x_0) * sin_theta + (y - y_0) * cos_theta
z = (abs(x_maj / a) ** 2 + abs(x_min / b) ** 2) ** (1 / 2)
profile = a0 + z * gred
return profile
......@@ -207,7 +207,7 @@ class Map2d(object):
xsh_rot = xsh * np.cos(pa_radians) + ysh * np.sin(pa_radians)
ysh_rot = -xsh * np.sin(pa_radians) + ysh * np.cos(pa_radians)
return ysh_rot, xsh_rot
def sersic_map(self, mag=12.0, r_eff=2.0, n=2.5, ellip=0.5, theta=-50.0):
"""
Generate 2D map of Sersic model
......@@ -246,11 +246,11 @@ class Map2d(object):
self.n = n
self.ellip = ellip
self.theta = theta
self.map = Sersic2D(self.x, self.y, mag=self.mag,
r_eff=self.reff, n=self.n,
ellip=self.ellip, theta=self.theta,
self.map = Sersic2D(self.x, self.y, mag=self.mag,
r_eff=self.reff, n=self.n,
ellip=self.ellip, theta=self.theta,
pixelscale=self.xsamp * self.ysamp)
def tanh_map(self, vmax=200.0, rt=2.0, ellip=0.5, theta=-50.0):
"""
Generate 2D velocity map of rotating disk according to tanh rotation curve
......@@ -284,9 +284,9 @@ class Map2d(object):
self.rt = rt / self.xsamp
self.ellip = ellip
self.theta = theta
self.map = VelMap2D(self.x, self.y, vmax=self.vmax, rt=self.rt,
self.map = VelMap2D(self.x, self.y, vmax=self.vmax, rt=self.rt,
ellip=self.ellip, theta=self.theta)
def gred_map(self, a0=10, r_eff=1, gred=-1, ellip=0.5, theta=0):
"""
Generate 2D maps according to the radial gradient form
......@@ -319,9 +319,9 @@ class Map2d(object):
self.gred = gred
self.ellip = ellip
self.theta = theta
self.map = GradMap2D(self.x, self.y, a0=self.a0, r_eff=self.reff,
self.map = GradMap2D(self.x, self.y, a0=self.a0, r_eff=self.reff,
gred=self.gred, ellip=self.ellip, theta=self.theta)
def load_map(self, image):
"""
Generate 2D map according to input image
......@@ -339,10 +339,10 @@ class Map2d(object):
class StellarPopulationMap():
"""
Class of 2D maps for the parameters of stellar population, such as
surface brightness, median age and metallicity of stellar population,
Class of 2D maps for the parameters of stellar population, such as
surface brightness, median age and metallicity of stellar population,
velocity and velocity dispersion maps, and dust extinction.
Parameters
----------
config : class
......@@ -360,7 +360,7 @@ class StellarPopulationMap():
ebv : class, optional
Class of the map of dust extinction, by default None
"""
def __init__(self, config, sbright=None, logage=None,
def __init__(self, config, sbright=None, logage=None,
feh=None, vel=None, vdisp=None, ebv=None):
self.nx = config.nx
......@@ -368,29 +368,29 @@ class StellarPopulationMap():
self.dpix = config.dpix
self.fov_x = config.fov_x
self.fov_y = config.fov_y
if (sbright is None):
print('Input SurfaceBrightness Map is empty!')
else:
self.sbright = sbright.map
self.mag = self.sbright - 2.5 * np.log10(self.dpix * self.dpix)
if (logage is None):
print('Input Age Map is empty!')
else:
self.logage = logage.map
self.age = 10 ** self.logage / 1e9
if (feh is None):
print('Input Metallicity Map is empty!')
else:
self.feh = feh.map
if (vel is None):
print('Input Velocity Map is empty!')
else:
self.vel = vel.map
if (vdisp is None):
print('Input VelocityDispersion Map is empty!')
else:
......@@ -399,7 +399,7 @@ class StellarPopulationMap():
if len(self.vdisp[ind_overrange]) > 0:
print("Notice: Spaxel with <10km/s in the input vdisp map will be automatically adjusted to 10km/s.")
self.vdisp[ind_overrange] = 10
if (ebv is None):
print('Input EBV Map is empty!')
else:
......@@ -408,12 +408,12 @@ class StellarPopulationMap():
if len(self.ebv[ind_overrange]) > 0:
print("Notice: Spaxel with < 0 mag in the input ebv map will be automatically adjusted to 0 mag.")
self.ebv[ind_overrange] = 0
class IonizedGasMap():
"""
Class of 2D maps for the parameters of ionized gas, such as
Halpha flux map, gas-phase metallicity map,
Class of 2D maps for the parameters of ionized gas, such as
Halpha flux map, gas-phase metallicity map,
velocity and velocity dispersion maps, and dust extinction.
Parameters
......@@ -432,13 +432,13 @@ class IonizedGasMap():
Class of the map of dust extinction, by default None
"""
def __init__(self, config, halpha=None, zh=None, vel=None, vdisp=None, ebv=None):
self.nx = config.nx
self.ny = config.ny
self.dpix = config.dpix
self.fov_x = config.fov_x
self.fov_y = config.fov_y
if (halpha is None):
print('Input Halpha Map is empty!')
else:
......@@ -470,4 +470,4 @@ class IonizedGasMap():
ind_overrange = (self.ebv < 0)
if len(self.ebv[ind_overrange]) > 0:
print("Notice: Spaxel with < 0 mag in the input ebv map will be automatically adjusted to 0 mag.")
self.ebv[ind_overrange] = 0
\ No newline at end of file
self.ebv[ind_overrange] = 0
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment