Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused modules, commented unused vars, some Ruff suggestions #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion BasicRun.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# ## Basic Operations of the SYOTools version of the HWO ETCs

#first the necessary imports
from syotools.models import Camera, Telescope, Spectrograph, PhotometricExposure, SpectrographicExposure
from syotools.models import Camera, Telescope, PhotometricExposure
from syotools.utils.jsonunit import str_jsunit

# create a Telescope, Camera, and Exposure
Expand Down
3 changes: 1 addition & 2 deletions camera_etc/get_hdi_seds.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from __future__ import print_function
import pysynphot as S
import os
from astropy.io import ascii

def add_spectrum_to_library():

cwd = os.getenv('LUVOIR_SIMTOOLS_DIR')
# cwd = os.getenv('LUVOIR_SIMTOOLS_DIR')

spec_dict = {}

Expand Down
6 changes: 2 additions & 4 deletions camera_etc/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import numpy as np
from bokeh.io import output_file
from bokeh.plotting import Figure
from bokeh.embed import components
from bokeh.models import ColumnDataSource, HoverTool, Paragraph, Range1d
from bokeh.models import ColumnDataSource, HoverTool, Range1d
from bokeh.models.callbacks import CustomJS
from bokeh.models import Column
from bokeh.layouts import row
Expand Down Expand Up @@ -95,7 +93,7 @@ def update_data(attrname, old, new):
new_f = np.array(new_f0)
spectrum_template.data = {'w':new_w, 'f':new_f, 'w0':new_w0, 'f0':new_f0}

interp_mags = spec_dict[template.value]
# interp_mags = spec_dict[template.value]
mag_arr = np.array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])
for pwave,index in zip(hdi.pivotwave,np.arange(10)):
mag_arr[index] = ss.sample(pwave)
Expand Down
8 changes: 4 additions & 4 deletions camera_etc/phot_compute_snr.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def compute_snr(telescope, camera, exposure_in_hours, ab_magnitudes):
diff_limit = 1.22*(500.*0.000000001)*206264.8062/telescope.aperture
#print 'diff_limit', diff_limit

source_magnitudes = np.array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]) * ab_magnitudes
# source_magnitudes = np.array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]) * ab_magnitudes

sky_brightness = np.array([23.807, 25.517, 22.627, 22.307, 21.917, 22.257, 21.757, 21.567, 22.417, 22.537])
fwhm_psf = 1.22 * camera.pivotwave * 0.000000001 * 206264.8062 / telescope.aperture
Expand All @@ -20,17 +20,17 @@ def compute_snr(telescope, camera, exposure_in_hours, ab_magnitudes):

desired_exposure_time = np.array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]) * exposure_in_hours * 3600.

time_per_exposure = desired_exposure_time / number_of_exposures
# time_per_exposure = desired_exposure_time / number_of_exposures

signal_counts = camera.total_qe * desired_exposure_time * camera.ab_zeropoint * camera.aperture_correction * (np.pi) / 4. * \
(telescope.aperture * 100.0)**2 * camera.derived_bandpass * 10.**(-0.4*ab_magnitudes)

shot_noise_in_signal = signal_counts ** 0.5
# shot_noise_in_signal = signal_counts ** 0.5

sky_counts = camera.total_qe * desired_exposure_time * camera.ab_zeropoint * np.pi / 4. * (telescope.aperture * 100.0)**2 * \
camera.derived_bandpass * 10.**(-0.4*sky_brightness) * (camera.pixel_size * sn_box)**2

shot_noise_in_sky = sky_counts ** 0.5
# shot_noise_in_sky = sky_counts ** 0.5

read_noise = camera.detector_read_noise * sn_box * number_of_exposures**0.5

