space-ska 2.2__tar.gz → 2.3__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.3
4
4
  Summary: Spectral-Kit for Asteroids
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "space-ska"
3
- version = "2.2"
3
+ version = "2.3"
4
4
  description = "Spectral-Kit for Asteroids"
5
5
  authors = ["Benoit Carry <benoit.carry@oca.eu>", "Max Mahlke"]
6
6
  license = "MIT"
@@ -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,42 @@ class Spectrum:
104
110
  self.flux = arr[order, 1]
105
111
  self.is_refl = reflectance
106
112
 
113
+
114
+ # --------------------------------------------------------------------------------
115
+ def from_waveflux(self, wave, flux, reflectance=False):
116
+ """Create a SKA spectrum from two list/arrays of wavelength and flux
117
+
118
+ Parameters
119
+ ----------
120
+ wave : np.ndarray | list
121
+ A numpy array or list containing the wavelength in micron.
122
+ flux : np.ndarray | list
123
+ A numpy array or list containing the Flux or Reflectance.
124
+
125
+ reflectance : boolean
126
+ Set True if the input is a reflectance spectrum (default=False)
127
+ """
128
+
129
+ if (not isinstance(wave, np.ndarray)) & (not isinstance(wave, list)):
130
+ rich.print(f"[red]wave is not a list or numpy array.[/red]")
131
+ sys.exit(1)
132
+
133
+ if (not isinstance(flux, np.ndarray)) & (not isinstance(flux, list)):
134
+ rich.print(f"[red]flux is not a list or numpy array.[/red]")
135
+ sys.exit(1)
136
+
137
+ if len(wave) != len(flux):
138
+ rich.print(f"[red]Wave and flux of different lengths ({len(wave)} vs {len(flux)}).[/red]")
139
+ sys.exit(1)
140
+
141
+ # Store attributes
142
+ order = np.argsort(wave)
143
+ self.wave = np.array(wave)[order]
144
+ self.flux = np.array(flux)[order]
145
+ self.is_refl = reflectance
146
+
147
+
148
+
107
149
  # --------------------------------------------------------------------------------
108
150
  def from_dataframe(self, df):
109
151
  """Create a SKA spectrum from a pandas DataFrame.
@@ -402,7 +444,6 @@ class Spectrum:
402
444
  filters = [filters]
403
445
 
404
446
  for f in filters:
405
-
406
447
  if isinstance(f, ska.Filter):
407
448
  filt = f
408
449
  else:
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes