pyreduce-astro 0.7a2__cp313-cp313-win_amd64.whl → 0.7a4__cp313-cp313-win_amd64.whl

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.
pyreduce/__main__.py CHANGED
@@ -11,11 +11,6 @@ Usage:
11
11
 
12
12
  import click
13
13
 
14
- from . import datasets
15
- from .configuration import get_configuration_for_instrument
16
- from .reduce import main as reduce_main
17
- from .tools.combine import combine as tools_combine
18
-
19
14
  ALL_STEPS = (
20
15
  "bias",
21
16
  "flat",
@@ -89,6 +84,9 @@ def run(
89
84
  INSTRUMENT: Name of the instrument (e.g., UVES, HARPS, XSHOOTER)
90
85
  TARGET: Target star name or regex pattern
91
86
  """
87
+ from .configuration import get_configuration_for_instrument
88
+ from .reduce import main as reduce_main
89
+
92
90
  # Parse steps
93
91
  if steps:
94
92
  steps = tuple(s.strip() for s in steps.split(","))
@@ -128,6 +126,8 @@ def combine(files, output, plot):
128
126
 
129
127
  FILES: Input .final.fits files to combine
130
128
  """
129
+ from .tools.combine import combine as tools_combine
130
+
131
131
  tools_combine(list(files), output, plot=plot)
132
132
 
133
133
 
@@ -138,6 +138,8 @@ def download(instrument):
138
138
 
139
139
  INSTRUMENT: Name of the instrument (e.g., UVES, HARPS)
140
140
  """
141
+ from . import datasets
142
+
141
143
  instrument = instrument.upper()
142
144
  dataset_func = getattr(datasets, instrument, None)
143
145
  if dataset_func is None:
@@ -153,6 +155,117 @@ def download(instrument):
153
155
  click.echo(f"Dataset downloaded to: {path}")
154
156
 
155
157
 
158
+ @cli.command()
159
+ @click.argument("filename", required=False)
160
+ @click.option(
161
+ "--list", "-l", "list_examples", is_flag=True, help="List available examples"
162
+ )
163
+ @click.option("--all", "-a", "download_all", is_flag=True, help="Download all examples")
164
+ @click.option("--run", "-r", is_flag=True, help="Run the example after downloading")
165
+ @click.option("--output", "-o", default=".", help="Output directory")
166
+ def examples(filename, list_examples, download_all, run, output):
167
+ """List, download, or run example scripts from GitHub.
168
+
169
+ Downloads examples matching your installed PyReduce version.
170
+
171
+ \b
172
+ Examples:
173
+ reduce examples # List available examples
174
+ reduce examples uves_example.py # Download to current dir
175
+ reduce examples -r uves_example.py # Download and run
176
+ reduce examples --all -o ~/scripts # Download all to ~/scripts
177
+ """
178
+ import json
179
+ import os
180
+ import subprocess
181
+ import sys
182
+ import tempfile
183
+ import urllib.request
184
+ from urllib.error import HTTPError
185
+
186
+ from pyreduce import __version__
187
+
188
+ version = __version__.split("+")[0]
189
+ if version == "unknown":
190
+ raise click.ClickException(
191
+ "Cannot determine package version. Install from PyPI or a tagged release."
192
+ )
193
+
194
+ github_api = (
195
+ f"https://api.github.com/repos/ivh/PyReduce/contents/examples?ref=v{version}"
196
+ )
197
+ github_raw = f"https://raw.githubusercontent.com/ivh/PyReduce/v{version}/examples"
198
+
199
+ # Fetch list of examples from GitHub API
200
+ try:
201
+ with urllib.request.urlopen(github_api) as resp:
202
+ contents = json.loads(resp.read().decode())
203
+ except HTTPError as e:
204
+ if e.code == 404:
205
+ raise click.ClickException(
206
+ f"Tag v{version} not found on GitHub. "
207
+ "Try installing a released version."
208
+ ) from None
209
+ raise click.ClickException(f"GitHub API error: {e}") from None
210
+
211
+ example_files = sorted(f["name"] for f in contents if f["name"].endswith(".py"))
212
+
213
+ # List mode
214
+ if list_examples or (not filename and not download_all):
215
+ click.echo(f"Available examples for v{version}:")
216
+ for name in example_files:
217
+ click.echo(f" {name}")
218
+ return
219
+
220
+ if run and download_all:
221
+ raise click.ClickException("Cannot use --run with --all")
222
+
223
+ # Run mode: download to temp and execute
224
+ if run:
225
+ if filename not in example_files:
226
+ raise click.ClickException(
227
+ f"Unknown example '{filename}'. Use 'reduce examples --list' to see available."
228
+ )
229
+ url = f"{github_raw}/{filename}"
230
+ with tempfile.NamedTemporaryFile(mode="w", suffix=".py", delete=False) as f:
231
+ try:
232
+ with urllib.request.urlopen(url) as resp:
233
+ f.write(resp.read().decode())
234
+ temp_path = f.name
235
+ except HTTPError as e:
236
+ raise click.ClickException(
237
+ f"Failed to download {filename}: {e}"
238
+ ) from None
239
+ try:
240
+ click.echo(f"Running {filename}...")
241
+ result = subprocess.run([sys.executable, temp_path], check=False)
242
+ sys.exit(result.returncode)
243
+ finally:
244
+ os.unlink(temp_path)
245
+
246
+ # Ensure output directory exists
247
+ os.makedirs(output, exist_ok=True)
248
+
249
+ def download_file(name):
250
+ url = f"{github_raw}/{name}"
251
+ dest = os.path.join(output, name)
252
+ try:
253
+ urllib.request.urlretrieve(url, dest)
254
+ click.echo(f"Downloaded: {dest}")
255
+ except HTTPError as e:
256
+ click.echo(f"Failed to download {name}: {e}", err=True)
257
+
258
+ if download_all:
259
+ for name in example_files:
260
+ download_file(name)
261
+ else:
262
+ if filename not in example_files:
263
+ raise click.ClickException(
264
+ f"Unknown example '{filename}'. Use 'reduce examples --list' to see available."
265
+ )
266
+ download_file(filename)
267
+
268
+
156
269
  @cli.command("list-steps")
157
270
  def list_steps():
158
271
  """List all available reduction steps."""
@@ -174,6 +287,9 @@ def make_step_command(step_name):
174
287
  @click.option("--output-dir", "-o", default="reduced", help="Output directory")
175
288
  @click.option("--plot", "-p", default=0, help="Plot level")
176
289
  def cmd(instrument, target, night, arm, base_dir, input_dir, output_dir, plot):
290
+ from .configuration import get_configuration_for_instrument
291
+ from .reduce import main as reduce_main
292
+
177
293
  config = get_configuration_for_instrument(instrument)
178
294
  reduce_main(
179
295
  instrument=instrument,
Binary file
Binary file
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyreduce-astro
3
- Version: 0.7a2
3
+ Version: 0.7a4
4
4
  Summary: A data reduction package for echelle spectrographs
5
5
  Project-URL: Homepage, https://github.com/ivh/PyReduce
6
6
  Project-URL: Documentation, https://pyreduce-astro.readthedocs.io
@@ -1,5 +1,5 @@
1
1
  pyreduce/__init__.py,sha256=e_576KbKh0jALuzvpI-VLeILhtQYJAPTDD0XMb189gM,1797
2
- pyreduce/__main__.py,sha256=z7iW2lyo5HOp-r7GyIiwBksRCVdO2UHDMDVEdNuHQgY,5625
2
+ pyreduce/__main__.py,sha256=KV5z5kqydHKMtTQ_LNEdQs8xtBmyFcOqY5cpOwtVrEg,9885
3
3
  pyreduce/cli.py,sha256=w8k5OticZ8rzh5JshYv3MBp_Sx0PtECiSOdR3VboNB0,10937
4
4
  pyreduce/clipnflip.py,sha256=S-9CaTfRwPHWJUq92Iv2K1T-4Oe6MmROJQpzv2cMaOI,5704
5
5
  pyreduce/combine_frames.py,sha256=VnvLXexXisunuZ05whbhzSemoahQ6pd7cOoz8Uz_fWU,30407
@@ -19,12 +19,12 @@ pyreduce/trace.py,sha256=VAl6sgjmfYmfNLsddzwx_f4x-oT3KsGiUfhHMoHNGxM,33667
19
19
  pyreduce/util.py,sha256=MpyEpjOzvINBx1ixMWaF7huYZ7GylDOXMdR0Va6ljUI,40870
20
20
  pyreduce/wavelength_calibration.py,sha256=1BT6KfAd7sIabQEb2D0n3511p3IY03G5pvGiB3j9e1E,70592
21
21
  pyreduce/clib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
- pyreduce/clib/_slitfunc_2d.cp311-win_amd64.pyd,sha256=-h4Z4Atluvem7d6Pv0DrfrXg2kXy65gNqJt5fEejcKk,35328
23
- pyreduce/clib/_slitfunc_2d.cp312-win_amd64.pyd,sha256=1fIf9DxkbV4vHRS85VUB-WxNtYUkBS4YHdxDRAv0W00,35328
24
- pyreduce/clib/_slitfunc_2d.cp313-win_amd64.pyd,sha256=KJeGQ0LX3iq7ji_Cf96UP_hfsua1Ff1bVE29Qr6fask,35328
25
- pyreduce/clib/_slitfunc_bd.cp311-win_amd64.pyd,sha256=iHJ6rD9rRzlQpX9LtvVLF2Ge3jINTImLlI_iEAsy32U,25600
26
- pyreduce/clib/_slitfunc_bd.cp312-win_amd64.pyd,sha256=RXwz73aVSoxmf7VS8nVwzEhaVY23DVMGF8Kf2Kvksdg,25600
27
- pyreduce/clib/_slitfunc_bd.cp313-win_amd64.pyd,sha256=-TtXOvH7t8ps4bHQRv7-XK_PoXFuKBYgcS5hcplcpnU,25600
22
+ pyreduce/clib/_slitfunc_2d.cp311-win_amd64.pyd,sha256=_7iPNwZZMAdA2UWggpT8tEK19y8nbeLIvXu43mEX3h4,35328
23
+ pyreduce/clib/_slitfunc_2d.cp312-win_amd64.pyd,sha256=NP-C2mXnABORwotN58gu6vN_c1QmH1v3GgWsXrd-x8I,35328
24
+ pyreduce/clib/_slitfunc_2d.cp313-win_amd64.pyd,sha256=zu6iCAIt6OAOqNgI1KMaSf9rTIADwkhlU-Mkt8-tO5c,35328
25
+ pyreduce/clib/_slitfunc_bd.cp311-win_amd64.pyd,sha256=rMif07DHX2oNN131Q7tqYWiLmpZiTUweBWfFU7wU7s8,25600
26
+ pyreduce/clib/_slitfunc_bd.cp312-win_amd64.pyd,sha256=MRhnTTKWiGhFnLgt2FS_pTbrvzGupK9sZTgTQv7oLiU,25600
27
+ pyreduce/clib/_slitfunc_bd.cp313-win_amd64.pyd,sha256=dqLb2--YnzFtSpMatJgYGBHs0L0WlRKZGbDVWZ22WqA,25600
28
28
  pyreduce/clib/build_extract.py,sha256=WTEpyRZWDR4AUkT1mkxmsWbXuRLG2jrRbJC5M8MKi3M,2020
29
29
  pyreduce/clib/slit_func_2d_xi_zeta_bd.c,sha256=o_R_3hq0tX2ZdaCRxJjY2mXQf4RaYENcVKVn2OZR_Rk,51279
30
30
  pyreduce/clib/slit_func_2d_xi_zeta_bd.h,sha256=ezWP3JXfbviCN5FAbB9AJYB1YnAGFhsO5N3wCt-rbmU,1567
@@ -36,14 +36,14 @@ pyreduce/clib/Release/_slitfunc_2d.cp312-win_amd64.exp,sha256=ap2hnA20RvdJAV-jrp
36
36
  pyreduce/clib/Release/_slitfunc_2d.cp312-win_amd64.lib,sha256=cD10d0NBKuPxsmHfYZ17F9O6tt2X3vwfHv49fx7i7mg,2104
37
37
  pyreduce/clib/Release/_slitfunc_2d.cp313-win_amd64.exp,sha256=xgcXydyjVF48BY3DHEU9l-3BIMHBtYVXENVCXG6mpHg,763
38
38
  pyreduce/clib/Release/_slitfunc_2d.cp313-win_amd64.lib,sha256=HtsGowOnstUvTx3wEiX3JcFgOzCsrie-6B5pdb69EVc,2104
39
- pyreduce/clib/Release/_slitfunc_2d.obj,sha256=pZqO9n3WDBfT6_gQFyJWt3zrDFwgDcIxd-kMGI0Tawo,225492
39
+ pyreduce/clib/Release/_slitfunc_2d.obj,sha256=HibN_mMVM9-_lX2oHaZIjmgpL6VCrRNmJ2qZwTexVDI,225492
40
40
  pyreduce/clib/Release/_slitfunc_bd.cp311-win_amd64.exp,sha256=vHZNO5hq4YBqgpgWXOW7wELiB-Pex2QFRvKbLH-vIYY,763
41
41
  pyreduce/clib/Release/_slitfunc_bd.cp311-win_amd64.lib,sha256=hcG-cWafgtz6nNO12lFFtkVLhVAsQyuCpPD78rfPQzs,2104
42
42
  pyreduce/clib/Release/_slitfunc_bd.cp312-win_amd64.exp,sha256=BWCVspYP1T2q5yNWlVpCfK6JWR44RuNiFhWW3H6kNLc,763
43
43
  pyreduce/clib/Release/_slitfunc_bd.cp312-win_amd64.lib,sha256=tJ-lz6MJn-UOdBfx7yFQqrNw4NEmKinrbm8vx2PSkzE,2104
44
44
  pyreduce/clib/Release/_slitfunc_bd.cp313-win_amd64.exp,sha256=v6YBEY_vzeHqhCMqQ7-ISyMP3m07qeSL4yA-Lq27vP8,763
45
45
  pyreduce/clib/Release/_slitfunc_bd.cp313-win_amd64.lib,sha256=R3sT-Vy8AWGitwFDqYI3ipcc86PVkyMgACcDMXMkA1U,2104
46
- pyreduce/clib/Release/_slitfunc_bd.obj,sha256=Y2BGH1xNSeftQXQr11ky8H7MHK_YIGNvwaU3pAo6uCM,175839
46
+ pyreduce/clib/Release/_slitfunc_bd.obj,sha256=kAcPgomQLBVkwA0S__Vbhk7LUk0QH9vf1vKTxDGpmOk,175839
47
47
  pyreduce/instruments/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
48
48
  pyreduce/instruments/aj.py,sha256=QSKo2IUvBugBRJF0Qr6T9GueBzeDrA4yGu-qAe7TZwg,155
49
49
  pyreduce/instruments/aj.yaml,sha256=peeQ2ZqvqemHWpNZoiXEscU6ZIzAImbhN_8D0XTeeME,904
@@ -169,8 +169,8 @@ pyreduce/wavecal/xshooter_nir.npz,sha256=0Fu5wxWutc8072n8Hk2AZAWSlyT4WdhJuhh0OzU
169
169
  pyreduce/wavecal/atlas/thar.fits,sha256=nPPNStZ281iPUNsOXu3YJfHNlnHBd1CWMLwTuZL8vvo,1529218
170
170
  pyreduce/wavecal/atlas/thar_list.txt,sha256=saK3YW1slxlXGeulZDdILWf952XOWToJcUULVSHMe6k,63515
171
171
  pyreduce/wavecal/atlas/une.fits,sha256=egHlchdM4AN9MSksEI5MlHkmB3g1G1VhEdzhUG3XU8I,2949057
172
- pyreduce_astro-0.7a2.dist-info/METADATA,sha256=MxuR7E_uOtsoXRY5jKe-nCwYPrhZflmbr7lKxul4_lc,3488
173
- pyreduce_astro-0.7a2.dist-info/WHEEL,sha256=PCIhMO61Z-RaGBFeYB07NemkwSKK2UsOquwuNeClEpE,97
174
- pyreduce_astro-0.7a2.dist-info/entry_points.txt,sha256=n045jK9XZFfdmasTNhriefYyJoY77JKm-RpRD1zgHZo,50
175
- pyreduce_astro-0.7a2.dist-info/licenses/LICENSE,sha256=IwGE9guuL-ryRPEKi6wFPI_zOhg7zDZbTYuHbSt_SAk,35823
176
- pyreduce_astro-0.7a2.dist-info/RECORD,,
172
+ pyreduce_astro-0.7a4.dist-info/METADATA,sha256=m5uMEQvbv9ra-r9T136x5VpNUTfJ0pDjfz0oGCoriTY,3488
173
+ pyreduce_astro-0.7a4.dist-info/WHEEL,sha256=PCIhMO61Z-RaGBFeYB07NemkwSKK2UsOquwuNeClEpE,97
174
+ pyreduce_astro-0.7a4.dist-info/entry_points.txt,sha256=n045jK9XZFfdmasTNhriefYyJoY77JKm-RpRD1zgHZo,50
175
+ pyreduce_astro-0.7a4.dist-info/licenses/LICENSE,sha256=IwGE9guuL-ryRPEKi6wFPI_zOhg7zDZbTYuHbSt_SAk,35823
176
+ pyreduce_astro-0.7a4.dist-info/RECORD,,