Skip to content

Commit

Permalink
replaced pillow with skimage
Browse files Browse the repository at this point in the history
  • Loading branch information
mommermi committed Nov 6, 2018
1 parent 23b3afa commit 0738cac
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 47 deletions.
70 changes: 33 additions & 37 deletions diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from astropy import wcs
from astropy.visualization import (astropy_mpl_style, ZScaleInterval,
ImageNormalize, LogStretch, LinearStretch)
from

try:
import matplotlib
Expand All @@ -43,9 +42,9 @@
sys.exit()

try:
from skimage import
from skimage.transform import resize
except ImportError:
print('Modules pillow not found. Please install with: pip install pillow')
print('Module skimage not found. Please install with: pip install skimage')
sys.exit()

# pipeline-specific modules
Expand Down Expand Up @@ -233,10 +232,10 @@ def create_index(filenames, directory, obsparam,
imgdat = hdulist[0].data
# clip extreme values
imgdat = np.clip(imgdat, np.percentile(imgdat, 1),
np.percentile(imgdat, 99))
imgdat = imresize(imgdat,
min(1., 1000./np.max(imgdat.shape)),
interp='nearest')
np.percentile(imgdat, 99))
imgdat = resize(imgdat,
(min(imgdat.shape[0], 1000),
min(imgdat.shape[1], 1000)))
# resize image larger than 1000px on one side

norm = ImageNormalize(imgdat, interval=ZScaleInterval(),
Expand Down Expand Up @@ -313,10 +312,10 @@ def add_registration(data, extraction_data, imagestretch='linear'):
imgdat = fits.open(dat['fits_filename'],
ignore_missing_end=True)[0].data
resize_factor = min(1., 1000./np.max(imgdat.shape))
# clip extreme values to prevent crash of imresize
imgdat = np.clip(imgdat, np.percentile(imgdat, 1),
np.percentile(imgdat, 99))
imgdat = imresize(imgdat, resize_factor, interp='nearest')
imgdat = resize(imgdat,
(min(imgdat.shape[0], 1000),
min(imgdat.shape[1], 1000)))

header = fits.open(dat['fits_filename'],
ignore_missing_end=True)[0].header

Expand Down Expand Up @@ -346,7 +345,7 @@ def add_registration(data, extraction_data, imagestretch='linear'):
try:
w = wcs.WCS(header)
world_coo = np.array(list(zip(refcat['ra.deg'],
refcat['dec.deg'])))
refcat['dec.deg'])))
img_coo = w.wcs_world2pix(world_coo, True)
img_coo = [c for c
in img_coo if (c[0] > 0 and c[1] > 0 and
Expand All @@ -355,7 +354,7 @@ def add_registration(data, extraction_data, imagestretch='linear'):
c[1] < header[obsparam['extent'][1]])]
plt.scatter([c[0]*resize_factor for c in img_coo],
[c[1]*resize_factor for c in img_coo],
s=5, marker='o', edgecolors='red', linewidth=0.1,
s=5, marker='o', edgecolors='red', linewidth=0.3,
facecolor='none')
except astropy.wcs._wcs.InvalidTransformError:
logging.error('could not plot reference sources due to '
Expand Down Expand Up @@ -536,7 +535,7 @@ def add_calibration(data, imagestretch='linear'):
+ clipping_steps[zp_idx][0] \
- match[0][0][clipping_steps[zp_idx][3]]
residuals_sig = np.sqrt(match[1][1][clipping_steps[zp_idx][3]]**2
+ clipping_steps[zp_idx][1]**2)
+ clipping_steps[zp_idx][1]**2)

ax3.errorbar(x, residuals, yerr=residuals_sig, color='black',
linestyle='')
Expand All @@ -546,8 +545,7 @@ def add_calibration(data, imagestretch='linear'):
plt.grid()
plt.savefig(('.diagnostics/%s_photcal.png') % cat.catalogname,
format='png')
data['zeropoints'][idx]['plotfilename'] = \
('.diagnostics/%s_photcal.png') % \
data['zeropoints'][idx]['plotfilename'] = ('.diagnostics/%s_photcal.png') % \
cat.catalogname
plt.close()

Expand Down Expand Up @@ -627,7 +625,7 @@ def add_calibration(data, imagestretch='linear'):
dat['zp']+dat['match'][1][0][idx],
np.sqrt(dat['zp_sig']**2 + dat['match'][1][1][idx]**2),
(dat['zp']+dat['match'][1][0][idx])-dat['match'][0][0][idx])
html += "</TABLE><P>derived zeropoint: %7.4f+-%6.4f mag\n" % \
html += "</TABLE><P>derived zeropoint: %7.4f+-%6.4f mag\n" % \
(dat['zp'], dat['zp_sig'])
html += "</TR></TD></TR></TABLE>\n"

Expand All @@ -636,10 +634,9 @@ def add_calibration(data, imagestretch='linear'):
'.fits'
imgdat = fits.open(fits_filename, ignore_missing_end=True)[0].data
resize_factor = min(1., 1000./np.max(imgdat.shape))
# clip extreme values to prevent crash of imresize
imgdat = np.clip(imgdat, np.percentile(imgdat, 1),
np.percentile(imgdat, 99))
imgdat = imresize(imgdat, resize_factor, interp='nearest')
imgdat = resize(imgdat,
(min(imgdat.shape[0], 1000),
min(imgdat.shape[1], 1000)))
header = fits.open(fits_filename, ignore_missing_end=True)[0].header

norm = ImageNormalize(imgdat, interval=ZScaleInterval(),
Expand Down Expand Up @@ -671,10 +668,9 @@ def add_calibration(data, imagestretch='linear'):
dat['match'][0][4][idx]]
for idx in dat['zp_usedstars']]
img_coo = w.wcs_world2pix(world_coo, True)

plt.scatter([c[0]*resize_factor for c in img_coo],
[c[1]*resize_factor for c in img_coo],
s=10, marker='o', edgecolors='red', linewidth=0.1,
s=10, marker='o', edgecolors='red', linewidth=0.3,
facecolor='none')
for i in range(len(dat['zp_usedstars'])):
plt.annotate(str(i+1), xy=((img_coo[i][0]*resize_factor)+15,
Expand Down Expand Up @@ -796,11 +792,10 @@ def add_results(data, imagestretch='linear'):

# create margin around image allowing for any cropping
composite = np.zeros((hdulist[0].data.shape[0]+2*boxsize,
hdulist[0].data.shape[1]+2*boxsize))
hdulist[0].data.shape[1]+2*boxsize))

composite[boxsize:boxsize+hdulist[0].data.shape[0],
boxsize:boxsize+hdulist[0].data.shape[1]] = \
hdulist[0].data
boxsize:boxsize+hdulist[0].data.shape[1]] = hdulist[0].data

# extract thumbnail data accordingly
thumbdata = composite[int(boxsize+obj_y-boxsize/2):
Expand Down Expand Up @@ -845,14 +840,15 @@ def add_results(data, imagestretch='linear'):
# place expected position (if within thumbnail)
if (abs(exp_x-obj_x) <= boxsize/2 and
abs(exp_y-obj_y) <= boxsize/2):
plt.scatter(exp_x-obj_x+boxsize/2),
exp_y-obj_y+boxsize/2),
plt.scatter(exp_x-obj_x+boxsize/2,
exp_y-obj_y+boxsize/2,
marker='+', s=100, color='green')

thumbfilename='.diagnostics/' +
target.translate(_pp_conf.target2filename) + '_' +
fitsfilename[:fitsfilename.find('.fit')] +
'_thumb.png'
thumbfilename = ('.diagnostics/' +
target.translate(_pp_conf.target2filename) +
'_' +
fitsfilename[:fitsfilename.find('.fit')] +
'_thumb.png')
plt.savefig(thumbfilename, format='png',
bbox_inches='tight',
pad_inches=0)
Expand All @@ -866,12 +862,12 @@ def add_results(data, imagestretch='linear'):
continue

