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