Skip to content

Commit

Permalink
rebase ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
samaloney committed May 17, 2024
1 parent a364bbf commit e4dbe8e
Show file tree
Hide file tree
Showing 14 changed files with 381 additions and 303 deletions.
19 changes: 10 additions & 9 deletions examples/rhessi.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,13 @@
###############################################################################
# Lets have a look at the point spread function (PSF) or dirty beam

psf_map = vis_psf_map(vis, shape=(101, 101)*apu.pixel,
pixel_size=1.5*apu.arcsec/apu.pixel,
scheme='uniform')
psf_map = vis_psf_map(vis, shape=(101, 101) * apu.pixel, pixel_size=1.5 * apu.arcsec / apu.pixel, scheme="uniform")

###############################################################################
# We can now make an image using the back projection algorithm essentially and
# inverse Fourier transform of the visibilities.

backproj_map = vis_to_map(vis, shape=[101, 101]*apu.pixel,
pixel_size=1.5*apu.arcsec/apu.pix)
backproj_map = vis_to_map(vis, shape=[101, 101] * apu.pixel, pixel_size=1.5 * apu.arcsec / apu.pix)

###############################################################################
# Back projection contain many artifact due to the incomplete sampling of the u-v
Expand All @@ -85,14 +82,18 @@
# vis_59 = Visibility(vis=vis_data_59['obsvis']*apu.Unit('ph/cm*s'), u=vis_data_59['u']/apu.arcsec,
# v=vis_data_59['v']/apu.arcsec, offset=vis_data_59['xyoffset'][0]*apu.arcsec)

clean_map, model_map, residual_map = vis_clean(vis, shape=[101, 101] * apu.pixel,
pixel_size=[1.5, 1.5] * apu.arcsec / apu.pix,
clean_beam_width=10 * apu.arcsec, niter=100)
clean_map, model_map, residual_map = vis_clean(
vis,
shape=[101, 101] * apu.pixel,
pixel_size=[1.5, 1.5] * apu.arcsec / apu.pix,
clean_beam_width=10 * apu.arcsec,
niter=100,
)

###############################################################################
# MEM

mem_map = mem(vis, shape=[129, 129] * apu.pixel, pixel=[2, 2] * apu.arcsec/apu.pix)
mem_map = mem(vis, shape=[129, 129] * apu.pixel, pixel=[2, 2] * apu.arcsec / apu.pix)
mem_map.plot()


Expand Down
19 changes: 10 additions & 9 deletions examples/stix.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,31 @@
###############################################################################
# Lets have a look at the point spread function (PSF) or dirty beam

psf_map = vis_psf_map(stix_vis, shape=(129, 129)*apu.pixel,
pixel_size=2*apu.arcsec/apu.pix,
scheme='uniform')
psf_map = vis_psf_map(stix_vis, shape=(129, 129) * apu.pixel, pixel_size=2 * apu.arcsec / apu.pix, scheme="uniform")
psf_map.plot()

###############################################################################
# Back projection

backproj_map = vis_to_map(stix_vis, shape=(129, 129)*apu.pixel,
pixel_size=2*apu.arcsec/apu.pix, scheme='uniform')
backproj_map = vis_to_map(stix_vis, shape=(129, 129) * apu.pixel, pixel_size=2 * apu.arcsec / apu.pix, scheme="uniform")
backproj_map.plot()

###############################################################################
# Clean

clean_map, model_map, resid_map = vis_clean(stix_vis, shape=[129, 129] * apu.pixel,
pixel_size=[2, 2] * apu.arcsec / apu.pix, clean_beam_width=20 * apu.arcsec,
niter=100)
clean_map, model_map, resid_map = vis_clean(
stix_vis,
shape=[129, 129] * apu.pixel,
pixel_size=[2, 2] * apu.arcsec / apu.pix,
clean_beam_width=20 * apu.arcsec,
niter=100,
)
clean_map.plot()

###############################################################################
# MEM

mem_map = mem(stix_vis, shape=[129, 129] * apu.pixel, pixel=[2, 2] * apu.arcsec/apu.pix)
mem_map = mem(stix_vis, shape=[129, 129] * apu.pixel, pixel=[2, 2] * apu.arcsec / apu.pix)
mem_map.plot()

###############################################################################
Expand Down
4 changes: 2 additions & 2 deletions xrayvision/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst

try:
from xrayvision.version import __version__ # type: ignore
from xrayvision.version import __version__ # type: ignore
except ImportError:
__version__ = "unknown"
__all__ = []

from pkg_resources import resource_filename

SAMPLE_RHESSI_VISIBILITIES = resource_filename('xrayvision', 'data/hsi_visibili_20131028_0156_20131028_0200_6_12.fits')
SAMPLE_RHESSI_VISIBILITIES = resource_filename("xrayvision", "data/hsi_visibili_20131028_0156_20131028_0200_6_12.fits")
29 changes: 17 additions & 12 deletions xrayvision/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@
"""


def clean(dirty_map, dirty_beam, pixel_size=None, clean_beam_width=4.0,
gain=0.1, thres=0.01, niter=5000):
def clean(dirty_map, dirty_beam, pixel_size=None, clean_beam_width=4.0, gain=0.1, thres=0.01, niter=5000):
r"""
Clean the image using Hogbom's original method.
Expand All @@ -84,8 +83,8 @@ def clean(dirty_map, dirty_beam, pixel_size=None, clean_beam_width=4.0,
pad = [0 if x % 2 == 0 else 1 for x in dirty_map.shape]

# Assume beam, map phase_centre is in middle
beam_center = (dirty_beam.shape[0] - 1)/2.0, (dirty_beam.shape[1] - 1)/2.0
map_center = (dirty_map.shape[0] - 1)/2.0, (dirty_map.shape[1] - 1)/2.0
beam_center = (dirty_beam.shape[0] - 1) / 2.0, (dirty_beam.shape[1] - 1) / 2.0
map_center = (dirty_map.shape[0] - 1) / 2.0, (dirty_map.shape[1] - 1) / 2.0

# Work out size of map for slicing over-sized dirty beam
shape = dirty_map.shape
Expand Down Expand Up @@ -135,18 +134,18 @@ def clean(dirty_map, dirty_beam, pixel_size=None, clean_beam_width=4.0,
# Convert from FWHM to StDev FWHM = sigma*(8ln2)**0.5 = 2.3548200450309493
x_stdev = (clean_beam_width / pixel_size[0] / 2.3548200450309493).value
y_stdev = (clean_beam_width / pixel_size[1] / 2.3548200450309493).value
clean_beam = Gaussian2DKernel(x_stdev, y_stdev, x_size=dirty_beam.shape[1],
y_size=dirty_beam.shape[0]).array
clean_beam = Gaussian2DKernel(x_stdev, y_stdev, x_size=dirty_beam.shape[1], y_size=dirty_beam.shape[0]).array
# Normalise beam
clean_beam = clean_beam / clean_beam.max()

# Convolve clean beam with model and scale
clean_map = (signal.convolve2d(model, clean_beam/clean_beam.sum(), mode='same')
/ (pixel_size[0] * pixel_size[1]))
clean_map = signal.convolve2d(model, clean_beam / clean_beam.sum(), mode="same") / (
pixel_size[0] * pixel_size[1]
)

# Scale residual map with model and scale
dirty_map = dirty_map / clean_beam.sum() / (pixel_size[0] * pixel_size[1])
return clean_map+dirty_map, model, dirty_map
return clean_map + dirty_map, model, dirty_map

return model + dirty_map, model, dirty_map

Expand All @@ -173,10 +172,16 @@ def vis_clean(vis, shape, pixel_size, clean_beam_width=4.0, niter=5000, map=True
"""

dirty_map = vis_to_map(vis, shape=shape, pixel_size=pixel_size, **kwargs)
dirty_beam_shape = [x.value*3 + 1 if x.value*3 % 2 == 0 else x.value*3 for x in shape]*shape.unit
dirty_beam_shape = [x.value * 3 + 1 if x.value * 3 % 2 == 0 else x.value * 3 for x in shape] * shape.unit
dirty_beam = vis_psf_image(vis, shape=dirty_beam_shape, pixel_size=pixel_size, **kwargs)
clean_map, model, residual = clean(dirty_map.data, dirty_beam.value, pixel_size=pixel_size,
clean_beam_width=clean_beam_width, gain=gain, niter=niter)
clean_map, model, residual = clean(
dirty_map.data,
dirty_beam.value,
pixel_size=pixel_size,
clean_beam_width=clean_beam_width,
gain=gain,
niter=niter,
)
if not map:
return clean_map, model, residual

Expand Down
Loading

0 comments on commit e4dbe8e

Please sign in to comment.