Skip to content

Commit 37c4516

Browse files
author
Thushara Weligepolage Perera
committed
Resolve merge conflict with upstream/main
2 parents 8b7bcd0 + 57914ed commit 37c4516

229 files changed

Lines changed: 25106 additions & 1420 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ jobs:
1414
FFTW_DIR: /opt/homebrew/opt/fftw/lib/
1515
targets: |
1616
# Linux wheels
17-
- cp3*-manylinux_x86_64
17+
- cp3*[!t]-manylinux_x86_64
1818
# MacOS wheels
19-
- cp3*-macosx_x86_64
19+
- cp3*[!t]-macosx_x86_64
2020
# MacOS arm64 wheels
21-
- cp3*-macosx_arm64
21+
- cp3*[!t]-macosx_arm64
2222
sdist: true
2323
test_command: python -c "from romanisim import ramp_fit_casertano"
2424
upload_to_pypi: ${{ (github.event_name == 'release') && (github.event.action == 'released') }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,4 @@ docs/source/api
149149

150150
# misc
151151
uv.lock
152+
romanisim/models/example_APIs.ipynb

.pre-commit-config.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
ci:
22
autoupdate_schedule: monthly
33

4-
exclude: ".*\\.asdf$"
4+
# exclude: ".*\\.asdf$"
5+
exclude: |
6+
(?x)^(
7+
.*\\.asdf$|
8+
romanisim/data/roman-technical-information/
9+
)
510
611
repos:
712
# basic checks
@@ -59,7 +64,7 @@ repos:
5964
- id: towncrier-check
6065
# format YAML and Markdown
6166
- repo: https://github.com/rbubley/mirrors-prettier
62-
rev: v3.8.1
67+
rev: v3.8.3
6368
hooks:
6469
- id: prettier
6570
types_or:

docs/romanisim/parameters.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ These values can be overridden by specifying a yaml config file on the
2121
command line to romanisim-make-image.
2222

2323
See the `code
24-
<https://github.com/spacetelescope/romanisim/blob/main/romanisim/parameters.py>`_
24+
<https://github.com/spacetelescope/romanisim/blob/main/romanisim/models/parameters.py>`_
2525
for the default values of these quantities.
2626

27-
.. automodapi:: romanisim.parameters
27+
.. automodapi:: romanisim.models.parameters
2828

romanisim/bandpass.py

Lines changed: 18 additions & 203 deletions
Original file line numberDiff line numberDiff line change
@@ -5,211 +5,26 @@
55
the nominal flat AB spectrum of 3631 Jy. The ultimate source of this
66
information is https://roman.gsfc.nasa.gov/science/WFI_technical.html .
77
"""
8-
import numpy as np
9-
from importlib import resources
10-
from scipy import integrate
11-
from astropy import constants
12-
from astropy.io import ascii
13-
from astropy import units as u
14-
from romanisim import parameters
158

16-
# to go from calibrated fluxes in maggies to counts in the Roman bands
17-
# we need to multiply by a constant determined by the AB magnitude
18-
# system and the shape of the Roman bands.
19-
# The constant is \int (3631 Jy) (1/hv) T(v) dv
20-
# T(v) should be the effective area at each wavelength, I guess
21-
# divided by some nominal overall effective area.
9+
import warnings
2210

11+
warnings.warn(
12+
"romanisim.bandpass is deprecated and will be removed in a future version. "
13+
"Please use 'romanisim.models.bandpass' instead.",
14+
DeprecationWarning,
15+
stacklevel=2,
16+
)
2317

24-
# provide some translation dictionaries for the mapping from
25-
# the galsim bandpass names to the Roman bandpass names and vice versa.
26-
# it would be nice to be agnostic about which one we use.
27-
galsim_bandpasses = [
28-
'R062', 'Z087', 'Y106', 'J129', 'H158', 'F184', 'K213', 'W146']
29-
galsim2roman_bandpass = {x: 'F' + x[1:] for x in galsim_bandpasses}
30-
roman2galsim_bandpass = {v: k for k, v in galsim2roman_bandpass.items()}
18+
def __getattr__(name):
19+
if name.startswith("__"):
20+
raise AttributeError(name)
3121

32-
# provide some no-ops if we are given a key in the right bandpass
33-
galsim2roman_bandpass.update(**{k: k for k in roman2galsim_bandpass})
34-
roman2galsim_bandpass.update(**{k: k for k in galsim_bandpasses})
22+
from romanisim.models import bandpass
3523

36-
# AB Zero Spectral Flux Density
37-
ABZeroSpFluxDens = 3631e-23 * u.erg / (u.s * u.cm**2 * u.hertz)
38-
39-
40-
def read_gsfc_effarea(sca, filename=None):
41-
"""Read an effective area file from Roman.
42-
43-
This just puts together the right invocation to get an Excel-converted
44-
ECSV file into memory.
45-
46-
Parameters
47-
----------
48-
sca : int
49-
the name of the detector. A number between 1-18.
50-
filename : str
51-
filename to read in
52-
53-
Returns
54-
-------
55-
astropy.table.Table
56-
table with effective areas for different Roman bandpasses.
57-
"""
58-
59-
# The throughput files come as ECSV from March 2024 so the invocation changed to properly read the ECSVs.
60-
if filename is None:
61-
filename = str(resources.files('romanisim') / 'data' / 'Roman_effarea_tables_20240327'
62-
/ f'Roman_effarea_v8_SCA{sca:02}_20240301.ecsv')
63-
out = ascii.read(filename)
64-
else:
65-
out = ascii.read(filename)
66-
return out
67-
68-
69-
def compute_abflux(sca, effarea=None):
70-
"""Compute the AB zero point fluxes for each filter.
71-
72-
How many electrons would a zeroth magnitude AB star deposit in
73-
Roman's detectors in a second?
74-
75-
Parameters
76-
----------
77-
sca : int
78-
the name of the detector. A number between 1-18.
79-
effarea : astropy.Table.table
80-
Table from GSFC with effective areas for each filter.
81-
82-
Returns
83-
-------
84-
dict[str] : float
85-
lookup table of zero point fluxes for each filter (electrons / s)
86-
"""
87-
88-
if effarea is None:
89-
effarea = read_gsfc_effarea(sca)
90-
91-
# get the filter names. This is a bit ugly since there's also
92-
# a wavelength column 'Wave', and Excel appends a column to each line
93-
# which astropy then gives a default name col12 to.
94-
filter_names = [x for x in effarea.dtype.names
95-
if x != 'Wave' and 'col' not in x]
96-
abfv = ABZeroSpFluxDens
97-
out = dict()
98-
for bandpass in filter_names:
99-
out[bandpass] = compute_count_rate(flux=abfv, bandpass=bandpass, sca=sca, effarea=effarea)
100-
101-
# Saving the SCA information to use the correct throughput curves for each detector.
102-
out = {f'SCA{sca:02}':out}
103-
return out
104-
105-
106-
def get_abflux(bandpass, sca):
107-
"""Get the zero point flux for a particular bandpass.
108-
109-
This is a simple wrapper for compute_abflux, caching the results.
110-
111-
Parameters
112-
----------
113-
bandpass : str
114-
the name of the bandpass
115-
sca : int
116-
the name of the detector. A number between 1-18.
117-
Returns
118-
-------
119-
float
120-
the zero point flux (electrons / s)
121-
"""
122-
bandpass = galsim2roman_bandpass.get(bandpass, bandpass)
123-
124-
# If abflux for this bandpass for the specified SCA has been calculated, return the calculated
125-
# value instead of rerunning an expensive calculation
126-
abflux = getattr(get_abflux, 'abflux', None)
127-
if (abflux is None) or (f'SCA{sca:02}' not in abflux):
128-
abflux = compute_abflux(sca)
129-
get_abflux.abflux = abflux
130-
return abflux[f'SCA{sca:02}'][bandpass]
131-
132-
133-
def compute_count_rate(flux, bandpass, sca, filename=None, effarea=None, wavedist=None):
134-
"""Compute the count rate in a given filter, for a specified SED.
135-
136-
How many electrons would an object with SED given by
137-
flux deposit in Roman's detectors in a second?
138-
139-
Parameters
140-
----------
141-
flux : float or np.ndarray with shape matching wavedist.
142-
Spectral flux density in units of ergs per second * hertz * cm^2
143-
bandpass : str
144-
the name of the bandpass
145-
sca : int
146-
the name of the detector. A number between 1-18.
147-
filename : str
148-
filename to read in
149-
effarea : astropy.Table.table
150-
Table from GSFC with effective areas for each filter.
151-
wavedist : numpy.ndarray
152-
Array of wavelengths along which spectral flux densities are defined in microns
153-
154-
Returns
155-
-------
156-
float
157-
the total bandpass flux (electrons / s)
158-
"""
159-
# Read in default Roman effective areas from Goddard, if areas not supplied
160-
if effarea is None:
161-
effarea = read_gsfc_effarea(sca, filename)
162-
163-
# If wavelength distribution is supplied, interpolate flux and area
164-
# over it and the effective area table layout
165-
if wavedist is not None:
166-
# Ensure that wavedist and flux have the same shape
167-
if wavedist.shape != flux.shape:
168-
raise ValueError('wavedist and flux must have identical shapes!')
169-
170-
all_wavel = np.unique(np.concatenate((effarea['Wave'], wavedist)))
171-
all_flux = np.interp(all_wavel, wavedist, flux)
172-
all_effarea = np.interp(all_wavel, effarea['Wave'], effarea[bandpass])
173-
else:
174-
all_wavel = effarea['Wave']
175-
all_flux = flux
176-
all_effarea = effarea[bandpass]
177-
178-
integrand = all_flux * constants.c / (
179-
all_wavel * u.micron)**2 # f_lambda
180-
integrand /= constants.h * constants.c / (
181-
all_wavel * u.micron) # hc/lambda
182-
integrand *= all_effarea * u.m**2 # effective area in filter
183-
# integrate.simpson looks like it loses units. So convert to something
184-
# we know about.
185-
integrand = integrand.to(1 / (u.s * u.micron)).value
186-
187-
zpflux = integrate.simpson(integrand, x=all_wavel)
188-
# effarea['Wave'] is in microns, so we're left with a number of counts
189-
# per second
190-
191-
return zpflux
192-
193-
194-
def etomjysr(bandpass, sca):
195-
"""Compute factor converting e/s/pix to MJy/sr.
196-
197-
Assumes a pixel scale of 0.11" (romanisim.parameters.pixel_scale)
198-
199-
Parameters
200-
----------
201-
bandpass : str
202-
the name of the bandpass
203-
sca : int
204-
the name of the detector. A number between 1-18.
205-
Returns
206-
-------
207-
float
208-
the factor F such that MJy / sr = F * DN/s
209-
"""
210-
211-
abflux = get_abflux(bandpass, sca) # e/s corresponding to 3631 Jy
212-
srpix = ((parameters.pixel_scale * u.arcsec) ** 2).to(u.sr).value
213-
mjysr = 1 / abflux * 3631 / 10 ** 6 / srpix # should be ~0.3
214-
return mjysr
215-
24+
warnings.warn(
25+
f"'romanisim.bandpass.{name}' is deprecated and will be removed in a future version."
26+
f"Please use 'romanisim.models.bandpass.{name}' instead.",
27+
DeprecationWarning,
28+
stacklevel=2,
29+
)
30+
return getattr(bandpass, name)

romanisim/catalog.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
import dataclasses
88
import numpy as np
99
import galsim
10-
from galsim import roman
1110
from astropy import coordinates, table
1211
from astropy import units as u
1312
from astropy.io import fits
1413
import astropy_healpix
1514
import astropy.time
1615
from romanisim import gaia as rsim_gaia
17-
from . import util, log, parameters
18-
import romanisim.bandpass
16+
from . import util, log
17+
import romanisim.models.bandpass
1918
import yaml
19+
from romanisim.models import parameters
2020

2121
# COSMOS constants taken from the COSMOS2020 paper:
2222
# https://arxiv.org/pdf/2110.13923
@@ -32,7 +32,7 @@
3232
F184_KS_COEFF = 0.3838145747397368
3333

3434
# Bandpass filters
35-
BANDPASSES = list(romanisim.bandpass.galsim2roman_bandpass.values())
35+
BANDPASSES = set(romanisim.models.bandpass.galsim2roman_bandpass.values())
3636

3737

3838
@dataclasses.dataclass
@@ -83,20 +83,20 @@ def make_dummy_catalog(coord,
8383
rng = galsim.UniformDeviate(seed)
8484

8585
if galaxy_sample_file_name is None:
86-
cat1 = galsim.COSMOSCatalog(sample='25.2', area=roman.collecting_area,
86+
cat1 = galsim.COSMOSCatalog(sample='25.2', area=parameters.collecting_area,
8787
exptime=1)
88-
cat2 = galsim.COSMOSCatalog(sample='23.5', area=roman.collecting_area,
88+
cat2 = galsim.COSMOSCatalog(sample='23.5', area=parameters.collecting_area,
8989
exptime=1)
9090
else:
9191
cat1 = galsim.COSMOSCatalog(galaxy_sample_file_name,
92-
area=roman.collecting_area, exptime=1)
92+
area=parameters.collecting_area, exptime=1)
9393
cat2 = cat1
9494

9595
if chromatic:
9696
# following Roman demo13, all stars currently have the SED of Vega.
9797
# fluxes are set to have a specific value in the y bandpass.
9898
vega_sed = galsim.SED('vega.txt', 'nm', 'flambda')
99-
y_bandpass = roman.getBandpasses(AB_zeropoint=True)['Y106']
99+
y_bandpass = romanisim.models.bandpass.getBandpasses(AB_zeropoint=True)['Y106']
100100

101101
objlist = []
102102
locs = util.random_points_in_cap(coord, radius, nobj, rng=rng)
@@ -115,7 +115,7 @@ def make_dummy_catalog(coord,
115115
mu = np.log(mu_x**2 / (mu_x**2 + sigma_x**2)**0.5)
116116
sigma = (np.log(1 + sigma_x**2 / mu_x**2))**0.5
117117
gd = galsim.GaussianDeviate(rng, mean=mu, sigma=sigma)
118-
flux = np.exp(gd()) / roman.exptime
118+
flux = np.exp(gd()) / parameters.exptime
119119
if chromatic:
120120
sed = vega_sed.withFlux(flux, y_bandpass)
121121
obj = galsim.DeltaFunction() * sed
@@ -411,8 +411,8 @@ def make_galaxies(coord,
411411
Table for use with table_to_catalog to generate catalog for simulation.
412412
"""
413413
if bandpasses is None:
414-
bandpasses = roman.getBandpasses().keys()
415-
bandpasses = [romanisim.bandpass.galsim2roman_bandpass[b]
414+
bandpasses = romanisim.models.bandpass.getBandpasses().keys()
415+
bandpasses = [romanisim.models.bandpass.galsim2roman_bandpass[b]
416416
for b in bandpasses]
417417
if rng is None:
418418
rng = galsim.UniformDeviate(seed)
@@ -592,8 +592,8 @@ def make_stars(coord,
592592
Table for use with table_to_catalog to generate catalog for simulation.
593593
"""
594594
if bandpasses is None:
595-
bandpasses = roman.getBandpasses().keys()
596-
bandpasses = [romanisim.bandpass.galsim2roman_bandpass[b]
595+
bandpasses = romanisim.models.bandpass.getBandpasses().keys()
596+
bandpasses = [romanisim.models.bandpass.galsim2roman_bandpass[b]
597597
for b in bandpasses]
598598
if rng is None:
599599
rng = galsim.UniformDeviate(seed)

romanisim/cr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import numpy as np
22
import scipy.interpolate as interpolate
33

4-
from . import parameters
4+
from romanisim.models import parameters
55

66

77
def create_sampler(pdf, x):

0 commit comments

Comments
 (0)