From b7c2ef0fbb3d1c82cce5fff04bf724a65c661985 Mon Sep 17 00:00:00 2001 From: tolgayapici Date: Fri, 23 Jun 2017 14:23:44 -0400 Subject: [PATCH 1/8] fiber placement variable added to the class. it is needed for dithering --- specsim/fiberloss.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/specsim/fiberloss.py b/specsim/fiberloss.py index 478d42b..e42a1f3 100644 --- a/specsim/fiberloss.py +++ b/specsim/fiberloss.py @@ -33,13 +33,17 @@ class GalsimFiberlossCalculator(object): Beta parameter value for the atmospheric PSF Moffat profile. maximum_fft_size : int Maximum size of FFT allowed. + fiber_placement: float + Fiber placement position in microns. It is needed for dithering """ def __init__(self, fiber_diameter, wlen_grid, num_pixels=16, - oversampling=32, moffat_beta=3.5, maximum_fft_size=32767): + oversampling=32, moffat_beta=3.5, maximum_fft_size=32767, + fiber_placement=[0., 0.]): self.wlen_grid = np.asarray(wlen_grid) self.moffat_beta = moffat_beta - + self.fiber_placement = fiber_placement + # Defer import to runtime. import galsim @@ -48,13 +52,17 @@ def __init__(self, fiber_diameter, wlen_grid, num_pixels=16, # rather than on-sky angles. scale = fiber_diameter / num_pixels self.image = galsim.Image(num_pixels, num_pixels, scale=scale) - self.gsparams = galsim.GSParams(maximum_fft_size=32767) # Prepare an anti-aliased image of the fiber aperture. nos = num_pixels * oversampling - dxy = (np.arange(nos) + 0.5 - 0.5 * nos) / (0.5 * nos) - rsq = dxy ** 2 + dxy[:, np.newaxis] ** 2 + + #dxy = (np.arange(nos) + 0.5 - 0.5 * nos) / (0.5 * nos) + dx = (np.arange(nos) + 0.5 - 0.5 * nos) / (0.5 * nos) - self.fiber_placement[0]/0.5/fiber_diameter + dy = (np.arange(nos) + 0.5 - 0.5 * nos) / (0.5 * nos) - self.fiber_placement[1]/0.5/fiber_diameter + + #rsq = dxy ** 2 + dxy[:, np.newaxis] ** 2 + rsq = dx ** 2 + dy[:, np.newaxis] ** 2 inside = (rsq <= 1).astype(float) s0, s1 = inside.strides blocks = numpy.lib.stride_tricks.as_strided( @@ -62,7 +70,6 @@ def __init__(self, fiber_diameter, wlen_grid, num_pixels=16, strides=(oversampling * s0, oversampling * s1, s0, s1)) self.aperture = blocks.sum(axis=(2, 3)) / oversampling ** 2 - def create_source(self, fractions, half_light_radius, minor_major_axis_ratio, position_angle): """Create a model for the on-sky profile of a single source. From 562e335faee5485ce6e657919a3c1bd6c8a50790 Mon Sep 17 00:00:00 2001 From: tolgayapici Date: Thu, 29 Jun 2017 10:27:33 -0400 Subject: [PATCH 2/8] some changes were made to fiberloss package for fiber placement --- specsim/fiberloss.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/specsim/fiberloss.py b/specsim/fiberloss.py index e42a1f3..77f1455 100644 --- a/specsim/fiberloss.py +++ b/specsim/fiberloss.py @@ -33,7 +33,7 @@ class GalsimFiberlossCalculator(object): Beta parameter value for the atmospheric PSF Moffat profile. maximum_fft_size : int Maximum size of FFT allowed. - fiber_placement: float + fiber_placement: array Fiber placement position in microns. It is needed for dithering """ def __init__(self, fiber_diameter, wlen_grid, num_pixels=16, @@ -248,7 +248,7 @@ def calculate(self, seeing_fwhm, scale, offset, blur_rms, convolved.drawImage(offset=offsets, **draw_args) # Calculate the fiberloss fraction for this fiber and wlen. fiberloss[j, i] = np.sum(self.image.array * self.aperture) - + if saved_images_file is not None: header['FIBER'] = j header['WLEN'] = wlen @@ -267,6 +267,7 @@ def calculate(self, seeing_fwhm, scale, offset, blur_rms, header['COMMENT'] = 'Atmospheric seeing model' hdu_list.append(astropy.io.fits.ImageHDU( data=self.image.array.copy(), header=header)) + if wlen == self.wlen_grid[-1]: # Render the source profile without any offset after # all other postage stamps for this fiber. @@ -287,7 +288,8 @@ def calculate_fiber_acceptance_fraction( focal_x, focal_y, wavelength, source, atmosphere, instrument, source_types=None, source_fraction=None, source_half_light_radius=None, source_minor_major_axis_ratio=None, source_position_angle=None, - oversampling=32, saved_images_file=None, saved_table_file=None): + oversampling=32, saved_images_file=None, saved_table_file=None, + fiber_placement=[0., 0.]): """Calculate the acceptance fraction for a single fiber. The behavior of this function is customized by the instrument.fiberloss @@ -352,7 +354,9 @@ def calculate_fiber_acceptance_fraction( extension determines the file format, and .ecsv is recommended. The saved file can then be used as a pre-tabulated input with instrument.fiberloss.method = 'table'. - + fiber_placement: array + Fiber placement position in microns. It is needed for dithering + Returns ------- numpy array @@ -391,7 +395,8 @@ def calculate_fiber_acceptance_fraction( wlen_grid.to(u.Angstrom).value, instrument.fiberloss_num_pixels, oversampling, - atmosphere.seeing_moffat_beta) + atmosphere.seeing_moffat_beta, + fiber_placement=fiber_placement) # Calculate the focal-plane optics at the fiber locations. scale, blur, offset = instrument.get_focal_plane_optics( From b72606c4c0286e3c4d273cd5629349a71b79d9e2 Mon Sep 17 00:00:00 2001 From: tolgayapici Date: Wed, 12 Jul 2017 18:21:43 -0400 Subject: [PATCH 3/8] changed travis yaml file to see whether the test fails are due to astropy version --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 113c902..2edb320 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,7 @@ env: # to repeat them for all configurations. - PYTHON_VERSION=3.6 - NUMPY_VERSION=stable - - ASTROPY_VERSION=stable + - ASTROPY_VERSION=1.3.3 - MAIN_CMD='python setup.py' - SETUP_CMD='test' - PIP_DEPENDENCIES='speclite' From 940088f38925cc652547f3b29fc4bada17d60fbe Mon Sep 17 00:00:00 2001 From: tolgayapici Date: Tue, 1 Aug 2017 15:47:02 -0400 Subject: [PATCH 4/8] changed the quickfiberloss.py to address issue72 --- specsim/quickfiberloss.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specsim/quickfiberloss.py b/specsim/quickfiberloss.py index f7ccf4a..3621c16 100644 --- a/specsim/quickfiberloss.py +++ b/specsim/quickfiberloss.py @@ -63,7 +63,7 @@ def main(args=None): args.num_wlen) * wlen_unit # Calculate the seeing at each wavelength. - simulator.atmosphere.seeing['fwhm_ref'] = args.seeing * u.arcsec + simulator.atmosphere.seeing_fwhm_ref = args.seeing * u.arcsec seeing_fwhm = simulator.atmosphere.get_seeing_fwhm( wlen_grid).to(u.arcsec).value From 9a70a121e65dd174420bc563d8ef132e5afb81d3 Mon Sep 17 00:00:00 2001 From: tolgayapici Date: Tue, 1 Aug 2017 15:49:15 -0400 Subject: [PATCH 5/8] reverted the .travis.yaml file to original --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2edb320..113c902 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,7 @@ env: # to repeat them for all configurations. - PYTHON_VERSION=3.6 - NUMPY_VERSION=stable - - ASTROPY_VERSION=1.3.3 + - ASTROPY_VERSION=stable - MAIN_CMD='python setup.py' - SETUP_CMD='test' - PIP_DEPENDENCIES='speclite' From fc29b12f8a9ce4bef9b1f76e662d26e3f5940cec Mon Sep 17 00:00:00 2001 From: tolgayapici Date: Tue, 1 Aug 2017 16:54:35 -0400 Subject: [PATCH 6/8] fixed the problem with transform.py --- specsim/transform.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specsim/transform.py b/specsim/transform.py index fe926cf..296ae4f 100644 --- a/specsim/transform.py +++ b/specsim/transform.py @@ -310,7 +310,7 @@ def create_observing_model(where, when, wavelength, temperature=15*u.deg_C, # See https://en.wikipedia.org/wiki/Vertical_pressure_variation if pressure is None: h = where.height - p0 = astropy.constants.atmosphere + p0 = astropy.constants.atm g0 = astropy.constants.g0 R = astropy.constants.R air_molar_mass = 0.0289644 * u.kg / u.mol From 110b1b65297e917d9267f21fd1041dd4e06883cc Mon Sep 17 00:00:00 2001 From: tolgayapici Date: Wed, 2 Aug 2017 12:12:29 -0400 Subject: [PATCH 7/8] added an astropy version check to make it work with different versions --- specsim/transform.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/specsim/transform.py b/specsim/transform.py index 296ae4f..c5a51a1 100644 --- a/specsim/transform.py +++ b/specsim/transform.py @@ -310,7 +310,10 @@ def create_observing_model(where, when, wavelength, temperature=15*u.deg_C, # See https://en.wikipedia.org/wiki/Vertical_pressure_variation if pressure is None: h = where.height - p0 = astropy.constants.atm + if astropy.version.major == 2: + p0 = astropy.constants.atm + if astropy.version.major == 1: + p0 = astropy.constants.atmosphere g0 = astropy.constants.g0 R = astropy.constants.R air_molar_mass = 0.0289644 * u.kg / u.mol From 170485e4f45a3815dc74b29c2031f6d64f57edfb Mon Sep 17 00:00:00 2001 From: tolgayapici Date: Wed, 2 Aug 2017 12:25:37 -0400 Subject: [PATCH 8/8] stable version of the astropy did not return a numerical value, so I changed it a bit --- specsim/transform.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/specsim/transform.py b/specsim/transform.py index c5a51a1..83ff00b 100644 --- a/specsim/transform.py +++ b/specsim/transform.py @@ -310,10 +310,10 @@ def create_observing_model(where, when, wavelength, temperature=15*u.deg_C, # See https://en.wikipedia.org/wiki/Vertical_pressure_variation if pressure is None: h = where.height - if astropy.version.major == 2: - p0 = astropy.constants.atm if astropy.version.major == 1: p0 = astropy.constants.atmosphere + else: + p0 = astropy.constants.atm g0 = astropy.constants.g0 R = astropy.constants.R air_molar_mass = 0.0289644 * u.kg / u.mol