Beispiel #1
0
    def __init__(self, table=None, tooltips=None, name=None, masked=None):
        Table.__init__(self, data=table, masked=masked)

        self.name = name

        # We have to carry internally a raw reference to the
        # table data so as to be able to use vstack() to perform
        # merging. This shouldn't be a problem as long as the
        # LineList instance is regarded as immutable. Which it
        # should be anyways.

        self._table = table

        # each list has associated color, height, and redshift attributes
        self.color = None
        self.height = DEFAULT_HEIGHT
        self.redshift = 0.
        self.z_units = 'z'

        if len(table[WAVELENGTH_COLUMN].data):
            self.wmin = table[WAVELENGTH_COLUMN].data.min()
            self.wmax = table[WAVELENGTH_COLUMN].data.max()
        else:
            self.wmin = self.wmax = None

        # A line list (but not the underlying table) can have
        # tool tips associated to each column.
        self.tooltips = tooltips
Beispiel #2
0
    def __init__(self, table=None, tooltips=None, name=None, masked=None):
        Table.__init__(self, data=table, masked=masked)

        self.name = name

        # We have to carry internally a raw reference to the
        # table data so as to be able to use vstack() to perform
        # merging. This shouldn't be a problem as long as the
        # LineList instance is regarded as immutable. Which it
        # should be anyways.

        self._table = table

        # each list has associated color, height, and redshift attributes
        self.color = None
        self.height = DEFAULT_HEIGHT
        self.redshift = 0.
        self. z_units = 'z'

        if len(table[WAVELENGTH_COLUMN].data):
            self.wmin = table[WAVELENGTH_COLUMN].data.min()
            self.wmax = table[WAVELENGTH_COLUMN].data.max()
        else:
            self.wmin = self.wmax = None

        # A line list (but not the underlying table) can have
        # tool tips associated to each column.
        self.tooltips = tooltips
Beispiel #3
0
    def __init__(self, x, y, var=None, names=None, debug=False):
        """

        Reads in the data, which can be expressed as y = y(x).

        """
        """ Set up the default names """
        if names is None:
            if var is None:
                names = ['x', 'y']
            else:
                names = ['x', 'y', 'var']
        if (debug):
            print(names)
            print('Length of x vector: %d' % x.size)
            print('Length of y vector: %d' % y.size)
        """ Link to the inherited class """
        if var is None:
            Table.__init__(self, [x, y], names=names)
        else:
            Table.__init__(self, [x, y, var], names=names)
        """ Assign simple names to the columns """
        self.x = self[self.colnames[0]]
        self.y = self[self.colnames[1]]
        if var is not None:
            self.var = self[self.colnames[2]]
        else:
            self.var = None
    def __init__(self, *args, **kwargs):
        """Initialize the object."""
        Table.__init__(self, *args, **kwargs)
        self.calibration_coeffs = {}
        self.calibration_uncerts = {}
        self.calibration = {}
        names = [
            "Dir", "File", "Scan Type", "Source", "Chan", "Feed", "Time",
            "Frequency", "Bandwidth", "Counts", "Counts Err", "Width",
            "Width Err", "Flux", "Flux Err", "Elevation", "Azimuth",
            "Flux/Counts", "Flux/Counts Err", "Flux Integral/Counts",
            "Flux Integral/Counts Err", "Calculated Flux",
            "Calculated Flux Err", "RA", "Dec", "Fit RA", "Fit Dec", "RA err",
            "Dec err"
        ]

        dtype = [
            'S200', 'S200', 'S200', 'S200', 'S200', np.int, np.double,
            np.float, np.float, np.float, np.float, np.float, np.float,
            np.float, np.float, np.float, np.float, np.float, np.float,
            np.float, np.float, np.float, np.float, np.float, np.float,
            np.float, np.float, np.float, np.float
        ]

        for n, d in zip(names, dtype):
            if n not in self.keys():
                self.add_column(Column(name=n, dtype=d))
Beispiel #5
0
    def __init__(self, target):
        self.target = target
        tab = Table.read(astrom_data[self.target])
        Table.__init__(self, tab)

        self['name'] = self['name'].astype('U20')

        return
Beispiel #6
0
 def __init__(self, *args, **kwargs):
     """
     Parameters
     ----------
     *args, **kwargs: Same used for astropy tables
     """
     APtable.__init__(self, *args, **kwargs)
     metakwargs = kwargs['meta'] if 'meta' in kwargs else {}
     metawkargs = {} if metakwargs is None else metakwargs
     self.meta = GCMetaData(**metakwargs)
Beispiel #7
0
    def __init__(self, target):
        self.target = target
        tab = Table.read(astrom_data[self.target])
        Table.__init__(self, tab)

        self['name'] = self['name'].astype('U20')
        self.cut = False  # Tracks whether the data has been cut or not
        self.time_cut = time_cuts[target]

        return
Beispiel #8
0
    def __init__(self, table=None, name=None, masked=None):
        Table.__init__(self, data=table, masked=masked)

        self.name = name

        # We have to carry internally a raw reference to the
        # table data so as to be able to use vstack() to perform
        # merging. This shouldn't be a problem as long as the
        # LineList instance is regarded as immutable. Which it
        # should be anyways.

        self._table = table
Beispiel #9
0
 def _init(self, *args, **kwargs):
     """Line table initializer shared between all LineTable classes."""
     names = kwargs.pop('names', None)
     assert names is not None
     assert len(names) == len(args)
     dtype = kwargs.pop('dtype', (np.float,)*len(args))
     assert len(dtype) == len(args)
     Table.__init__(self,
                    args + (np.zeros((args[0].size,)),)*3,
                    names=names+('fit', 'id', 'resid'),
                    dtype=dtype+(np.float,)*3,
                    masked=True)
     self.meta['class'] = self.__class__.__name__
     self.meta['id.mask_value'] = self['id'].fill_value
     self.mask['id'] = self.mask['resid'] = True
     self.meta['indep'] = names[:-1]
     if kwargs:
         self.meta.update(kwargs)
Beispiel #10
0
 def _init(self, *args, **kwargs):
     """Line table initializer shared between all LineTable classes."""
     names = kwargs.pop('names', None)
     assert names is not None
     assert len(names) == len(args)
     dtype = kwargs.pop('dtype', (np.float, ) * len(args))
     assert len(dtype) == len(args)
     Table.__init__(self,
                    args + (np.zeros((args[0].size, )), ) * 3,
                    names=names + ('fit', 'id', 'resid'),
                    dtype=dtype + (np.float, ) * 3,
                    masked=True)
     self.meta['class'] = self.__class__.__name__
     self.meta['id.mask_value'] = self['id'].fill_value
     self.mask['id'] = self.mask['resid'] = True
     self.meta['indep'] = names[:-1]
     if kwargs:
         self.meta.update(kwargs)
 def __init__(self, *args, **kwargs):
     Table.__init__(self, *args, **kwargs)
     self.sn = None
     self.nondetSigmas = 3.
     self.groupby = {'filt', 'filter', 'source'}
     self.markers = markers.copy()
Beispiel #12
0
 def __init__(self, *args, **kwargs):
     Table.__init__(self, *args, **kwargs)
     self.sn = None
Beispiel #13
0
    def __init__(self, data=None, config_file=None, norefilt=True,
                 interactive=False, nosave=False, debug=False,
                 freqsplat=None, nofilt=False, nosub=False, avoid_regions=None,
                 save_spectrum=False, **kwargs):
        """Load a Scan object

        Parameters
        ----------
        data : str or None
            data can be one of the following: None, in which case an empty Scan
            object is created; a FITS or HDF5 archive, containing an on-the-fly
            or cross scan in one of the accepted formats; another `Scan` or
            `astropy.Table` object
        config_file : str
            Config file containing the parameters for the images and the
            directories containing the image and calibration data
        norefilt : bool
            If an HDF5 archive is present with the same basename as the input
            FITS file, do not re-run the filtering (default True)
        freqsplat : str
            See :class:`srttools.scan.interpret_frequency_range`
        nofilt : bool
            See :class:`srttools.scan.clean_scan_using_variability`
        nosub : bool
            Do not run the baseline subtraction.

        Other Parameters
        ----------------
        kwargs : additional arguments
            These will be passed to `astropy.Table` initializer
        """
        if config_file is None:
            config_file = get_config_file()

        if isinstance(data, Table):
            Table.__init__(self, data, **kwargs)
        elif data is None:
            Table.__init__(self, **kwargs)
            self.meta['config_file'] = config_file
            self.meta.update(read_config(self.meta['config_file']))
        else:  # if data is a filename
            h5name = root_name(data) + '.hdf5'
            if os.path.exists(h5name) and norefilt:
                # but only if the modification time is later than the
                # original file (e.g. the fits file was not modified later)
                if os.path.getmtime(h5name) > os.path.getmtime(data):
                    data = h5name
            if debug:
                logging.info('Loading file {}'.format(data))
            table = read_data(data)
            Table.__init__(self, table, masked=True, **kwargs)
            if not data.endswith('hdf5'):
                self.meta['filename'] = os.path.abspath(data)
            self.meta['config_file'] = config_file

            self.meta.update(read_config(self.meta['config_file']))

            self.check_order()

            self.clean_and_splat(freqsplat=freqsplat, nofilt=nofilt,
                                 noise_threshold=self.meta['noise_threshold'],
                                 debug=debug, save_spectrum=save_spectrum)

            if interactive:
                self.interactive_filter()

            if (('backsub' not in self.meta.keys() or
                    not self.meta['backsub'])) and not nosub:
                logging.info('Subtracting the baseline')
                self.baseline_subtract(avoid_regions=avoid_regions,
                                       plot=debug)

            if not nosave:
                self.save()
Beispiel #14
0
 def __init__(self, masked=None):
     Table.__init__(self, names=self.names, dtype=self.dtype, masked=masked)
Beispiel #15
0
    def __init__(self,
                 data=None,
                 norefilt=True,
                 config_file=None,
                 freqsplat=None,
                 nofilt=False,
                 nosub=False,
                 **kwargs):
        """Class obtained by a set of scans.

        Once the scans are loaded, this class contains all functionality that
        will be used to produce (calibrated or uncalibrated) maps with WCS
        information.

        Parameters
        ----------
        data : str or None
            data can be one of the following:
            + a config file, containing the information on the scans to load
            + an HDF5 archive, containing a former scanset
            + another ScanSet or an Astropy Table
        config_file : str
            Config file containing the parameters for the images and the
            directories containing the image and calibration data
        norefilt : bool
            See :class:`srttools.scan.Scan`
        freqsplat : str
            See :class:`srttools.scan.interpret_frequency_range`
        nofilt : bool
            See :class:`srttools.scan.clean_scan_using_variability`
        nosub : bool
            See :class:`srttools.scan.Scan`

        Other Parameters
        ----------------
        kwargs : additional arguments
            These will be passed to Scan initializers

        Examples
        --------
        >>> scanset = ScanSet()  # An empty scanset
        >>> isinstance(scanset, ScanSet)
        True
        """
        if data is None and config_file is None:
            Table.__init__(self, data, **kwargs)
            return
        self.norefilt = norefilt
        self.freqsplat = freqsplat

        if isinstance(data, six.string_types) and data.endswith('hdf5'):
            data = Table.read(data, path='scanset')

            txtfile = data.meta['scan_list_file']

            with open(txtfile, 'r') as fobj:
                self.scan_list = []
                for i in fobj.readlines():
                    self.scan_list.append(i.strip())

        if isinstance(data, Table):
            Table.__init__(self, data, **kwargs)
            if config_file is not None:
                config = read_config(config_file)
                self.meta.update(config)

            self.create_wcs()

        else:  # data is a config file
            config_file = data
            config = read_config(config_file)
            self.meta.update(config)
            self.meta['config_file'] = config_file

            scan_list = \
                self.list_scans()

            scan_list.sort()

            tables = []

            for i_s, s in self.load_scans(scan_list,
                                          freqsplat=freqsplat,
                                          nofilt=nofilt,
                                          nosub=nosub,
                                          **kwargs):

                if 'FLAG' in s.meta.keys() and s.meta['FLAG']:
                    continue
                s['Scan_id'] = i_s + np.zeros(len(s['time']), dtype=np.long)

                ras = s['ra'][:, 0]
                decs = s['dec'][:, 0]

                ravar = (np.max(ras) - np.min(ras)) / np.cos(np.mean(decs))
                decvar = np.max(decs) - np.min(decs)
                s['direction'] = np.array(ravar > decvar, dtype=bool)

                del s.meta['filename']
                del s.meta['calibrator_directories']
                del s.meta['list_of_directories']
                tables.append(s)

            scan_table = Table(vstack(tables))

            Table.__init__(self, scan_table)
            self.scan_list = scan_list

            self.meta['scan_list_file'] = None

            self.analyze_coordinates(altaz=False)

            self.convert_coordinates()

        self.chan_columns = np.array(
            [i for i in self.columns if chan_re.match(i)])
        self.current = None
Beispiel #16
0
 def _initfromtable(self, table):
     """Initializer for table, used by classmethod read"""
     assert {'x', 'peak'}.issubset(table.columns)
     Table.__init__(self, table, masked=True)
     self.mask['id'] = self.mask['resid'] = (
         self['id'] == self.meta['id.mask_value'])
Beispiel #17
0
 def _initfromtable(self, table):
     """Initializer for table, used by classmethod read"""
     assert {'x', 'peak'}.issubset(table.columns)
     Table.__init__(self, table, masked=True)
     self.mask['id'] = self.mask['resid'] = (self['id'] ==
                                             self.meta['id.mask_value'])