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

mk3 projectiontype is not validated upon initialization #102

Closed
veenstrajelmer opened this issue Oct 19, 2023 · 1 comment · Fixed by #92
Closed

mk3 projectiontype is not validated upon initialization #102

veenstrajelmer opened this issue Oct 19, 2023 · 1 comment · Fixed by #92
Labels
bug Something isn't working

Comments

@veenstrajelmer
Copy link
Collaborator

veenstrajelmer commented Oct 19, 2023

Describe the bug
There is not feedback on an incorrect projection when initializing a mk instance. Also, there is an unclear error upon get_projection.

To Reproduce

import meshkernel
mk2 = meshkernel.MeshKernel(projection='spherical123')
mk2.get_projection()

Raises ValueError:

Traceback (most recent call last):

  Cell In[12], line 2
    mk2.get_projection()

  File ~\Anaconda3\envs\dfm_tools_py311\Lib\site-packages\meshkernel\meshkernel.py:1508 in get_projection
    return ProjectionType(projection.value)

  File ~\Anaconda3\envs\dfm_tools_py311\Lib\enum.py:712 in __call__
    return cls.__new__(cls, value)

  File ~\Anaconda3\envs\dfm_tools_py311\Lib\enum.py:1128 in __new__
    raise ve_exc

ValueError: 1613394736 is not a valid ProjectionType

Also, when aquiring the projectiontype, there is no useful feedback about the available options:

meshkernel.ProjectionType('cartesian')
Traceback (most recent call last):

  Cell In[17], line 1
    meshkernel.ProjectionType('cartesian')

  File ~\Anaconda3\envs\dfm_tools_py311\Lib\enum.py:712 in __call__
    return cls.__new__(cls, value)

  File ~\Anaconda3\envs\dfm_tools_py311\Lib\enum.py:1128 in __new__
    raise ve_exc

ValueError: 'cartesian' is not a valid ProjectionType

Expected behavior
Feedback upon initialization about the options. Strings should be parsed to enum automatically.

Version info (please complete the following information):

  • OS: [e.g. Windows]
  • Version 3.0.0
@veenstrajelmer veenstrajelmer added the bug Something isn't working label Oct 19, 2023
@veenstrajelmer veenstrajelmer changed the title mk3 projectiontype mk3 projectiontype is not validated upon initialization Oct 19, 2023
@ahmad-el-sayed
Copy link
Contributor

MeshKernel constructor is not parametrised by a string:

class MeshKernel:
    """This class is the entry point for interacting with the MeshKernel library"""

    def __init__(self, projection: ProjectionType = ProjectionType.CARTESIAN):
        """Constructor of MeshKernel

        Args:
            projection (ProjectionType, optional): The projection type. Default is `ProjectionType.CARTESIAN`.

        Raises:
            OSError: This gets raised in case MeshKernel is used within an unsupported OS.
        """

where

@unique
class ProjectionType(IntEnum):
    """The projection types."""

    CARTESIAN = 0
    SPHERICAL = 1
    SPHERICALACCURATE = 2

The named param projection should be set to the ProjectionType enum.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants