예제 #1
0
def load_wedges(
    av_image,
    core_sample,
    wedge_angle=40,
    wedge_radius=10,
    av_image_error=None,
    core_rel_pos=0.1,
    angle_res=1.0,
    wedge_width=3,
):

    region_dict = {}
    core_wedge_angles = {}
    # angles are counter-clockwise from north
    core_wedge_angles = {
        # Taurus
        'G174.40-13.45': 45,
        'G174.70-15.47': 100,
        'G174.05-15.82': 20,
        'G172.93-16.73': 160,
        'G172.12-16.94': 190,
        'G171.14-17.57': 200,
        'G171.49-14.91': 0,
        'G171.00-15.80': 195,
        'G169.32-16.17': 210,
        'G168.10-16.38': 230,
        # Perseus
        'G160.49-16.81': 20,
        'G160.46-17.99': 90,
        'G159.80-18.49': 0,
        'G160.14-19.08': 120,
        'G160.53-19.73': 170,
        'G159.19-20.11': 10,
        'G158.39-20.72': 0,
        'G159.17-21.09': 100,
        'G158.89-21.60': 170,
        'G158.26-21.81': 270,
        # California
        'G168.54-6.22': 100,
        'G168.12-6.42': 0,
        'G166.91-7.76': 60,
        'G165.71-9.15': 180,
        'G165.36-7.51': 90,
        'G164.99-8.60': 250,
        'G164.70-7.63': 40,
        'G164.18-8.84': 290,
        'G164.26-8.39': 0,
        'G164.65-8.12': 140,
    }

    for cloud_name in core_sample:
        #for cloud_name in ('perseus',):
        cloud_df = core_sample[cloud_name]
        gradient_sums_list = []
        for core_name in cloud_df['Name']:
            #for core_name in ('G158.26-21.81',):

            core = cloud_df[cloud_df['Name'] == core_name]

            #print('Calculating optimal angle for core {:s}'.format(core_name))

            # Get center position in pixels
            core_pos = [core['xpix'].values[0], core['ypix'].values[0]][::-1]

            wedge_vertices = myg.create_wedge(
                core_pos,
                wedge_radius,
                wedge_angle,
                center_rel_pos=core_rel_pos,
                width=wedge_width,
            )

            # angle of wedge
            if core_name not in core_wedge_angles:
                core_wedge_angles[core_name] = 0
            angle_ideal = core_wedge_angles[core_name]

            wedge_vertices_rotated = myg.rotate_wedge(wedge_vertices, core_pos,
                                                      angle_ideal)

            region_dict[core_name] = {}
            region_dict[core_name]['xpix'] = wedge_vertices_rotated[:, 1]
            region_dict[core_name]['ypix'] = wedge_vertices_rotated[:, 0]

    return region_dict
