Coverage for src/susi/model/input_flux.py: 94%

18 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2025-06-13 14:15 +0000

1#!/usr/bin/env python3 

2# -*- coding: utf-8 -*- 

3""" 

4@author: iglesias 

5""" 

6import os 

7import numpy as np 

8import csv 

9from scipy import interpolate 

10from .. import ROOT_DIR 

11 

12INPUT_FLUX_PATH = os.path.abspath(os.path.join(ROOT_DIR, "..", "data", "susi", "modeled", "susi_flux_20220511.csv")) 

13 

14 

15def input_flux(wl): 

16 """ 

17 Returns the expected photon flux [kilo-photons/s] at SUSI SP cameras from `susi_flux.csv` 

18 which is based on SR3-MPS-TN-US000-002_D_b. The format of `susi_flux.csv` is "wl [nm], flux [1e4 e-/pix/s]" 

19 

20 :param wl: Array or scalar with wavelengths at wich you want to get the flux [nm]. Must be in the 300-410 nm range 

21 """ 

22 if np.min(wl) < 300.0 or np.max(wl) > 410.0: 

23 raise Exception("The input wavelength is not int the 300-410 nm range") 

24 

25 flux = np.array([[0, 0]]) 

26 with open(INPUT_FLUX_PATH, newline="") as csvfile: 

27 spamreader = csv.reader(csvfile) 

28 for row in spamreader: 

29 # [wl in nm, flux in 1e4 photons/s] 

30 flux = np.concatenate((flux, [np.array(row).astype(float)])) 

31 flux = flux[1:, :] 

32 # interpolates to get the flux at wl 

33 tck = interpolate.splrep(flux[:, 0], flux[:, 1], s=0) 

34 return np.array(interpolate.splev(wl, tck))