Exo-TiC / ExoTiC-LD

Limb-darkening package to calculate the coefficients for specific instruments, stars, and wavelength ranges
https://exotic-ld.readthedocs.io
MIT License
8 stars 6 forks source link

HTTPError: JWST_NIRSpec_prism_throughput.csv cannot be found #49

Closed LorenzoMugnai closed 2 months ago

LorenzoMugnai commented 3 months ago

Hello, I was running the Calculate probabilistic coefficients tutorial for @openjournals/joss-reviews#6816 and I got the following error.

from exotic_ld import StellarLimbDarkening

sld = StellarLimbDarkening(M_H=0.01, Teff=5512, logg=4.47,
                           ld_model="mps1",
                           ld_data_path="exotic_ld_data")

us, us_sigmas = sld.compute_4_parameter_non_linear_ld_coeffs(wavelength_range=[20000., 30000.],
                                                             mode="JWST_NIRSpec_prism",
                                                             return_sigmas=True)

results in

---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
File ~/anaconda3/envs/py3.9/lib/python3.9/site-packages/exotic_ld/ld_requests.py:13, in download(url, local_file_name, verbose, chunk_size)
     12 response = requests.get(url, stream=True)
---> 13 response.raise_for_status()
     14 total = int(response.headers.get("content-length", 0))

File ~/anaconda3/envs/py3.9/lib/python3.9/site-packages/requests/models.py:1024, in Response.raise_for_status(self)
   1023 if http_error_msg:
-> 1024     raise HTTPError(http_error_msg, response=self)

HTTPError: 404 Client Error: Not Found for url: https://www.star.bris.ac.uk/exotic-ld-data/Sensitivity_files/JWST_NIRSpec_prism_throughput.csv

During handling of the above exception, another exception occurred:

HTTPError                                 Traceback (most recent call last)
Cell In[6], line 12
      6 from exotic_ld import StellarLimbDarkening
      8 sld = StellarLimbDarkening(M_H=0.01, Teff=5512, logg=4.47,
      9                            ld_model="mps1",
     10                            ld_data_path="exotic_ld_data")
---> 12 us, us_sigmas = sld.compute_4_parameter_non_linear_ld_coeffs(wavelength_range=[20000., 30000.],
     13                                                              mode="JWST_NIRSpec_prism",
     14                                                              return_sigmas=True)
     16 # for u_idx, u, u_sigma in zip(range(1, 5), us, us_sigmas):
     17 #     print("u_{}={}+-{}".format(u_idx, round(u, 4), round(u_sigma, 4)))
     18 
   (...)
     40 # plt.legend(loc="upper left", fontsize=13)
     41 # plt.show()

File ~/anaconda3/envs/py3.9/lib/python3.9/site-packages/exotic_ld/ld_computation.py:484, in StellarLimbDarkening.compute_4_parameter_non_linear_ld_coeffs(self, wavelength_range, mode, custom_wavelengths, custom_throughput, mu_min, return_sigmas)
    433 """
    434 Compute the four-parameter non-linear limb-darkening coefficients.
    435 
   (...)
    481 
    482 """
    483 # Compute I(mu) for a given response function.
--> 484 self._integrate_I_mu(wavelength_range, mode,
    485                      custom_wavelengths, custom_throughput)
    487 # Fit limb-darkening law.
    488 return self._fit_ld_law(nonlinear_4param_ld_law, mu_min, return_sigmas)

File ~/anaconda3/envs/py3.9/lib/python3.9/site-packages/exotic_ld/ld_computation.py:551, in StellarLimbDarkening._integrate_I_mu(self, wavelength_range, mode, custom_wavelengths, custom_throughput)
    546         print("Using custom instrument throughput with wavelength "
    547               "range {}-{} A.".format(s_wavelengths[0],
    548                                       s_wavelengths[-1]))
    549 else:
    550     # Read in mode specific throughput.
--> 551     s_wavelengths, s_throughputs = self._read_sensitivity_data(mode)
    552     if self.verbose > 1:
    553         print("Loading instrument mode={} with wavelength range "
    554               "{}-{} A.".format(mode, s_wavelengths[0],
    555                                 s_wavelengths[-1]))

File ~/anaconda3/envs/py3.9/lib/python3.9/site-packages/exotic_ld/ld_computation.py:527, in StellarLimbDarkening._read_sensitivity_data(self, mode)
    525 # Check if exists locally.
    526 if not os.path.exists(local_sensitivity_file_path):
--> 527     download(remote_sensitivity_file_path,
    528              local_sensitivity_file_path, self.verbose)
    529     if self.verbose > 1:
    530         print("Downloaded {}.".format(local_sensitivity_file_path))

File ~/anaconda3/envs/py3.9/lib/python3.9/site-packages/exotic_ld/ld_requests.py:26, in download(url, local_file_name, verbose, chunk_size)
     23                 bar.update(size)
     25 except HTTPError as err:
---> 26     raise HTTPError("HTTP error occurred: url={}, msg={}"
     27                     .format(err.request.url, err))
     29 except requests.exceptions.ConnectionError as err:
     30     raise ConnectionError("Connection error occurred: url={}, msg={}"
     31                           .format(err.request.url, "Cannot connect to URL."))

HTTPError: HTTP error occurred: url=https://www.star.bris.ac.uk/exotic-ld-data/Sensitivity_files/JWST_NIRSpec_prism_throughput.csv, msg=404 Client Error: Not Found for url: https://www.star.bris.ac.uk/exotic-ld-data/Sensitivity_files/JWST_NIRSpec_prism_throughput.csv

It seems that https://www.star.bris.ac.uk/exotic-ld-data/Sensitivity_files/JWST_NIRSpec_prism_throughput.csv cannot be found.

The same error is raised by the Use a custom stellar model tutorial:

sld = StellarLimbDarkening(ld_data_path="exotic_ld_data",
                           ld_model="custom",
                           custom_wavelengths=s_wvs,
                           custom_mus=s_mus,
                           custom_stellar_model=stellar_intensity)

cs = sld.compute_4_parameter_non_linear_ld_coeffs(wavelength_range=[20000., 30000.],
                                                  mode="JWST_NIRSpec_prism")

Curiously, the error is not raised by the quickstart tutorial that still involves "JWST_NIRSpec_prism":

# Path to store stellar and instrument data.
ld_data_path = 'exotic_ld_data'

# Stellar models grid.
ld_model = 'mps1'

# Metallicty [dex].
M_H = 0.01

# Effective temperature [K].
Teff = 5512

# Surface gravity [dex].
logg = 4.47

from exotic_ld import StellarLimbDarkening

sld = StellarLimbDarkening(M_H, Teff, logg, ld_model, ld_data_path)

# Start and end of wavelength interval [angstroms].
wavelength_range = [20000., 30000.]

# Instrument mode.
mode = 'JWST_NIRSpec_Prism'

u1, u2 = sld.compute_quadratic_ld_coeffs(wavelength_range, mode)
DavoGrant commented 2 months ago

Thanks @LorenzoMugnai. Looks like this is a simple capitalisation bug. "JWST_NIRSpec_prism" should be "JWST_NIRSpec_Prism", I have just fixed this in the tutorials. For backwards compatibility, I have also added the lowercase version to the data server to prevent any earlier users running into the same error.