pyredshift 1.10__tar.gz → 1.11__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: pyredshift
3
- Version: 1.10
3
+ Version: 1.11
4
4
  Summary: Interactive redshifting of 1D astronomical spectra (Python successor of pdlredshift / redshift.f)
5
5
  Home-page: https://github.com/karlglazebrook/pyredshift
6
6
  Author: Karl Glazebrook
@@ -264,9 +264,14 @@ def read_spectrum(fname, fmt=None):
264
264
  def main():
265
265
  ap = argparse.ArgumentParser(
266
266
  prog="pyredshift",
267
+ usage="pyredshift [-help] [-f FORMAT] [-z REDSHIFT] [--retro] "
268
+ "[--microns] file",
267
269
  description="Interactive redshifting of 1D spectra (port of pdlredshift).",
268
- epilog="Formats: ascii csv fits sdss table (=jwst,jwst2,gabe,dja) "
269
- "xs xs2 outthere. Default is auto-detection.")
270
+ formatter_class=argparse.RawDescriptionHelpFormatter,
271
+ # format documentation lives in the module (FORMAT_HELP) so the
272
+ # -h epilog and the '?' help page cannot drift apart
273
+ epilog=redshift_module.formats_text())
274
+ ap.add_argument("-help", action="help", help=argparse.SUPPRESS)
270
275
  ap.add_argument("file", help="spectrum file (FITS, CSV or 2-column ascii)")
271
276
  ap.add_argument("-f", "--format", default=None, metavar="FORMAT",
272
277
  help="force the input format instead of auto-detecting")
@@ -13,7 +13,7 @@ from setuptools import setup
13
13
 
14
14
  setup(
15
15
  name="pyredshift",
16
- version="1.10",
16
+ version="1.11",
17
17
  description="Interactive redshifting of 1D astronomical spectra "
18
18
  "(Python successor of pdlredshift / redshift.f)",
19
19
  long_description=open("README.md").read(),
@@ -98,13 +98,16 @@ colours as plotted):</p>
98
98
  <h2>Guide</h2>
99
99
  <p>pyredshift is a tool for measuring the redshift of a galaxy or quasar
100
100
  from a 1D spectrum, by eye. Run it as <code>pyredshift file</code> &mdash;
101
- the format (FITS image or table, SDSS, JWST, XSHOOTER, OutThere, CSV,
102
- 2-column ascii) is auto-detected, with <code>-f</code> to force one,
103
- <code>-z</code> to start from a known redshift and <code>--retro</code>
104
- for a retro PGPLOT-style black background. It plots the spectrum histogram-style with a
101
+ the file format is auto-detected (see the table below), with
102
+ <code>-f</code> to force one, <code>-z</code> to start from a known
103
+ redshift and <code>--retro</code> for a retro PGPLOT-style black
104
+ background. It plots the spectrum histogram-style with a
105
105
  crosshair cursor, and overlays rest-frame line identifications that
106
106
  follow the trial redshift shown at top left.</p>
107
107
 
108
+ <h2>File formats</h2>
109
+ {formats}
110
+
108
111
  <p>The basic game: spot a feature you can identify, put the crosshair on
109
112
  it and press <code>ESC</code> then the line's shortcut key (or
110
113
  <code>g</code> to type any rest wavelength) &mdash; the line labels jump
@@ -49,6 +49,9 @@ V1.10 - The cursor works over the whole window, as PGPLOT's did: keys and
49
49
  'x'/'y'/'e' can be pressed just outside the axis, pdlredshift
50
50
  style), the crosshair and the readout follow into the margins,
51
51
  and rubber-band drags may extend past the plot edge.
