Skip to content

Commit

Permalink
Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Jammy2211 committed Nov 13, 2020
1 parent 714e021 commit 46abcf5
Show file tree
Hide file tree
Showing 81 changed files with 1,711 additions and 1,316 deletions.
4 changes: 2 additions & 2 deletions autoarray/dataset/imaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ def from_fits(
cls,
image_path,
pixel_scales,
noise_map_path,
image_hdu=0,
noise_map_path=None,
noise_map_hdu=0,
psf_path=None,
psf_hdu=0,
Expand Down Expand Up @@ -449,7 +449,7 @@ def __init__(
renormalize_psf : bool
If `True`, the PSF kernel is renormalized so all values sum to 1.0.
read_noise : float
The level of read-noise added to the simulated imaging by drawing from a Gaussian distribution with
The level of read-noise added to the simulated imaging by drawing from a Gaussian distribution with
sigma equal to the value `read_noise`.
add_poisson_noise : bool
Whether Poisson noise corresponding to photon count statistics on the imaging observation is added.
Expand Down
12 changes: 6 additions & 6 deletions autoarray/dataset/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def array_counts_to_counts_per_second(array_counts, exposure_time):


def array_with_random_uniform_values_added(array, upper_limit=0.001):
""" Add random values drawn from a uniform distribution between zero and an input upper limit to an array.
"""Add random values drawn from a uniform distribution between zero and an input upper limit to an array.
The current use-case of this function is adding small random values to a noise-map that is constant (e.g. all noise
map values are the same). Constant noise-maps have been found to create "broken" inversions where the source is
Expand All @@ -133,9 +133,9 @@ def array_with_random_uniform_values_added(array, upper_limit=0.001):


def noise_map_from_data_eps_and_exposure_time_map(data_eps, exposure_time_map):
""" Estimate the noise-map value in every data-point, by converting the data to units of counts and taking the
"""Estimate the noise-map value in every data-point, by converting the data to units of counts and taking the
square root of these values.
For datasets that may have a background noise component, this function does not return the overall noise-map if the
data is background subtracted. In this case, the returned noise-map is the Poisson noise-map.
Expand Down Expand Up @@ -193,7 +193,7 @@ def noise_map_from_inverse_noise_map(inverse_noise_map):
def noise_map_from_data_eps_exposure_time_map_and_background_noise_map(
data_eps, exposure_time_map, background_noise_map
):
""" Estimate the noise-map values in every data-point, by converting the data to units of counts, adding the
"""Estimate the noise-map values in every data-point, by converting the data to units of counts, adding the
background noise-map and taking the square root of these values.
This function assumes the input data is in electrons per second and returns the noise-map in electrons per second.
Expand All @@ -206,7 +206,7 @@ def noise_map_from_data_eps_exposure_time_map_and_background_noise_map(
The exposure time at every data-point of the data.
background_noise_map : aa.Array
The RMS standard deviation error in every data point due to a background component of the noise-map in units
of electrons per second.
of electrons per second.
"""
return (
np.sqrt(
Expand Down Expand Up @@ -282,7 +282,7 @@ def exposure_time_map_from_exposure_time_and_background_noise_map(
):
"""
Compute the exposure time map from the exposure time of the observation and the background noise-map.
This function assumes the only source of noise in the background noise-map is due to a variable exposure time in
every pixel due to effects like dithering, cosmic rays, etc.
Expand Down
10 changes: 5 additions & 5 deletions autoarray/instruments/acs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

def fits_hdu_from_quadrant_letter(quadrant_letter):

if quadrant_letter is "A" or quadrant_letter is "B":
if quadrant_letter == "A" or quadrant_letter == "B":
return 1
elif quadrant_letter is "C" or quadrant_letter is "D":
elif quadrant_letter == "C" or quadrant_letter == "D":
return 4
else:
raise exc.FrameException("Quadrant letter for FrameACS must be A, B, C or D.")
Expand Down Expand Up @@ -96,7 +96,7 @@ def from_ccd(
See the docstring of the `FrameACS` class for a complete description of the Euclid FPA, quadrants and
rotations.
"""
if quadrant_letter is "B" or quadrant_letter is "C":
if quadrant_letter == "B" or quadrant_letter == "C":

return cls.left(
array_electrons=array_electrons[0:parallel_size, 0:serial_size],
Expand All @@ -106,7 +106,7 @@ def from_ccd(
parallel_overscan_size=parallel_overscan_size,
exposure_info=exposure_info,
)
elif quadrant_letter is "A" or quadrant_letter is "D":
elif quadrant_letter == "A" or quadrant_letter == "D":
return cls.right(
array=array_electrons[0:parallel_size, serial_size : serial_size * 2],
parallel_size=parallel_size,
Expand Down Expand Up @@ -209,7 +209,7 @@ def update_fits(self, original_file_path, new_file_path):
overwrite : bool
If a file already exists at the path, if overwrite=True it is overwritten else an error is raised."""

new_file_dir = new_file_path.rsplit("/", 1)[0]
new_file_dir = os.path.split(new_file_path)[0]

if not os.path.exists(new_file_dir):

Expand Down
54 changes: 32 additions & 22 deletions autoarray/inversion/inversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,20 +552,26 @@ def from_data_mapper_and_regularization(
settings=SettingsInversion(),
):

transformed_mapping_matrices = transformer.transformed_mapping_matrices_from_mapping_matrix(
mapping_matrix=mapper.mapping_matrix
transformed_mapping_matrices = (
transformer.transformed_mapping_matrices_from_mapping_matrix(
mapping_matrix=mapper.mapping_matrix
)
)

real_data_vector = inversion_util.data_vector_via_transformed_mapping_matrix_from(
transformed_mapping_matrix=transformed_mapping_matrices[0],
visibilities=visibilities[:, 0],
noise_map=noise_map[:, 0],
real_data_vector = (
inversion_util.data_vector_via_transformed_mapping_matrix_from(
transformed_mapping_matrix=transformed_mapping_matrices[0],
visibilities=visibilities[:, 0],
noise_map=noise_map[:, 0],
)
)

imag_data_vector = inversion_util.data_vector_via_transformed_mapping_matrix_from(
transformed_mapping_matrix=transformed_mapping_matrices[1],
visibilities=visibilities[:, 1],
noise_map=noise_map[:, 1],
imag_data_vector = (
inversion_util.data_vector_via_transformed_mapping_matrix_from(
transformed_mapping_matrix=transformed_mapping_matrices[1],
visibilities=visibilities[:, 1],
noise_map=noise_map[:, 1],
)
)

real_curvature_matrix = inversion_util.curvature_matrix_via_mapping_matrix_from(
Expand All @@ -586,10 +592,12 @@ def from_data_mapper_and_regularization(

if settings.use_preconditioner:

preconditioner_matrix = inversion_util.preconditioner_matrix_via_mapping_matrix_from(
mapping_matrix=mapper.mapping_matrix,
regularization_matrix=regularization_matrix,
preconditioner_noise_normalization=np.sum(1.0 / noise_map ** 2),
preconditioner_matrix = (
inversion_util.preconditioner_matrix_via_mapping_matrix_from(
mapping_matrix=mapper.mapping_matrix,
regularization_matrix=regularization_matrix,
preconditioner_noise_normalization=np.sum(1.0 / noise_map ** 2),
)
)

preconditioner_inv = np.linalg.inv(preconditioner_matrix)
Expand Down Expand Up @@ -739,20 +747,22 @@ def from_data_mapper_and_regularization(
Op = Fop * Aop

Rop = reg.RegularizationLop(
regularization_matrix=regularization_matrix, dtype="float128"
regularization_matrix=regularization_matrix, dtype="float64"
)

calculation_time = time.time() - start
print("Time to compute Ops = {}".format(calculation_time))

start = time.time()

preconditioner_matrix = inversion_util.preconditioner_matrix_via_mapping_matrix_from(
mapping_matrix=mapper.mapping_matrix,
regularization_matrix=regularization_matrix,
preconditioner_noise_normalization=np.sum(
np.divide(1.0, np.square(noise_map))
),
preconditioner_matrix = (
inversion_util.preconditioner_matrix_via_mapping_matrix_from(
mapping_matrix=mapper.mapping_matrix,
regularization_matrix=regularization_matrix,
preconditioner_noise_normalization=np.sum(
np.divide(1.0, np.square(noise_map))
),
)
)

calculation_time = time.time() - start
Expand Down Expand Up @@ -788,7 +798,7 @@ def from_data_mapper_and_regularization(
else:

Mop = pylops.MatrixMult(
np.linalg.inv(preconditioner_matrix), dtype="float128"
np.linalg.inv(preconditioner_matrix), dtype="float64"
)

reconstruction = pylops.NormalEquationsInversion(
Expand Down
38 changes: 19 additions & 19 deletions autoarray/mask/abstract_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ def __new__(
*args,
**kwargs
):
""" An abstract class for a mask that represents data structure that can be in 1D, 2D or other shapes.
When applied to data it extracts or masks the unmasked image pixels corresponding to mask entries that are
`False` or 0).
The mask also defines the geometry of the data structure it is paired with, for example how its pixels convert
to physical units via the ``pixel_scales`` and ``origin`` parameters and a sub-grid which is used for
perform calculations via super-sampling.
Parameters
----------
mask : np.ndarray
The ``ndarray`` containing the ``bool``'s representing the ``mask``, where `False` signifies an entry is
unmasked and used in calculations.
pixel_scales : (float, float) or float
The scaled units to pixel units conversion factors of every pixel. If this is input as a ``float``, it is
converted to a ``(float, float)`` structure.
origin : (float, float)
The origin of the ``mask``'s coordinate system in scaled units.
"""An abstract class for a mask that represents data structure that can be in 1D, 2D or other shapes.
When applied to data it extracts or masks the unmasked image pixels corresponding to mask entries that are
`False` or 0).
The mask also defines the geometry of the data structure it is paired with, for example how its pixels convert
to physical units via the ``pixel_scales`` and ``origin`` parameters and a sub-grid which is used for
perform calculations via super-sampling.
Parameters
----------
mask : np.ndarray
The ``ndarray`` containing the ``bool``'s representing the ``mask``, where `False` signifies an entry is
unmasked and used in calculations.
pixel_scales : (float, float) or float
The scaled units to pixel units conversion factors of every pixel. If this is input as a ``float``, it is
converted to a ``(float, float)`` structure.
origin : (float, float)
The origin of the ``mask``'s coordinate system in scaled units.
"""

# noinspection PyArgumentList
Expand Down
4 changes: 2 additions & 2 deletions autoarray/mask/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ def extent(self):
@property
def yticks(self):
"""
Returns the yticks labels of this grid, used for plotting the y-axis ticks when visualizing an image-grid"""
Returns the yticks labels of this grid, used for plotting the y-axis ticks when visualizing an image-grid"""
return np.linspace(self.scaled_minima[0], self.scaled_maxima[0], 4)

@property
def xticks(self):
"""
Returns the xticks labels of this grid, used for plotting the x-axis ticks when visualizing an image-grid"""
Returns the xticks labels of this grid, used for plotting the x-axis ticks when visualizing an image-grid"""
return np.linspace(self.scaled_minima[1], self.scaled_maxima[1], 4)

@property
Expand Down
2 changes: 1 addition & 1 deletion autoarray/mask/mask_1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __new__(
*args,
**kwargs
):
""" A 1D mask, representing 1D data on a uniform line of pixels with equal spacing.
"""A 1D mask, representing 1D data on a uniform line of pixels with equal spacing.
When applied to 1D data it extracts or masks the unmasked image pixels corresponding to mask entries that are
`False` or 0).
Expand Down
12 changes: 6 additions & 6 deletions autoarray/mask/mask_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def resized_mask_from_new_shape(self, new_shape):
def trimmed_array_from_padded_array_and_image_shape(
self, padded_array, image_shape
):
""" Map a padded 1D array of values to its original 2D array, trimming all edge values.
"""Map a padded 1D array of values to its original 2D array, trimming all edge values.
Parameters
-----------
Expand Down Expand Up @@ -321,7 +321,7 @@ def circular(
) -> "Mask2D":
"""
Returns a Mask2D (see *Mask2D.__new__*) where all `False` entries are within a circle of input radius.
The ``radius`` and ``centre`` are both input in scaled units.
Parameters
Expand Down Expand Up @@ -374,8 +374,8 @@ def circular_annular(
) -> "Mask2D":
"""
Returns a Mask2D (see *Mask2D.__new__*) where all `False` entries are within an annulus of input
inner radius and outer radius.
inner radius and outer radius.
The ``inner_radius``, ``outer_radius`` and ``centre`` are all input in scaled units.
Parameters
Expand Down Expand Up @@ -435,8 +435,8 @@ def circular_anti_annular(
) -> "Mask2D":
"""
Returns a Mask2D (see *Mask2D.__new__*) where all `False` entries are within an inner circle and second
outer circle, forming an inverse annulus.
outer circle, forming an inverse annulus.
The ``inner_radius``, ``outer_radius``, ``outer_radius_2`` and ``centre`` are all input in scaled units.
Parameters
Expand Down
10 changes: 8 additions & 2 deletions autoarray/operators/convolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ def __init__(self, mask, kernel):
for x in range(self.mask_index_array.shape[0]):
for y in range(self.mask_index_array.shape[1]):
if not mask[x][y]:
image_frame_1d_indexes, image_frame_1d_kernels = self.frame_at_coordinates_jit(
(
image_frame_1d_indexes,
image_frame_1d_kernels,
) = self.frame_at_coordinates_jit(
coordinates=(x, y),
mask=mask,
mask_index_array=self.mask_index_array,
Expand Down Expand Up @@ -241,7 +244,10 @@ def __init__(self, mask, kernel):
for x in range(mask.shape[0]):
for y in range(mask.shape[1]):
if mask[x][y] and not self.blurring_mask[x, y]:
image_frame_1d_indexes, image_frame_1d_kernels = self.frame_at_coordinates_jit(
(
image_frame_1d_indexes,
image_frame_1d_kernels,
) = self.frame_at_coordinates_jit(
coordinates=(x, y),
mask=mask,
mask_index_array=self.mask_index_array,
Expand Down
28 changes: 18 additions & 10 deletions autoarray/operators/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ def real_transformed_mapping_matrix_from_mapping_matrix(self, mapping_matrix):

if self.preload_transform:

return transformer_util.real_transformed_mapping_matrix_via_preload_jit_from(
mapping_matrix=mapping_matrix,
preloaded_reals=self.preload_real_transforms,
return (
transformer_util.real_transformed_mapping_matrix_via_preload_jit_from(
mapping_matrix=mapping_matrix,
preloaded_reals=self.preload_real_transforms,
)
)

else:
Expand All @@ -108,9 +110,11 @@ def imag_transformed_mapping_matrix_from_mapping_matrix(self, mapping_matrix):

if self.preload_transform:

return transformer_util.imag_transformed_mapping_matrix_via_preload_jit_from(
mapping_matrix=mapping_matrix,
preloaded_imags=self.preload_imag_transforms,
return (
transformer_util.imag_transformed_mapping_matrix_via_preload_jit_from(
mapping_matrix=mapping_matrix,
preloaded_imags=self.preload_imag_transforms,
)
)

else:
Expand All @@ -123,11 +127,15 @@ def imag_transformed_mapping_matrix_from_mapping_matrix(self, mapping_matrix):

def transformed_mapping_matrices_from_mapping_matrix(self, mapping_matrix):

real_transformed_mapping_matrix = self.real_transformed_mapping_matrix_from_mapping_matrix(
mapping_matrix=mapping_matrix
real_transformed_mapping_matrix = (
self.real_transformed_mapping_matrix_from_mapping_matrix(
mapping_matrix=mapping_matrix
)
)
imag_transformed_mapping_matrix = self.imag_transformed_mapping_matrix_from_mapping_matrix(
mapping_matrix=mapping_matrix
imag_transformed_mapping_matrix = (
self.imag_transformed_mapping_matrix_from_mapping_matrix(
mapping_matrix=mapping_matrix
)
)

return [real_transformed_mapping_matrix, imag_transformed_mapping_matrix]
Expand Down
Loading

0 comments on commit 46abcf5

Please sign in to comment.