Ejemplo n.º 1
0
def dqm_check_single(n):
    prev_time = start_time
    is_dqm_zero = np.ones(ni, dtype=bool)
    hdu_r = fits.open(work_dir + 'fits/best_single/' + single_dqm_fn[k][2])
    for ii in range(0, ni):
        # read the celestial coordinate
        cel_coord = [[sex_cat_r[galaxy_r]['ALPHA_J2000'][ii+n*ni],
                      sex_cat_r[galaxy_r]['DELTA_J2000'][ii+n*ni]], [0, 0]]
        # sky_coord = SkyCoord(arr_for_coord['ALPHA_J2000'][i],
        #                      arr_for_coord['DELTA_J2000'][i], unit='deg')
        # for every CCD

        # lock.acquire()
        # try:
        for jj in range(1, len(hdu_r)):
            # read WCS
            w = wcs.WCS(hdu_r[jj].header)
            pixcrd = w.wcs_world2pix(cel_coord, 1)
            # if w.footprint_contains(sky_coord):
            if (pixcrd[0][0] > 0) & (pixcrd[0][0] < hdu_r[jj].shape[1]) & \
                    (pixcrd[0][1] > 0) & (pixcrd[0][1] < hdu_r[jj].shape[0]):
                dqm_fits = hdu_r[jj].data
                # check the value of DQM
                if dqm_fits[int(pixcrd[0][1])][int(pixcrd[0][0])] % 128:
                    # toggle on saturated bool array
                    is_dqm_zero[ii] = False
        # finally:
        #     lock.release()
        if ii % 1000 == 0:
            print("--- %06.2f minutes ---" % ((time.time() - prev_time) / 60.0))
            print("--- %d / %d - %d (single r)---" % (ii, n*ni, (n+1)*ni))
            my_module.print_time()
            prev_time = time.time()
    hdu_r.close()
    return is_dqm_zero
def dqm_check_single(n):
    prev_time = start_time
    is_dqm_zero = np.ones(ni, dtype=bool)
    hdu_r = fits.open(work_dir + 'fits/best_single/' + single_dqm_fn[k][2])
    for ii in range(0, ni):
        # read the celestial coordinate
        cel_coord = [[sex_cat_r[criteria_r]['ALPHA_J2000'][ii+n*ni],
                      sex_cat_r[criteria_r]['DELTA_J2000'][ii+n*ni]], [0, 0]]

        for jj in range(1, len(hdu_r)):
            # read WCS
            w = wcs.WCS(hdu_r[jj].header)
            pixcrd = w.wcs_world2pix(cel_coord, 1)
            # if w.footprint_contains(sky_coord):
            if (pixcrd[0][0] > 0) & (pixcrd[0][0] < hdu_r[jj].shape[1]) & \
                    (pixcrd[0][1] > 0) & (pixcrd[0][1] < hdu_r[jj].shape[0]):
                dqm_fits = hdu_r[jj].data
                # check the value of DQM
                if k == 0:      # Somehow A754 has value 7 (cosmic ray) in galaxies
                    if dqm_fits[int(pixcrd[0][1])][int(pixcrd[0][0])] % 7:
                        # toggle on saturated bool array
                        is_dqm_zero[ii] = False
                else:           # somehow other clusters have value 128 (?) in galaxies
                    if dqm_fits[int(pixcrd[0][1])][int(pixcrd[0][0])] % 128:
                        # toggle on saturated bool array
                        is_dqm_zero[ii] = False

        if ii % 1000 == 0:
            print("--- %06.2f minutes ---" % ((time.time() - prev_time) / 60.0))
            print("--- %d / %d - %d (single r)---" % (ii, n*ni, (n+1)*ni))
            my_module.print_time()
            prev_time = time.time()
    hdu_r.close()
    return is_dqm_zero
                ref_r['FROM_WHERE']
                [i]) else 'green'  # red for stack green for short
            # color = 'darkorange'

            # regFile.writelines("j2000; ellipse({:12.7f}, {:12.7f}, {:7.3f}\", {:7.3f}\", {:7.3f}) #  "
            #                    "color={} \n".format(
            #     coords_r[i].ra.value,
            #     coords_r[i].dec.value,
            #     ref_r['A_WORLD'][i] * 3600 * ref_r['KRON_RADIUS'][i],
            #     ref_r['B_WORLD'][i] * 3600 * ref_r['KRON_RADIUS'][i],
            #     180 - ref_r['THETA_WORLD'][i],
            #     color))

            regFile.writelines(
                "j2000; ellipse({:12.7f}, {:12.7f}, {:7.3f}\", {:7.3f}\", {:7.3f}) # text=\'{}\' "
                "color={} \n".format(
                    coords_r[i].ra.value, coords_r[i].dec.value,
                    ref_r['A_WORLD'][i] * 3600 * ref_r['KRON_RADIUS'][i],
                    ref_r['B_WORLD'][i] * 3600 * ref_r['KRON_RADIUS'][i],
                    180 - ref_r['THETA_WORLD'][i], i, color))

            if i % 10000 == 0:
                print("--- %06.2f minutes ---" %
                      (((time.time() - prev_time)) / 60.0))
                print("--- %d / %d (write cat) ---" % (i, num_all))
                my_module.print_time()
                prev_time = time.time()

    print(f"--- {ab.clusters[k]} Done ---")
    my_module.print_time()
Ejemplo n.º 4
0
#from os import getcwd

#def print_path():
#    print('The execution location: {0}'.format(getcwd()))

## VERSION 4 (Create my_script.py, my_module.py, my_module2.py)

## This is my_script.py

from my_module import print_time
from my_module2 import print_path

#help(print_time)
#print(print_time.__doc__)

print_time(print_path())

## This is my_module.py

#import datetime
#
#def print_time(my_path):
#    a=datetime.datetime.now()
#    print('Execution time: {0}'.format(a))
#    print(my_path)
#    return

## This is my_module2.py

#from os import getcwd