52
+ V1.11 - Proper file-format documentation: a per-format table in the
53
+ script's -h and a File formats section in the help page, both
54
+ generated from FORMAT_HELP here so they cannot drift apart.
52
55
  """
53
56
 
54
57
  import ctypes
@@ -88,12 +91,33 @@ try:
88
91
  except AttributeError:
89
92
  pass
90
93
 
91
- __version__ = "1.10"
94
+ __version__ = "1.11"
92
95
 
93
96
  C_LIGHT = 2.99792458e8 # m/s
94
97
 
95
98
  TEMPLATE_NAME = "GNIRS_N4608" # template for the 't' key
96
99
 
100
+ # One description per reader in the pyredshift script - the single source
101
+ # for both the script's -h epilog and the Formats section of the help page.
102
+ # Keep in sync when adding a reader to the script.
103
+ FORMAT_HELP = [
104
+ ("fits", "1D (or 2D - row 1 used) FITS image with WCS; CD1_1 "
105
+ "overrides CDELT1, IRAF/SDSS log-lambda flags handled"),
106
+ ("sdss", "SDSS/BOSS binary table (LOGLAM/FLUX, either case)"),
107
+ ("table", "generic binary table with wave+flux columns; TUNIT "
108
+ "(um, nm, A) converted automatically "
109
+ "(aliases: jwst, jwst2, gabe, dja)"),
110
+ ("xs", "XSHOOTER 1D table spectrum (nm)"),
111
+ ("xs2", "XSHOOTER as a FITS image in extension 1"),
112
+ ("outthere", "OutThere multi-extension grism spectra, stitched "
113
+ "and flat-calibrated"),
114
+ ("csv", "comma-separated, header rows skipped"),
115
+ ("ascii", "2-column text"),
116
+ ]
117
+ FORMAT_NOTES = ("Default is auto-detection. Wavelengths that look like "
118
+ "microns are converted to Angstroms (--microns keeps them); "
119
+ "NaNs are treated as bad pixels and plot as gaps.")
120
+
97
121
  CONFIG_FILE = os.path.expanduser("~/.pyredshift.json") # remembers window size
98
122
  DEFAULT_FIGSIZE = (13.0, 5.5) # inches
99
123
 
@@ -215,11 +239,35 @@ def linelist_html():
215
239
  return "<table class='linelist'>\n%s\n</table>" % "\n".join(rows)
216
240
 
217
241
 
242
+ def formats_html():
243
+ """FORMAT_HELP as table rows + notes for the help page."""
244
+ rows = ["<tr><th>Format</th><th>Description</th></tr>"]
245
+ for name, desc in FORMAT_HELP:
246
+ rows.append("<tr><td><code>%s</code></td><td>%s</td></tr>"
247
+ % (name, desc))
248
+ return ("<table>\n%s\n</table>\n<p>%s</p>"
249
+ % ("\n".join(rows), FORMAT_NOTES))
250
+
251
+
252
+ def formats_text():
253
+ """FORMAT_HELP as aligned plain text for the script's -h epilog."""
254
+ import textwrap
255
+ width = max(len(name) for name, _ in FORMAT_HELP)
256
+ lines = ["Formats (-f):"]
257
+ for name, desc in FORMAT_HELP:
258
+ lines.append(textwrap.fill(
259
+ desc, width=79, initial_indent=" %-*s " % (width, name),
260
+ subsequent_indent=" " * (width + 4)))
261
+ lines.append(textwrap.fill(FORMAT_NOTES, width=79))
262
+ return "\n".join(lines)
263
+
264
+
218
265
  def help_html():
219
266
  """The help HTML body with the placeholders filled in."""
220
267
  if HELP_RAW is None:
221
268
  return None
222
- return HELP_RAW.format(template=TEMPLATE_NAME, linelist=linelist_html())
269
+ return HELP_RAW.format(template=TEMPLATE_NAME, linelist=linelist_html(),
270
+ formats=formats_html())
223
271
 
224
272
 
225
273
  # ---------------------------------------------------------------------------
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyredshift
3
- Version: 1.10
3
+ Version: 1.11
4
4
  Summary: Interactive redshifting of 1D astronomical spectra (Python successor of pdlredshift / redshift.f)
5
5
  Home-page: https://github.com/karlglazebrook/pyredshift
6
6
  Author: Karl Glazebrook
File without changes
File without changes
File without changes
File without changes