space-classy 0.4.2__tar.gz → 0.6__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.
Files changed (72) hide show
  1. {space_classy-0.4.2 → space_classy-0.6}/PKG-INFO +6 -6
  2. {space_classy-0.4.2 → space_classy-0.6}/classy/__init__.py +2 -2
  3. space_classy-0.6/classy/cache.py +115 -0
  4. space_classy-0.6/classy/cli.py +168 -0
  5. {space_classy-0.4.2 → space_classy-0.6}/classy/config.py +2 -2
  6. {space_classy-0.4.2 → space_classy-0.6}/classy/core.py +203 -277
  7. {space_classy-0.4.2 → space_classy-0.6}/classy/data.py +9 -13
  8. {space_classy-0.4.2 → space_classy-0.6}/classy/decision_tree.py +3 -1
  9. {space_classy-0.4.2 → space_classy-0.6}/classy/defs.py +2 -1
  10. space_classy-0.6/classy/feature.py +531 -0
  11. space_classy-0.6/classy/gui.py +552 -0
  12. space_classy-0.6/classy/index.py +97 -0
  13. {space_classy-0.4.2 → space_classy-0.6}/classy/mixnorm.py +1 -1
  14. {space_classy-0.4.2 → space_classy-0.6}/classy/plotting.py +96 -31
  15. {space_classy-0.4.2 → space_classy-0.6}/classy/preprocessing.py +4 -0
  16. space_classy-0.6/classy/sources/__init__.py +27 -0
  17. {space_classy-0.4.2 → space_classy-0.6}/classy/sources/akari.py +87 -47
  18. space_classy-0.6/classy/sources/gaia.py +168 -0
  19. space_classy-0.6/classy/sources/mithneos.py +306 -0
  20. space_classy-0.6/classy/sources/pds/__init__.py +203 -0
  21. space_classy-0.6/classy/sources/pds/ecas.py +268 -0
  22. space_classy-0.6/classy/sources/pds/fornasier_m_types.py +69 -0
  23. space_classy-0.6/classy/sources/pds/fornasier_trojans.py +75 -0
  24. space_classy-0.6/classy/sources/pds/ftcas.py +183 -0
  25. space_classy-0.6/classy/sources/pds/hendrix_iue.py +1 -0
  26. space_classy-0.6/classy/sources/pds/irtf.py +86 -0
  27. space_classy-0.6/classy/sources/pds/lebofsky_three_micron.py +74 -0
  28. space_classy-0.6/classy/sources/pds/moskovitz_v_types.py +85 -0
  29. space_classy-0.6/classy/sources/pds/primass.py +94 -0
  30. space_classy-0.6/classy/sources/pds/reddy_main_belt.py +80 -0
  31. space_classy-0.6/classy/sources/pds/reddy_nea.py +87 -0
  32. space_classy-0.6/classy/sources/pds/reddy_nea_mc.py +79 -0
  33. space_classy-0.6/classy/sources/pds/reddy_vesta.py +77 -0
  34. space_classy-0.6/classy/sources/pds/rivkin_three_micron.py +88 -0
  35. space_classy-0.6/classy/sources/pds/s3os2.py +72 -0
  36. space_classy-0.6/classy/sources/pds/sawyer.py +72 -0
  37. space_classy-0.6/classy/sources/pds/scas.py +132 -0
  38. space_classy-0.6/classy/sources/pds/tfcas.py +197 -0
  39. space_classy-0.6/classy/sources/pds/vilas.py +80 -0
  40. space_classy-0.6/classy/sources/pds/willman_iannini.py +75 -0
  41. space_classy-0.6/classy/sources/private.py +84 -0
  42. space_classy-0.6/classy/sources/smass.py +215 -0
  43. space_classy-0.6/classy/taxonomies/__init__.py +110 -0
  44. space_classy-0.6/classy/taxonomies/bus.py +169 -0
  45. {space_classy-0.4.2 → space_classy-0.6}/classy/taxonomies/demeo.py +33 -20
  46. {space_classy-0.4.2 → space_classy-0.6}/classy/taxonomies/mahlke.py +59 -2
  47. {space_classy-0.4.2 → space_classy-0.6}/classy/taxonomies/tholen.py +153 -5
  48. space_classy-0.6/classy/tools.py +104 -0
  49. {space_classy-0.4.2 → space_classy-0.6}/pyproject.toml +4 -4
  50. {space_classy-0.4.2 → space_classy-0.6}/setup.py +5 -5
  51. space_classy-0.4.2/classy/cache.py +0 -48
  52. space_classy-0.4.2/classy/cli.py +0 -88
  53. space_classy-0.4.2/classy/sources/__init__.py +0 -9
  54. space_classy-0.4.2/classy/sources/ecas.py +0 -270
  55. space_classy-0.4.2/classy/sources/gaia.py +0 -111
  56. space_classy-0.4.2/classy/sources/mithneos.py +0 -2500
  57. space_classy-0.4.2/classy/sources/smass.py +0 -149
  58. space_classy-0.4.2/classy/taxonomies/__init__.py +0 -35
  59. space_classy-0.4.2/classy/taxonomies/bus.py +0 -0
  60. space_classy-0.4.2/classy/tools.py +0 -35
  61. {space_classy-0.4.2 → space_classy-0.6}/LICENSE +0 -0
  62. {space_classy-0.4.2 → space_classy-0.6}/README.md +0 -0
  63. {space_classy-0.4.2 → space_classy-0.6}/classy/classify.py +0 -0
  64. {space_classy-0.4.2 → space_classy-0.6}/classy/data/classy/classy_data.csv +0 -0
  65. {space_classy-0.4.2 → space_classy-0.6}/classy/data/input/classy_data_classified.csv +0 -0
  66. {space_classy-0.4.2 → space_classy-0.6}/classy/data/input/classy_data_preprocessed.csv +0 -0
  67. {space_classy-0.4.2 → space_classy-0.6}/classy/data/mcfa/mcfa.pkl +0 -0
  68. {space_classy-0.4.2 → space_classy-0.6}/classy/data/mixnorm/mixnorm.pkl +0 -0
  69. {space_classy-0.4.2 → space_classy-0.6}/classy/data/mixnorm/neighbours.csv +0 -0
  70. {space_classy-0.4.2 → space_classy-0.6}/classy/data/nironly_1_classified.csv +0 -0
  71. {space_classy-0.4.2 → space_classy-0.6}/classy/gmm.py +0 -0
  72. {space_classy-0.4.2 → space_classy-0.6}/classy/log.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: space-classy