def load_wedges(av_image, core_sample, wedge_angle=40, wedge_radius=10,
        av_image_error=None, core_rel_pos=0.1, angle_res=1.0, wedge_width=3,):

    region_dict = {}
    core_wedge_angles = {}
    # angles are counter-clockwise from north
    core_wedge_angles = {
                         # Taurus
                         'G174.40-13.45': 45,
                         'G174.70-15.47': 100,
                         'G174.05-15.82': 20,
                         'G172.93-16.73': 160,
                         'G172.12-16.94': 190,
                         'G171.14-17.57': 200,
                         'G171.49-14.91': 0,
                         'G171.00-15.80': 195,
                         'G169.32-16.17': 210,
                         'G168.10-16.38': 230,
                         # Perseus
                         'G160.49-16.81': 20,
                         'G160.46-17.99': 90,
                         'G159.80-18.49': 0,
                         'G160.14-19.08': 120,
                         'G160.53-19.73': 170,
                         'G159.19-20.11': 10,
                         'G158.39-20.72': 0,
                         'G159.17-21.09': 100,
                         'G158.89-21.60': 170,
                         'G158.26-21.81': 270,
                         # California
                         'G168.54-6.22': 100,
                         'G168.12-6.42': 0,
                         'G166.91-7.76': 60,
                         'G165.71-9.15': 180,
                         'G165.36-7.51': 90,
                         'G164.99-8.60': 250,
                         'G164.70-7.63': 40,
                         'G164.18-8.84': 290,
                         'G164.26-8.39': 0,
                         'G164.65-8.12': 140,
                         }

    for cloud_name in core_sample:
    #for cloud_name in ('perseus',):
        cloud_df = core_sample[cloud_name]
        gradient_sums_list = []
        for core_name in cloud_df['Name']:
        #for core_name in ('G158.26-21.81',):

            core = cloud_df[cloud_df['Name'] == core_name]

            #print('Calculating optimal angle for core {:s}'.format(core_name))

            # Get center position in pixels
            core_pos = [core['xpix'].values[0], core['ypix'].values[0]][::-1]

            wedge_vertices = myg.create_wedge(core_pos,
                                              wedge_radius,
                                              wedge_angle,
                                              center_rel_pos=core_rel_pos,
                                              width=wedge_width,
                                              )

            # angle of wedge
            if core_name not in core_wedge_angles:
                core_wedge_angles[core_name] = 0
            angle_ideal = core_wedge_angles[core_name]

            wedge_vertices_rotated = myg.rotate_wedge(wedge_vertices,
                                                      core_pos,
                                                      angle_ideal)

            region_dict[core_name] = {}
            region_dict[core_name]['xpix'] = wedge_vertices_rotated[:,1]
            region_dict[core_name]['ypix'] = wedge_vertices_rotated[:,0]

    return region_dict
예제 #3
0
def derive_ideal_wedge(av_image,
                       core_sample,
                       wedge_angle=40,
                       wedge_radius=10,
                       av_image_error=None,
                       core_rel_pos=0.1,
                       angle_res=1.0,
                       width=3):

    import mygeometry as myg
    import myimage_analysis as myim
    """
    Parameters
    ----------
    angle_res : float
        Resolution with which to rotate each new box in degrees. 1.0 degree
        gives 360 different box orientations.


    """

    angle_grid = np.arange(0, 360, angle_res)
    region_dict = {}

    for cloud_name in core_sample:
        #for cloud_name in ('perseus',):
        cloud_df = core_sample[cloud_name]
        gradient_sums_list = []
        for core_name in cloud_df['Name']:
            #for core_name in ('G158.26-21.81',):

            core = cloud_df[cloud_df['Name'] == core_name]

            print('Calculating optimal angle for core {:s}'.format(core_name))

            # Get center position in pixels
            core_pos = [core['xpix'].values[0], core['ypix'].values[0]][::-1]

            wedge_vertices = myg.create_wedge(
                core_pos,
                wedge_radius,
                wedge_angle,
                center_rel_pos=core_rel_pos,
                width=wedge_width,
            )

            gradient_sums = np.zeros((len(angle_grid)))

            for i, angle in enumerate(angle_grid):
                wedge_vertices_rotated = myg.rotate_wedge(
                    wedge_vertices, core_pos, angle)

                try:
                    mask = \
                        myg.get_polygon_mask(av_image,
                                             wedge_vertices_rotated)
                    av_image_masked = np.copy(av_image)

                    # extract radial profile weighted by SNR
                    radii, profile = \
                        myim.get_radial_profile(av_image,
                                                binsize=1,
                                                center=core_pos, #[::-1],
                                                #weights=av_image_error,
                                                mask=mask
                                                )

                    if angle == 90:
                        av_image_masked = np.copy(av_image)
                        mask = myg.get_polygon_mask(av_image_masked,
                                                    wedge_vertices)
                        av_image_masked[mask == 0] = np.NaN

                    indices = np.where((radii == radii) & \
                                       (profile == profile))
                    profile, radii = profile[indices], radii[indices]

                    # steeper gradients will have smaller sums
                    gradient_sum = np.sum(np.gradient(profile, radii))
                    gradient_sums[i] = gradient_sum
                except IndexError:
                    gradient_sums[i] = 0.

                gradient_sums_list.append(gradient_sums)

                #print wedge_vertices_rotated

            # find steepest profile and recreate the box mask
            angle_ideal = angle_grid[gradient_sums == np.min(gradient_sums)][0]

            wedge_vertices_rotated = myg.rotate_wedge(wedge_vertices, core_pos,
                                                      angle_ideal)

            region_dict[core_name] = {}
            region_dict[core_name]['xpix'] = wedge_vertices_rotated[:, 1]
            region_dict[core_name]['ypix'] = wedge_vertices_rotated[:, 0]

    return region_dict
