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

BTSettl-CIFIST models error with read_model.py and scipy interpnd #59

Closed
logan-pearce opened this issue Aug 10, 2022 · 2 comments
Closed
Labels
bug Something isn't working question Further information is requested

Comments

@logan-pearce
Copy link

I am trying to use the BTSettl-CIFIST models because they go up to the higher temperatures I need for the stars, and I am encountering an error that seems to be deep within the API that I am not able to solve. It seems that when read_model.py interfaces with scipy interpolate.interpnd, there is an error on reshaping an array. This error has not been a problem with any other models I have tried.
I installed species yesterday, version 0.5.3

I am following the "synthetic photometry" tutorial:

import species
species.SpeciesInit()
database = species.Database()
database.add_model(model='bt-settl-cifist', teff_range=(2000., 7000.))
database.add_filter('SLOAN/SDSS.g')
database.add_filter('SLOAN/SDSS.r')
database.add_filter('SLOAN/SDSS.i')
database.add_filter('SLOAN/SDSS.z')
model_param = {'teff':5400, 'logg':4.0, 'feh':0.5, 'distance': Adistance[0], 'radius':1000}
model_box = read_model.get_model(model_param=model_param, spec_res=200., smooth=True)

Produces the error:
`---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Input In [10], in <cell line: 1>()
----> 1 model_box = read_model.get_model(model_param=model_param, spec_res=200., smooth=True)

File ~/anaconda3/envs/py39/lib/python3.9/site-packages/typeguard/init.py:1033, in typechecked..wrapper(*args, **kwargs)
1031 memo = _CallMemo(python_func, _localns, args=args, kwargs=kwargs)
1032 check_argument_types(memo)
-> 1033 retval = func(*args, **kwargs)
1034 try:
1035 check_return_type(retval, memo)

File ~/anaconda3/envs/py39/lib/python3.9/site-packages/species/read/read_model.py:747, in ReadModel.get_model(self, model_param, spec_res, wavel_resample, magnitude, smooth)
743 parameters.append(model_param["log_kzz"])
745 # Interpolate the spectrum from the grid
--> 747 flux = self.spectrum_interp(parameters)[0]
749 # Add the radius to the parameter dictionary if the mass if given
751 if "mass" in model_param and "radius" not in model_param:

File ~/anaconda3/envs/py39/lib/python3.9/site-packages/scipy/interpolate/_interpolate.py:2515, in RegularGridInterpolator.call(self, xi, method)
2512 raise ValueError("Method '%s' is not defined" % method)
2514 ndim = len(self.grid)
-> 2515 xi = _ndim_coords_from_arrays(xi, ndim=ndim)
2516 if xi.shape[-1] != len(self.grid):
2517 raise ValueError("The requested sample points xi have dimension "
2518 "%d, but this RegularGridInterpolator has "
2519 "dimension %d" % (xi.shape[1], ndim))

File interpnd.pyx:157, in scipy.interpolate.interpnd._ndim_coords_from_arrays()

File interpnd.pyx:182, in scipy.interpolate.interpnd._ndim_coords_from_arrays()

ValueError: cannot reshape array of size 3 into shape (2)`

@tomasstolker
Copy link
Owner

Hi @logan-pearce,

Thanks for opening this issue! I think that the problem might be the 'feh' parameter that is included in your model_param dictionary while this isn't a free parameter with the BT-Setll CIFIST grid.

That should have printed a warning and ignored the parameter when interpolating a spectrum, but I see now that the parameter is actually not ignored by species so therefore it runs into the interpolation error. Thanks for pointing this out. I will fix that!

You can use methods such as get_parameters, get_bounds, and get_points from the ReadModel class to check which parameters are required.

I hope this solves the problem but let me know otherwise!

@tomasstolker tomasstolker added bug Something isn't working question Further information is requested labels Aug 11, 2022
@tomasstolker
Copy link
Owner

Parameters that are not mandatory are now ignored by ReadModel. See commit fa82915 that will be part of a next release.

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

No branches or pull requests

2 participants