diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 17234c053..883cbcfef 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -26,7 +26,7 @@ repos: - id: text-unicode-replacement-char - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.8.0' + rev: 'v0.9.1' hooks: - id: ruff args: ["--fix", "--show-fixes"] diff --git a/docs/conf.py b/docs/conf.py index f27d86d5b..96dc56f37 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -158,7 +158,7 @@ def check_sphinx_version(expected_version): # General information about the project project = setup_cfg["name"] -author = f'{setup_cfg["authors"][0]["name"]} <{setup_cfg["authors"][0]["email"]}>' +author = f"{setup_cfg['authors'][0]['name']} <{setup_cfg['authors'][0]['email']}>" copyright = f"{datetime.datetime.now().year}, {author}" # The version info for the project you're documenting, acts as replacement for diff --git a/docs/exts/numfig.py b/docs/exts/numfig.py index cac46dcec..8bae0c8eb 100644 --- a/docs/exts/numfig.py +++ b/docs/exts/numfig.py @@ -81,9 +81,7 @@ def doctree_resolved(app, doctree, docname): if app.builder.name == "html": target_doc = app.builder.env.figid_docname_map[target] link = f"{app.builder.get_relative_uri(docname, target_doc)}#{target}" - html = ( - f'{labelfmt %(figids[target])}' - ) + html = f'{labelfmt % (figids[target])}' ref_info.replace_self(raw(html, html, format="html")) else: ref_info.replace_self(Text(labelfmt % (figids[target]))) diff --git a/romancal/associations/lib/process_list.py b/romancal/associations/lib/process_list.py index 095a0c1db..c6d1aee8a 100644 --- a/romancal/associations/lib/process_list.py +++ b/romancal/associations/lib/process_list.py @@ -154,7 +154,7 @@ def update(self, process_list, full=False): self.only_on_match = process_list.only_on_match def __str__(self): - result = f"{self.__class__.__name__}(n_items: {len(self.items)}, {({str_attr: getattr(self, str_attr) for str_attr in self._str_attrs})})" + result = f"{self.__class__.__name__}(n_items: {len(self.items)}, { ({str_attr: getattr(self, str_attr) for str_attr in self._str_attrs}) })" return result diff --git a/romancal/associations/lib/rules_elpp_base.py b/romancal/associations/lib/rules_elpp_base.py index 6a5f25111..0a419cdcb 100644 --- a/romancal/associations/lib/rules_elpp_base.py +++ b/romancal/associations/lib/rules_elpp_base.py @@ -219,9 +219,7 @@ def _dms_product_name(association): if subarray: subarray = "-" + subarray - product_name = ( - "r{program}-{acid}" "_{target}" "_{instrument}" "_{opt_elem}{subarray}" - ) + product_name = "r{program}-{acid}_{target}_{instrument}_{opt_elem}{subarray}" if "Full" in association.data["asn_rule"]: subarray = "Full" @@ -396,7 +394,7 @@ def _add(self, item): members.append(member) if member["exposerr"] not in _EMPTY: logger.warning( - f"Member {item['filename']} has exposure error \"{member['exposerr']}\"" + f'Member {item["filename"]} has exposure error "{member["exposerr"]}"' ) # Update meta info diff --git a/romancal/associations/skycell_asn.py b/romancal/associations/skycell_asn.py index 50f66bec1..488c6b9a3 100644 --- a/romancal/associations/skycell_asn.py +++ b/romancal/associations/skycell_asn.py @@ -180,9 +180,7 @@ def _cli(args=None): "--rule", type=str, default="DMS_ELPP_Base", - help=( - "The rule to base the association structure on." ' Default: "%(default)s"' - ), + help=('The rule to base the association structure on. Default: "%(default)s"'), ) parser.add_argument( "-i", diff --git a/romancal/ramp_fitting/ramp_fit_step.py b/romancal/ramp_fitting/ramp_fit_step.py index a15838c29..bee9e8f19 100644 --- a/romancal/ramp_fitting/ramp_fit_step.py +++ b/romancal/ramp_fitting/ramp_fit_step.py @@ -116,7 +116,7 @@ def ols_cas22(self, input_model, readnoise_model, gain_model, dark_model): # Force read pattern to be pure lists not LNodes read_pattern = [list(reads) for reads in input_model.meta.exposure.read_pattern] if len(read_pattern) != resultants.shape[0]: - raise RuntimeError("mismatch between resultants shape and " "read_pattern.") + raise RuntimeError("mismatch between resultants shape and read_pattern.") # add dark current back into resultants so that Poisson noise is # properly accounted for diff --git a/romancal/regtest/test_resample.py b/romancal/regtest/test_resample.py index a1c715925..368c4cb7b 100644 --- a/romancal/regtest/test_resample.py +++ b/romancal/regtest/test_resample.py @@ -31,21 +31,19 @@ def test_resample_single_file(rtdata, ignore_asdf_paths): step.log.info( "ResampleStep recorded as complete? :" - f' {resample_out.meta.cal_step.resample == "COMPLETE"}' + f" {resample_out.meta.cal_step.resample == 'COMPLETE'}" ) assert resample_out.meta.cal_step.resample == "COMPLETE" step.log.info( "ResampleStep created 'meta.resample'? :" - f' {hasattr(resample_out.meta, "resample")}' + f" {hasattr(resample_out.meta, 'resample')}" ) assert hasattr(resample_out.meta, "resample") step.log.info( f"""DMS342 MSG: Was ICRS used as the mosaic astrometric reference frame? :\ - { - resample_out.meta.coordinates.reference_frame == "ICRS" - } + {resample_out.meta.coordinates.reference_frame == "ICRS"} """ ) assert resample_out.meta.coordinates.reference_frame == "ICRS" @@ -53,16 +51,17 @@ def test_resample_single_file(rtdata, ignore_asdf_paths): step.log.info( f"""DMS343 MSG: ResampleStep created new attribute data quality information? :\ { - all( - hasattr(resample_out, x) for x in [ - "data", - "err", - "var_poisson", - "var_rnoise", - "var_flat", - ] - ) - }""" + all( + hasattr(resample_out, x) + for x in [ + "data", + "err", + "var_poisson", + "var_rnoise", + "var_flat", + ] + ) + }""" ) assert all( hasattr(resample_out, x) @@ -72,13 +71,14 @@ def test_resample_single_file(rtdata, ignore_asdf_paths): step.log.info( f"""DMS343 MSG: Were the variance arrays populated (variance propagation)? :\ { - all( - np.sum(~np.isnan(getattr(resample_out, x))) for x in [ - "var_poisson", - "var_rnoise", - ] - ) - }""" + all( + np.sum(~np.isnan(getattr(resample_out, x))) + for x in [ + "var_poisson", + "var_rnoise", + ] + ) + }""" ) assert all( np.sum(~np.isnan(getattr(resample_out, x))) @@ -88,16 +88,17 @@ def test_resample_single_file(rtdata, ignore_asdf_paths): step.log.info( f"""DMS343 MSG: Are there NaNs or zeros in the variance arrays, indicating poor data quality? :\ { - any( - np.sum( - np.logical_or( - np.isnan(getattr(resample_out, x)), - np.equal(getattr(resample_out, x), 0) - ) - ) > 0 for x in ["var_poisson", "var_rnoise", "var_flat"] + any( + np.sum( + np.logical_or( + np.isnan(getattr(resample_out, x)), + np.equal(getattr(resample_out, x), 0), + ) ) - - }""" + > 0 + for x in ["var_poisson", "var_rnoise", "var_flat"] + ) + }""" ) assert all( np.sum(np.isnan(getattr(resample_out, x))) @@ -114,19 +115,19 @@ def test_resample_single_file(rtdata, ignore_asdf_paths): step.log.info( f"""DMS345 MSG: ResampleStep included all metadata relevant to the creation of the mosaic? :\ { - all( - hasattr(resample_out.meta.resample, x) - and bool(getattr(resample_out.meta.resample, x)) - for x in [ - "pixel_scale_ratio", - "pixfrac", - "pointings", - "product_exposure_time", - "weight_type", - "members", - ] - ) - }""" + all( + hasattr(resample_out.meta.resample, x) + and bool(getattr(resample_out.meta.resample, x)) + for x in [ + "pixel_scale_ratio", + "pixfrac", + "pointings", + "product_exposure_time", + "weight_type", + "members", + ] + ) + }""" ) assert all( hasattr(resample_out.meta.resample, x) @@ -142,5 +143,5 @@ def test_resample_single_file(rtdata, ignore_asdf_paths): ) diff = compare_asdf(rtdata.output, rtdata.truth, **ignore_asdf_paths) - step.log.info("Was the proper Resample data produced?" f" : {diff.identical}") + step.log.info(f"Was the proper Resample data produced? : {diff.identical}") assert diff.identical, diff.report() diff --git a/romancal/regtest/test_tweakreg.py b/romancal/regtest/test_tweakreg.py index f2d988c02..8d17c6bdd 100644 --- a/romancal/regtest/test_tweakreg.py +++ b/romancal/regtest/test_tweakreg.py @@ -44,7 +44,7 @@ def test_tweakreg(rtdata, ignore_asdf_paths, tmp_path): step.log.info( "DMS280 MSG: TweakReg step recorded as complete? :" - f' {tweakreg_out.meta.cal_step.tweakreg == "COMPLETE"}' + f" {tweakreg_out.meta.cal_step.tweakreg == 'COMPLETE'}" ) assert tweakreg_out.meta.cal_step.tweakreg == "COMPLETE" diff --git a/romancal/regtest/test_wfi_dq_init.py b/romancal/regtest/test_wfi_dq_init.py index 5e9a4367b..4e779f171 100644 --- a/romancal/regtest/test_wfi_dq_init.py +++ b/romancal/regtest/test_wfi_dq_init.py @@ -30,10 +30,10 @@ def test_dq_init_image_step(rtdata, ignore_asdf_paths): "mask file applied." ) - step.log.info(f'DMS25 MSG: First data file: {rtdata.input.rsplit("/", 1)[1]}') + step.log.info(f"DMS25 MSG: First data file: {rtdata.input.rsplit('/', 1)[1]}") ref_file_path = step.get_reference_file(model, "mask") step.log.info( - f'DMS25 MSG: CRDS matched mask file: {ref_file_path.rsplit("/", 1)[1]}' + f"DMS25 MSG: CRDS matched mask file: {ref_file_path.rsplit('/', 1)[1]}" ) ref_file_name = os.path.split(ref_file_path)[-1] @@ -52,7 +52,7 @@ def test_dq_init_image_step(rtdata, ignore_asdf_paths): ramp_out = rdm.open(rtdata.output) step.log.info( "DMS25 MSG: Does ramp data contain pixeldq from mask file? :" - f' {("roman.pixeldq" in ramp_out.to_flat_dict())}' + f" {('roman.pixeldq' in ramp_out.to_flat_dict())}" ) assert "roman.pixeldq" in ramp_out.to_flat_dict() @@ -85,10 +85,10 @@ def test_dq_init_grism_step(rtdata, ignore_asdf_paths): "mask file applied." ) - step.log.info(f'DMS25 MSG: First data file: {rtdata.input.rsplit("/", 1)[1]}') + step.log.info(f"DMS25 MSG: First data file: {rtdata.input.rsplit('/', 1)[1]}") ref_file_path = step.get_reference_file(model, "mask") step.log.info( - f'DMS25 MSG: CRDS matched mask file: {ref_file_path.rsplit("/", 1)[1]}' + f"DMS25 MSG: CRDS matched mask file: {ref_file_path.rsplit('/', 1)[1]}" ) ref_file_name = os.path.split(ref_file_path)[-1] @@ -107,7 +107,7 @@ def test_dq_init_grism_step(rtdata, ignore_asdf_paths): ramp_out = rdm.open(rtdata.output) step.log.info( "DMS25 MSG: Does ramp data contain pixeldq from mask file? :" - f' {("roman.pixeldq" in ramp_out.to_flat_dict())}' + f" {('roman.pixeldq' in ramp_out.to_flat_dict())}" ) assert "roman.pixeldq" in ramp_out.to_flat_dict() diff --git a/romancal/regtest/test_wfi_flat_field.py b/romancal/regtest/test_wfi_flat_field.py index 7e30909f3..0884acd46 100644 --- a/romancal/regtest/test_wfi_flat_field.py +++ b/romancal/regtest/test_wfi_flat_field.py @@ -90,12 +90,12 @@ def test_flat_field_crds_match_image_step(rtdata, ignore_asdf_paths): " correct use after date" ) - step.log.info(f'DMS79 MSG: First data file: {rtdata.input.rsplit("/", 1)[1]}') + step.log.info(f"DMS79 MSG: First data file: {rtdata.input.rsplit('/', 1)[1]}") step.log.info(f"DMS79 MSG: Observation date: {model.meta.exposure.start_time}") ref_file_path = step.get_reference_file(model, "flat") step.log.info( - f'DMS79 MSG: CRDS matched flat file: {ref_file_path.rsplit("/", 1)[1]}' + f"DMS79 MSG: CRDS matched flat file: {ref_file_path.rsplit('/', 1)[1]}" ) flat = rdm.open(ref_file_path) step.log.info(f"DMS79 MSG: flat file UseAfter date: {flat.meta.useafter}") @@ -118,9 +118,7 @@ def test_flat_field_crds_match_image_step(rtdata, ignore_asdf_paths): diff = compare_asdf(rtdata.output, rtdata.truth, **ignore_asdf_paths) step.log.info( - "DMS79 MSG: Was proper flat fielded " - "Level 2 data produced? : " - f"{diff.identical}" + f"DMS79 MSG: Was proper flat fielded Level 2 data produced? : {diff.identical}" ) assert diff.identical, diff.report() @@ -137,12 +135,12 @@ def test_flat_field_crds_match_image_step(rtdata, ignore_asdf_paths): step = FlatFieldStep() model = rdm.open(rtdata.input) - step.log.info(f'DMS79 MSG: Second data file: {rtdata.input.rsplit("/", 1)[1]}') + step.log.info(f"DMS79 MSG: Second data file: {rtdata.input.rsplit('/', 1)[1]}") step.log.info(f"DMS79 MSG: Observation date: {model.meta.exposure.start_time}") ref_file_path_b = step.get_reference_file(model, "flat") step.log.info( - f'DMS79 MSG: CRDS matched flat file: {ref_file_path_b.rsplit("/", 1)[1]}' + f"DMS79 MSG: CRDS matched flat file: {ref_file_path_b.rsplit('/', 1)[1]}" ) flat = rdm.open(ref_file_path_b) step.log.info(f"DMS79 MSG: flat file UseAfter date: {flat.meta.useafter}") @@ -164,9 +162,7 @@ def test_flat_field_crds_match_image_step(rtdata, ignore_asdf_paths): rtdata.get_truth(f"truth/WFI/image/{output}") diff = compare_asdf(rtdata.output, rtdata.truth, **ignore_asdf_paths) step.log.info( - "DMS79 MSG: Was proper flat fielded " - "Level 2 data produced? : " - f"{diff.identical}" + f"DMS79 MSG: Was proper flat fielded Level 2 data produced? : {diff.identical}" ) assert diff.identical, diff.report() @@ -174,8 +170,8 @@ def test_flat_field_crds_match_image_step(rtdata, ignore_asdf_paths): step.log.info( "DMS79 MSG REQUIRED TEST: Are the two data files " "matched to different flat files? : " - f'{("/".join(ref_file_path.rsplit("/", 3)[1:]))} != ' - f'{("/".join(ref_file_path_b.rsplit("/", 3)[1:]))}' + f"{('/'.join(ref_file_path.rsplit('/', 3)[1:]))} != " + f"{('/'.join(ref_file_path_b.rsplit('/', 3)[1:]))}" ) assert "/".join(ref_file_path.rsplit("/", 1)[1:]) != "/".join( ref_file_path_b.rsplit("/", 1)[1:] diff --git a/romancal/regtest/test_wfi_photom.py b/romancal/regtest/test_wfi_photom.py index 3b1e31879..591f107a8 100644 --- a/romancal/regtest/test_wfi_photom.py +++ b/romancal/regtest/test_wfi_photom.py @@ -33,7 +33,7 @@ def test_absolute_photometric_calibration(rtdata, ignore_asdf_paths): "CRDS selected photom file applied." ) - step.log.info(f'DMS140 MSG: Image data file: {rtdata.input.rsplit("/", 1)[1]}') + step.log.info(f"DMS140 MSG: Image data file: {rtdata.input.rsplit('/', 1)[1]}") # Note: if any of the following tests fail, check for a different # photom match from CRDS. Values come from roman_wfi_photom_0034.asdf @@ -52,7 +52,7 @@ def test_absolute_photometric_calibration(rtdata, ignore_asdf_paths): step.log.info( "DMS140 MSG: Photom step recorded as complete? :" - f' {photom_out.meta.cal_step.photom == "COMPLETE"}' + f" {photom_out.meta.cal_step.photom == 'COMPLETE'}" ) assert photom_out.meta.cal_step.photom == "COMPLETE" diff --git a/romancal/resample/gwcs_drizzle.py b/romancal/resample/gwcs_drizzle.py index 75eeb2a39..e2005f528 100644 --- a/romancal/resample/gwcs_drizzle.py +++ b/romancal/resample/gwcs_drizzle.py @@ -421,7 +421,7 @@ def dodrizzle( pixmap = resample_utils.calc_gwcs_pixmap(input_wcs, output_wcs, insci.shape) # inwht[np.isnan(pixmap[:,:,0])] = 0. - log.debug(f"Pixmap shape: {pixmap[:,:,0].shape}") + log.debug(f"Pixmap shape: {pixmap[:, :, 0].shape}") log.debug(f"Input Sci shape: {insci.shape}") log.debug(f"Output Sci shape: {outsci.shape}") diff --git a/romancal/resample/resample.py b/romancal/resample/resample.py index 0e9ad543c..1448bea71 100644 --- a/romancal/resample/resample.py +++ b/romancal/resample/resample.py @@ -726,7 +726,7 @@ def drizzle_arrays( # for use in drizzle.cdrizzle.tdriz pixmap = resample_utils.calc_gwcs_pixmap(input_wcs, output_wcs, insci.shape) - log.debug(f"Pixmap shape: {pixmap[:,:,0].shape}") + log.debug(f"Pixmap shape: {pixmap[:, :, 0].shape}") log.debug(f"Input Sci shape: {insci.shape}") log.debug(f"Output Sci shape: {outsci.shape}") diff --git a/romancal/skymatch/skymatch.py b/romancal/skymatch/skymatch.py index 8cc8b806e..dc5cd5677 100644 --- a/romancal/skymatch/skymatch.py +++ b/romancal/skymatch/skymatch.py @@ -291,7 +291,7 @@ def match(images, skymethod="global+match", match_down=True, subtract=False): # (intersecting) images. if do_match: log.info(" ") - log.info("---- Computing differences in sky values in " "overlapping regions.") + log.info("---- Computing differences in sky values in overlapping regions.") # find "optimum" sky changes: sky_deltas = _find_optimum_sky_deltas(images, apply_sky=not subtract) @@ -330,7 +330,7 @@ def match(images, skymethod="global+match", match_down=True, subtract=False): "across *all* input images." ) else: - log.info("---- Sky values computed per image and/or image " "groups.") + log.info("---- Sky values computed per image and/or image groups.") sky_deltas = [] for img in images: @@ -344,7 +344,7 @@ def match(images, skymethod="global+match", match_down=True, subtract=False): if minsky is None: log.warning(' Unable to compute "global" sky value') sky_deltas = len(sky_deltas) * [minsky] - log.info(f' "Global" sky value correction: {minsky} ' "[not converted]") + log.info(f' "Global" sky value correction: {minsky} [not converted]') if do_match: log.info(" ") @@ -393,7 +393,7 @@ def _apply_sky(images, sky_deltas, do_global, do_skysub, show_old): new_img_sky = [im.sky for im in img] # log sky values: - log.info(f" * Group ID={img.id}. Sky background of " "component images:") + log.info(f" * Group ID={img.id}. Sky background of component images:") for im, old_sky, new_sky in zip( img, old_img_sky, new_img_sky, strict=False @@ -499,14 +499,14 @@ def is_valid(i, j): try: rank = np.linalg.matrix_rank(K, 1.0e-12) except np.linalg.LinAlgError: - log.warning("Unable to compute sky: No valid data in common " "image areas") + log.warning("Unable to compute sky: No valid data in common image areas") deltas = np.full(ns, np.nan, dtype=float) return deltas if rank < ns - 1: log.warning(f"There are more unknown sky values ({ns}) to be solved for") log.warning( - "than there are independent equations available " f"(matrix rank={rank})." + f"than there are independent equations available (matrix rank={rank})." ) log.warning("Sky matching (delta) values will be computed only for") log.warning("a subset (or more independent subsets) of input images.") diff --git a/romancal/tests/test_dms_requirements.py b/romancal/tests/test_dms_requirements.py index 3ace0a49a..ed71ce563 100644 --- a/romancal/tests/test_dms_requirements.py +++ b/romancal/tests/test_dms_requirements.py @@ -31,4 +31,6 @@ def test_requirements(): existing_tests.add(test) missing_tests = required_tests - existing_tests - assert not missing_tests, f"could not find the following tests correlated with DMS requirements: {missing_tests}" + assert not missing_tests, ( + f"could not find the following tests correlated with DMS requirements: {missing_tests}" + )