;+
; NAME: spobs__define
;
;
;
; PURPOSE: Definition of the sp (SOT/SP) super class, a subclass of hinobs. 
;          You will work with an object of one of the subclasses sp1dobs or 
;          sp2dobs. 
;
;
;
;
; METHODS: 
;
;
;
; COMMON BLOCKS: none
;
;
;
; WRITTEN: Terje Fredvik, UiO, January 2010
;
;
;
;
; MODIFICATION HISTORY:
;          5. Jan 2011 Terje Fredvik: first working version.
;         11. Jan 2011 Terje Fredvik: cleaned up code
;-

FUNCTION spobs::init, file, destdir=destdir, _ref_extra=extra
  IF self->hinobs::init(file, destdir=destdir, _extra=extra) EQ 0 $
  THEN return,0
  
  return,1 
END


PRO spobs::cleanup
  self->hinobs::cleanup
 
  print,"Cleaning up (spobs)"
END



;; ++++++++++++++++++++++++++++++++++++++++++++++++++++++
;;      <overridden _ensure_properties help methods
;; ++++++++++++++++++++++++++++++++++++++++++++++++++++++

PRO spobs::_ensure_instrument_specific_properties
  self->private
  self->_ensure_nexp
END

PRO spobs::_ensure_nicons 
  self->private 
  self.nicons = n_elements(self->images_indices())
END


;; -----------------------------------------------------
;;      </overridden _ensure_properties help methods
;; -----------------------------------------------------



;; -----------------------------------------------------
;;      <_image_final_touch help methods
;; -----------------------------------------------------
FUNCTION spobs::_final_touch_mask0, im
  self->private
  badpix = where(im EQ 0, nbadpix, complement=goodpix, ncomplement=ngoodpix)
  IF nbadpix GT 0 AND ngoodpix GT 0 THEN im[badpix] = median(im[goodpix])
  im = bytscl(sigrange(im))
  IF nbadpix GT 0 THEN im[badpix] = 0
  return, im
END

FUNCTION spobs::_final_touch_bytscl, im
  self->private
  limit = (abs(min(sigrange(im)))+max(sigrange(im)))/2.
  im = bytscl(im > (-limit) < limit ,/nan)
  return, im
END
;; -----------------------------------------------------
;;      <_/image_final_touch help methods
;; -----------------------------------------------------


;; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;;   <overridden extract_image and other plot_image help methods
;; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
PRO spobs::_cenAndfov, xcen, ycen, fovx, fovy
  self->private
  
  header =  *(self->get(/header))
  xcen = gt_fkw(reform(header[1,*]), 'XCEN')
  ycen = gt_fkw(reform(header[0,*]), 'YCEN')
  fovx = gt_fkw(reform(header[2,*]), 'XCEN')-gt_fkw(reform(header[0,*]), 'XCEN')+$
         gt_fkw(reform(header[0,*]), 'FOVX')
  fovy = gt_fkw(reform(header[0,*]), 'FOVY')
END



;; ---------------------------------------------------------------
;;   <overridden extract_image and other plot_image help methods
;; ---------------------------------------------------------------



PRO spobs::read_header
  self->read_data
END



PRO spobs__define
  INT = 0
  STR = ''
  d = {spobs, $
       nexp: INT,$
       ;nicons: INT, $
       inherits hinobs}
END
