Beispiel #1
0
    def run(self, nima=0, **kwargs):
        """Run the offset and comparison
        """
        if nima not in range(self.nimages):
            upipe.print_error(
                "nima not within the range allowed by self.nimages ({0})".
                format(self.nimages))
            return

        # Overwrite the plot option if given
        self.plot = kwargs.pop("plot", self.plot)

        if "extra_pixel" in kwargs:
            extra_pixel = kwargs.pop("extra_pixel", [0., 0.])
            extra_arcsec = pixel_to_arcsec(self.list_muse_hdu[nima],
                                           extra_pixel)
        else:
            extra_arcsec = kwargs.pop("extra_arcsec", [0., 0.])

        # Add the offset from user
        self.shift_arcsecond(extra_arcsec, nima)

        # Compare contours if plot is set to True
        if self.plot:
            self.compare(self.list_offmuse_hdu[nima],
                         self.list_proj_refhdu[nima],
                         nima=nima,
                         **kwargs)
Beispiel #2
0
def chunk_stats(list_data, chunk_size=15):
    """Cut the datasets in chunks and take the median
    Return the set of medians
    """
    ndatasets = len(list_data)

    nchunk_x = np.int(list_data[0].shape[0] // chunk_size - 1)
    nchunk_y = np.int(list_data[0].shape[1] // chunk_size - 1)
    # Check that all datasets have the same size
    med_data = np.zeros((ndatasets, nchunk_x * nchunk_y), dtype=np.float32)
    std_data = np.zeros_like(med_data)

    if not all([d.size for d in list_data]):
        upipe.print_error(
            "Datasets are not of the same size in median_compare")
    else:
        for i in range(0, nchunk_x):
            for j in range(0, nchunk_y):
                for k in range(ndatasets):
                    # Taking the median
                    med_data[k, i * nchunk_y + j] = np.median(
                        list_data[k][i * chunk_size:(i + 1) * chunk_size,
                                     j * chunk_size:(j + 1) * chunk_size])
                    std_data[k, i * nchunk_y + j] = mad_std(
                        list_data[k][i * chunk_size:(i + 1) * chunk_size,
                                     j * chunk_size:(j + 1) * chunk_size])

    return med_data, std_data
Beispiel #3
0
 def _get_table_expo(self, expotype, stage="master"):
     try:
         return getattr(self._dic_tables[stage],
                        self._get_attr_expo(expotype))
     except AttributeError:
         upipe.print_error(
             "No attributed table with expotype {0} and stage {1}".format(
                 expotype, stage))
         return Table()
Beispiel #4
0
 def save_image(self, newfits_name=None, nima=0):
     """Save the newly determined hdu
     """
     if hasattr(self, "list_offmuse_hdu"):
         if newfits_name is None:
             newfits_name = self.list_name_museimages[nima].replace(
                 ".fits", "_shift.fits")
         self.list_offmuse_hdu[nima].writeto(newfits_name, overwrite=True)
     else:
         upipe.print_error("There are not yet any new hdu to save")
Beispiel #5
0
    def open_offset_table(self, name_table=None):
        """Read offset table from fits file
        """
        if name_table is None:
            if not hasattr(self, name_table):
                upipe.print_error("No FITS table name provided, Aborting Open")
                return None, Table()

        if not os.path.isfile(name_table):
            upipe.print_warning("FITS Table does not exist yet"
                                "({0})".format(name_table))
            return False, Table()

        return True, Table.read(name_table)
Beispiel #6
0
    def __init__(self, galaxyname=None, list_pointings=[1]) :
        if galaxyname not in MUSEPIPE_sample.keys() :
            upipe.print_error("ERROR: no Galaxy named {gal} in the defined sample".format(gal=galaxyname))
            return

        # Galaxy name
        upipe.print_info("Initialising Target {name}".format(name=galaxyname))
        self.targetname = galaxyname

        # Info of the pointings and extracting the observing run for each pointing
        self.info_pointings = MUSEPIPE_sample[galaxyname]
        if any([_ not in self.info_pointings.keys() for _ in list_pointings]) :
            upipe.print_error("ERROR: no pointing {0} for the Galaxy".format(list_pointings))
            return
        self.list_pointings = list_pointings
        self.observing_run = [self.info_pointing[_] for _ in self.list_pointings]
Beispiel #7
0
    def save_fits_offset_table(self,
                               name_output_table=None,
                               overwrite=False,
                               suffix=""):
        """Save the Offsets into a fits Table
        """
        if name_out_table is None: name_out_table = self.name_input_table
        self.suffix = suffix
        name_output_table = name_output_table.replace(
            ".fits", "{0}.fits".format(self.suffix))

        exist_table, fits_table = self.open_offset_table(self.name_out_table)
        if exist_table is None:
            upipe.print_error("Save is aborted")
            return

        # Check if RA_OFFSET is there
        if 'RA_OFFSET' in fits_table.columns:
            # if yes, then check if the ORIG column is there
            if 'RA_OFFSET_ORIG' not in fits_table.columns:
                fits_table['RA_OFFSET_ORIG'] = fits_table['RA_OFFSET']
                fits_table['DEC_OFFSET_ORIG'] = fits_table['DEC_OFFSET']
            # if not, just continue
            # as it means the ORIG columns were already done

        # Saving the final values
        fits_table['RA_OFFSET'] = self.total_off_arcsec[:, 0] / 3600.
        fits_table['DEC_OFFSET'] = self.total_off_arcsec[:, 1] / 3600.
        fits_table['RA_CROSS_OFFSET'] = self.cross_off_arcsec[:, 0] / 3600.
        fits_table['DEC_CROSS_OFFSET'] = self.cross_off_arcsec[:, 1] / 3600.

        # Writing it up
        if exist_table and not overwrite:
            upipe.print_warning(
                "Table already exists, but overwrite is set to False")
            upipe.print_warning(
                "If you wish to overwrite the table {0}, "
                "please set overwrite to True".format(name_output_table))
            return

        fits_table.write(self.name_output_table, overwrite=overwrite)
        self.name_output_table = name_output_table
Beispiel #8
0
    def print_offset_fromfits(self, name_table=None):
        """Print out the offset
        """
        exist_table, fits_table = self.open_offset_table(name_table)
        if exist_table is None:
            return

        if ('RA_OFFSET'
                not in fits_table.columns) or ('DEC_OFFSET'
                                               not in fits_table.columns):
            upipe.print_error(
                "Table does not contain 'RA/DEC_OFFSET' columns, Aborting")
            return

        upipe.print_info("Offset recorded in OFFSET_LIST Table")
        upipe.print_info("Total in ARCSEC")
        for i in self.nimages:
            upipe.print_info("Image {0}: "
                             "{1:8.4f} {1:8.4f}".format(
                                 fits_table['RA_OFFSET'] * 3600,
                                 fits_table['DEC_OFFSET'] * 3600.))
Beispiel #9
0
    def run_pipeline(self, list_pointings=[1], fakemode=False, 
            suffix_logfile="logfile", suffix_rcfile="rcfile", suffix_calfile="calfile"):
        """Run the pipeline for all pointings in the list
        """
        if any([_ not in self.info_pointings.keys() for _ in self.list_pointings]) :
            upipe.print_error("ERROR: some pointing are not in "
                "the available list ({0})".format(self.list_pointings))
            return

        # Setting up the suffixes for the files
        self.suffix_logfile = suffix_logfile
        self.suffix_calfile = suffix_calfile
        self.suffix_rcfile = suffix_rcfile

        # Loop on the pointings
        self.pipelines = []
        upipe.print_info("---- Starting the Data Reduction ----")
        self.history = []
        for pointing in list_pointings:

            # Setting up the names of the output files
            logfile = self._get_logfile_name(self.suffix_logfile, pointing)
            calfile = self._get_calfile_name(self.suffix_calfile, pointing)
            rcfile = self._get_rcfile_name(self.suffix_rcfile, pointing)
            
            python_command = ("mypipe = musepipe.MusePipe(galaxyname={0}, "
                    "pointing={1}, rc_filename={2}, cal_filename={3}, "
                    "outlog=None, logfile={4}, fakemode={5}, "
                    "nocache=False)".format(galaxyname, pointing, rcfile, calfile, 
                            logfile, fakemode))
            upipe.print_info("====== START - POINTING {0:2d} ======".format(pointing))
            upipe.print_info(python_command)
            upipe.print_info("====== END   - POINTING {0:2d} ======".format(pointing))
            self.history.append(python_command)
            mypipe = MusePipe(galaxyname=galaxyname, pointing=pointing, 
                    rc_filename=rcfile, cal_filename=calfile, outlog=None, 
                    logfile=logfile, fakemode=fakemode, nocache=False)

            self.pipelines.append(mypipe)
            mypipe.run_all_recipes()