tomasstolker / species

Toolkit for atmospheric characterization of directly imaged exoplanets
https://species.readthedocs.io
MIT License
22 stars 10 forks source link

Problem in add_custom_model with data_path #102

Open cosmicbabs opened 1 month ago

cosmicbabs commented 1 month ago

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

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 commented 1 month ago

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!