Skip to content

Replace level_map and deprecate reference_point and center parameters#92

Open
cfs-data wants to merge 35 commits into
mainfrom
replace-map-level
Open

Replace level_map and deprecate reference_point and center parameters#92
cfs-data wants to merge 35 commits into
mainfrom
replace-map-level

Conversation

@cfs-data

@cfs-data cfs-data commented Jan 21, 2026

Copy link
Copy Markdown
Collaborator

Changes:

  1. Our implementation of level_map() is replaced by a built-in function from surfalize
  2. It seems reference_point has no influence on end-to-end tests so this parameter has been removed in this branch.
  3. It seems center property of Mark had no influence on end-to-end tests, so this property has been removed as well

@cfs-data cfs-data changed the title Replace level_map with built-in function [Draft] Replace level_map with built-in function Jan 21, 2026
@cfs-data cfs-data marked this pull request as draft January 21, 2026 13:43
@cfs-data cfs-data changed the title [Draft] Replace level_map with built-in function [Draft] Replace level_map with built-in function and depecrate reference_point parameter Jan 21, 2026
@cfs-data cfs-data changed the title [Draft] Replace level_map with built-in function and depecrate reference_point parameter [Draft] Replace level_map and depecrate reference_point parameter Jan 21, 2026
@cfs-data cfs-data changed the title [Draft] Replace level_map and depecrate reference_point parameter [Draft] Replace level_map and deprecrate reference_point parameter Jan 21, 2026
@cfs-data cfs-data changed the title [Draft] Replace level_map and deprecrate reference_point parameter [Draft] Replace level_map and deprecate reference_point parameter Jan 21, 2026
@snregales

Copy link
Copy Markdown
Collaborator

@Raytesnel will PR impact us?

@Raytesnel

Copy link
Copy Markdown
Collaborator

@Raytesnel will PR impact us?

ja

@cfs-data cfs-data requested a review from SimoneAriens February 9, 2026 15:29
@cfs-data cfs-data changed the title [Draft] Replace level_map and deprecate reference_point parameter Replace level_map and deprecate reference_point parameter Feb 16, 2026
@snregales

Copy link
Copy Markdown
Collaborator

Is this PR still applicable?

@cfs-data cfs-data changed the title Replace level_map and deprecate reference_point parameter [Draft] Replace level_map and deprecate reference_point parameter Mar 3, 2026
@cfs-data cfs-data changed the title [Draft] Replace level_map and deprecate reference_point parameter [Draft] Replace level_map and deprecate reference_point and Mark.center parameter Mar 16, 2026
@cfs-data cfs-data changed the title [Draft] Replace level_map and deprecate reference_point and Mark.center parameter [Draft] Replace level_map and deprecate reference_point parameter Mar 16, 2026
@cfs-data cfs-data changed the title Replace level_map and deprecate reference_point parameter [Draft] Replace level_map and deprecate reference_point parameter Mar 19, 2026
@cfs-data cfs-data changed the title [Draft] Replace level_map and deprecate reference_point parameter Replace level_map and deprecate reference_point parameter May 13, 2026
@cfs-data cfs-data marked this pull request as ready for review May 13, 2026 08:29
@cfs-data cfs-data requested a review from vergep May 13, 2026 08:43
Comment thread packages/scratch-core/src/conversion/leveling/core.py Outdated
Comment thread packages/scratch-core/src/mutations/filter.py Outdated
@cfs-data cfs-data requested a review from SimoneAriens May 18, 2026 13:02
@cfs-data cfs-data changed the title Replace level_map and deprecate reference_point parameter Replace level_map and deprecate reference_point and center parameters May 18, 2026
@github-actions

Copy link
Copy Markdown

Diff Coverage

Diff: origin/main..HEAD, staged and unstaged changes

  • packages/scratch-core/src/conversion/leveling/init.py (100%)
  • packages/scratch-core/src/conversion/leveling/core.py (86.7%): Missing lines 21,41
  • packages/scratch-core/src/conversion/leveling/data_types.py (100%)
  • packages/scratch-core/src/conversion/preprocess_impression/preprocess_impression.py (100%)
  • packages/scratch-core/src/conversion/preprocess_impression/tilt.py (100%)
  • packages/scratch-core/src/conversion/preprocess_impression/utils.py (100%)
  • packages/scratch-core/src/mutations/filter.py (100%)