3
- Version: 0.4.2
3
+ Version: 0.6
4
4
  Summary: classification tool for minor bodies using reflectance spectra and visual albedos
5
5
  Home-page: https://github.com/maxmahlke/classy
6
6
  License: MIT
@@ -13,20 +13,20 @@ Classifier: Programming Language :: Python :: 3.8
13
13
  Classifier: Programming Language :: Python :: 3.9
14
14
  Classifier: Programming Language :: Python :: 3.10
15
15
  Provides-Extra: docs
16
- Requires-Dist: click (>=8.1.2,<9.0.0)
16
+ Requires-Dist: click (>=8.1.2)
17
17
  Requires-Dist: furo (>=2022.9.15,<2023.0.0)
18
18
  Requires-Dist: importlib-resources (>=5.10.2,<6.0.0)
19
19
  Requires-Dist: jinja2 (<3.1)
20
20
  Requires-Dist: mcfa (>=0.1,<0.2)
21
- Requires-Dist: numpy (>=1.22.3,<2.0.0)
21
+ Requires-Dist: numpy (>=1.22.3)
22
22
  Requires-Dist: pandas (>=1.4.2,<2.0.0)
23
- Requires-Dist: rich (>=12.2.0,<13.0.0)
23
+ Requires-Dist: rich (>=12.2.0)
24
24
  Requires-Dist: scikit-learn (>=1.2.1,<2.0.0)
25
25
  Requires-Dist: space-rocks (>=1.7.2,<2.0.0)
26
- Requires-Dist: sphinx (>=4,<5); extra == "docs"
26
+ Requires-Dist: sphinx (>=4,<5) ; extra == "docs"
27
27
  Requires-Dist: sphinx-copybutton (>=0.5.0,<0.6.0)
28
28
  Requires-Dist: sphinx-hoverxref
29
- Requires-Dist: sphinx-redactor-theme (>=0.0.1,<0.0.2); extra == "docs"
29
+ Requires-Dist: sphinx-redactor-theme (>=0.0.1,<0.0.2) ; extra == "docs"
30
30
  Requires-Dist: sphinx_design (>=0.3.0,<0.4.0)
31
31
  Requires-Dist: tox (>=4.4.5,<5.0.0)
32
32
  Project-URL: Documentation, https://classy.readthedocs.io/en/latest/
@@ -1,4 +1,4 @@
1
- """Taxonomic classification of asteroid observations following Mahlke+ 2022."""
1
+ """Taxonomic classification of asteroid reflectance spectra."""
2
2
  import os
3
3
 
4
4
  os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
@@ -8,4 +8,4 @@ from .core import Spectrum
8
8
  from .core import Spectra
9
9
 
10
10
  # Welcome to classy
