Skip to content

Commit

Permalink
fix: consistent doc string wrapping (#116)
Browse files Browse the repository at this point in the history
* fix: consistent doc string wrapping for angle.py

* fix: put back private doc strings

* fix: wrap doc strings for bessel, bounds, and box

* fix: doc string wrapping for celestial.py

* fix: doc string wrapping for convolve.py

* fix: wrap doc strings in exp, fitswcs, gsobject, and gaussian

* fix: wrap doc strings gsparams and image

* fix: wrap interpolant

* fix: wrong attribute

* fix: wrap doc strings for interpolated images and moffat

* fix: wrap doc strings for noise

* fix: wrap doc strings for photon arrays

* fix: add some caveats for properties

* fix: wrap doc strings for position

* fix: no round method

* fix: wrap doc strings for random, sensor, shear and remove extra text

* fix: wrap doc strings for spergel, sum and transform

* fix: start wrapping wcs

* fix: finish doc strings in wcs

* fix: no function signatures

* Update interpolatedimage.py

Co-authored-by: Ismael Mendoza <[email protected]>

* Update interpolatedimage.py

Co-authored-by: Ismael Mendoza <[email protected]>

* Update interpolatedimage.py

Co-authored-by: Ismael Mendoza <[email protected]>

---------

Co-authored-by: Ismael Mendoza <[email protected]>
  • Loading branch information
beckermr and ismael-mendoza authored Sep 10, 2024
1 parent 48bf965 commit 047cf19
Show file tree
Hide file tree
Showing 26 changed files with 301 additions and 772 deletions.
23 changes: 7 additions & 16 deletions jax_galsim/angle.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,13 @@ class AngleUnit(object):
valid_names = ["rad", "deg", "hr", "hour", "arcmin", "arcsec"]

def __init__(self, value):
"""
:param value: The measure of the unit in radians.
"""
if isinstance(value, AngleUnit):
raise TypeError("Cannot construct AngleUnit from another AngleUnit")
self._value = cast_to_float(value)

@property
@implements(_galsim.AngleUnit.value)
def value(self):
"""A read-only attribute giving the measure of the AngleUnit in radians."""
return self._value

def __rmul__(self, theta):
Expand Down Expand Up @@ -146,19 +143,13 @@ def __init__(self, theta, unit=None):
self._rad = cast_to_float(theta) * unit.value

@property
@implements(_galsim.Angle.rad)
def rad(self):
"""Return the Angle in radians.
Equivalent to angle / coord.radians
"""
return self._rad

@property
@implements(_galsim.Angle.deg)
def deg(self):
"""Return the Angle in degrees.
Equivalent to angle / coord.degrees
"""
return self / degrees

def __neg__(self):
Expand Down Expand Up @@ -213,20 +204,20 @@ def wrap(self, center=None):
) # How many full cycles to subtract
return _Angle(self._rad - offset * 2.0 * jnp.pi)

@implements(_galsim.Angle.sin)
def sin(self):
"""Return the sin of an Angle."""
return jnp.sin(self._rad)

@implements(_galsim.Angle.cos)
def cos(self):
"""Return the cos of an Angle."""
return jnp.cos(self._rad)

@implements(_galsim.Angle.tan)
def tan(self):
"""Return the tan of an Angle."""
return jnp.tan(self._rad)

@implements(_galsim.Angle.sincos)
def sincos(self):
"""Return both the sin and cos of an Angle as a numpy array [sint, cost]."""
sin = jnp.sin(self._rad)
cos = jnp.cos(self._rad)
return sin, cos
Expand Down
2 changes: 1 addition & 1 deletion jax_galsim/bessel.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ def si(x):
)


@implements(_galsim.bessel.kv)
@jax.jit
def kv(nu, x):
"""Modified Bessel 2nd kind"""
nu = 1.0 * nu
x = 1.0 * x
return _tfp_bessel_kve(nu, x) / jnp.exp(jnp.abs(x))
6 changes: 1 addition & 5 deletions jax_galsim/bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,8 @@ def _parse_args(self, *args, **kwargs):
self._isdefined = False

