Skip to content

Commit

Permalink
Removing formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gmegh committed Apr 12, 2024
1 parent 61c1716 commit 98ab871
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
19 changes: 19 additions & 0 deletions python/lsst/ts/imsim/imsim_cmpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def assemble_config_yaml(
then will use policy/requiredModulesDefault.yaml.
(The default is None.)
"""

if required_modules_file is None:
required_modules_file = os.path.join(
get_config_dir(), "requiredModulesDefault.yaml"
Expand Down Expand Up @@ -361,6 +362,7 @@ def write_yaml_and_run_imsim(
code will just default to sending it to stdout.
(The default is "".)
"""

with open(config_path, "w") as file:
yaml.safe_dump(config_yaml, file)
self.run_imsim(config_path, imsim_log_file=imsim_log_file)
Expand Down Expand Up @@ -389,6 +391,7 @@ def add_sources_to_config(
dict
Updated yaml configuration.
"""

if use_ccd_img:
config_yaml["image"].pop("nobjects")
config_yaml["image"]["world_pos"] = {"type": "InstCatWorldPos"}
Expand Down Expand Up @@ -511,6 +514,7 @@ def generate_star(
str
Instance catalog entry for star.
"""

content = "object %2d\t%9.6f\t%9.6f %9.6f %s " % (
star_id,
ra,
Expand Down Expand Up @@ -557,6 +561,7 @@ def analyze_opd_data(
pssn_file_name : str, optional
PSSN file name. (the default is "PSSN.txt".)
"""

# Set the weighting ratio and field positions of OPD
if cam_type == CamType.LsstCam:
self.opd_metr.set_default_lsst_wfs_gq()
Expand Down Expand Up @@ -584,6 +589,7 @@ def _write_opd_zk_file(
num_opd : int
Number of OPD positions calculated.
"""

file_path = os.path.join(self.output_img_dir, zk_file_name)
opd_data = self._map_opd_to_zk(rot_opd_in_deg, num_opd)
file_txt = (
Expand Down Expand Up @@ -615,6 +621,7 @@ def _map_opd_to_zk(self, rot_opd_in_deg: float, num_opd: int) -> np.ndarray:
the column is z4 to z22 in um. The order of OPD index is based on
the file name.
"""

# Map the OPD to the Zk basis and do the collection
# Get the number of OPD locations by looking at length of fieldX
opd_data = np.zeros((num_opd, self.num_of_zk))
Expand Down Expand Up @@ -660,6 +667,7 @@ def _write_opd_pssn_file(self, pssn_file_name: str, num_opd: int) -> None:
num_opd : int
Number of OPD positions calculated.
"""

# Calculate the PSSN
pssn_list, gq_eff_pssn = self._calc_pssn_opd(num_opd)

Expand Down Expand Up @@ -697,6 +705,7 @@ def _calc_pssn_opd(self, num_opd: int) -> tuple[list[float], float]:
float
GQ effective PSSN.
"""

pssn_list = []
for idx in range(num_opd):
wavelength_in_um = fits.getheader(self.opd_file_path, idx)["WAVELEN"] * 1e-3
Expand Down Expand Up @@ -730,6 +739,7 @@ def _calc_eff_fwhm_opd(self, pssn_list: list[float]) -> tuple[list[float], float
float
GQ effective FWHM.
"""

# Calculate the list of effective FWHM
eff_fwhm_list = []
for pssn in pssn_list:
Expand Down Expand Up @@ -765,6 +775,7 @@ def map_opd_data_to_list_of_wf_err(
list [lsst.ts.wep.ctrlIntf.SensorWavefrontError]
List of SensorWavefrontError object.
"""

opd_zk = get_zk_from_file(os.path.join(self.output_img_dir, opd_zk_file_name))

list_of_wf_err = []
Expand Down Expand Up @@ -797,6 +808,7 @@ def get_opd_gq_eff_fwhm_from_file(self, pssn_file_name: str) -> float:
float
OPD GQ effective FWHM.
"""

data = self._get_data_of_pssn_file(pssn_file_name)
gq_eff_fwhm = data[1, -1]

Expand Down Expand Up @@ -825,6 +837,7 @@ def get_list_of_fwhm_sensor_data(
data type is `object` because each element may have different
number of elements.
"""

# Get the FWHM data from the PSSN file
# The first row is the PSSN and the second one is the FWHM
# The final element in each row is the GQ value
Expand Down Expand Up @@ -853,6 +866,7 @@ def get_opd_pssn_from_file(self, pssn_file_name: str) -> np.ndarray:
numpy.ndarray
PSSN.
"""

data = self._get_data_of_pssn_file(pssn_file_name)
pssn = data[0, :-1]

Expand All @@ -873,6 +887,7 @@ def _get_data_of_pssn_file(self, pssn_file_name: str) -> np.ndarray:
numpy.ndarray
Data of the PSSN file.
"""

file_path = os.path.join(self.output_img_dir, pssn_file_name)
data = np.loadtxt(file_path)

Expand Down Expand Up @@ -902,6 +917,7 @@ def reorder_and_save_wf_err_file(
zk_file_name : str, optional
Wavefront error file name. (the default is "wfs.zer".)
"""

# Get the sensor name that in the wavefront error map
wf_err_map = self._trans_list_of_wf_err_to_map(list_of_wf_err, camera)
name_list_in_wf_err_map = list(wf_err_map.keys())
Expand Down Expand Up @@ -944,6 +960,7 @@ def _trans_list_of_wf_err_to_map(
abbreviated sensor name (e.g. R22_S11). The dictionary item
[numpy.ndarray] is the averaged wavefront error (z4-z22) in um.
"""

map_sensor_name_and_id = dict(
[(detector.getId(), detector.getName()) for detector in camera]
)
Expand Down Expand Up @@ -978,6 +995,7 @@ def _get_wf_err_values_and_stack_to_matrix(
is the individual sensor. The order is the same as the input of
wfErrMap.
"""

value_matrix = np.empty((0, self.num_of_zk))
for wf_err in wf_err_map.values():
value_matrix = np.vstack((value_matrix, wf_err))
Expand All @@ -997,6 +1015,7 @@ def save_dof_in_um_file_for_next_iter(
File name to save the DOF in um. (the default is
"dofPertInNextIter.mat".)
"""

file_path = os.path.join(self.output_dir, dof_in_um_file_name)
header = "The followings are the DOF in um:"
np.savetxt(file_path, np.transpose(self.dof_in_um), header=header)
7 changes: 5 additions & 2 deletions tests/test_imsim_cmpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def setUp(self):
"testData",
"imsimConfig",
"imsimConfigLsstCam.yaml",
)
),
"r",
) as test_file:
self.full_test_yaml = yaml.safe_load(test_file)
self.imsim_cmpt = ImsimCmpt(num_of_zk=19)
Expand Down Expand Up @@ -122,7 +123,9 @@ def test_convert_obs_metadata_to_text(self):
obs_variables_text = self.imsim_cmpt.convert_obs_metadata_to_text(
self.obs_metadata_test
)
with open(os.path.join(get_config_dir(), "obsVariablesDefault.yaml")) as file:
with open(
os.path.join(get_config_dir(), "obsVariablesDefault.yaml"), "r"
) as file:
default_vars = yaml.safe_load(file)
self.assertDictEqual(yaml.safe_load(obs_variables_text), default_vars)

Expand Down

0 comments on commit 98ab871

Please sign in to comment.