[Python] How can I mask unwanted data for a display_bins() function (using pPXF data)?

Discussão em 'Python' iniciado por Stack, Setembro 2, 2025.

  1. Stack

    Stack Membro Participativo

    first time posting, I am currently working on making a velocity and dispersion array for the galaxy NGC 4684. I have run through all the steps to get a pPXF data, but there is a star (I'm assuming) that is providing a massive discrepancy in my final output (as seen in the kinematics plots provided). Kinematics Plot (V and Sig)

    For reference, this is what the velocity plots should look like (replicated using limits in vmin and vmax) Expected Velocity Plot

    I want to completely mask out that section of data as I will be using this set extensively in further labs.

    Here is my original code in full:

    # Make 1x2 sub plot
    fig, ax = plt.subplots(1,2,figsize=(10,10))

    #
    # Start first plot - Velocity
    #============================
    plt.subplot(121)


    # Subtract off the median (systemic) velocity, so that the rotation is around zero
    ax = display_bins(xpos, ypos, binNum, vpxf-numpy.median(vpxf), vmin=-160, vmax=160)

    # Set labels
    plt.title('Velocity') # Plot title
    plt.ylabel('Arcsec') # y-axis label
    plt.xlabel('Arcsec') # x-axis label

    # Plot colour bar
    cbar = plt.colorbar(ax, fraction=0.05, pad=0.04)
    cbar.ax.get_yaxis().labelpad = 15
    cbar.ax.set_ylabel('km/s', rotation=270)
    #cbar.ax.set_clim(-200,200)

    #cbar = plt.colorbar(fig, fraction=0.05, pad=0.04, vmin=-200, vmax=200)
    #cbar.set_clim(-200, 200) # Set colorbar limits from 20 to 80

    #
    # Start 2nd plot - Dispersion
    #============================
    plt.subplot(122)

    # Call display_bins for the dispersion values
    ax = display_bins(xpos, ypos, binNum, spxf)

    # Insert code to overplot contours here:


    # Titles and colour bar
    plt.title('Dispersion') # y-axis label
    plt.ylabel('Arcsec') # y-axis label
    plt.xlabel('Arcsec') # y-axis label
    cbar = plt.colorbar(ax, fraction=0.05, pad=0.04)
    cbar.ax.get_yaxis().labelpad = 15
    cbar.ax.set_ylabel('km/s', rotation=270)

    # Tweak the spacing
    fig.tight_layout(pad=2.5)

    # Show plots
    plt.show()


    SOLUTION ATTEMPT


    The following is my code I have used to attempt a mask:


    # Start first plot - Velocity
    #============================
    plt.subplot(121)

    fixed_vel = []
    fixed_binNum =[]
    fixed_xpos =[]
    fixed_ypos =[]
    for i in binNum:
    if vpxf-numpy.median(vpxf) > -500:
    fixed_vel.append(vpxf)
    fixed_binNum.append(binNum)
    fixed_xpos.append(xpos)
    fixed_ypos.append(ypos)
    else:
    print(i, xpos,ypos,vpxf)

    fixed_vel = numpy.unique(numpy.array(fixed_vel))
    fixed_vel_med = fixed_vel - numpy.median(fixed_vel)
    fixed_binNum = numpy.array(fixed_binNum)
    fixed_xpos =numpy.array(fixed_ypos)
    fixed_ypos =numpy.array(fixed_xpos)



    Output from else loop:

    2 -20.8 12.0 -73.56390273059304
    2 -20.8 12.0 -73.56390273059304
    3 -20.8 12.8 -51.887747700703116
    3 -20.8 12.8 -51.887747700703116
    5 -20.8 14.4 -74.47643398005997
    2 -20.8 12.0 -73.56390273059304
    2 -20.8 12.0 -73.56390273059304
    3 -20.8 12.8 -51.887747700703116
    3 -20.8 12.8 -51.887747700703116
    5 -20.8 14.4 -74.47643398005997
    5 -20.8 14.4 -74.47643398005997
    0 -21.6 14.4 -60.09910926725628
    1 -21.6 15.2 -51.57607782626809
    18 -19.2 8.8 -41.037816701653114
    18 -19.2 8.8 -41.037816701653114
    6 -20.8 15.2 -66.84680647265044
    6 -20.8 15.2 -66.84680647265044
    7 -20.0 9.6 -59.045807879638694
    18 -19.2 8.8 -41.037816701653114
    6 -20.8 15.2 -66.84680647265044
    6 -20.8 15.2 -66.84680647265044
    36 -18.4 11.2 -45.629206849673224
    36 -18.4 11.2 -45.629206849673224
    36 -18.4 11.2 -45.629206849673224


    As far as I'm aware it does everything I want it to, except the binNum array isn't correct. The following is a readout for each variable used in the display_bins() function:

    ==============original==============
    x 2045
    y 2045
    bin 2045
    unique bin 293
    vel 293
    =============="fixed"==============
    x 2021
    y 2021
    bin 2021
    unique bin 14
    vel 284


    As you can see the unique bins has been reduced massively in the "fixed" values which is causing an error as unique bins !== vel. For some reason the bins getting appended is a massive amount of the same numbers, instead of 2-15 of the same number, as expected.

    If anyone knows a way of masking while keeping the unique bins happy I would very much appreciate it.

    Continue reading...

Compartilhe esta Página