Skip to content

Commit d7e5b40

Browse files
committed
Added some questions/TODOs and setup the file to accept the previous arguments but instead have the draw function return the photon array
Added makefromimage function to fft generated galaxies for their photonarray. General concept for a way to do the sampling, but all of this will likely need to be wrapped in its own method or Buildfromstamps will need to be modified to accept photonarray as an output. Removing file I previously made to test ways to do the photonarray combination changes to sca.py to just generate an image from photon arrays Stamp now is just for the photon shooting. The sca.py has been changed to conver a dt photon array into an image. Generate an image of 1/20th an exposure using full image photon arrays. Corrected the flux scaling issue for the photons resulting in a brighter image than expected, changed photon array concatenation as well. removed egg-info and __pycache__ added a input register and value register for the resultants strategy. Implemented the resultant image builder. resultant image headers, BFE, optimizations still need to be done Some comments Separate classes so it can be merged with main. fixing formating and preparing for merge into main
1 parent f94c804 commit d7e5b40

4 files changed

Lines changed: 886 additions & 6 deletions

File tree

roman_imsim/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@
1616
from .skycat import *
1717
from .stamp import *
1818
from .wcs import *
19+
from .resultants import *

roman_imsim/resultants.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import galsim
2+
import galsim.config
3+
import galsim.roman as roman
4+
import yaml
5+
from galsim.config import InputLoader, RegisterInputType, RegisterValueType
6+
7+
8+
class ResultantDataLoader(object):
9+
"""Read the resultant information from the resultant strategy."""
10+
11+
_req_params = {
12+
"file_name": str,
13+
"strategy_name": str,
14+
}
15+
16+
def __init__(self, file_name, strategy_name, logger=None):
17+
self.logger = galsim.config.LoggerWrapper(logger)
18+
self.file_name = file_name
19+
self.strategy_name = strategy_name
20+
self.data = {}
21+
22+
# try:
23+
self.read_resultants()
24+
# except:
25+
# # Read visit info from the config file.
26+
# self.logger.warning('Reading visit info from config file.')
27+
28+
def read_resultants(self):
29+
"""Load the YAML file and get the requested strategy."""
30+
self.logger.info("Reading resultants from YAML file: %s", self.file_name)
31+
try:
32+
with open(self.file_name, "r") as f:
33+
all_strategies = yaml.safe_load(f)
34+
except Exception as e:
35+
raise IOError(f"Could not read YAML file '{self.file_name}': {e}")
36+
37+
if self.strategy_name not in all_strategies:
38+
raise ValueError(f"Strategy '{self.strategy_name}' not found in YAML file.")
39+
40+
strategy = all_strategies[self.strategy_name]
41+
if not isinstance(strategy, list):
42+
raise ValueError(f"Invalid strategy format for '{self.strategy_name}': must be a list of lists.")
43+
44+
self.data["strategy"] = strategy
45+
46+
def resultants_to_dt(self, config, base):
47+
"""Compute dt from list-of-lists."""
48+
strategy = self.data["strategy"]
49+
if len(strategy) < 2:
50+
raise ValueError("Need at least two resultants to compute dt.")
51+
52+
avg_last = sum(strategy[-1]) / len(strategy[-1])
53+
avg_second = sum(strategy[0]) / len(strategy[0])
54+
55+
if "exptime" in config:
56+
exptime = galsim.config.ParseValue(config, "exptime", base, float)[0]
57+
else:
58+
exptime = roman.exptime
59+
60+
dt = exptime / (avg_last - avg_second)
61+
return dt
62+
63+
def get(self, field, default=None):
64+
if field not in self.data and default is None:
65+
raise KeyError(f"Field '{field}' not found in data.")
66+
return self.data.get(field, default)
67+
68+
69+
def ResultantData(config, base, value_type):
70+
"""Returns the resultant dt data."""
71+
rdata = galsim.config.GetInputObj("resultant_data", config, base, "ResultantDataLoader")
72+
req = {"field": str}
73+
kwargs, safe = galsim.config.GetAllParams(config, base, req=req)
74+
field = kwargs["field"]
75+
76+
if field == "dt":
77+
val = rdata.resultants_to_dt(config, base)
78+
else:
79+
val = rdata.get(field)
80+
81+
return value_type(val), safe
82+
83+
84+
RegisterInputType("resultant_data", InputLoader(ResultantDataLoader, file_scope=True, takes_logger=True))
85+
RegisterValueType("ResultantData", ResultantData, [float, list], input_type="resultant_data")

0 commit comments

Comments
 (0)