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

GH version of load_results has different behaviour than pip-installable version #11

Open
Kamuish opened this issue Apr 2, 2024 · 4 comments

Comments

@Kamuish
Copy link
Contributor

Kamuish commented Apr 2, 2024

When running the

 res = kima.load_results(diagnostic=False)

we get the traceback

Traceback (most recent call last):
  File "/home/amiguel/first_author_articles/WG1targets_Andre/kima_analysis/plot_kima.py", line 23, in <module>
    res = kima.load_results(diagnostic=False)
TypeError: load_results() missing 1 required positional argument: 'model_or_file'

An attempt to pass the current directory through the model_or_file argument leads to:

IsADirectoryError: [Errno 21] Is a directory: '.'

The same issue occurs when directly calling KimaResults that -- from the docs -- should be able to load data from the current directory

res = KimaResults.load(diagnostic=False)

PS: all of this was run with the context manager from kima.pykima.utils.chdir

@j-faria
Copy link
Contributor

j-faria commented Apr 10, 2024

Currently (on main) you must call load_results as

res = kima.load_results(model, diagnostic=False)

but I will keep this issue open because I want to restore the ability to "guess" the model from the directory where the function runs.

@Kamuish
Copy link
Contributor Author

Kamuish commented Apr 10, 2024

Do you have to re-define all of the priors (and known_planets) or can kima infer those from the disk products?

@j-faria
Copy link
Contributor

j-faria commented Apr 10, 2024

Those settings are stored in (both) the model and the kima_model_setup.txt file, so they should be inferred.

@Kamuish
Copy link
Contributor Author

Kamuish commented Apr 10, 2024

It seems that that is the case. For the loading, I guess that it is fairly straightforward. I am running it like this:

model_map = {"GPmodel": GPmodel, "RVFWHMmodel": RVFWHMmodel}
selected_folder = paths["run4"]
with chdir(selected_folder):
    with open(selected_folder / "kima_model_setup.txt") as to_read:
        for line in to_read:
            if "model" in line:
                Kimamodel = model_map[line.split(":")[-1].strip()]
            if "fix" in line:
                state = line.split(":")[-1].strip()
                fix = False if state == "false" else True
            if "npmax" in line:
                npmax = int(line.split(":")[-1])
            if "files" in line:
                input_files = line.split(":")[-1].split(",")[:-1]
                break

    data = RVData(
        filenames=input_files,
        units="ms",
        skip=0,
        indicators=["fwhm", "s-fwhm", "cont", "s-cont", "bis", "s-bis"],
    )

    model = Kimamodel(fix=fix, npmax=npmax, data=data)

    res = kima.load_results(model, diagnostic=False)

I will not open a PR due to:

  1. I am fairly certain that such an approach is missing a few edge cases
  2. not exactly sure if this functionality should be placed directly in the KimaResults objects or in the load_results function

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

2 participants