Summary

  • Total: 46 lines
  • Missing: 2 lines
  • Coverage: 95%

packages/scratch-core/src/conversion/leveling/core.py

  17 
  18 def get_polynomial_degree(terms: SurfaceTerms) -> int:
  19     """Get the highest polynomial degree present in the given surface terms."""
  20     if terms == SurfaceTerms.NONE:
! 21         raise ValueError(f"No degree defined for {terms}")
  22     return max(_DEGREE_MAP[term] for term in terms)
  23 
  24 
  25 def level_map(scan_image: ScanImage, terms: SurfaceTerms) -> LevelingResult:

  37             leveled_map=scan_image.data,
  38             fitted_surface=np.full_like(scan_image.data, 0.0),
  39         )
  40     if scan_image.valid_mask.sum() < 3:
! 41         raise ValueError("At least 3 values are needed for the least squares solver.")
  42 
  43     surface = Surface(
  44         height_data=scan_image.data,
  45         step_x=scan_image.scale_x,

@github-actions

Copy link
Copy Markdown

Code Coverage

Package Line Rate Branch Rate Health
. 96% 92%
computations 94% 67%
container_models 99% 100%
conversion 96% 89%
conversion.export 99% 93%
conversion.filter 97% 89%
conversion.leveling 94% 67%
conversion.plots 99% 88%
conversion.preprocess_impression 98% 88%
conversion.preprocess_striation 90% 62%
conversion.profile_correlator 96% 82%
conversion.surface_comparison 99% 89%
conversion.surface_comparison.cell_registration 100% 90%
conversion.surface_comparison.cmc_consensus 91% 65%
extractors 97% 75%
mutations 100% 100%
parsers 97% 50%
parsers.patches 89% 60%
preprocessors 100% 100%
processors 100% 83%
renders 99% 50%
utils 71% 100%
Summary 97% (3276 / 3361) 85% (351 / 412)

Minimum allowed line rate is 50%

@vergep vergep left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this PR, you do two things:

  1. You remove the center functionality, which I think is really nice! It is redundant for surface corrections indeed.
  2. You use surfalize to lavel_map. This is a bit trickier in my opinion. If I understand it correctly, the surfalize detrend_polynomial operation to degree 1 equals SurfaceTerms=Plane, and to degree 2 equals SurfaceTerms = Plane + Sphere. But SurfaceTerms uses a lot of 'subterms', that are not covered by surfalize. Still all the tests pass. That means: I think we don't need all those subterms, but it would be good to check this explicitly. If that is the case, the code can be simplified even further, where we only have two SurfaceTerms: Plane, Plane + Sphere. That would lead to a major deletion of code lines as put forward in this PR, which is really nice! However, if we do need the subterms, we have to include a lot of the original code back in i'm afraid.

"""Get the highest polynomial degree present in the given surface terms."""
if terms == SurfaceTerms.NONE:
raise ValueError(f"No degree defined for {terms}")
return max(_DEGREE_MAP[term] for term in terms)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this conversion is tricky. SurfaceTerms.Plane is the only case for which degree is 1. And SurfaceTerms.Sphere is the only case for which degree is 2. When i look at the definition of the designmatrix in detrend_polynomial.

leveled_map=scan_image.data,
fitted_surface=np.full_like(scan_image.data, 0.0),
)
if scan_image.valid_mask.sum() < 3:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 + degree ipv 3?

if self.terms == SurfaceTerms.NONE:
return True
# We need at least 3 values for the least squares solver
return scan_image.valid_mask.sum() < 3

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 + get_polynomial_degree(self.terms)?

assert not np.allclose(
result_centered.leveled_map, result_ref.leveled_map, equal_nan=True
@pytest.mark.parametrize("terms", list(SurfaceTerms))
def test_map_level_has_effect(scan_image_with_nans: ScanImage, terms: SurfaceTerms):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wat test je hier nou? of, in her geval van geen surface term er niks gebeurt is, en anders of er wel iets gebeurt is. Maar gebeurt er dan het goede?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants