Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions iris/iris.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self, image_path, force_refresh=False,
:param daemon_port: Listening port of the viewer daemon.
"""

kwargs['config_file_name'] = 'config.sitelle.orb'
kwargs['instrument'] = 'sitelle'

Tools.__init__(self, **kwargs)

Expand Down Expand Up @@ -117,7 +117,7 @@ def _get_outcube_path(self, camera, absolute=False):
elif camera == 0:
path = self._data_prefix + 'cube.m.hdf5'
else:
self._print_error('camera must be 0, 1 or 2.')
raise StandardError('camera must be 0, 1 or 2.')
if absolute:
return os.path.abspath(path)
else:
Expand Down
98 changes: 50 additions & 48 deletions iris/stats.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import os
import numpy as np
import time
import logging
import warnings


class ImageStats(Tools):
Expand Down Expand Up @@ -76,7 +78,7 @@ def __init__(self, image_path, force_refresh=False,
ORB documentation).
"""

kwargs['config_file_name'] = 'config.sitelle.orb'
kwargs['instrument'] = 'sitelle'

Tools.__init__(self, **kwargs)
self.kwargs = kwargs
Expand All @@ -88,7 +90,7 @@ def __init__(self, image_path, force_refresh=False,
if force_refresh:
self.refresh = True
elif not os.path.exists(self._get_reference_file_path()):
self._print_warning('No reference file created yet. Image taken as reference image.')
warnings.warn('No reference file created yet. Image taken as reference image.')
self.refresh = True

# open reference file
Expand All @@ -115,15 +117,15 @@ def __init__(self, image_path, force_refresh=False,
# find alignment parameters if nescessary
if self.refresh:
start_time = time.time()
self._print_msg('Computing alignment parameters')
logging.info('Computing alignment parameters')
init_angle = float(self._get_config_parameter('INIT_ANGLE'))
init_dx = float(self._get_config_parameter('INIT_DX'))
init_dy = float(self._get_config_parameter('INIT_DY'))
aligner = Aligner(self.im1, self.im2, fwhm_arc, fov, fov, 1, 1,
pix_size, pix_size, init_angle, init_dx, init_dy,
overwrite=True, **kwargs)
result = aligner.compute_alignment_parameters(
correct_distorsion=False,
correct_distortion=False,
brute_force=True)

self.reffile.append('align-params', result['coeffs'])
Expand All @@ -134,19 +136,19 @@ def __init__(self, image_path, force_refresh=False,
self.reffile.append('zoom-factor', result['zoom_factor'])
self.reffile.append('ref-odometer', self.odometer_nb)

self._print_msg('Alignment parameters ({}) computed in {:.2f} s'.format(self.reffile.get('align-params'), time.time() - start_time))
logging.info('Alignment parameters ({}) computed in {:.2f} s'.format(self.reffile.get('align-params'), time.time() - start_time))

self.astro1 = Astrometry(self.im1, fwhm_arc, fov, **kwargs)
self.astro1 = Astrometry(self.im1, fwhm_arc=fwhm_arc, **kwargs)
self.astro1.reset_star_list(self.reffile.get('star-list1'))
self.astro1.reset_fwhm_arc(self.reffile.get('fwhm-arc'))
self.astro2 = Astrometry(self.im2, fwhm_arc, fov, **kwargs)
self.astro2 = Astrometry(self.im2, fwhm_arc=fwhm_arc, **kwargs)
self.astro2.reset_star_list(self.reffile.get('star-list2'))
self.astro2.reset_fwhm_arc(self.reffile.get('fwhm-arc'))


# creating merged frame
align_params = self.reffile.get('align-params')
self._print_msg('Creating merged frame')
logging.info('Creating merged frame')
start_time = time.time()
self.imM = np.empty_like(self.im1)
self.imM.fill(np.nan)
Expand Down Expand Up @@ -174,11 +176,11 @@ def __init__(self, image_path, force_refresh=False,
self.im1[xmin[isec]:xmax[isec], ymin[isec]:ymax[isec]]
+ sections[isec])

self._print_msg('Merged frame created in {:.2f} s'.format(
logging.info('Merged frame created in {:.2f} s'.format(
time.time() - start_time))

# init astrometry of merged frame
self.astroM = Astrometry(self.imM, fwhm_arc, fov, **kwargs)
self.astroM = Astrometry(self.imM, fwhm_arc=fwhm_arc, **kwargs)
self.astroM.reset_star_list(self.reffile.get('star-list1'))
self.astroM.reset_fwhm_arc(self.reffile.get('fwhm-arc'))

Expand All @@ -195,7 +197,7 @@ def _get_hdr_keyword(self, key):
if key in self.hdr:
return self.hdr[key]
else:
self._print_error('Invalid image file the keyword {} must be present.'.format(key))
raise StandardError('Invalid image file the keyword {} must be present.'.format(key))

def _get_stars_params_group(self, camera, ref=False):
"""Return the hdf5 group of a set of stars parameters given
Expand Down Expand Up @@ -227,29 +229,29 @@ def compute_stats(self):

# stars fit
start_time = time.time()
self._print_msg('Fitting_stars in camera 1')
fit1 = self.astro1.fit_stars_in_frame(0, multi_fit=True,
logging.info('Fitting_stars in camera 1')
fit1 = self.astro1.fit_stars_in_frame(0, multi_fit=False,
estimate_local_noise=False,
no_aperture_photometry=True)
self._print_msg('Stars fitted in {:.2f} s'.format(
logging.info('Stars fitted in {:.2f} s'.format(
time.time() - start_time))
fit1.save_stars_params(self._get_reference_file_path(),
self._get_stars_params_group(1))

start_time = time.time()
self._print_msg('Fitting_stars in camera 2')
fit2 = self.astro2.fit_stars_in_frame(0, multi_fit=True,
logging.info('Fitting_stars in camera 2')
fit2 = self.astro2.fit_stars_in_frame(0, multi_fit=False,
estimate_local_noise=False,
no_aperture_photometry=True)
self._print_msg('Stars fitted in {:.2f} s'.format(
logging.info('Stars fitted in {:.2f} s'.format(
time.time() - start_time))
fit2.save_stars_params(self._get_reference_file_path(),
self._get_stars_params_group(2))

start_time = time.time()
self._print_msg('Getting star photometry on merged frame')
logging.info('Getting star photometry on merged frame')
fitM = self.astroM.fit_stars_in_frame(0, no_fit=True)
self._print_msg('Photometry computed in {:.2f} s'.format(
logging.info('Photometry computed in {:.2f} s'.format(
time.time() - start_time))
fitM.save_stars_params(self._get_reference_file_path(),
self._get_stars_params_group(0))
Expand Down Expand Up @@ -289,66 +291,66 @@ def add_data(name, data):

# dx 1
if self.refresh:
dx1 = od.array(0., fit1[:,'x_err'][0])
dx1 = od.array(0., np.nanmedian(fit1[:,'x_err']))
else:
x1 = od.array(fit1[:,'x'][0], fit1[:,'x_err'][0])
x1_ref = od.array(fitR1[:,'x'][0], fitR1[:,'x_err'][0])
x1 = od.array(np.nanmedian(fit1[:,'x']), np.nanmedian(fit1[:,'x_err']))
x1_ref = od.array(np.nanmedian(fitR1[:,'x']), np.nanmedian(fitR1[:,'x_err']))
dx1 = x1 - x1_ref
add_data('dx-pix-1', dx1)

# dx 2
if self.refresh:
dx2 = od.array(0., fit2[:,'x_err'][0])
dx2 = od.array(0., np.nanmedian(fit2[:,'x_err']))
else:
x2 = od.array(fit2[:,'x'][0], fit2[:,'x_err'][0])
x2_ref = od.array(fitR2[:,'x'][0], fitR2[:,'x_err'][0])
x2 = od.array(np.nanmedian(fit2[:,'x']), np.nanmedian(fit2[:,'x_err']))
x2_ref = od.array(np.nanmedian(fitR2[:,'x']), np.nanmedian(fitR2[:,'x_err']))
dx2 = x2 - x2_ref
add_data('dx-pix-2', dx2)

# dy 1
if self.refresh:
dy1 = od.array(0., fit1[:,'y_err'][0])
dy1 = od.array(0., np.nanmedian(fit1[:,'y_err']))
else:
y1 = od.array(fit1[:,'y'][0], fit1[:,'y_err'][0])
y1_ref = od.array(fitR1[:,'y'][0], fitR1[:,'y_err'][0])
y1 = od.array(np.nanmedian(fit1[:,'y']), np.nanmedian(fit1[:,'y_err']))
y1_ref = od.array(np.nanmedian(fitR1[:,'y']), np.nanmedian(fitR1[:,'y_err']))
dy1 = y1 - y1_ref
add_data('dy-pix-1', dy1)

# dx 2
if self.refresh:
dy2 = od.array(0., fit2[:,'y_err'][0])
dy2 = od.array(0., np.nanmedian(fit2[:,'y_err']))
else:
y2 = od.array(fit2[:,'y'][0], fit2[:,'y_err'][0])
y2_ref = od.array(fitR2[:,'y'][0], fitR2[:,'y_err'][0])
y2 = od.array(np.nanmedian(fit2[:,'y']), np.nanmedian(fit2[:,'y_err']))
y2_ref = od.array(np.nanmedian(fitR2[:,'y']), np.nanmedian(fitR2[:,'y_err']))
dy2 = y2 - y2_ref
add_data('dy-pix-2', dy2)

# fwhm 1
add_data('fwhm-pix-1', od.array(fit1[:, 'fwhm_pix'][0],
fit1[:, 'fwhm_err'][0]))
add_data('fwhm-arc-1', od.array(fit1[:, 'fwhm_arc'][0],
fit1[:, 'fwhm_arc_err'][0]))

add_data('fwhm-pix-2', od.array(fit2[:, 'fwhm_pix'][0],
fit2[:, 'fwhm_err'][0]))
add_data('fwhm-arc-2', od.array(fit2[:, 'fwhm_arc'][0],
fit2[:, 'fwhm_arc_err'][0]))
add_data('fwhm-pix-1', od.array(np.nanpercentile(fit1[:, 'fwhm_pix'],10),
np.nanmedian(fit1[:, 'fwhm_err'])))
add_data('fwhm-arc-1', od.array(np.nanpercentile(fit1[:, 'fwhm_arc'],10),
np.nanmedian(fit1[:, 'fwhm_arc_err'])))

add_data('fwhm-pix-2', od.array(np.nanpercentile(fit2[:, 'fwhm_pix'],10),
np.nanmedian(fit2[:, 'fwhm_err'])))
add_data('fwhm-arc-2', od.array(np.nanpercentile(fit2[:, 'fwhm_arc'],10),
np.nanmedian(fit2[:, 'fwhm_arc_err'])))


# flux
flux = od.nanmean(od.array(fitM[:, 'aperture_flux'],
fitM[:, 'aperture_flux_err']))
flux = od.array(np.nanmedian(fitM[:, 'aperture_flux']),
np.nanmedian(fitM[:, 'aperture_flux_err']))
add_data('flux', flux)

# extinction
fluxR = od.nanmean(od.array(fitRM[:, 'aperture_flux'],
fitRM[:, 'aperture_flux_err']))
fluxR = od.array(np.nanmedian(fitRM[:, 'aperture_flux']),
np.nanmedian(fitRM[:, 'aperture_flux_err']))
add_data('extinction', -2.5 * od.log10(flux / fluxR))

# background
add_data('background', od.nanmean(
od.array(fitM[:, 'aperture_background'],
fitM[:, 'aperture_background_err'])))
add_data('background', od.array(
np.nanmedian(fitM[:, 'aperture_background']),
np.nanmedian(fitM[:, 'aperture_background_err'])))


stats['odometer_nb'] = self.odometer_nb
Expand Down Expand Up @@ -436,5 +438,5 @@ def get(self, dataset, no_error=True):
elif no_error:
return None
else:
self._print_error('{} not in reference file'.format(dataset))
raise StandardError('{} not in reference file'.format(dataset))

5 changes: 2 additions & 3 deletions iris/utils.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,5 @@ def send_msg_to_daemon(msg, port):
s.connect((socket.gethostname(), port))
s.send(msg.encode('ascii'))
s.close()
except Exception, e:
print 'Error on sending {} to listener daemon on port {}: {}'.format(
msg, port, e)
except:
raise StandardError('Error on sending {} to listener daemon on port {}: {}'.format(msg, port, e))
17 changes: 13 additions & 4 deletions iris/viewer.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@
import socket
import threading
import gtk
import gobject
gobject.threads_init()
import os
from orb.core import HDFCube
from orb.astrometry import StarsParams
from stats import ReferenceFile

import logging
import warnings

class IrisViewer(BaseViewer):
"""Iris Viewer class."""
Expand Down Expand Up @@ -104,7 +107,7 @@ def _get_hplugins(self):
stats_tv.append_column(col_value)
stats_tv.append_column(col_err)

stats_tv.set_size_request(200,-1)
stats_tv.set_size_request(220,-1)
sw.add(stats_tv)
statsbox.pack_start(sw, fill=True, expand=True)

Expand Down Expand Up @@ -132,6 +135,7 @@ def _start_listener_daemon(self, daemon_port=9000):
s.close()
"""
def _listen():
gobject.threads_init()
stop = False
while not stop:
# establish connection with client socket
Expand All @@ -144,9 +148,13 @@ def _listen():
if os.path.abspath(path) == os.path.abspath(
self.filepath):
if not self._lock:
self._reload_file()
gobject.idle_add(self._reload_file)
if self.image_region is not None:
gobject.idle_add(self._on_select_region_cb,self.region)
#self._reload_file()
else:
self.load_file(path)
gobject.idle_add(self.load_file,path)
#self.load_file(path)
elif msg == 'stop':
stop = True
clientSocket.close()
Expand All @@ -157,6 +165,7 @@ def _listen():
socket.SOCK_STREAM)
s.bind((socket.gethostname(), self.daemon_port))
s.listen(5)
#gobject.threads_init()
self.daemon = threading.Thread(target=_listen)
self.daemon.daemon = True
self.daemon.start()
Expand Down
34 changes: 26 additions & 8 deletions scripts/iris
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ import orb.version
import iris.utils
import traceback
import os
from orb.core import Logger
import warnings

if not os.path.exists(iris.constants.DATA_PREFIX):
os.makedirs(iris.constants.DATA_PREFIX)

stdout_path = os.path.join(iris.constants.DATA_PREFIX, 'iris.stdout')
stderr_path = os.path.join(iris.constants.DATA_PREFIX, 'iris.stderr')
log_path = os.path.join(iris.constants.DATA_PREFIX, 'iris.log')

# stdout and stderr are redirected to a logfile
sys.stdout = open(stdout_path, 'a')
Expand Down Expand Up @@ -77,6 +80,14 @@ def main(args):
results_list.append(str(np.nan))
sys.stdout.write(' '.join(results_list) + '\n')

# start and config logging
try:
logger = Logger(debug=args.debug)
except AttributeError:
logger = Logger(debug=False)

logger.start_file_logging(logfile_path=log_path)

# Init Iris
try:
if args.debug:
Expand All @@ -87,17 +98,11 @@ def main(args):
proc = iris.iris.Iris(
args.cam1_image_path,
force_refresh=args.force_refresh,
data_prefix=iris.constants.DATA_PREFIX,
no_log=True)
data_prefix=iris.constants.DATA_PREFIX)

# Run Stats
results = proc.run_stats()

# Update viewer
iris.utils.send_msg_to_daemon(
'update {}'.format(proc._get_outcube_path(1, absolute=True)),
args.port)

# write results on stdout
sys.stdout = sys.__stdout__
print_results(results)
Expand All @@ -108,7 +113,17 @@ def main(args):
except KeyboardInterrupt, e:
stop_on_error(args.debug, e)


# Update the viewer if present. This has been moved out of the first exception
try:
# Update viewer
iris.utils.send_msg_to_daemon(
'update {}'.format(proc._get_outcube_path(1, absolute=True)),
args.port)
except:
warnings.warn("Could not refresh viewer. Make sure the viewer is started and listening to port %d"%args.port)



sys.exit(0)


Expand All @@ -118,6 +133,9 @@ def main(args):

if __name__ == "__main__":

#import pydevd
#pydevd.settrace('localhost', port=8888, stdoutToServer=True, stderrToServer=True, suspend=False)

# Create the parser class and the command line options
parser = ArgumentParser(
version=('IRIS-version: {}, ORB-version: {}'.format(
Expand Down
Loading