# create gif animation
gif_filename=('%s.gif' % target.translate(_pp_conf.target2filename))
gif_filename = ('%s.gif' % target.translate(_pp_conf.target2filename))
logging.info('converting images to gif: %s' % gif_filename)
root=os.getcwd()
root = os.getcwd()
os.chdir(_pp_conf.diagroot)
try:
convert=subprocess.Popen(['convert', '-delay', '50',
convert = subprocess.Popen(['convert', '-delay', '50',
('%s*thumb.png' %
(target.translate(_pp_conf.target2filename))),
'-loop', '0',
Expand Down Expand Up @@ -920,8 +916,8 @@ def add_results(data, imagestretch='linear'):
data[target][idx][10],
plts[1].split('.diagnostics/')[1])
filename = '.diagnostics/' + \
target.translate(_pp_conf.target2filename) + \
'_' + 'results.html'
target.translate(_pp_conf.target2filename) + \
'_' + 'results.html'
create_website(filename, html)
data['resultswebsites'][target] = filename

Expand Down
14 changes: 7 additions & 7 deletions doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ directory.
Software Requirements
.....................

PP requires `git`_ for the installation, a number of non-standard
Python modules (either Python2 or Python3; available from the `Python
PP only runs on Python 3. It furthermore requires requires `git`_, a
number of non-standard Python modules (available from the `Python
Package Index`_ through `pip`_):

* `numpy`_
Expand All @@ -28,9 +28,9 @@ Package Index`_ through `pip`_):
* `astroquery`_
* `matplotlib`_
* `callhorizons`_
* `future`_
* `pillow`_

* `future`_
* `skimage`_
and some freely available software:

* `imagemagick`_
Expand Down Expand Up @@ -81,7 +81,7 @@ Unpack SCAMP and install using::

Install Python modules::

pip install numpy scipy astropy astroquery matplotlib matplotlib callhorizons future pillow
pip install numpy scipy astropy astroquery matplotlib matplotlib callhorizons

Add these lines to the ``.bashrc`` file in your home directory and
replace ``<path>`` with the actual path to the PP directory::
Expand Down Expand Up @@ -251,7 +251,7 @@ and I will take care of implementing your telescope.
.. _matplotlib: http://matplotlib.org/
.. _callhorizons: https://pypi.python.org/pypi/CALLHORIZONS
.. _future: http://python-future.org/
.. _pillow: http://python-pillow.org/
.. _skimage: https://scikit-image.org/
.. _imagemagick: http://www.imagemagick.org/
.. _Source Extractor: http://www.astromatic.net/software/sextractor
.. _SCAMP: http://www.astromatic.net/software/scamp
Expand Down
6 changes: 3 additions & 3 deletions readme.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Photometry Pipeline
===================

The Photometry Pipeline (PP) is a Python software package for
The Photometry Pipeline (PP) is a Python 3 software package for
automated photometric analysis of imaging data from small to
medium-sized observatories. It uses `Source Extractor`_ and `SCAMP`_ to
register and photometrically calibrate images based on catalogs that
Expand All @@ -27,7 +27,7 @@ Python modules:
* `matplotlib`_
* `callhorizons`_
* `future`_
* `pillow`_
* `skimage`_

and some freely available software:

Expand Down Expand Up @@ -83,7 +83,7 @@ Feel free to contact me in case of questions or suggestions: mommermiscience (at
.. _matplotlib: http://matplotlib.org/
.. _callhorizons: http://pypi.python.org/pypi/CALLHORIZONS
.. _future: http://python-future.org/
.. _pillow: http://python-pillow.org/
.. _skimage: https://scikit-image.org/
.. _Source Extractor: http://www.astromatic.net/software/sextractor
.. _SCAMP: http://www.astromatic.net/software/scamp
.. _documentation: http://photometrypipeline.readthedocs.io/en/latest/
Expand Down

0 comments on commit 0738cac

Please sign in to comment.