def derive_ideal_wedge(av_image, core_sample, wedge_angle=40, wedge_radius=10,
        av_image_error=None, core_rel_pos=0.1, angle_res=1.0, width=3):

    import mygeometry as myg
    import myimage_analysis as myim

    """
    Parameters
    ----------
    angle_res : float
        Resolution with which to rotate each new box in degrees. 1.0 degree
        gives 360 different box orientations.


    """

    angle_grid = np.arange(0, 360, angle_res)
    region_dict = {}

    for cloud_name in core_sample:
    #for cloud_name in ('perseus',):
        cloud_df = core_sample[cloud_name]
        gradient_sums_list = []
        for core_name in cloud_df['Name']:
        #for core_name in ('G158.26-21.81',):

            core = cloud_df[cloud_df['Name'] == core_name]

            print('Calculating optimal angle for core {:s}'.format(core_name))

            # Get center position in pixels
            core_pos = [core['xpix'].values[0], core['ypix'].values[0]][::-1]

            wedge_vertices = myg.create_wedge(core_pos,
                                              wedge_radius,
                                              wedge_angle,
                                              center_rel_pos=core_rel_pos,
                                              width=wedge_width,
                                              )

            gradient_sums = np.zeros((len(angle_grid)))

            for i, angle in enumerate(angle_grid):
                wedge_vertices_rotated = myg.rotate_wedge(wedge_vertices,
                                                          core_pos,
                                                          angle)

                try:
                    mask = \
                        myg.get_polygon_mask(av_image,
                                             wedge_vertices_rotated)
                    av_image_masked = np.copy(av_image)

                    # extract radial profile weighted by SNR
                    radii, profile = \
                        myim.get_radial_profile(av_image,
                                                binsize=1,
                                                center=core_pos, #[::-1],
                                                #weights=av_image_error,
                                                mask=mask
                                                )

                    if angle == 90:
                        av_image_masked = np.copy(av_image)
                        mask = myg.get_polygon_mask(av_image_masked,
                                                    wedge_vertices)
                        av_image_masked[mask==0] = np.NaN

                    indices = np.where((radii == radii) & \
                                       (profile == profile))
                    profile, radii = profile[indices], radii[indices]

                    # steeper gradients will have smaller sums
                    gradient_sum = np.sum(np.gradient(profile, radii))
                    gradient_sums[i] = gradient_sum
                except IndexError:
                    gradient_sums[i] = 0.

                gradient_sums_list.append(gradient_sums)

                #print wedge_vertices_rotated

            # find steepest profile and recreate the box mask
            angle_ideal = angle_grid[gradient_sums == np.min(gradient_sums)][0]

            wedge_vertices_rotated = myg.rotate_wedge(wedge_vertices,
                                                      core_pos,
                                                      angle_ideal)

            region_dict[core_name] = {}
            region_dict[core_name]['xpix'] = wedge_vertices_rotated[:,1]
            region_dict[core_name]['ypix'] = wedge_vertices_rotated[:,0]

    return region_dict