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

Decide how to pass size of projected grid and whether to remove its centre through code #170

Open
Jammy2211 opened this issue Jul 14, 2021 · 0 comments

Comments

@Jammy2211
Copy link
Owner

To create a 1D projected grid from a 2D Grid I use the following:

    def grid_2d_radial_projected_from(
        self, centre: Tuple[float, float] = (0.0, 0.0), angle: float = 0.0
    ) -> grid_2d_irregular.Grid2DIrregular:
        """
        Determine a projected radial grid of points from a 2D region of coordinates defined by an
        extent [xmin, xmax, ymin, ymax] and with a (y,x) centre. This functions operates as follows:

        1 Given the region defined by the extent [xmin, xmax, ymin, ymax], the algorithm finds the longest 1D distance
        of the 4 paths from the (y,x) centre to the edge of the region e.g. following the positive / negative y and
        x axes.

        2: Use the pixel-scale corresponding to the direction chosen e.g. if the positive x-axis was the longest, the
        pixel_scale in the x dimension is used.

        3: Determine the number of pixels between the centre and the edge of the region using the longest path between
        the two chosen above.

        4: Create a (y,x) grid of radial points where all points are at the centre's y value = 0.0 and the x values
        iterate from the centre in increasing steps of the pixel-scale.

        5: Rotate these radial coordinates by the input `angle` clockwise.

        A schematic is shown below:

        -------------------
        |                 |
        |<- - -  - ->x    | x = centre
        |                 | <-> = longest radial path from centre to extent edge
        |                 |
        -------------------

        4: Create a (y,x) grid of radial points where all points are at the centre's y value = 0.0 and the x values
        iterate from the centre in increasing steps of the pixel-scale.

        5: Rotate these radial coordinates by the input `angle` clockwise.

        Parameters
        ----------
        centre
            The (y,x) central coordinate which the radial grid is traced outwards from.
        angle
            The angle with which the radial coordinates are rotated clockwise.

        Returns
        -------
        grid_2d_irregular.Grid2DIrregular
            A radial set of points sampling the longest distance from the centre to the edge of the extent in along the
            positive x-axis.
        """

        **if hasattr(self, "radial_projected_shape_slim"):**
            shape_slim = self.radial_projected_shape_slim
        else:
            shape_slim = 0

        grid_radial_projected_2d = grid_2d_util.grid_scaled_2d_slim_radial_projected_from(
            extent=self.extent,
            centre=centre,
            pixel_scales=self.pixel_scales,
            sub_size=self.sub_size,
            shape_slim=shape_slim
        )

        grid_radial_projected_2d = geometry_util.transform_grid_2d_to_reference_frame(
            grid_2d=grid_radial_projected_2d, centre=centre, angle=angle
        )

        grid_radial_projected_2d = geometry_util.transform_grid_2d_from_reference_frame(
            grid_2d=grid_radial_projected_2d, centre=centre, angle=0.0
        )

        **if conf.instance["general"]["grid"]["remove_projected_centre"]:**

            grid_radial_projected_2d = grid_radial_projected_2d[1:,:]

        return grid_2d_irregular.Grid2DIrregular(grid=grid_radial_projected_2d)

The lines in bold are hacks, which work for getting figures together for a paper but are not great in general.

We probably watch to pass these are an input to all Grid class methods so a user can set them up with a Grid. But we should think about whether this is creating a lot of superflous extra code and if some sort of Settings object might help.

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

No branches or pull requests

1 participant