@property
@implements(_galsim.Bounds.true_center)
def true_center(self):
"""The central position of the `Bounds` as a `PositionD`.
This is always (xmax + xmin)/2., (ymax + ymin)/2., even for integer `BoundsI`, where
this may not necessarily be an integer `PositionI`.
"""
if not self.isDefined():
raise _galsim.GalSimUndefinedBoundsError(
"true_center is invalid for an undefined Bounds"
Expand Down
6 changes: 3 additions & 3 deletions jax_galsim/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ def _maxL(self):
return jnp.maximum(self.width, self.height)

@property
@implements(_galsim.Box.width)
def width(self):
"""The width of the `Box`."""
return self.params["width"]

@property
@implements(_galsim.Box.height)
def height(self):
"""The height of the `Box`."""
return self.params["height"]

def __hash__(self):
Expand Down Expand Up @@ -115,7 +115,6 @@ def tree_unflatten(cls, aux_data, children):
**aux_data,
)

@implements(_galsim.Box._shoot)
def _shoot(self, photons, rng):
ud = UniformDeviate(rng)

Expand All @@ -134,6 +133,7 @@ def __init__(self, scale, flux=1.0, gsparams=None):
)

@property
@implements(_galsim.Pixel.scale)
def scale(self):
"""The linear scale size of the `Pixel`."""
return self.width
Expand Down
7 changes: 4 additions & 3 deletions jax_galsim/celestial.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,18 @@ def __init__(self, ra, dec=None):
self._dec = dec

@property
@implements(_galsim.celestial.CelestialCoord.ra)
def ra(self):
"""A read-only attribute, giving the Right Ascension as an Angle"""
return self._ra

@property
@implements(_galsim.celestial.CelestialCoord.dec)
def dec(self):
"""A read-only attribute, giving the Declination as an Angle"""
return self._dec

@property
@implements(_galsim.celestial.CelestialCoord.rad)
def rad(self):
"""A convenience property, giving a tuple (ra.rad, dec.rad)"""
return (self._ra.rad, self._dec.rad)

@jax.jit
Expand Down Expand Up @@ -930,6 +930,7 @@ def from_galsim(gcoord):
return _CelestialCoord(_Angle(gcoord.ra.rad), _Angle(gcoord.dec.rad))


@implements(_coord._CelestialCoord)
def _CelestialCoord(ra, dec):
ret = CelestialCoord.__new__(CelestialCoord)
ret._ra = ra
Expand Down
24 changes: 5 additions & 19 deletions jax_galsim/convolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,25 +140,17 @@ def __init__(self, *args, **kwargs):
self._params = {"obj_list": self._obj_list}

@property
@implements(_galsim.Convolution.obj_list)
def obj_list(self):
"""The list of objects being convolved."""
return self._obj_list

@property
@implements(_galsim.Convolution.real_space)
def real_space(self):
"""Whether this `Convolution` should be drawn using real-space convolution rather
than FFT convolution.
"""
return self._real_space

@implements(_galsim.Convolution.withGSParams)
def withGSParams(self, gsparams=None, **kwargs):
"""Create a version of the current object with the given gsparams
.. note::
Unless you set ``propagate_gsparams=False``, this method will also update the gsparams
of each object being convolved.
"""
if gsparams == self.gsparams:
return self
from copy import copy
Expand Down Expand Up @@ -391,8 +383,8 @@ def _inv_min_acc_kvalue(self):
return 1.0 / self._min_acc_kvalue

@property
@implements(_galsim.Deconvolution.orig_obj)
def orig_obj(self):
"""The original object that is being deconvolved."""
return self._orig_obj

@property
Expand All @@ -401,14 +393,8 @@ def _noise(self):
galsim_warn("Unable to propagate noise in galsim.Deconvolution")
return None

