SNEWS2 / snewpy

A Python package for working with supernova neutrinos
https://snewpy.readthedocs.io
BSD 3-Clause "New" or "Revised" License
24 stars 17 forks source link

Searching model parameters in a path #304

Closed KaraMelih closed 4 months ago

KaraMelih commented 4 months ago

https://github.com/SNEWS2/snewpy/blob/f897dd99b4b7abe133cf1e4f13a49a742be0e4f0/python/snewpy/_model_downloader.py#L20

I use snewpy in the server, and I need to access the common SNEWP_Models/ from different locations. Therefore, I normally access them using a full path.

However, accessing a model with the model parameter is more convenient, and avoids confusion. Also, I see that accessing by file name is deprecated. I tried to follow and understand how the models are fetched based on their input model parameters, it seems at the release there is supposed to be a model_path which presumably points to cwd/SNEWPY_Models but I can't seem to find that within the files at the time of the release.

Is there a way, in which I can specify the location of "SNEWPY_Models/" folder and then only pass the model parameters?

JostMigenda commented 4 months ago

The model_path by default points to the AstroPy cache directory; see python/snewpy/__init__.py where it's defined.

So by default, this would be independent of your current working directory; which I think is what you want? (In principle, you could also import snewpy and then set snewpy.model_path to a custom directory, if necessary.)

KaraMelih commented 4 months ago

Thanks!

Looks like, indeed;

import snewpy
import astropy.units as u
snewpy.model_path = "my_snewpy_models_path"
from snewpy.models.ccsn import Nakazato_2013
n = Nakazato_2013(progenitor_mass=20*u.solMass, revival_time=100*u.ms, metallicity=0.004, eos='shen')

works! Closing the issue.