11
- __version__ = "0.4.2"
11
+ __version__ = "0.6"
@@ -0,0 +1,115 @@
1
+ """Cache management for classy."""
2
+
3
+ import shutil
4
+
5
+ import pandas as pd
6
+
7
+ # import percache
8
+ import requests
9
+ import rich
10
+
11
+ from classy import config
12
+ from classy import index
13
+ from classy import sources
14
+
15
+ # cache = percache.Cache(str(config.PATH_CACHE / "cache"))
16
+
17
+
18
+ def load_mahlke_index():
19
+ """Load the index of spectra from Mahlke+ 2022."""
20
+ PATH_INDEX = config.PATH_CACHE / "mahlke/index.csv"
21
+ return pd.read_csv(PATH_INDEX, dtype={"number": "Int64"})
22
+
23
+
24
+ # ------
25
+ # Load spectra from cache
26
+ def load_spectra(idx_spectra):
27
+ """Load a spectrum from a known source.
28
+
29
+ Returns
30
+ -------
31
+ list of classy.core.Spectrum
32
+ """
33
+
34
+ spectra = [
35
+ getattr(sources, spec.host.lower()).load_spectrum(spec)
36
+ for _, spec in idx_spectra.iterrows()
37
+ ]
38
+
39
+ return spectra
40
+
41
+
42
+ def remove():
43
+ """Remove the cache directory."""
44
+ shutil.rmtree(config.PATH_CACHE)
45
+
46
+
47
+ def echo_inventory():
48
+ idx = index.load()
49
+ sources_ = list(idx.source.unique())
50
+
51
+ rich.print(
52
+ f"""\nContents of {config.PATH_CACHE}:
53
+
54
+ {len(idx)} asteroid reflectance spectra from {len(sources_)} sources
55
+ """
56
+ )
57
+
58
+ if sources_:
59
+ for i, (source, obs) in enumerate(
60
+ idx.sort_values("source").groupby("source"), 1
61
+ ):
62
+ rich.print(f" {source:<8} {len(obs):>5}", end="")
63
+
64
+ if not i % 4:
65
+ rich.print()
66
+ else:
67
+ rich.print("\n")
68
+
69
+
70
+ # @cache
71
+ def miriade_ephems(name, epochs):
72
+ """Gets asteroid ephemerides from IMCCE Miriade.
73
+
74
+ Parameters
75
+ ----------
76
+ name : str
77
+ Name or designation of asteroid.
78
+ epochs : list
79
+ List of observation epochs in iso format.
80
+
81
+ Returns
82
+ -------
83
+ :returns: pd.DataFrame - Input dataframe with ephemerides columns appended
84
+ False - If query failed somehow
85
+ """
86
+
87
+ # Pass sorted list of epochs to speed up query
88
+ files = {"epochs": ("epochs", "\n".join(sorted(epochs)))}
89
+
90
+ # ------
91
+ # Query Miriade for phase angles
92
+ url = "http://vo.imcce.fr/webservices/miriade/ephemcc_query.php"
93
+
94
+ params = {
95
+ "-name": f"a:{name}",
96
+ "-mime": "json",
97
+ "-tcoor": "5",
98
+ "-output": "--jul",
99
+ "-tscale": "UTC",
100
+ }
101
+
102
+ # Execute query
103
+ try:
104
+ r = requests.post(url, params=params, files=files, timeout=50)
105
+ except requests.exceptions.ReadTimeout:
106
+ return False
107
+ j = r.json()
108
+
109
+ # Read JSON response
110
+ try:
111
+ ephem = pd.DataFrame.from_dict(j["data"])
112
+ except KeyError:
113
+ return False
114
+
115
+ return ephem
@@ -0,0 +1,168 @@
1
+ from pathlib import Path
2
+ import sys
3
+ import webbrowser
4
+
5
+ import click
6
+ import rich
7
+ import rocks
8
+
9
+ import classy.classify
10
+ from classy import cache
11
+ from classy import core
12
+ from classy import config
13
+ from classy import index
14
+ from classy.log import logger
15
+ import classy.preprocessing
16
+ from classy import taxonomies
17
+ from classy import sources
18
+
19
+
20
+ @click.group()
21
+ @click.version_option(version=classy.__version__, message="%(version)s")
22
+ def cli_classy():
23
+ """CLI for minor body classification."""
24
+ pass
25
+
26
+
27
+ @cli_classy.command()
28
+ def docs():
29
+ """Open the classy documentation in browser."""
30
+ webbrowser.open("https://classy.readthedocs.io/en/latest/", new=2)
31
+
32
+
33
+ @cli_classy.command()
34
+ @click.argument("id_", type=str)
35
+ @click.option("-c", "--classify", is_flag=True, help="Classify the spectra.")
36
+ @click.option(
37
+ "-t",
38
+ "--taxonomy",
39
+ default="mahlke",
40
+ help="Specify the taxonomic system.",
41
+ type=click.Choice(taxonomies.SYSTEMS),
42
+ )
43
+ @click.option(
44
+ "--templates",
45
+ default=None,
46
+ help="Add class templates of the specified complex.",
47
+ type=click.Choice(taxonomies.COMPLEXES.keys()),
48
+ )
49
+ @click.option(
50
+ "-s",
51
+ "--source",
52
+ type=click.Choice(sources.SOURCES),
53
+ multiple=True,
54
+ help="Select one or more online repositories.",
55
+ )
56
+ @click.option(
57
+ "-e",
58
+ "--exclude",
59
+ type=click.Choice(sources.SOURCES),
60
+ multiple=True,
61
+ help="Exclude one or more online repositories.",
62
+ )
63
+ @click.option(
64
+ "--save",
65
+ is_flag=True,
66
+ help="Save plot to file in current working directory.",
67
+ )
68
+ @click.option("-v", is_flag=True, help="Set verbose output.")
69
+ def spectra(id_, classify, taxonomy, templates, source, exclude, save, v):
70
+ """Retrieve, plot, classify spectra of an individual asteroid."""
71
+
72
+ if v:
73
+ classy.set_log_level("DEBUG")
74
+ rocks.set_log_level("DEBUG")
75
+ else:
76
+ rocks.set_log_level("ERROR")
77
+
78
+ name, number = rocks.id(id_)
79
+
80
+ if name is None:
81
+ logger.error("Cannot retrieve spectra for unidentified asteroid.")
82
+ sys.exit()
83
+ else:
84
+ logger.debug(f"Looking for reflectance spectra of ({number}) {name}")
85
+
86
+ if not source:
87
+ source = None
88
+
89
+ if exclude:
90
+ # If exclude but no sources defined (default case), load sources
91
+ if source is None:
92
+ source = index.load().source.unique()
93
+
94
+ source = [s for s in source if s not in exclude]
95
+
96
+ # Load spectra
97
+ spectra = core.Spectra(id_, source=source)
98
+
99
+ if not spectra:
100
+ sys.exit()
101
+
102
+ # Classify
103
+ if classify:
104
+ spectra.classify(taxonomy=taxonomy)
105
+ else:
106
+ taxonomy = None # required for the plotting function
107
+
108
+ # Plot
109
+ if save:
110
+ save = f"{number}_{name}_classy.png"
111
+
112
+ spectra.plot(taxonomy=taxonomy, save=save if save else None, templates=templates)
113
+
114
+ if save:
115
+ logger.info(f"Figure stored under {Path().cwd() / save}")
116
+
117
+
118
+ @cli_classy.command()
119
+ @click.argument("path", type=str)
120
+ def add(path):
121
+ """Add a private spectra collection."""
122
+ path = Path(path)
123
+
124
+ if not path.is_file():
125
+ click.echo("You need to pass the path of an index CSV file.")
126
+ sys.exit()
127
+
128
+ sources.private.parse_index(path)
129
+
130
+
131
+ @cli_classy.command()
132
+ def status():
133
+ """Manage the index of asteroid spectra."""
134
+ from rich import prompt
135
+
136
+ # ------
137
+ # Echo inventory
138
+ cache.echo_inventory()
139
+
140
+ # ------
141
+ # Download all or clear
142
+ decision = prompt.Prompt.ask(
143
+ "Choose one of these actions:\n"
144
+ "[blue][0][/blue] Do nothing "
145
+ "[blue][1][/blue] Clear the cache "
146
+ "[blue][2][/blue] Retrieve all spectra",
147
+ choices=["0", "1", "2"],
148
+ show_choices=False,
149
+ default="0",
150
+ )
151
+
152
+ if decision == "1":
153
+ decision = prompt.Prompt.ask(
154
+ f"\nThis will delete the cache directory and all its contents. Are you sure?",
155
+ choices=["y", "n"],
156
+ show_choices=True,
157
+ )
158
+
159
+ if decision in ["y"]:
160
+ cache.remove()
161
+
162
+ elif decision == "2":
163
+ rich.print()
164
+ rocks.set_log_level("CRITICAL")
165
+ classy.set_log_level("CRITICAL")
166
+ sources._retrieve_spectra()
167
+
168
+ # cache.echo_inventory()
@@ -6,5 +6,5 @@ from platformdirs import user_cache_dir
6
6
 
7
7
  PATH_CACHE = Path(user_cache_dir()) / "classy"
8
8
 
9
-
10
- EXTRAPOLATION_LIMIT = 10
9
+ # Maximum missing wavelength range to extrapolate for classification
10
+ EXTRAPOLATION_LIMIT = 10 # in percent