@implements(_galsim.Deconvolution.withGSParams)
def withGSParams(self, gsparams=None, **kwargs):
"""Create a version of the current object with the given gsparams
.. note::
Unless you set ``propagate_gsparams=False``, this method will also update the gsparams
of the wrapped component object.
"""
if gsparams == self.gsparams:
return self
from copy import copy
Expand Down
12 changes: 1 addition & 11 deletions jax_galsim/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ def _func(i, args):
#
# fmt: on

_galsim_signature_re = re.compile(r"^([\w., ]+=)?\s*[\w\.]+\([\w\W]*?\)$", re.MULTILINE)
_docreference = re.compile(r":doc:`(.*?)\s*<.*?>`")


Expand Down Expand Up @@ -337,18 +336,9 @@ def _parse_galsimdoc(docstr):
docstr = _docreference.sub(lambda match: f"{match.groups()[0]}", docstr)

signature, body = "", docstr
match = _galsim_signature_re.match(body)
if match:
signature = match.group()
body = docstr[match.end() :]

firstline, body = _break_off_body_section_by_newline(body)

match = _galsim_signature_re.match(body)
if match:
signature = match.group()
body = body[match.end() :]

summary = firstline
if not summary:
summary, body = _break_off_body_section_by_newline(body)
Expand Down Expand Up @@ -429,9 +419,9 @@ def decorator(wrapped_fun):
docstr += f"\nLAX-backend implementation of :func:`{name}`.\n"
if lax_description:
docstr += "\n" + lax_description.strip() + "\n"
docstr += "\n*Original docstring below.*\n"

if parsed.front_matter:
docstr += "\n*Original docstring below.*\n"
docstr += "\n" + parsed.front_matter.strip() + "\n"
except Exception:
docstr = original_fun.__doc__
Expand Down
4 changes: 2 additions & 2 deletions jax_galsim/exponential.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def __init__(
super().__init__(scale_radius=scale_radius, flux=flux, gsparams=gsparams)

@property
@implements(_galsim.Exponential.scale_radius)
def scale_radius(self):
"""The scale radius of the profile."""
return self.params["scale_radius"]

@property
Expand All @@ -68,8 +68,8 @@ def _norm(self):
return self.flux * Exponential._inv_twopi * self._inv_r0**2

@property
@implements(_galsim.Exponential.half_light_radius)
def half_light_radius(self):
"""The half-light radius of the profile."""
return self.params["scale_radius"] * Exponential._hlr_factor

def __hash__(self):
Expand Down
3 changes: 2 additions & 1 deletion jax_galsim/fitswcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ def tree_unflatten(cls, aux_data, children):
# shiftOrigin to get the current origin value. We don't use it in this class, though, so
# just make origin a dummy property that returns 0,0.
@property
@implements(_galsim.GSFitsWCS.origin)
def origin(self):
"""The origin in image coordinates of the WCS function."""
return PositionD(0.0, 0.0)

def _read_header(self, header):
Expand Down Expand Up @@ -821,6 +821,7 @@ def _writeHeader(self, header, bounds):
def _readHeader(header):
return GSFitsWCS(header=header)

@implements(_galsim.GSFitsWCS.copy)
def copy(self):
# The copy module version of copying the dict works fine here.
return copy.copy(self)
Expand Down
6 changes: 3 additions & 3 deletions jax_galsim/gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@ def __init__(
super().__init__(sigma=sigma, flux=flux, gsparams=gsparams)

@property
@implements(_galsim.Gaussian.sigma)
def sigma(self):
"""The sigma of this Gaussian profile"""
return self.params["sigma"]

@property
@implements(_galsim.Gaussian.half_light_radius)
def half_light_radius(self):
"""The half-light radius of this Gaussian profile"""
return self.sigma * Gaussian._hlr_factor

@property
@implements(_galsim.Gaussian.fwhm)
def fwhm(self):
"""The FWHM of this Gaussian profile"""
return self.sigma * Gaussian._fwhm_factor

@property
Expand Down
Loading

0 comments on commit 047cf19

Please sign in to comment.