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

Problem in add_custom_model with data_path #102

Open
cosmicbabs opened this issue Jul 19, 2024 · 1 comment
Open

Problem in add_custom_model with data_path #102

cosmicbabs opened this issue Jul 19, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@cosmicbabs
Copy link

Hi! I was using the new version, but I get an error when using add_custom_model. It doesn't recognize the data_path as a str (?)
I get this error:

TypeCheckError: value assigned to data_path (pathlib.PosixPath) is not an instance of str

I tried using

  • '/Users/cosmicbabs/libraries/raw/
  • "/Users/cosmicbabs/libraries/raw/"
  • from pathlib import Path -> data_path = str(Path('/Users/cosmicbabs/libraries/raw/'))

I downgraded to v0.8.3, and I got no errors.

Here is the full error (the problem is in _):


TypeCheckError Traceback (most recent call last)
Cell In[15], line 6
1 # ADD all models
2
3 # add btsett-agss
4 data_path_btsett_agss = str(Path('/Users/cosmicbabs/libraries/raw/btsett-agss/ascii_4Species_R250'))
----> 6 database.add_custom_model(model='btsett-agss',
7 data_path=data_path_btsett_agss,
8 parameters = ['teff', 'logg', 'feh'],
9 wavel_range=(0.30, 5.49),
10 teff_range=(2700,3500)
11 )
12 # add btsett-cifist
13 database.add_custom_model(model='btsett-cifist',
14 data_path='/Users/cosmicbabs/libraries/raw/btsett-cifist/ascii_4Species_R250/',
15 parameters = ['teff', 'logg', 'feh'],
16 wavel_range=(0.30, 5.49),
17 teff_range=(2700,3500)
18 )

File ~/anaconda3/envs/speciesenv/lib/python3.10/site-packages/species/data/database.py:821, in add_custom_model(self, model, data_path, parameters, wavel_range, wavel_sampling, teff_range)
818 from species.data.model_data.custom_model import add_custom_model_grid
820 with h5py.File(self.database, "a") as hdf5_file:
--> 821 add_custom_model_grid(
822 model,
823 data_path,
824 parameters,
825 hdf5_file,
826 wavel_range,
827 teff_range,
828 wavel_sampling,
829 )

File ~/anaconda3/envs/speciesenv/lib/python3.10/site-packages/species/data/model_data/custom_model.py:152, in add_custom_model_grid(model_name, data_path, parameters, database, wavel_range, teff_range, wavel_sampling)
149 print_message = ""
150 count = 0
--> 152 data_path = Path(data_path)
153 model_files = sorted(data_path.glob("*"))
155 for file_item in model_files:

File ~/anaconda3/envs/speciesenv/lib/python3.10/site-packages/typeguard/_functions.py:251, in check_variable_assignment(value, varname, annotation, memo)
248 return value
250 try:
--> 251 check_type_internal(value, annotation, memo)
252 except TypeCheckError as exc:
253 qualname = qualified_name(value, add_class_prefix=True)

File ~/anaconda3/envs/speciesenv/lib/python3.10/site-packages/typeguard/_checkers.py:866, in check_type_internal(value, annotation, memo)
864 if isclass(origin_type):
865 if not isinstance(value, origin_type):
--> 866 raise TypeCheckError(f"is not an instance of {qualified_name(origin_type)}")
867 elif type(origin_type) is str: # noqa: E721
868 warnings.warn(
869 f"Skipping type check against {origin_type!r}; this looks like a "
870 f"string-form forward reference imported from another module",
871 TypeHintWarning,
872 stacklevel=get_stacklevel(),
873 )

TypeCheckError: value assigned to data_path (pathlib.PosixPath) is not an instance of str

@tomasstolker
Copy link
Owner

Hi Bárbara, thanks for opening this issue and trying out add_custom_model!

There was indeed a problem introduced in this function when I recently changed the use of the os.path module to pathlib.

I have fixed this in the latest commit that I just pushed so if you install the Github version then it should work.

Let me know in case you run into any further problems!

@tomasstolker tomasstolker added the bug Something isn't working label Jul 22, 2024
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

No branches or pull requests

2 participants