How to use the astropy.table.Table function in astropy

To help you get started, weā€™ve selected a few astropy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zooniverse / Data-digging / scripts_ProjectExamples / ouroboros_galaxyzoo / reduction / gz_reduce.py View on Github external
#     continue
        # if tmp != '':
        #     line = tmp + line
        #     tmp = ''
        if re.search(stub, line) is not None:
            ls = line.strip().split(',', maxsplit=3)
            match = re.match('ObjectId\((.+)\)', ls[0])
            subject_id.append(match.group(1))
            zooniverse_id.append(ls[1])
            metadata = ls[3].replace('""', '"')[1:-1]
            metadata = json.loads(metadata)
            if survey_id_field in metadata.keys():
                survey_id.append(metadata[survey_id_field])
            else:
                survey_id.append(None)
    subjects = Table([np.array(subject_id), np.array(survey_id, dtype=np.str),
                      np.array(zooniverse_id)],
                     names=('subject_id', 'survey_id', 'zooniverse_id'))
    return subjects
github MITHaystack / scikit-dataaccess / skdaccess / astro / kepler / data_fetcher.py View on Github external
break

            bio = BytesIO()
            ftp.retrbinary('RETR ' + filename, bio.write)
            bio.seek(0)

            # Read tar file
            tfile = tfile = TarFile(fileobj=bio)
            member_list = [member for member in tfile.getmembers()]

            # Extract data from tar file
            data_list = []
            for member in member_list:
                file = tfile.extractfile(member)
                fits_data = fits.open(file)
                data = Table(fits_data[1].data).to_pandas()
                data.set_index('CADENCENO',inplace=True)
                data.loc[:,'QUARTER'] = fits_data[0].header['QUARTER']
                data_list.append(data)
            full_data = pd.concat(data_list)
            return_data[kid] = full_data

        try:
            ftp.quit()
        except:
            ftp.close()

        return return_data
github astropy / astrowidgets / astrowidgets / core.py View on Github external
xy_col[mask] = image.wcs.wcspt_to_datapt(radec_col[mask])

            # Fill in RA,DEC from X,Y
            mask = np.isnan(radec_col[:, 0])
            if np.any(mask):
                radec_col[mask] = image.wcs.datapt_to_wcspt(xy_col[mask])

            sky_col = SkyCoord(radec_col[:, 0], radec_col[:, 1], unit='deg')

        # Convert X,Y from 0-indexed to 1-indexed
        if self._pixel_offset != 0:
            xy_col += self._pixel_offset

        # Build table
        if include_skycoord:
            markers_table = Table(
                [xy_col[:, 0], xy_col[:, 1], sky_col],
                names=(x_colname, y_colname, skycoord_colname))
        else:
            markers_table = Table(xy_col, names=(x_colname, y_colname))

        # Either way, add the marker names
        markers_table['marker name'] = marker_name
        return markers_table
github cta-observatory / ctapipe / ctapipe / tools / get_training_params.py View on Github external
"ASTRI": (3, 6),
                         "SCTCam": (3, 6)
                         }

        # Calibrators set to default for now
        self.r1 = HessioR1Calibrator(None, None)
        self.dl0 = CameraDL0Reducer(None, None)

        self.calibrator = CameraDL1Calibrator(None, None, extractor=FullIntegrator(None, None))

        # If we don't set this just use everything
        if len(self.telescopes) < 2:
            self.telescopes = None
        self.source = hessio_event_source(self.infile, allowed_tels=self.telescopes,
                                          max_events=100)
        self.output = Table(names=['EVENT_ID', 'TEL_TYPE', 'AMP', 'WIDTH', 'LENGTH',
                                   'SIM_EN', 'IMPACT'],
                            dtype=[np.int64, np.str, np.float64, np.float64,
                                   np.float64, np.float64, np.float64])
github sdss / marvin / python / marvin / utils / datamodel / dap / base.py View on Github external
max_width (int or None):
                A keyword to pass to ``astropy.table.Table.pprint()`` with the
                maximum width of the table, in characters.

        Returns:
            result (``astropy.table.Table``):
                If ``pprint=False``, returns an astropy table containing
                the name of the model, whether the property has ``ivar`` or
                ``mask``, the units, and a description (if
                ``description=True``). Additonal information such as the
                bintypes, templates, release, etc. is included in
                the metadata of the table (use ``.meta`` to access them).

        """

        model_table = table.Table(
            None, names=['name', 'ivar', 'mask', 'unit', 'description',
                         'db_table', 'db_column', 'fits_extension'],
            dtype=['S20', bool, bool, 'S20', 'S500', 'S20', 'S20', 'S20'])

        if self.parent:
            model_table.meta['release'] = self.parent.release
            model_table.meta['bintypes'] = self.parent.bintypes
            model_table.meta['templates'] = self.parent.templates
            model_table.meta['default_bintype'] = self.parent.default_bintype
            model_table.meta['default_template'] = self.parent.default_template

        for model in self:
            unit = model.unit.to_string()

            model_table.add_row((model.name,
                                 model._extension_ivar is not None,
github astropy / photutils / photutils / psf / photometry.py View on Github external
other parameter in the psf model is free (i.e., the
            ``fixed`` attribute of that parameter is ``False``).

        Returns
        -------
        result_tab : `~astropy.table.Table`
            Astropy table that contains photometry results.
        image : numpy.ndarray
            Residual image.
        """

        result_tab = Table()
        for param_tab_name in self._pars_to_output.keys():
            result_tab.add_column(Column(name=param_tab_name))

        unc_tab = Table()
        for param, isfixed in self.psf_model.fixed.items():
            if not isfixed:
                unc_tab.add_column(Column(name=param + "_unc"))

        y, x = np.indices(image.shape)

        star_groups = star_groups.group_by('group_id')
        for n in range(len(star_groups.groups)):
            group_psf = get_grouped_psf_model(self.psf_model,
                                              star_groups.groups[n],
                                              self._pars_to_set)
            usepixel = np.zeros_like(image, dtype=bool)

            for row in star_groups.groups[n]:
                usepixel[overlap_slices(large_array_shape=image.shape,
                                        small_array_shape=self.fitshape,
github glue-viz / glue / glue / core / data_factories / hdf5.py View on Github external
def visitor(name, item):
        if isinstance(item, h5py.Dataset):
            full_path = item.name
            if item.dtype.kind in ('f', 'i', 'S'):
                offset = item.id.get_offset()
                # If an offset is available, the data is contiguous and we can
                # use memory mapping for efficiency.
                if not memmap or offset is None:
                    arrays[full_path] = item[()]
                else:
                    arrays[full_path] = dict(offset=offset, shape=item.shape, dtype=item.dtype)
            elif item.dtype.kind in ('V',):
                arrays[full_path] = Table.read(item, format='hdf5')
github spel-uchile / Star_Tracker / RPI / StarTracker_RPI.py View on Github external
np_aux2 = np_matched_B2[0][0]
# Define el menor numero como el contador de inicio para la busqueda.
if np_aux1>np_aux2:
    np_cont1 = np_aux2
else:
    np_cont1 = np_aux1
# Crea nueva tabla con las estrellas que hizo match.
np_tabla1 = Table([[], [], []])
# Busqueda de estrellas para agregar a tabla.
for i in range(0, len(np_matched_B1), 1):
    np_cont2 = np_matched_B1[i][0] - np_cont1
    np_tabla1.add_row([new_cat2[np_cont2][0], new_cat2[np_cont2][1], new_cat2[np_cont2][2]])


# Iniciamos arrays vacios.
cat_tran1 = Table([[], [], []])
conv1_largo1 = len(np_tabla1)
# Ciclo donde crea el arreglo de datos transformados.
for index in range (0, conv1_largo1):
    conv1_alpha_d = np_tabla1[index][0]
    conv1_delta_d = np_tabla1[index][1]
    conv1_mag = np_tabla1[index][2]
    # Conversion de grados a radianes.
    conv1_alpha_r = (np.pi/180)*conv1_alpha_d
    conv1_delta_r = (np.pi/180)*conv1_delta_d
    conv1_alpha_0_r = (np.pi/180)*dep1_alpha1
    conv1_delta_0_r = (np.pi/180)*dep1_delta1
    # Calculo de Xi (analogo a RA).
    conv1_xi_up = np.cos(conv1_delta_r)*np.sin(conv1_alpha_r - conv1_alpha_0_r)
    conv1_xi_down = np.sin(conv1_delta_0_r)*np.sin(conv1_delta_r) + np.cos(conv1_delta_0_r)*np.cos(conv1_delta_r)*np.cos(conv1_alpha_r - conv1_alpha_0_r)
    conv1_xi = conv1_xi_up/conv1_xi_down
    # Calculo de Eta (analogo a DEC).
github cta-observatory / ctapipe / ctapipe / io / serializer.py View on Github external
Returns
    -------
    Table: astropy.Table
    """
    names = list()
    columns = list()
    for k, v in writeable_items(container).items():

        v_arr = np.array(v)
        v_arr = v_arr.reshape((1,) + v_arr.shape)
        log.debug("Creating column for item '{0}' of shape {1}".
                  format(k, v_arr.shape))
        names.append(k)
        columns.append(Column(v_arr))

    return Table(data=columns,  # dtypes are inferred by columns
                 names=names,
                 meta=container.meta)
github astrofrog / sedfitter / sedfitter / utils / io.py View on Github external
def read_table(file_name):
    try:
        return Table.read(file_name, format='fits', character_as_bytes=False)
    except TypeError:  # older versions of Astropy
        return Table.read(file_name, format='fits')