space-ska 2.2__tar.gz → 2.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: space-ska
3
- Version: 2.2
3
+ Version: 2.4
4
4
  Summary: Spectral-Kit for Asteroids
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -13,6 +13,7 @@ Classifier: Programming Language :: Python :: 3.11
13
13
  Classifier: Programming Language :: Python :: 3.12
14
14
  Classifier: Programming Language :: Python :: 3.13
15
15
  Classifier: Programming Language :: Python :: 3.14
16
+ Classifier: Programming Language :: Python :: 3.15
16
17
  Provides-Extra: docs
17
18
  Requires-Dist: astropy (>=7.1,<8.0)
18
19
  Requires-Dist: click (>=8.3,<9.0)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "space-ska"
3
- version = "2.2"
3
+ version = "2.4"
4
4
  description = "Spectral-Kit for Asteroids"
5
5
  authors = ["Benoit Carry <benoit.carry@oca.eu>", "Max Mahlke"]
6
6
  license = "MIT"
@@ -103,7 +103,6 @@ def download_sun_and_vega():
103
103
  """Download the spectra of the Sun and Vega"""
104
104
 
105
105
  try:
106
-
107
106
  # Get the spectrum of the Sun
108
107
  r = requests.get(
109
108
  "https://raw.githubusercontent.com/bcarry/ska/main/data/e490_sun.csv"
@@ -129,7 +128,6 @@ def download_mahlke_taxonomy():
129
128
  """Download the template spectra of Mahlke+2022 taxonomy"""
130
129
 
131
130
  try:
132
-
133
131
  # Get the spectrum of the Sun
134
132
  r = requests.get(
135
133
  "https://raw.githubusercontent.com/bcarry/ska/main/data/template_mahlke2022.csv"
@@ -10,7 +10,7 @@ import ska
10
10
 
11
11
  class Spectrum:
12
12
  # --------------------------------------------------------------------------------
13
- def __init__(self, input=None):
13
+ def __init__(self, input=None, second=None, reflectance=False):
14
14
  """Initiate a SKA spectrum class"""
15
15
 
16
16
  # Store attributes
@@ -19,10 +19,8 @@ class Spectrum:
19
19
  self.is_refl = False
20
20
 
21
21
  if "input" in locals():
22
-
23
22
  # Initialize from a str: file or a taxonomic class
24
23
  if isinstance(input, str):
25
-
26
24
  if os.path.isfile(input):
27
25
  self.from_csv(input)
28
26
  else:
@@ -33,8 +31,16 @@ class Spectrum:
33
31
  self.from_dataframe(input)
34
32
 
35
33
  # Initialize from a numpy.ndarray
36
- if isinstance(input, np.ndarray):
37
- self.from_numpy(input)
34
+ if isinstance(input, np.ndarray) and second is None:
35
+ self.from_numpy(input, reflectance=reflectance)
36
+
37
+ # Initialize from two lists or np.array
38
+ if (
39
+ ("second" in locals())
40
+ & (isinstance(input, np.ndarray) | isinstance(input, list))
41
+ & (isinstance(second, np.ndarray) | isinstance(second, list))
42
+ ):
43
+ self.from_waveflux(input, second, reflectance=reflectance)
38
44
 
39
45
  # Initialize from a temperature (simple float or int) -> Blackbody
40
46
  if isinstance(input, int) | isinstance(input, float):
@@ -104,6 +110,41 @@ class Spectrum:
104
110
  self.flux = arr[order, 1]
105
111
  self.is_refl = reflectance
106
112
 
113
+ # --------------------------------------------------------------------------------
114
+ def from_waveflux(self, wave, flux, reflectance=False):
115
+ """Create a SKA spectrum from two list/arrays of wavelength and flux
116
+
117
+ Parameters
118
+ ----------
119
+ wave : np.ndarray | list
120
+ A numpy array or list containing the wavelength in micron.
121
+ flux : np.ndarray | list
122
+ A numpy array or list containing the Flux or Reflectance.
123
+
124
+ reflectance : boolean
125
+ Set True if the input is a reflectance spectrum (default=False)
126
+ """
127
+
128
+ if (not isinstance(wave, np.ndarray)) & (not isinstance(wave, list)):
129
+ rich.print(f"[red]wave is not a list or numpy array.[/red]")
130
+ sys.exit(1)
131
+
132
+ if (not isinstance(flux, np.ndarray)) & (not isinstance(flux, list)):
133
+ rich.print(f"[red]flux is not a list or numpy array.[/red]")
134
+ sys.exit(1)
135
+
136
+ if len(wave) != len(flux):
137
+ rich.print(
138
+ f"[red]Wave and flux of different lengths ({len(wave)} vs {len(flux)}).[/red]"
139
+ )
140
+ sys.exit(1)
141
+
142
+ # Store attributes
143
+ order = np.argsort(wave)
144
+ self.wave = np.array(wave)[order]
145
+ self.flux = np.array(flux)[order]
146
+ self.is_refl = reflectance
147
+
107
148
  # --------------------------------------------------------------------------------
108
149
  def from_dataframe(self, df):
109
150
  """Create a SKA spectrum from a pandas DataFrame.
@@ -402,7 +443,6 @@ class Spectrum:
402
443
  filters = [filters]
403
444
 
404
445
  for f in filters:
405
-
406
446
  if isinstance(f, ska.Filter):
407
447
  filt = f
408
448
  else:
@@ -18,7 +18,6 @@ def download_filter_list():
18
18
  """
19
19
 
20
20
  try:
21
-
22
21
  # Main SVO filter list
23
22
  r = requests.get(
24
23
  "https://svo.cab.inta-csic.es/wp-content/uploads/download/FPS_info.xml"
@@ -41,8 +40,7 @@ def download_filter_list():
41
40
  return True
42
41
 
43
42
  except:
44
- # raise Exception("Error downloading filter list")
45
- rich.print(f"[red]Error downloading filter {id} VOTable[/red].")
43
+ rich.print(f"[red]Error downloading filter list from SVO[/red].")
46
44
  return False
47
45
 
48
46
 
@@ -89,7 +87,7 @@ def download_filter(id, force=False):
89
87
  sys.exit(1)
90
88
 
91
89
  # SVO Base URL for queries
92
- url = f"http://svo2.cab.inta-csic.es/theory/fps3/fps.php?"
90
+ url = "http://svo2.cab.inta-csic.es/theory/fps/fps.php?"
93
91
 
94
92
  # Output name for the filter VOTable
95
93
  out = os.path.join(ska.PATH_CACHE, id.replace("/", "_") + ".xml")
@@ -109,7 +107,6 @@ def download_filter(id, force=False):
109
107
  except:
110
108
  rich.print(f"[red]Error downloading filter {id} VOTable[/red].")
111
109
  sys.exit(1)
112
- # raise Exception("Error downloading filter VOTable")
113
110
 
114
111
  # Return path to filter VOTable
115
112
  return out
File without changes
File without changes
File without changes
File without changes
File without changes