-
Notifications
You must be signed in to change notification settings - Fork 0
Introduction of returns to our system #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
+2,606
−1,752
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
fc6c1b2
Add returns dependency
snregales 9eed14e
create railway logger decorator
snregales 4a20096
Rewrite tests with the railway way containers in mind
snregales 99ee3f9
Rewrite functions scratch-core with returns
snregales 4a6bef3
Create an abstract generic pipeline module
snregales 2ed5414
Create some preprocessors pipelines
snregales 86a49be
Update preprocessors schemas
snregales c468306
Entegrate new pipeline structure to the pipeline
snregales ba6e75f
Cleanup old/unused scratch core code
snregales d133d0f
Remove unused api code
snregales 8a6e3cf
Make deptry happy
snregales b6705ff
remove surface normals
snregales 5d665a1
mask and crop functionality added (#67)
SimoneAriens 0e8db97
Gaussian filter - filter_apply.m (#60)
SimoneAriens 68d65ba
Add map_level.m to translations (#66)
cfs-data a3d07bc
Resampling method added (#71)
SimoneAriens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| """ | ||
| Immutable data container models for railway-oriented programming pipelines. | ||
|
|
||
| This module provides Pydantic-based data models that are propagated through railway | ||
| functions in functional pipelines. These models serve as type-safe, validated containers | ||
| for scientific and imaging data, ensuring data integrity as it flows through processing | ||
| pipelines. | ||
|
|
||
| Notes | ||
| ----- | ||
| These models are designed specifically for railway-oriented programming where data | ||
| flows through a sequence of transformations. The immutability ensures that each | ||
| function in the pipeline receives unmodified input, preventing side effects and | ||
| making pipelines easier to reason about and debug. | ||
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| from collections.abc import Sequence | ||
| from functools import partial | ||
| from typing import Annotated, TypeAlias | ||
|
|
||
| from numpy import array, bool_, float64, number, uint8 | ||
| from numpy.typing import DTypeLike, NDArray | ||
| from pydantic import BaseModel, BeforeValidator, ConfigDict, PlainSerializer | ||
|
|
||
|
|
||
| def serialize_ndarray[T: number](array_: NDArray[T]) -> list[T]: | ||
| """Serialize numpy array to a Python list for JSON serialization.""" | ||
| return array_.tolist() | ||
|
|
||
|
|
||
| def coerce_to_array[T: number]( | ||
| dtype: DTypeLike, value: Sequence[T] | NDArray[T] | None | ||
snregales marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) -> NDArray[T] | None: | ||
| """ | ||
| Coerce input to dtype numpy array. | ||
|
|
||
| Handles JSON deserialization where Python creates int64 integers by default. | ||
| """ | ||
| if isinstance(value, Sequence): | ||
| try: | ||
| return array(value, dtype=dtype) | ||
| except OverflowError as ofe: | ||
| raise ValueError("Array's value(s) out of range") from ofe | ||
|
|
||
| return value | ||
|
|
||
|
|
||
| ScanMapRGBA: TypeAlias = Annotated[ | ||
| NDArray[uint8], | ||
| BeforeValidator(partial(coerce_to_array, uint8)), | ||
| PlainSerializer(serialize_ndarray), | ||
| ] | ||
|
|
||
| ScanMap2DArray = ScanVectorField2DArray = UnitVector3DArray = Annotated[ | ||
| NDArray[float64], | ||
| BeforeValidator(partial(coerce_to_array, float64)), | ||
| PlainSerializer(serialize_ndarray), | ||
| ] | ||
|
|
||
| MaskArray = Annotated[ | ||
| NDArray[bool_], | ||
| BeforeValidator(partial(coerce_to_array, bool_)), | ||
| PlainSerializer(serialize_ndarray), | ||
| ] | ||
|
|
||
|
|
||
| class ConfigBaseModel(BaseModel): | ||
| """Base model with common configuration for all pydantic models in this project.""" | ||
|
|
||
| model_config = ConfigDict( | ||
| frozen=True, | ||
| extra="forbid", | ||
| arbitrary_types_allowed=True, | ||
| regex_engine="rust-regex", | ||
| ) | ||
48 changes: 48 additions & 0 deletions
48
packages/scratch-core/src/container_models/light_source.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| from functools import cached_property | ||
| import numpy as np | ||
| from pydantic import Field | ||
| from .base import UnitVector3DArray, ConfigBaseModel | ||
|
|
||
|
|
||
| class LightSource(ConfigBaseModel): | ||
| """ | ||
| Representation of a light source using an angular direction (azimuth and elevation) | ||
| together with a derived 3D unit direction vector. | ||
| """ | ||
|
|
||
| azimuth: float = Field( | ||
| ..., | ||
| description="Horizontal angle in degrees measured from the –x axis in the x–y plane. " | ||
| "0° is –x direction, 90° is +y direction, 180° is +x direction.", | ||
| examples=[90, 45, 180], | ||
| ge=0, | ||
| le=360, | ||
| ) | ||
| elevation: float = Field( | ||
| ..., | ||
| description="Vertical angle in degrees measured from the x–y plane. " | ||
| "0° is horizontal, +90° is upward (+z), –90° is downward (–z).", | ||
| examples=[90, 45, 180], | ||
| ge=-90, | ||
| le=90, | ||
| ) | ||
|
|
||
| @cached_property | ||
cfs-data marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def unit_vector(self) -> UnitVector3DArray: | ||
| """ | ||
| Returns the unit direction vector [x, y, z] corresponding to the azimuth and | ||
| elevation angles. The conversion follows a spherical-coordinate convention: | ||
| azimuth defines the horizontal direction, and elevation defines the vertical | ||
| tilt relative to the x–y plane. | ||
| """ | ||
| azimuth = np.deg2rad(self.azimuth) | ||
| elevation = np.deg2rad(self.elevation) | ||
| vec = np.array( | ||
| [ | ||
| -np.cos(azimuth) * np.cos(elevation), | ||
| np.sin(azimuth) * np.cos(elevation), | ||
| np.sin(elevation), | ||
| ] | ||
| ) | ||
| vec.setflags(write=False) | ||
| return vec | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| from pydantic import Field | ||
| from .base import ScanMap2DArray, ConfigBaseModel | ||
|
|
||
|
|
||
| class ScanImage(ConfigBaseModel): | ||
| """ | ||
| A 2D image/array of floats. | ||
|
|
||
| Used for: depth maps, intensity maps, single-channel images. | ||
| Shape: (height, width) | ||
| """ | ||
|
|
||
| data: ScanMap2DArray | ||
| scale_x: float = Field(..., gt=0.0, description="pixel size in meters (m)") | ||
| scale_y: float = Field(..., gt=0.0, description="pixel size in meters (m)") | ||
| meta_data: dict = Field(default_factory=dict) | ||
|
|
||
| @property | ||
| def width(self) -> int: | ||
| """The image width in pixels.""" | ||
| return self.data.shape[1] | ||
|
|
||
| @property | ||
| def height(self) -> int: | ||
| """The image height in pixels.""" | ||
| return self.data.shape[0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,33 @@ | ||
| from conversion.subsample import subsample_array | ||
| """ | ||
| Staging area for MATLAB-to-Python converted code. | ||
|
|
||
| __all__ = ("subsample_array",) | ||
| This module serves as a temporary dumping ground for newly translated MATLAB code | ||
| before it undergoes full integration into the main codebase. Code placed here is | ||
| in a transitional state and may not yet conform to project standards, architectural | ||
| patterns, or best practices. | ||
|
|
||
| Purpose | ||
| ------- | ||
| The conversion module provides a designated space where developers can: | ||
| 1. Place initial MATLAB-to-Python translations without disrupting the main codebase | ||
| 2. Test and validate converted algorithms in isolation | ||
| 3. Iteratively refactor and improve code quality before final integration | ||
| 4. Document conversion notes, gotchas, and MATLAB-specific behaviors | ||
|
|
||
| Workflow | ||
| -------- | ||
| 1. **Convert**: Translate MATLAB code to Python and place it in this module | ||
| 2. **Validate**: Verify the converted code produces correct results | ||
| 3. **Refactor**: Adapt code to project standards (type hints, Pydantic models, etc.) | ||
| 4. **Integrate**: Move refined code to appropriate modules (pipelines, preprocessors, etc.) | ||
| 5. **Remove**: Delete the staging code once integration is complete | ||
|
|
||
| After migration, the staging code in this module should be deleted. | ||
|
|
||
| Warnings | ||
| -------- | ||
| - DO NOT import from this module in production code | ||
| - DO NOT depend on code in this module for long-term functionality | ||
| - Code here may be incomplete, buggy, or subject to breaking changes | ||
| - This module should remain empty or nearly empty in a mature codebase | ||
| """ |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.