Skip to content
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

[feature] changes to sampler/computing classes #39

Open
lachlangrose opened this issue Feb 21, 2024 · 0 comments
Open

[feature] changes to sampler/computing classes #39

lachlangrose opened this issue Feb 21, 2024 · 0 comments
Labels
medium priority we will do this soon

Comments

@lachlangrose
Copy link
Member

The sampler/compute/sorter classes should be changed so that the compute method is only called with the object that they are working on.

E.g. for a sampler it would be sampler.sample(shapefile), any augmentations should be specified in the constructor of the sampler. This means that the samples can be augmented with additional data but not changing the method used within map2loop. It also removes any unused variables and/or wild card passing of objects through the map_data class.

An example of this for the SamplerDecimator below modified from #38

Another idea is to change the sample/sort/calculate functions to __call__ @RoyThomsonMonash do you have any reason not to? It does make the task of the class less clear but the class name should be descriptive enough? for the sampler you could call using sampler(shapefile)....

class SamplerDecimator(Sampler):
    """
    Decimator sampler class which decimates the geo data frame based on the decimation value
    ie. decimation = 10 means take every tenth point
    Note: This only works on data frames with lists of points with columns "X" and "Y"
    """

    @beartype.beartype
    def __init__(self, geology: geopandas.GeoDataFrame, decimation: int = 1):
        """
        Initialiser for decimator sampler

        Args:
            geology (GeoDataFrame): the geology shapefile to copy layerId from
            decimation (int, optional): stride of the points to sample. Defaults to 1.
        """
        self.geology = geology
        self.sampler_label = "SamplerDecimator"
        decimation = max(decimation, 1)
        self.decimation = decimation

    @beartype.beartype
    def __call__(
        self, spatial_data: geopandas.GeoDataFrame
    ) -> pandas.DataFrame:
        """
        Execute sample method takes full point data, samples the data and returns the decimated points

        Args:
            spatial_data (geopandas.GeoDataFrame): the data frame to sample

        Returns:
            pandas.DataFrame: the sampled data points
        """
        data = spatial_data.copy()
        data["X"] = data.geometry.x
        data["Y"] = data.geometry.y
        data["layerID"] = geopandas.sjoin(
            data,
            self.geology,
            how='left',
        )['ID_right'].values
        data.reset_index(drop=True, inplace=True)
        return pandas.DataFrame(data[:: self.decimation].drop(columns="geometry"))
@AngRodrigues AngRodrigues added high priority on top of our to do medium priority we will do this soon and removed high priority on top of our to do labels May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
medium priority we will do this soon
Projects
None yet
Development

No branches or pull requests

2 participants