Coverage for src/susi/atlantes/hamburg.py: 100%

41 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""" 

4Module to access the original Hamburg atlas. 

5Per default located in `data/atlases/FTS-Atlas` 

6 

7@author: hoelken 

8""" 

9import os 

10import numpy as np 

11 

12from .atlas import Atlas 

13from ..base import ROOT_DIR, IllegalStateException 

14 

15 

16class FTSAtlas(Atlas): 

17 """ 

18 Hamburg FTS Atlas data class 

19 """ 

20 

21 #: ATLAS_LOCATION 

22 ATLAS_LOCATION = os.path.join(ROOT_DIR, '..', 'data', 'atlantes', 'FTS-Atlas') 

23 #: List of file names forming the Hamburg Atlas 

24 ATLAS_FILES = [f'file{i:02d}' for i in range(1, 11)] 

25 

26 def __init__(self, start: float, stop: float, location: str = ATLAS_LOCATION): 

27 # list of file pathes 

28 self.files = [os.path.join(location, f) for f in FTSAtlas.ATLAS_FILES] 

29 # Containers for the loaded atlas 

30 #: (Quasi-) continuum 

31 self.continuum = [] 

32 # Build class 

33 super().__init__(start, stop) 

34 

35 def load(self): 

36 """Read the content of the atlas to mem""" 

37 if len(self.wl) > 0: 

38 return self 

39 

40 if not os.path.exists(self.files[0]): 

41 file0 = os.path.relpath(self.files[0]) 

42 readme = os.path.abspath(os.path.join(FTSAtlas.ATLAS_LOCATION, '..', 'Readme.md')) 

43 raise IllegalStateException(f'{file0} not found. Atlas not available.\nSee {readme} for details.') 

44 

45 self.__load_data() 

46 self.wl = np.array(self.wl) 

47 self.intensity = np.array(self.intensity) 

48 self.continuum = np.array(self.continuum) 

49 return self 

50 

51 def __load_data(self) -> None: 

52 for file in self.files: 

53 if not self.__load_file(os.path.relpath(file)): 

54 return 

55 

56 def __load_file(self, file: str): 

57 with open(file) as f: 

58 for line in f: 

59 content = line.split() 

60 wl = float(content[0]) 

61 if wl > self.stop: 

62 return False 

63 

64 if wl < self.start: 

65 continue 

66 

67 self.wl.append(wl) 

68 self.intensity.append(float(content[1])) 

69 self.continuum.append(float(content[2])) 

70 return True