Expand Down
16 changes: 8 additions & 8 deletions coron_model/coronagraph/Observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def planetzoo_observation(name='earth', telescope=Telescope(), planet=Planet(),
try:
l = os.listdir(planetdir)
except OSError:
print "Error in planetzoo_observation(): planetdir does not exist in current location. \nSet planetdir='location/of/planets/'"
print ("Error in planetzoo_observation(): planetdir does not exist in current location. \nSet planetdir='location/of/planets/'")
return None

whichplanet = name
Expand Down Expand Up @@ -298,15 +298,15 @@ def planetzoo_observation(name='earth', telescope=Telescope(), planet=Planet(),
# Save plot if saveplot==True
if saveplot:
fig.savefig(plot_tag)
print 'Saved: '+plot_tag
print ('Saved: '+plot_tag)
fig.show()

# Save Synthetic data file (wavelength, albedo, error) if savedata=True
if savedata:
data_tag = 'observed_'+tag+'.txt'
y_sav = np.array([lam,spec,sig])
np.savetxt(data_tag, y_sav.T)
print 'Saved: '+data_tag
print ('Saved: '+data_tag)

# Return Synthetic data and high-res spec
return lam, spec, sig
Expand Down Expand Up @@ -419,15 +419,15 @@ def generate_observation(wlhr, Ahr, solhr, itime, telescope, planet, star,
# Save plot if saveplot==True
if saveplot:
fig.savefig(plot_tag)
print 'Saved: '+plot_tag
print ('Saved: '+plot_tag)
fig.show()

# Save Synthetic data file (wavelength, albedo, error) if savedata=True
if savedata:
data_tag = 'observed_'+tag+'.txt'
y_sav = np.array([lam,spec,sig])
np.savetxt(data_tag, y_sav.T)
print 'Saved: '+data_tag
print ('Saved: '+data_tag)

# Return Synthetic data and high-res spec

Expand Down Expand Up @@ -553,15 +553,15 @@ def smart_observation(radfile, itime, telescope, planet, star,
# Save plot if saveplot==True
if saveplot:
fig.savefig(plot_tag)
print 'Saved: '+plot_tag
print ('Saved: '+plot_tag)
fig.show()

# Save Synthetic data file (wavelength, albedo, error) if savedata=True
if savedata:
data_tag = 'observed_smart_'+tag+'.txt'
y_sav = np.array([lam,spec,sig])
np.savetxt(data_tag, y_sav.T)
print 'Saved: '+data_tag
print ('Saved: '+data_tag)

# Return Synthetic data and high-res spec

Expand Down Expand Up @@ -620,7 +620,7 @@ def plot_spec():
# Save plot if saveplot==True
if saveplot:
fig.savefig(plot_tag)
print 'Saved: '+plot_tag
print ('Saved: '+plot_tag)
fig.show()

def process_noise(Dt, Cratio, cp, cb):
Expand Down
1 change: 0 additions & 1 deletion coron_model/coronagraph/Spectrum.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np
import readsmart as rs

class Spectrum(object):

Expand Down
3 changes: 1 addition & 2 deletions coron_model/coronagraph/call_noise.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import numpy as np
from .make_noise import make_noise
from .teleplanstar import Star
import pdb

__all__ = ['call_noise']

Expand All @@ -26,7 +25,7 @@ def call_noise(telescope,planet,Ahr='',lamhr='', solhr='',
lamhr = model[:,0]
radhr = model[:,1]
solhr = model[:,2]
reflhr = model[:,3]
# reflhr = model[:,3]
Ahr = np.pi*(np.pi*radhr/solhr) # hi-resolution reflectivity
planet.Rp = 1.0 # Earth radii
planet.r = 1.0 # semi-major axis (AU)
Expand Down
3 changes: 1 addition & 2 deletions coron_model/coronagraph/convolve_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import scipy as sp
from .degrade_spec import degrade_spec
from scipy import interp
from scipy import ndimage

__all__ = ['convolve_spec']

Expand All @@ -19,7 +18,7 @@ def convolve_spec(Ahr, lamhr, filters, forceTopHat=False):
tdict = sorted(filters.__dict__.iteritems(), key=lambda x: x[1].bandcenter)
F = []
for x in tdict:
if (x[1].wl == None) or (x[1].response == None) or forceTopHat:
if (x[1].wl is None) or (x[1].response is None) or forceTopHat:
# Use FWHM with tophat convolution
Fi = tophat_instrument(Ahr, lamhr, x[1].bandcenter, FWHM=x[1].FWHM)
else:
Expand Down
11 changes: 5 additions & 6 deletions coron_model/coronagraph/count_rates.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# Import dependent modules
import numpy as np
import sys
from .degrade_spec import degrade_spec, downbin_spec
from .degrade_spec import downbin_spec
from .convolve_spec import convolve_spec
from .noise_routines import Fstar, Fplan, FpFs, cplan, czodi, cezodi, cspeck, \
cdark, cread, ctherm, ccic, f_airy, ctherm_earth, construct_lam, \
cdark, cread, ctherm, f_airy, ctherm_earth, construct_lam, \
set_quantum_efficiency, set_read_noise, set_dark_current, set_cic, set_lenslet, \
set_throughput, set_atmos_throughput, get_thermal_ground_intensity, \
exptime_element, lambertPhaseFunction
import pdb
import os


__all__ = ['count_rates']

Expand Down Expand Up @@ -215,7 +214,7 @@ def count_rates(Ahr, lamhr, solhr,
lam = np.array([x[1].bandcenter for x in tdict])
# Construct array of wavelength bin widths (FWHM)
dlam = np.array([x[1].FWHM for x in tdict])
Nlam = len(lam)
# Nlam = len(lam)
elif mode == 'IFS':
IMAGE = False
COMPUTE_LAM = True
Expand Down Expand Up @@ -297,7 +296,7 @@ def count_rates(Ahr, lamhr, solhr,
# Compute fluxes
Fs = Fstar(lam, Teff, Rs, r, AU=True) # stellar flux on planet
Fp = Fplan(A, Phi, Fs, Rp, d) # planet flux at telescope
i = (lam >= 0.54) & (lam <= 0.56)
# i = (lam >= 0.54) & (lam <= 0.56)


Cratio = FpFs(A, Phi, Rp, r)
Expand Down
15 changes: 7 additions & 8 deletions coron_model/coronagraph/count_rates_onirs.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# Import dependent modules
import numpy as np
import sys
from .degrade_spec import degrade_spec, downbin_spec
from .degrade_spec import downbin_spec
from .convolve_spec import convolve_spec
from .noise_routines import Fobj, cobj, czodi, \
cdark, cread, ctherm, ccic, f_airy, ctherm_earth, construct_lam, \
cdark, cread, ctherm, f_airy, ctherm_earth, construct_lam, \
set_quantum_efficiency, set_read_noise, set_dark_current, set_lenslet, \
set_throughput, set_atmos_throughput, get_thermal_ground_intensity, \
exptime_element, lambertPhaseFunction
import pdb
import os
set_atmos_throughput, get_thermal_ground_intensity, \
exptime_element


__all__ = ['count_rates_onirs']

Expand Down Expand Up @@ -163,7 +162,7 @@ def count_rates_onirs(Fohr, lamhr,
lam = np.array([x[1].bandcenter for x in tdict])
# Construct array of wavelength bin widths (FWHM)
dlam = np.array([x[1].FWHM for x in tdict])
Nlam = len(lam)
# Nlam = len(lam)
elif mode == 'IFS':
IMAGE = False
COMPUTE_LAM = True
Expand Down Expand Up @@ -257,7 +256,7 @@ def count_rates_onirs(Fohr, lamhr,

cb = (cz + cD + cR + cth)
cnoise = co + 2*cb # assumes background subtraction
ctot = co + cz + cD + cR + cth
# ctot = co + cz + cD + cR + cth

'''
Giada: where does the factor of 2 come from [above]?
Expand Down
3 changes: 0 additions & 3 deletions coron_model/coronagraph/count_rates_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Import dependent modules
import numpy as np
import sys
from .count_rates import count_rates
from .Noise import Output
import pdb

__all__ = ['count_rates_wrapper']

Expand Down
1 change: 0 additions & 1 deletion coron_model/coronagraph/degrade_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""

import numpy as np
import scipy as sp
from scipy import interpolate
from scipy.stats import binned_statistic

Expand Down
8 changes: 4 additions & 4 deletions coron_model/coronagraph/filters/imager.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,19 @@ def plot(self, ax=None):
#ax1.set_ylim([0.0,10.0])
ax1.axes.get_yaxis().set_visible(False)

Nfilt = len(self.__dict__)
# Nfilt = len(self.__dict__)
#colors,scalarMap,cNorm = scalarmap(np.arange(Nfilt),cmap='Dark2')
i = 0
fmax = 1.0
for attr, value in self.__dict__.iteritems():
for _, value in self.__dict__.iteritems():
if np.max(value.response) > fmax: fmax = np.max(value.response)
wl, response = value.wl, value.response
#ax1.plot(wl,response, lw=3.0, label=value.name, c=colors[i])
ax1.fill_between(wl,response, color='purple', alpha=0.3)
i += 1
ax1.set_ylim([0.0,fmax*10.])

if ax==None:
if ax is None:
return ax1

def __str__(self):
Expand Down Expand Up @@ -143,7 +143,7 @@ def read_landsat():
swir1 = np.genfromtxt(path+'SWIR1.txt', skip_header=1)
swir2 = np.genfromtxt(path+'SWIR2.txt', skip_header=1)
LANDSAT_names = ['Coastal Aerosols','Blue','Green','Red','NIR','SWIR1','SWIR2','Pan','Cirrus']
titles = ['wl','response','std','bandwidth','FWHM_low','FWHM_high','bandcenter']
# titles = ['wl','response','std','bandwidth','FWHM_low','FWHM_high','bandcenter']
wl = [coastal[:,0]/1e3, blue[:,0]/1e3, green[:,0]/1e3, red[:,0]/1e3, nir[:,0]/1e3, swir1[:,0]/1e3, swir2[:,0]/1e3, pan[:,0]/1e3, cirrus[:,0]/1e3]
response = [coastal[:,1], blue[:,1], green[:,1], red[:,1], nir[:,1], swir1[:,1], swir2[:,1], pan[:,1], cirrus[:,1]]
FWHM = np.array([15.98, 60.04, 57.33, 37.47, 28.25, 84.72, 186.66, 172.40, 20.39]) / 1e3
Expand Down
11 changes: 5 additions & 6 deletions coron_model/coronagraph/make_noise.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Import dependent modules
import numpy as np
from .degrade_spec import degrade_spec, downbin_spec
from .degrade_spec import degrade_spec
from .convolve_spec import convolve_spec
from .noise_routines import Fstar, Fplan, FpFs, cplan, czodi, cezodi, cspeck, cdark, cread, ctherm, ccic, f_airy
import pdb
from .noise_routines import Fstar, Fplan, FpFs, cplan, czodi, cezodi, cspeck, cdark, cread, ctherm, f_airy

__all__ = ['make_noise']

Expand Down Expand Up @@ -54,7 +53,7 @@ def make_noise(Ahr, lamhr, solhr, telescope, planet, star, wantsnr=10.0, FIX_OWA
IWA=telescope.IWA
OWA=telescope.OWA
Tsys=telescope.Tsys
Tdet=telescope.Tdet
# Tdet=telescope.Tdet
emis=telescope.emissivity

# Set the Imaging Mode?
Expand Down Expand Up @@ -190,8 +189,8 @@ def make_noise(Ahr, lamhr, solhr, telescope, planet, star, wantsnr=10.0, FIX_OWA
else:
cth = np.zeros_like(cp)
cnoise = cp + 2*(cz + cez + csp + cD + cR + cth) # assumes background subtraction
cb = (cz + cez + csp + cD + cR + cth)
ctot = cp + cz + cez + csp + cD + cR + cth
# cb = (cz + cez + csp + cD + cR + cth)
# ctot = cp + cz + cez + csp + cD + cR + cth

'''
Giada: where does the factor of 2 come from?
Expand Down
5 changes: 2 additions & 3 deletions coron_model/coronagraph/noise_routines.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np
import scipy as sp
from scipy import special
from numba import jit
import os
Expand Down Expand Up @@ -283,6 +282,7 @@ def cezodi(q, X, T, lam, dlam, D, r, Fstar, Nez, Mezv, SUN=False, CIRC=True):
else:
Teffs = 5778. # Sun effective temperature
Rs = 1. # Sun radius (in solar radii)
# Teffs and Rs are never ccessed
#Fsol = Fstar(lam, Teffs, Rs, 1., AU=True) # Sun as blackbody (W/m**2/um)
rat = np.zeros(len(lam))
rat[:]= Fstar[:]/FsolV # ratio of solar flux to V-band solar flux
Expand Down Expand Up @@ -526,7 +526,7 @@ def f_airy_int(X):
# sum intensities
E = E + Iairy[i,j]*dA
E = 4.*E # factor of 4 as integral only over one quadrant
fpa = E/E0
# fpa = E/E0

def ctherm(q, X, lam, dlam, D, Tsys, emis, T):
"""
Expand Down Expand Up @@ -958,7 +958,6 @@ def set_throughput(lam, Tput, Tput_uv, Tput_nir, o_Tput_vis, o_Tput_uv, o_Tput_n
SILENT : bool, optional
Suppress printing
"""
from scipy.interpolate import interp1d

Nlam = len(lam)
T = 1 + np.zeros(Nlam)
Expand Down
2 changes: 1 addition & 1 deletion coron_model/coronagraph/observe.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def planetzoo_observation(name='earth', telescope=Telescope(), planet=Planet(),
lamhr = model[:,0]
radhr = model[:,1]
solhr = model[:,2]
reflhr = model[:,3]
# reflhr = model[:,3]
Ahr = np.pi*(np.pi*radhr/solhr) # hi-resolution reflectivity
planet.Rp = 1.0 # Earth radii
planet.r = 1.0 # semi-major axis (AU)
Expand Down
2 changes: 1 addition & 1 deletion coron_model/coronagraph/teleplanstar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

import numpy as np
from .utils import Input, Loadin
from .utils import Loadin

__all__ = ['Telescope', 'Planet', 'Star']

Expand Down
Loading