Skip to content

Base folder/dir for coho might be needed to access samples #11

@a-attia

Description

@a-attia

Trying to run coho, following the initial example.
The attribute file_path of cho.configs.models.simulations.SampleProfile is relative path (which is fine). However, if the script (.py) used to run coho code is not at the root of coho, it won't fine the sample.
Would it make sens to define a coho ROOT_PATH attribute, or even a coho.RESOURCES to define the absolute path of resources, and point to things under it?
e.g., under SampleProfile, file_path=os.path.join(coho.RESOURCES, "samples/lena.npy" or something!

Here is the error log:

  File "~~~~/coho/examples/main.py", line 8, in <module>
    forward = coho.Holography(config)
  File "~~~~/coho/coho/core/operator/forward.py", line 16, in __init__
    self._init_components(config.simulation)
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "~~~~/coho/coho/core/operator/forward.py", line 37, in _init_components
    self.sample = SampleFactory().create(
                  ~~~~~~~~~~~~~~~~~~~~~~^
        model=config.sample.model,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
        properties=config.sample.properties
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "~~~~/coho/coho/factories/base_factory.py", line 25, in create
    return component_class(properties or {})
  File "~~~~/coho/coho/core/simulation/element.py", line 20, in __init__
    self._initialize_element()
    ~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "~~~~/coho/coho/core/simulation/element.py", line 27, in _initialize_element
    self.profile = self.generate_profile()
                   ~~~~~~~~~~~~~~~~~~~~~^^
  File "~~~~/coho/coho/core/simulation/sample.py", line 35, in generate_profile
    profile = np.load(file_path)
  File "~~~~/coho/venv/lib/python3.13/site-packages/numpy/lib/_npyio_impl.py", line 459, in load
    fid = stack.enter_context(open(os.fspath(file), "rb"))
                              ~~~~^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'coho/resources/samples/lena.npy'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions