def main(obj, test, mag_min, mag_max, increment, instrument):
    properties = p.object_params_instrument(obj, instrument=instrument)
    output = p.object_output_params(obj=obj, instrument=instrument)
    paths = p.object_output_paths(obj=obj, instrument=instrument)

    synth_path = properties['data_dir'] + 'synthetic/'
    u.mkdir_check(synth_path)
    synth_path = synth_path + 'frb_position/'
    u.mkdir_check(synth_path)

    now = time.Time.now()
    now.format = 'isot'
    synth_path += f'range_{now}/'
    u.mkdir_check(synth_path)

    filters = output['filters']

    for magnitude in np.arange(mag_min, mag_max, increment):
        magnitudes = []
        for i in range(len(filters)):
            magnitudes.append(magnitude)
        test_spec = test + '_' + str(u.round_to_sig_fig(magnitude, 4))
        test_path = synth_path + test_spec + '/'
        ph.insert_synthetic_at_frb(obj=properties,
                                   test_path=test_path,
                                   filters=filters,
                                   magnitudes=magnitudes,
                                   add_path=False,
                                   psf=True,
                                   output_properties=output,
                                   instrument=instrument,
                                   paths=paths)

    p.add_output_path(obj=obj,
                      key='subtraction_image_synth_frb_range',
                      path=synth_path,
                      instrument=instrument)
Exemplo n.º 2
0
def main(obj, test, n, filter_dist, instrument, limit):
    properties = p.object_params_instrument(obj, instrument=instrument)
    burst_properties = p.object_params_frb(obj=obj[:-2])
    output = p.object_output_params(obj=obj, instrument=instrument)
    paths = p.object_output_paths(obj=obj, instrument=instrument)

    z = burst_properties['z']
    mjd_burst = burst_properties['mjd_burst']
    ebv_mw = burst_properties['dust_ebv']

    mjd_obs = properties['mjd']
    synth_path = properties['data_dir'] + 'synthetic/'
    u.mkdir_check(synth_path)
    synth_path = synth_path + 'sn_random/'
    u.mkdir_check(synth_path)

    epoch = mjd_obs - mjd_burst

    f_0 = filter_dist[0]

    hg_ra = burst_properties['hg_ra']
    hg_dec = burst_properties['hg_dec']

    burst_ra = burst_properties['burst_ra']
    burst_dec = burst_properties['burst_dec']

    image_path = paths[f_0 + '_' + properties['subtraction_image']]

    image = fits.open(image_path)

    wcs_info = wcs.WCS(image[0].header)

    burst_x, burst_y = wcs_info.all_world2pix(burst_ra, burst_dec, 0)

    now = time.Time.now()
    now.format = 'isot'
    synth_path += test + '_' + str(now) + '/'
    u.mkdir_check(synth_path)

    filters = output['filters']

    psf_models = []
    for i, f in enumerate(filters):
        sn.register_filter(f=f, instrument=instrument)
        psf_model = fits.open(paths[f[0] + '_psf_model'])
        psf_models.append(psf_model)

    for i in range(n):
        test_spec = test + '_' + str(i)
        test_path = synth_path + test_spec + '/'

        magnitudes = []
        mags_filters, model, x, y, tbl = sn.random_light_curves_type_ia(
            filters=filters,
            image=image,
            hg_ra=hg_ra,
            hg_dec=hg_dec,
            z=z,
            ebv_mw=ebv_mw,
            output_path=test_path,
            output_title=test,
            limit=limit,
            x=burst_x,
            y=burst_y,
            ra=burst_ra,
            dec=burst_dec)
        days = mags_filters['days']

        for f in filters:
            magnitude = sn.magnitude_at_epoch(epoch=epoch,
                                              days=days,
                                              mags=mags_filters[f])
            print(f, 'mag:', magnitude)
            magnitudes.append(magnitude)

        ph.insert_synthetic(x=float(x),
                            y=float(y),
                            obj=properties,
                            test_path=test_path,
                            filters=filters,
                            magnitudes=magnitudes,
                            suffix='sn_random_random_ia',
                            extra_values=tbl,
                            paths=paths,
                            output_properties=output,
                            psf_models=psf_models,
                            instrument=instrument)

    p.add_output_path(obj=obj,
                      key='subtraction_image_synth_sn_random_ia',
                      path=synth_path,
                      instrument=instrument)
Exemplo n.º 3
0
def main(field, destination, epoch, instrument, template_instrument,
         comparison_type):
    if destination[-1] != '/':
        destination = destination + '/'

    p.refresh_params_frbs()
    types = ['normal', 'synth_random', 'synth_frb']
    if comparison_type not in types:
        raise ValueError(comparison_type +
                         ' is not a valid synthetic argument; choose from ' +
                         str(types))
    if comparison_type == 'normal':
        comparison_type = ''
    else:
        comparison_type = '_' + comparison_type

    params = p.object_params_frb(field)
    u.mkdir_check(f'{params["data_dir"]}subtraction/')
    destination_path = f'{params["data_dir"]}subtraction/{destination}/'
    u.mkdir_check(destination_path)

    comparison_title = f'{field}_{epoch}'

    comparison_paths = p.object_output_paths(obj=comparison_title,
                                             instrument=instrument)
    comparison_params = p.object_params_instrument(obj=comparison_title,
                                                   instrument=instrument)

    params = p.object_params_frb(field)
    template_epoch = params['template_epoch_' + template_instrument.lower()]

    template_title = f'{field}_{template_epoch}'
    template_paths = p.object_output_paths(obj=template_title,
                                           instrument=template_instrument)
    template_outputs = p.object_output_params(obj=template_title,
                                              instrument=template_instrument)
    template_params = p.object_params_instrument(
        obj=template_title, instrument=template_instrument)

    filters = params['filters']
    for f in filters:

        values = {}

        f_0 = f[0]
        destination_path_filter = f'{destination_path}{f}/'
        u.mkdir_check(destination_path_filter)

        # COMPARISON IMAGE:

        comparison_image_name = comparison_params[
            'subtraction_image'] + comparison_type

        # Get path to comparison image from parameter .yaml file
        if f'{f_0}_{comparison_image_name}' in comparison_paths:
            comparison_origin = comparison_paths[
                f'{f_0}_{comparison_image_name}']
        elif f'{f_0.lower()}_{comparison_image_name}' in comparison_paths:
            comparison_origin = comparison_paths[
                f'{f_0.lower()}_{comparison_image_name}']
        else:
            raise ValueError(
                f'{f_0.lower()}_{comparison_image_name} not found in {comparison_title} paths'
            )

        comparison_destination = f'{comparison_title}_comparison.fits'

        if comparison_type != '':
            shutil.copyfile(
                comparison_origin.replace('.fits',
                                          '.csv'), destination_path_filter +
                comparison_destination.replace('.fits', '.csv'))

        print('Copying comparison image')
        print('From:')
        print('\t', comparison_origin)

        print('To:')
        print(f'\t {destination_path}{f}/{comparison_destination}')
        shutil.copy(
            comparison_params['data_dir'] + 'output_values.yaml',
            f'{destination_path}{f}/{comparison_title}_comparison_output_values.yaml'
        )
        shutil.copy(
            comparison_params['data_dir'] + 'output_values.json',
            f'{destination_path}{f}/{comparison_title}_comparison_output_values.json'
        )
        shutil.copy(comparison_origin,
                    f'{destination_path}{f}/{comparison_destination}')
        values['comparison_file'] = comparison_origin

        # TEMPLATE IMAGE

        if template_instrument != 'FORS2' and template_instrument != 'XSHOOTER':
            f_0 = f_0.lower()

        template_image_name = template_params[
            'subtraction_image'] + comparison_type
        if f'{f_0}_{template_image_name}' in template_paths:
            template_origin = template_paths[f'{f_0}_{template_image_name}']
        elif f'{f_0.lower()}_{template_image_name}' in template_paths:
            template_origin = template_paths[
                f'{f_0.lower()}_{template_image_name}']
        else:
            raise ValueError(
                f'{f_0.lower()}_{template_image_name} not found in {template_title} paths'
            )
        fwhm_template = template_outputs[f_0 + '_fwhm_pix']
        template_destination = f'{template_title}_template.fits'

        print('Copying template')
        print('From:')
        print('\t', template_origin)
        print('To:')
        print(f'\t {destination_path}{f}/{template_destination}')
        shutil.copy(
            template_params['data_dir'] + 'output_values.yaml',
            f'{destination_path}{f}/{template_title}_template_output_values.yaml'
        )
        shutil.copy(
            template_params['data_dir'] + 'output_values.json',
            f'{destination_path}{f}/{template_title}_template_output_values.json'
        )
        shutil.copy(template_origin,
                    f'{destination_path}{f}/{template_destination}')
        values['template_file'] = comparison_origin

        p.add_params(f'{destination_path}{f}/output_values.yaml', values)
Exemplo n.º 4
0
def plot_galaxy(fig: plt.figure, data_title: str, instrument: str, f: str, ra: float, dec: float,
                frame: Union[int, float], world_frame: bool = False,
                n: int = 1, n_x: int = 1, n_y: int = 1,
                cmap: str = 'viridis', show_cbar: bool = False, stretch: str = 'sqrt', vmin: float = None,
                vmax: float = None,
                show_filter: bool = True, show_instrument: bool = False,
                show_grid: bool = False,
                image_name: str = 'astrometry_image',
                object_name: str = None, ticks: int = None, interval: str = 'minmax',
                show_coords=True,
                reverse_y=False):
    instrument = instrument.lower()
    instruments = {'fors2': 'FORS2', 'imacs': 'IMACS', 'xshooter': 'X-shooter', 'gmos': 'GMOS'}

    if instrument == 'imacs':
        f_0 = f
    else:
        f_0 = f[0]

    epoch_properties = p.object_params_instrument(obj=data_title, instrument=instrument)
    paths = p.object_output_paths(obj=data_title, instrument=instrument)

    if 'sdss' in image_name:
        instrument_formal = 'SDSS'
    elif 'des' in image_name:
        instrument_formal = 'DES'
    else:
        instrument_formal = instruments[instrument]

    print(f_0)
    print(image_name)
    print(f_0 + '_' + image_name)
    if f_0 + '_' + image_name in paths:
        path = paths[f_0 + '_' + image_name]
    elif f_0 + '_' + image_name in epoch_properties:
        path = epoch_properties[f_0 + '_' + image_name]
    else:
        raise ValueError(f'No path for {f_0}_{image_name} found.')

    title = object_name
    if title is None:
        title = ''
        if show_instrument:
            title += f'({instrument_formal}'
        if show_filter:
            if instrument == 'imacs':
                title += f'${f[-1]}$-band'
            else:
                title += f'${f_0}$-band'

    else:
        if show_filter:
            if instrument == 'imacs':
                title += f' (${f[-1]}$-band)'
            else:
                title += f' (${f_0}$-band)'
        if show_instrument:
            title = title.replace('(', f'({instrument_formal}, ')

    plot, hdu_cut = plot_subimage(fig=fig, hdu=path, ra=ra, dec=dec,
                                  frame=frame, world_frame=world_frame, title=title,
                                  n=n, n_x=n_x, n_y=n_y,
                                  cmap=cmap, show_cbar=show_cbar, stretch=stretch, vmin=vmin,
                                  vmax=vmax,
                                  show_grid=show_grid,
                                  ticks=ticks, interval=interval,
                                  show_coords=show_coords,
                                  reverse_y=reverse_y)

    return plot, hdu_cut
Exemplo n.º 5
0
def main(obj, test, n, mag_lower, mag_upper, colour_upper, colour_lower):
    properties = p.object_params_fors2(obj)
    output = p.object_output_params(obj=obj, instrument='FORS2')
    paths = p.object_output_paths(obj)
    burst_properties = p.object_params_frb(obj[:-2])

    synth_path = properties['data_dir'] + 'synthetic/'

    u.mkdir_check(synth_path)
    synth_path = synth_path + 'random/'
    u.mkdir_check(synth_path)
    now = time.Time.now()
    now.format = 'isot'
    test = str(now) + '_' + test
    test_path = synth_path + test + '/'
    u.mkdir_check(test_path)

    filters = {}
    bluest = None
    bluest_lambda = np.inf
    for f in output['filters']:
        filter_properties = p.filter_params(f=f, instrument='FORS2')
        filters[f] = filter_properties
        lambda_eff = filter_properties['lambda_eff']
        if lambda_eff < bluest_lambda:
            bluest_lambda = lambda_eff
            bluest = f

    # Insert random sources in the bluest filter.

    f_0 = bluest[0]
    output_properties = p.object_output_params(obj)
    fwhm = output_properties[f_0 + '_fwhm_pix']
    zeropoint, _, airmass, _ = ph.select_zeropoint(obj,
                                                   bluest,
                                                   instrument='fors2')

    base_path = paths[f_0 + '_subtraction_image']

    output_path = test_path + f_0 + '_random_sources.fits'
    _, sources = ph.insert_random_point_sources_to_file(file=base_path,
                                                        fwhm=fwhm,
                                                        output=output_path,
                                                        n=n,
                                                        airmass=airmass,
                                                        zeropoint=zeropoint)

    p.add_output_path(obj=obj,
                      key=f_0 + '_subtraction_image_synth_random',
                      path=output_path)

    # Now insert sources at the same positions in other filters, but with magnitudes randomised.
    for f in filters:
        if f != bluest:
            f_0 = f[0]
            output_properties = p.object_output_params(obj)
            fwhm = output_properties[f_0 + '_fwhm_pix']
            zeropoint, _, airmass, _ = ph.select_zeropoint(obj,
                                                           f,
                                                           instrument='fors2')

            base_path = paths[f_0 + '_subtraction_image']

            mag = np.random.uniform(mag_lower, mag_upper, size=n)

            output_path = test_path + f_0 + '_random_sources.fits'
            ph.insert_point_sources_to_file(file=base_path,
                                            fwhm=fwhm,
                                            output=output_path,
                                            x=sources['x_0'],
                                            y=sources['y_0'],
                                            mag=mag,
                                            airmass=airmass,
                                            zeropoint=zeropoint)

            p.add_output_path(obj=obj,
                              key=f_0 + '_subtraction_image_synth_random',
                              path=output_path)
def main(obj, test, n, filter_dist, sn_type, instrument, limit):
    properties = p.object_params_instrument(obj, instrument=instrument)
    burst_properties = p.object_params_frb(obj=obj[:-2])
    output = p.object_output_params(obj=obj, instrument=instrument)
    paths = p.object_output_paths(obj=obj, instrument=instrument)

    z = burst_properties['z']
    mjd_burst = burst_properties['mjd_burst']
    ebv_mw = burst_properties['dust_ebv']

    mjd_obs = properties['mjd']
    synth_path = properties['data_dir'] + 'synthetic/'
    u.mkdir_check(synth_path)
    synth_path = synth_path + 'sn_random/'
    u.mkdir_check(synth_path)

    epoch = mjd_obs - mjd_burst

    f_0 = filter_dist[0]

    hg_ra = burst_properties['hg_ra']
    hg_dec = burst_properties['hg_dec']

    image_path = paths[f_0 + '_' + properties['subtraction_image']]

    image = fits.open(image_path)

    now = time.Time.now()
    now.format = 'isot'
    test += sn_type + '_'
    synth_path += test + str(now) + '/'
    u.mkdir_check(synth_path)

    filters = output['filters']

    if 'FRB190608' in obj:
        limit = 45

    psf_models = []
    for f in filters:
        sn.register_filter(f=f)
        psf_model = fits.open(paths[f[0] + '_psf_model'])
        psf_models.append(psf_model)

    for i in range(n):
        test_spec = test + str(i)
        test_path = synth_path + test_spec + '/'

        magnitudes = []
        mags_filters, model, x, y, tbl = sn.random_light_curves(
            sn_type=sn_type,
            filters=filters,
            image=image,
            hg_ra=hg_ra,
            hg_dec=hg_dec,
            z=z,
            ebv_mw=ebv_mw,
            output_path=test_path,
            output_title=test,
            limit=limit)
        days = mags_filters['days']

        for f in filters:
            magnitude = sn.magnitude_at_epoch(epoch=epoch,
                                              days=days,
                                              mags=mags_filters[f])
            print(f, 'mag:', magnitude)
            magnitudes.append(magnitude)

        ph.insert_synthetic(x=x,
                            y=y,
                            obj=properties,
                            test_path=test_path,
                            filters=filters,
                            magnitudes=magnitudes,
                            suffix='sn_random_random_' + sn_type,
                            extra_values=tbl,
                            paths=paths,
                            output_properties=output,
                            psf_models=psf_models,
                            instrument=instrument)

    p.add_output_path(obj=obj,
                      key='subtraction_image_synth_sn_random_' + sn_type,
                      path=synth_path,
                      instrument=instrument)
Exemplo n.º 7
0
def main(field, destination, epoch, instrument, template_instrument,
         comparison_type):
    if destination[-1] != '/':
        destination = destination + '/'

    # p.refresh_params_frbs()
    # types = ['multi_frb_range', 'multi_sn_models', 'multi_sn_random', 'multi_sn_random_ia', 'multi_sn_random_ib']
    # if comparison_type not in types:
    #     raise ValueError(comparison_type + ' is not a valid multi-synthetic argument; choose from ' + str(types))
    comparison_type = '_' + comparison_type
    type_suffix = comparison_type[7:]

    params = p.object_params_frb(field)
    u.mkdir_check(f'{params["data_dir"]}subtraction/')
    destination_path = f'{params["data_dir"]}subtraction/{destination}/'
    u.mkdir_check(destination_path)

    comparison_title = f'{field}_{epoch}'

    comparison_paths = p.object_output_paths(obj=comparison_title,
                                             instrument=instrument)

    comparison_origin_top = comparison_paths['subtraction_image_synth_' +
                                             type_suffix]
    comparison_tests = os.listdir(comparison_origin_top)

    comparison_params = p.object_params_instrument(obj=comparison_title,
                                                   instrument=instrument)

    params = p.object_params_frb(field)
    template_epoch = params['template_epoch_' + template_instrument.lower()]

    template_title = f'{field}_{template_epoch}'
    template_paths = p.object_output_paths(obj=template_title,
                                           instrument=template_instrument)
    template_outputs = p.object_output_params(obj=template_title,
                                              instrument=template_instrument)
    template_params = p.object_params_instrument(
        obj=template_title, instrument=template_instrument)

    filters = params['filters']

    for test in comparison_tests:

        destination_test = destination_path + test + '/'
        origin_test = comparison_origin_top + test + '/'
        u.mkdir_check(destination_test)

        test_files = os.listdir(origin_test)

        for f in filters:

            for file in filter(lambda fil: fil[:2] != f + '_',
                               os.listdir(origin_test)):
                shutil.copyfile(origin_test + file, destination_test + file)

            values = {}

            f_0 = f[0]
            destination_path_filter = f'{destination_test}{f}/'
            u.mkdir_check(destination_path_filter)

            # COMPARISON IMAGE:

            # Get path to comparison image from parameter .yaml file

            comparison_origin = origin_test + filter(
                lambda file: file[0] == f_0 and file[-5:] == '.fits',
                test_files).__next__()

            comparison_destination = f'{comparison_title}_comparison.fits'

            shutil.copyfile(comparison_origin,
                            destination_path_filter + comparison_destination)
            shutil.copyfile(
                comparison_origin.replace('.fits',
                                          '.csv'), destination_path_filter +
                comparison_destination.replace('.fits', '.csv'))

            print('Copying comparison image from:')
            print('\t', comparison_origin)

            print('To:')
            print(f'\t {destination_test}{f}/{comparison_destination}')
            shutil.copy(
                comparison_params['data_dir'] + 'output_values.yaml',
                f'{destination_test}{f}/{comparison_title}_comparison_output_values.yaml'
            )
            shutil.copy(
                comparison_params['data_dir'] + 'output_values.json',
                f'{destination_test}{f}/{comparison_title}_comparison_output_values.json'
            )
            shutil.copy(comparison_origin,
                        f'{destination_test}{f}/{comparison_destination}')
            values['comparison_file'] = comparison_origin

            if template_instrument != 'FORS2':

                # TEMPLATE IMAGE

                if template_instrument != 'XSHOOTER':
                    f_0 = f_0.lower()

                template_image_name = template_params['subtraction_image']
                if f'{f_0}_{template_image_name}' in template_paths:
                    template_origin = template_paths[
                        f'{f_0}_{template_image_name}']
                elif f'{f_0.lower()}_{template_image_name}' in template_paths:
                    template_origin = template_paths[
                        f'{f_0.lower()}_{template_image_name}']
                else:
                    raise ValueError(
                        f'{f_0.lower()}_{template_image_name} not found in {template_title} paths'
                    )
                fwhm_template = template_outputs[f_0 + '_fwhm_pix']
                template_destination = f'{template_title}_template.fits'

                print('Copying template from:')
                print('\t', template_origin)
                print('To:')
                print(f'\t {destination_test}{f}/{template_destination}')
                shutil.copy(
                    template_params['data_dir'] + 'output_values.yaml',
                    f'{destination_test}{f}/{template_title}_template_output_values.yaml'
                )
                shutil.copy(
                    template_params['data_dir'] + 'output_values.json',
                    f'{destination_test}{f}/{template_title}_template_output_values.json'
                )
                shutil.copy(template_origin,
                            f'{destination_test}{f}/{template_destination}')
                values['template_file'] = comparison_origin

                p.add_params(f'{destination_test}{f}/output_values.yaml',
                             values)
Exemplo n.º 8
0
def plot_galaxy(fig: plt.Figure, data_title: str, instrument: str, f: str, ra: float, dec: float,
                frame: Union[int, float], world_frame: bool = False,
                n: int = 1, n_x: int = 1, n_y: int = 1,
                cmap: str = 'viridis', show_cbar: bool = False, stretch: str = 'sqrt', vmin: float = None,
                vmax: float = None,
                show_filter: bool = True, show_instrument: bool = False,
                show_grid: bool = False,
                image_name: str = 'astrometry_image',
                object_name: str = None, ticks: int = None, interval: str = 'minmax',
                show_coords=True,
                reverse_y=False,
                show_frb=False, ellipse_colour: str = 'white',
                line_width=1.):
    instrument = instrument.lower()
    instruments = {'fors2': 'FORS2', 'imacs': 'IMACS', 'xshooter': 'X-shooter', 'gmos': 'GMOS',
                   'hst': 'Hubble Space Telescope'}

    if instrument == 'imacs':
        f_0 = f
    else:
        f_0 = f[0]

    epoch_properties = p.object_params_instrument(obj=data_title, instrument=instrument)
    paths = p.object_output_paths(obj=data_title, instrument=instrument)

    if 'sdss' in image_name:
        instrument_formal = 'SDSS'
    elif 'des' in image_name:
        instrument_formal = 'DES'
    else:
        instrument_formal = instruments[instrument]

    print(f_0)
    print(image_name)
    print(f_0 + '_' + image_name)
    if f_0 + '_' + image_name in paths:
        path = paths[f_0 + '_' + image_name]
    elif f_0 + '_' + image_name in epoch_properties:
        path = epoch_properties[f_0 + '_' + image_name]
    else:
        raise ValueError(f'No path for {f_0}_{image_name} found.')

    title = object_name
    if title is None:
        title = ''
        if show_instrument:
            title += f'({instrument_formal}'
        if show_filter:
            if instrument == 'imacs':
                title += f'${f[-1]}$-band'
            else:
                title += f'${f_0}$-band'

    else:
        if show_filter:
            if instrument == 'imacs':
                title += f' (${f[-1]}$-band)'
            else:
                title += f' (${f_0}$-band)'
        if show_instrument:
            title = title.replace('(', f'({instrument_formal}, ')

    plot, hdu_cut = plot_subimage(fig=fig, hdu=path, ra=ra, dec=dec,
                                  frame=frame, world_frame=world_frame, title=title,
                                  n=n, n_x=n_x, n_y=n_y,
                                  cmap=cmap, show_cbar=show_cbar, stretch=stretch, vmin=vmin,
                                  vmax=vmax,
                                  show_grid=show_grid,
                                  ticks=ticks, interval=interval,
                                  show_coords=show_coords,
                                  reverse_y=reverse_y,
                                  )

    burst_name = data_title[:data_title.find("_")]
    name = burst_name[3:]
    burst_properties = p.object_params_frb(burst_name)
    burst_ra = burst_properties['burst_ra']
    burst_dec = burst_properties['burst_dec']

    if show_frb is True:
        show_frb = 'quadrature'

    if show_frb == 'all':
        # Statistical
        a, b, theta = am.calculate_error_ellipse(burst_properties, error='statistical')
        plot_gal_params(hdu=hdu_cut, ras=[burst_ra], decs=[burst_dec], a=[a],
                        b=[b],
                        theta=[-theta], colour=ellipse_colour, ls='-')
        # Systematic
        a, b, theta = am.calculate_error_ellipse(burst_properties, error='systematic')
        plot_gal_params(hdu=hdu_cut, ras=[burst_ra], decs=[burst_dec], a=[a],
                        b=[b],
                        theta=[-theta], colour=ellipse_colour, ls='--')
        # Quadrature
        a, b, theta = am.calculate_error_ellipse(burst_properties, error='quadrature')
        plot_gal_params(hdu=hdu_cut, ras=[burst_ra], decs=[burst_dec], a=[a],
                        b=[b],
                        theta=[-theta], colour=ellipse_colour, ls=':')

    elif show_frb is not False:
        a, b, theta = am.calculate_error_ellipse(burst_properties, error=show_frb)
        plot_gal_params(hdu=hdu_cut, ras=[burst_ra], decs=[burst_dec], a=[a],
                        b=[b],
                        theta=[-theta], colour=ellipse_colour, ls='-', lw=line_width)

    return plot, hdu_cut
Exemplo n.º 9
0
def main(obj, test_name, sex_x_col, sex_y_col, sex_ra_col, sex_dec_col,
         sex_flux_col, get_sextractor_names, mag_tol, stars_only,
         star_class_col, star_class_tol, show_plots, mag_range_sex_lower,
         mag_range_sex_upper, pix_tol, separate_chips, write):
    print(separate_chips)

    sextractor_names = p.sextractor_names_psf()  # None to auto-detect

    properties = p.object_params_des(obj=obj)
    outputs = p.object_output_params(obj=obj, instrument='des')
    paths = p.object_output_paths(obj=obj)

    cat_name = 'DES'
    cat_path = properties['data_dir'] + 'des_objects.csv'
    output = properties['data_dir'] + '/3-zeropoint/'
    mkdir_check(output)
    output = output + 'field/'
    mkdir_check(output)

    for fil in properties['filters']:

        f_0 = fil[0]

        f_up = f_0.upper()

        output_path = output + f_0

        cat_zeropoint = 0.
        cat_zeropoint_err = 0.

        now = time.Time.now()
        now.format = 'isot'
        test_name = str(now) + '_' + test_name

        mkdir_check(output_path)
        output_path = output_path + '/' + f_0 + '/'
        mkdir_check(output_path)
        output_path = output_path + '/' + test_name + '/'
        mkdir_check(output_path)

        if not os.path.isdir(output_path):
            os.mkdir(output_path)

        output_path = output_path + test_name + '/'

        if not os.path.isdir(output_path):
            os.mkdir(output_path)

        image_path = properties[
            'data_dir'] + '2-sextractor/' + f_0 + '_cutout.fits'
        sextractor_path = properties[
            'data_dir'] + '2-sextractor/' + f_0 + '_psf-fit.cat'
        # We override here because there's no need to separate the chips if we're using the DES image.
        separate_chips = False
        # pix_tol = 1.
        mag_range_lower = 16
        mag_range_upper = 25

        exp_time = 1.

        print('SExtractor catalogue path:', sextractor_path)
        print('Image path:', image_path)
        print('Catalogue path:', cat_path)
        print('Output:', output_path + test_name)
        print()

        print(cat_zeropoint)

        up = photometry.determine_zeropoint_sextractor(
            sextractor_cat=sextractor_path,
            image=image_path,
            image_name='DES',
            cat_path=cat_path,
            cat_name=cat_name,
            output_path=output_path + "/chip_1/",
            show=show_plots,
            cat_ra_col='RA',
            cat_dec_col='DEC',
            cat_mag_col='WAVG_MAG_PSF_' + f_up,
            sex_ra_col=sex_ra_col,
            sex_dec_col=sex_dec_col,
            sex_x_col=sex_x_col,
            sex_y_col=sex_y_col,
            dist_tol=pix_tol,
            mag_tol=mag_tol,
            flux_column=sex_flux_col,
            mag_range_cat_upper=mag_range_upper,
            mag_range_cat_lower=mag_range_lower,
            mag_range_sex_upper=mag_range_sex_upper,
            mag_range_sex_lower=mag_range_sex_lower,
            stars_only=stars_only,
            star_class_tol=star_class_tol,
            star_class_col=star_class_col,
            exp_time=exp_time,
            get_sextractor_names=get_sextractor_names,
            sextractor_names=sextractor_names,
            cat_type='csv',
            cat_zeropoint=cat_zeropoint,
            cat_zeropoint_err=cat_zeropoint_err,
        )

        if write:
            update_dict = {
                f_0 + '_zeropoint_derived':
                float(up['zeropoint_sub_outliers']),
                f_0 + '_zeropoint_derived_err': float(up['zeropoint_err'])
            }

            p.add_output_values(obj=obj, params=update_dict, instrument='des')