spacetelescope / imexam

imexam is a python tool for simple image examination, and plotting, with similar functionality to IRAF's imexamine
http://imexam.readthedocs.io
BSD 3-Clause "New" or "Revised" License
74 stars 45 forks source link

viewer.imexam() giving inaccurate results from time to time #119

Closed sanast closed 6 years ago

sanast commented 6 years ago

Hi. I am trying to do a radial plot using the 'r' key after loading an image to ds9 .

but from time to time it gives me wrong radial plots . It basically doesn't read the cursor position correctly when using the r key . But it works fine for line and column fit for the same location. This doesn't happen always. I have a lot of three hundred objects loaded from a regions file. I need to check each one to make sure they have a nice PSF .

Following is an example Xc and Yc shown below are recorded for the same star from the two tasks ( r and j keys ). the second one xc=359.537205 yc=8461.496825. is consistent with the ds9 image coordinate and is the correct one. also the Gaussian 1D plot looks fine as expected and radial profile is not correct .

Current image /Users/sandanuwankalawila/Documents/tempA426ppp_2/A426RBCG.fits xc=49.935372 yc=8461.034706 using model: <class 'astropy.modeling.functional_models.Gaussian1D'> Name: Gaussian1D Inputs: (u'x',) Outputs: (u'y',) Fittable parameters: ('amplitude', 'mean', 'stddev') xc=359.537205 yc=8461.496825 (359,8460) mean= 359.48, fwhm= 4.45

Thank you .

sosey commented 6 years ago

Hi @sanast - I'm away at a conference, so my response time may be spotty the next few days.

Try turning off the 2D gaussian fit for centering the radial plots? That's is on by default in order try and get better centering for the radial profile itself. My guess is that the result is spotty because of the signal to noise variation in the stellar profiles themselves.

You can turn off the centering for just the radial profile plot like this:

a=imexam.connect()
a.view(some array)
a.set_plot_pars('r', 'center', False)

you can see what the current settings are for the 'r' key using:

a.rimexam()

Let me know if that fixes the issue or if you run into any other problems?

It sounds like you're doing this interactively with DS9, if you want you can also script the same interaction to loop over all your psfs (if you already have centers) and save the plots, or results to log, see the example here: Example 5: using imexam as a library with no viewer

thanks!

sanast commented 6 years ago

Hi. Sosey

Yes . That fixed the problem .
Thank you so much .

Yes I do have the centers . I will try this . I am relatively new to python. I looked at the example .

I am confused , how to input the third array ( "data “ in your example ). DO I need to read the pixel values from my image using something like PYFITS and input it as an array ?

Thank you again for the quick fix .

On Oct 25, 2017, at 3:35 PM, Megan Sosey notifications@github.com wrote:

Hi @sanast https://github.com/sanast - I'm away at a conference, so my response time may be spotty the next few days.

Try turning off the 2D gaussian fit for centering the radial plots? That's is on by default in order try and get better centering for the radial profile itself. My guess is that the result is spotty because of the signal to noise variation in the stellar profiles themselves.

You can turn off the centering for just the radial profile plot like this:

a=imexam.connect() a.view(some array) a.set_plot_pars('r', 'center', False) you can see what the current settings are for the 'r' key using:

a.rimexam() Let me know if that fixes the issue or if you run into any other problems?

It sounds like you're doing this interactively with DS9, if you want you can also script the same interaction to loop over all your psfs (if you already have centers) and save the plots, or results to log, see the example here: Example 5: using imexam as a library with no viewer http://imexam.readthedocs.io/en/v0.7.1/imexam/examples.html#use-the-imexamine-library-standalone-to-create-plots-without-viewing thanks!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/spacetelescope/imexam/issues/119#issuecomment-339462993, or mute the thread https://github.com/notifications/unsubscribe-auth/AfkQMQi0OnpPi5LiV-eNOAf6jan1kyDuks5sv5uZgaJpZM4QGYZZ.

sanast commented 6 years ago

Hi

I managed to loop through it by reading the image through PYFITS .

But how I can disable again the centering for the radial plot s .

Even it disabled it for interactive sessions it is still TRUE in plots.radial_profile_pars.

plots.radial_profile_pars Out[247]: {'background': [False, 'Subtract background? [bool]'], 'center': [True, 'Solve for center using 2d Gaussian? [bool]'], 'fitplot': [False, 'Overplot profile fit?'], 'fittype': ['Gaussian2D', 'Profile type to fit (Gaussian2D)'], 'function': ['radial_profile'], 'getdata': [False, 'print the plotted data values'], 'magzero': [25.0, 'magnitude zero point'], 'marker': ['o', 'The marker character to use, matplotlib style'], 'pixels': [True, 'Plot all pixels at each radius? (False bins the data)'], 'pointmode': [True, 'plot points instead of lines? [bool]'], 'rplot': [8.0, 'Plotting radius in pixels'], 'skyrad': [10.0, 'Background inner radius in pixels, from center of object'], 'title': [None, 'Title of the plot'], 'width': [5.0, 'Background annulus width in pixels'], 'xlabel': ['Radius', 'The string for the xaxis label'], 'ylabel': ['Flux', 'The string for the yaxis label']}

I am trying this :

plots.radial_profile_pars('center',False)

But it keep giving me the following error massage :

'dict' object is not callable

Even it disabled it in interactive sessions it is still TRUE in plots.radial_profile_pars.

I am sorry , if I am asking too many things .

Thank you .

On Oct 25, 2017, at 3:35 PM, Megan Sosey notifications@github.com wrote:

Hi @sanast https://github.com/sanast - I'm away at a conference, so my response time may be spotty the next few days.

Try turning off the 2D gaussian fit for centering the radial plots? That's is on by default in order try and get better centering for the radial profile itself. My guess is that the result is spotty because of the signal to noise variation in the stellar profiles themselves.

You can turn off the centering for just the radial profile plot like this:

a=imexam.connect() a.view(some array) a.set_plot_pars('r', 'center', False) you can see what the current settings are for the 'r' key using:

a.rimexam() Let me know if that fixes the issue or if you run into any other problems?

It sounds like you're doing this interactively with DS9, if you want you can also script the same interaction to loop over all your psfs (if you already have centers) and save the plots, or results to log, see the example here: Example 5: using imexam as a library with no viewer http://imexam.readthedocs.io/en/v0.7.1/imexam/examples.html#use-the-imexamine-library-standalone-to-create-plots-without-viewing thanks!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/spacetelescope/imexam/issues/119#issuecomment-339462993, or mute the thread https://github.com/notifications/unsubscribe-auth/AfkQMQi0OnpPi5LiV-eNOAf6jan1kyDuks5sv5uZgaJpZM4QGYZZ.

sosey commented 6 years ago

right, you're missing the argument that tells the radial_profile_pars() method which option you like to change the default for; change this plots.radial_profile_pars('center',False) to this plots.radial_profile_pars('r', 'center', False). The accepted form is plots.radial_profile_pars(imexam key function, option , value).

The error you're seeing is because the code is looking up the options in a python dictionary structure.

plots.radial_profile_pars()

This is the dictionary:

Out[247]:
{'background': [False, 'Subtract background? [bool]'],
 'center': [True, 'Solve for center using 2d Gaussian? [bool]'], <--- where 'center' is the dictionary key for this line
 'fitplot': [False, 'Overplot profile fit?'],
 'fittype': ['Gaussian2D', 'Profile type to fit (Gaussian2D)'],
 'function': ['radial_profile'],
 'getdata': [False, 'print the plotted data values'],
 'magzero': [25.0, 'magnitude zero point'],
 'marker': ['o', 'The marker character to use, matplotlib style'],
 'pixels': [True, 'Plot all pixels at each radius? (False bins the data)'],
 'pointmode': [True, 'plot points instead of lines? [bool]'],
 'rplot': [8.0, 'Plotting radius in pixels'],
 'skyrad': [10.0, 'Background inner radius in pixels, from center of object'],
 'title': [None, 'Title of the plot'],
 'width': [5.0, 'Background annulus width in pixels'],
 'xlabel': ['Radius', 'The string for the xaxis label'],
 'ylabel': ['Flux', 'The string for the yaxis label']}

Let me know if this works, I'll try and improve the documentation and example a bit. thanks!

sanast commented 6 years ago

Hi

I already tried it with three argument s . But I got the same error

In [264]: plots.radial_profile_pars('r', 'center', False)

TypeError Traceback (most recent call last)

in () ----> 1 plots.radial_profile_pars('r', 'center', False) TypeError: 'dict' object is not callable Sorry that I forgot to mention about it in my mail . Thank you. > On Oct 26, 2017, at 6:18 AM, Megan Sosey wrote: > > right, you're missing the argument that tells the radial_profile_pars() method which option you like to change the default for; change this plots.radial_profile_pars('center',False) to this plots.radial_profile_pars('r', 'center', False). The accepted form is plots.radial_profile_pars(imexam key function, option , value). > > The error you're seeing is because the code is looking up the options in a python dictionary structure. > > plots.radial_profile_pars() > This is the dictionary: > > Out[247]: > {'background': [False, 'Subtract background? [bool]'], > 'center': [True, 'Solve for center using 2d Gaussian? [bool]'], <--- where 'center' is the dictionary key for this line > 'fitplot': [False, 'Overplot profile fit?'], > 'fittype': ['Gaussian2D', 'Profile type to fit (Gaussian2D)'], > 'function': ['radial_profile'], > 'getdata': [False, 'print the plotted data values'], > 'magzero': [25.0, 'magnitude zero point'], > 'marker': ['o', 'The marker character to use, matplotlib style'], > 'pixels': [True, 'Plot all pixels at each radius? (False bins the data)'], > 'pointmode': [True, 'plot points instead of lines? [bool]'], > 'rplot': [8.0, 'Plotting radius in pixels'], > 'skyrad': [10.0, 'Background inner radius in pixels, from center of object'], > 'title': [None, 'Title of the plot'], > 'width': [5.0, 'Background annulus width in pixels'], > 'xlabel': ['Radius', 'The string for the xaxis label'], > 'ylabel': ['Flux', 'The string for the yaxis label']} > Let me know if this works, I'll try and improve the documentation and example a bit. > thanks! > > — > You are receiving this because you were mentioned. > Reply to this email directly, view it on GitHub , or mute the thread . >
sosey commented 6 years ago

no worries, I'll take a closer look at what's going on with the code in the next couple days. Thanks for being a great tester!

sanast commented 6 years ago

Hi

Ok. Thank you .

On Oct 26, 2017, at 10:14 AM, Megan Sosey notifications@github.com wrote:

no worries, I'll take a closer look at what's going on with the code in the next couple days. Thanks for being a great tester!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/spacetelescope/imexam/issues/119#issuecomment-339699375, or mute the thread https://github.com/notifications/unsubscribe-auth/AfkQMTTpe-M2oxXzsaT5NilxIcLdUW-uks5swKHVgaJpZM4QGYZZ.

sosey commented 6 years ago

Hi @sanast - I think I know what's going on, I had to run through it in person myself to remember, as it's been a while since I used the package. I don't think there's a bug, there's just 2 ways to set the parameters for each imexam function depending on if you're using the simple interactive method, or the programmatic one - which assumes a little more python knowledge, but I could probably make this identical to the interactive one. I'll update the documentation to make this process much more clear, in the mean time here's the example to try:

Startup imexam and load an image:

ds9=imexam.connect()
ds9.load_fits('something.fits')
ds9.zoom()
ds9.scale()

When using the interactive loop, this should work:

ds9.imexam()
--> hit the r key to display radial plot
ds9.set_plot_pars('r','center', False)  <-- turn off centering
ds9.imexam()
--> hit the r key, no centering should be reported now and
ds9.rimexam()   <-- should show that center is false

when using the programmitic method, just making the plots object for lots of calls:

from imexam.imexamine import Imexamine
plots=Imexamine()

# You can load data into an array using astropy.io.fits or
# if you already have data displayed using imexam in ds9 for example
# you can grab the data from the current window frame with
# numpy_array = ds9.get_data()
plots.set_data(numpy_array)  

plots.radial_profile(99, 149)  <--- plot the radial profile at this location
radius, flux = plot.radial_profile(99, 149, genplot=False) <--- return the fit to the data instead of making the plot

# look at the dictionary for the radial_profile plot, this is the actual dictionary of values
plots.radial_profile_pars

# turn off centering
plots.radial_profile_pars['center'][0] = False

The reason the syntax looks like the above is because 'center' is the key in the dictionary, this key references a list of values, the first one is the one we want to change, to False, the second value is a convenience string that helps the user know what the option does.

Let me know if this works for you?

sosey commented 6 years ago

Hey @sanast, just checking in - any luck? I'm gunna make a new release of imexam tomorrow and wanted to make sure things are working for you.

cheers

sanast commented 6 years ago

Hi.

I am really sorry that I couldn’t. Reply to you .

I dint have time to test it again . I am just finishing my thesis and was really busy .
I went to a different method that I can test it without looking at radial profiles . So I didn’t check it after that .

But thank you so much for updating it with me. My plan is to use imexam in my future work and I am glad that you plan to update it .

Thank you .

On Nov 3, 2017, at 7:00 PM, Megan Sosey notifications@github.com wrote:

Hey @sanast https://github.com/sanast, just checking in - any luck? I'm gunna make a new release of imexam tomorrow and wanted to make sure things are working for you.

cheers

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/spacetelescope/imexam/issues/119#issuecomment-341855153, or mute the thread https://github.com/notifications/unsubscribe-auth/AfkQMYfktTkta_9PWfQSmUvCmffvdE7Sks5sy6k6gaJpZM4QGYZZ.

sosey commented 6 years ago

no problem. Good luck with your thesis! cheers,

sanast commented 6 years ago

Hi I was able to test it . Yes it works in that way .

One issue I have is , I need to loop through around 200 stars to get the radial profile . Even though the loops works it does not out put all the plots . It only show me last plot . ( I guess it replace s the previous one each time the loop runs ).

My code was like this

from imexam.imexamine import Imexamine plots=Imexamine() plots.radial_profile_pars['center'][0] = False plots.radial_profile_pars['marker'][0]= 'x' plots.radial_profile_pars['rplot'][0]= 20.0 for i in range(3): plots.radial_profile(data_x[i],data_y[i],pix) plots.save('radial.png')

(. It basically reads x ,y coordinates from a data file and radial plot needed to be done for each x,y ) Is there a way to use a command like append so that I can save all the plots to one png or pdf file ? Also it only displays the last plot only . I am using Jupyter notebook .

Thank you

On Nov 3, 2017, at 7:45 PM, Megan Sosey notifications@github.com wrote:

no problem. Good luck with your thesis! cheers,

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/spacetelescope/imexam/issues/119#issuecomment-341859191, or mute the thread https://github.com/notifications/unsubscribe-auth/AfkQMSNCTpAbpV8qMyd-in2WYNyN-1fLks5sy7OVgaJpZM4QGYZZ.

sosey commented 6 years ago

I think that the plotting issue is specific to jupyter notebooks, it should only display the last plot for the cell. You can have it display as you go, but if you want all of them to display it's probably better to save the data and use matplotlib to create a plot which has all of them ordered in an NxN matrix.

You can also run the plotting in a loop and save to a single file, here's an example that saves to a multipage PDF file, you could also save single files:

# save the data to a dictionary, this one gets indexed by the
# center location, but you can index by id as well
# you can also save from the loop that creates the radial_profile data
# by adding the plotting commands below to that loop.

plot_data={}
for y,x in zip(data_y, data_x):
    plot_data[(x,y)]=plots.radial_profile(x,y, genplot=False) <-- returns the data to create the plot

# make a multipage plot in pdf format
pp = PdfPages('radial_profiles.pdf')
for star in plot_data:
    plt.clf()
    plt.figure(figsize=(10.5, 8), dpi=100)
    plt.xlabel('Radius (pixels)')
    plt.ylabel('Flux')
    plt.title('Rad. Prof for {}'.format(star))
    plt.plot(plot_data[star][0],plot_data[star][1])
    plt.tight_layout()
    pp.savefig()
    plt.close(plt.gcf())
pp.close()
sanast commented 6 years ago

HI

For some reason, it reads completely different coordinates and out put pdf file has empty set of graphs . ( Attached here )

I had to include another argument before genplot=False to get it to work for the following function.

for y,x in zip(data_y, data_x): plot_data[(x,y)]=plots.radial_profile(x,y, genplot=False) <-- returns the data to create the plot

I guess that is to identify the pixel s in the image .

My code is like this

import numpy as np import pyfits from astropy.io import fits f = pyfits.open('A496RBCG.fits') pix = f[0].data. <———————————————————————read pixel data in my image

data_x = np.loadtxt('A496_179.ref',dtype=int,skiprows=1,usecols=(1))
data_y = np.loadtxt('A496_179.ref',dtype=int,skiprows=1,usecols=(2)) <—————————read x and Y data from a txt file

from imexam.imexamine import Imexamine plots=Imexamine()

plot_data={} for y,x in zip(data_y, data_x): plots.radial_profile_pars['center'][0] = False plot_data[(x,y)]=plots.radial_profile(x,y,pix,genplot=False) <——————————— I added “pix” here to make it to work

make a multipage plot in pdf format

import matplotlib import matplotlib.pyplot as plt from matplotlib.backends.backend_pdf import PdfPages pp = PdfPages('radial_profiles.pdf') for star in plot_data: plt.clf() plt.figure(figsize=(10.5, 8), dpi=100) plt.xlabel('Radius (pixels)') plt.ylabel('Flux') plt.title('Rad. Prof for {}'.format(star))

plt.plot(plot_data[star][0],plot_data[star][1]). <——————————Had to comment this to make it to work for some reason

plt.tight_layout()
pp.savefig()
plt.close(plt.gcf())

pp.close()

———————————————————————————————————————————— I check the data_x and data_y values and they are correctly read from the txt file .

Also again if you loop though like below , It plot the final graph in the loop and it is correct ( screen shoe is attached )

plot_data={} for y,x in zip(data_y, data_x):

print y, x

plot_data[(x,y)]=plots.radial_profile(x,y, pix)

On Nov 8, 2017, at 2:41 PM, Megan Sosey notifications@github.com wrote:

I think that the plotting issue is specific to jupyter notebooks, it should only display the last plot for the cell. You can have it display as you go, but if you want all of them to display it's probably better to save the data and use matplotlib to create a plot which has all of them ordered in an NxN matrix.

You can also run the plotting in a loop and save to a single file, here's an example that saves to a multipage PDF file, you could also save single files:

save the data to a dictionary, this one gets indexed by the

center location, but you can index by id as well

you can also save from the loop that creates the radial_profile data

by adding the plotting commands below to that loop.

plot_data={} for y,x in zip(data_y, data_x): plot_data[(x,y)]=plots.radial_profile(x,y, genplot=False) <-- returns the data to create the plot

make a multipage plot in pdf format

pp = PdfPages('radial_profiles.pdf') for star in plot_data: plt.clf() plt.figure(figsize=(10.5, 8), dpi=100) plt.xlabel('Radius (pixels)') plt.ylabel('Flux') plt.title('Rad. Prof for {}'.format(star)) plt.plot(plot_data[star][0],plot_data[star][1]) plt.tight_layout() pp.savefig() plt.close(plt.gcf()) pp.close()

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/spacetelescope/imexam/issues/119#issuecomment-342952424, or mute the thread https://github.com/notifications/unsubscribe-auth/AfkQMe3ZYv-DUxzomJBO49qervvOEu5Gks5s0hHjgaJpZM4QGYZZ.

sanast commented 6 years ago

Just to update you ,

I tried this in a separate python program and it worked . I was able to print all the graphs in to a pdf file .

Only issue I have for now is with this line

plt.title('Rad. Prof for {}'.format(star))

Because the the title I see in each graph, the coordinates are complete different and not sure where it come from. I was expecting the x,y coordinates

to print there from the file ( that come out from the plot_data function ).

For. Example when x= 5661 and y = 262 graph title says Rad. Prof for (6308, 3754).

I still couldn’t find how this happens.

I will update you if I fix it .

Thank you .

On Nov 8, 2017, at 8:42 PM, sandanuwan prasadh kvsprasadh@gmail.com wrote:

HI

For some reason, it reads completely different coordinates and out put pdf file has empty set of graphs . ( Attached here )

I had to include another argument before genplot=False to get it to work for the following function.

for y,x in zip(data_y, data_x): plot_data[(x,y)]=plots.radial_profile(x,y, genplot=False) <-- returns the data to create the plot

I guess that is to identify the pixel s in the image .

My code is like this

import numpy as np import pyfits from astropy.io http://astropy.io/ import fits f = pyfits.open('A496RBCG.fits') pix = f[0].data. <———————————————————————read pixel data in my image

data_x = np.loadtxt('A496_179.ref',dtype=int,skiprows=1,usecols=(1))
data_y = np.loadtxt('A496_179.ref',dtype=int,skiprows=1,usecols=(2)) <—————————read x and Y data from a txt file

from imexam.imexamine import Imexamine plots=Imexamine()

plot_data={} for y,x in zip(data_y, data_x): plots.radial_profile_pars['center'][0] = False plot_data[(x,y)]=plots.radial_profile(x,y,pix,genplot=False) <——————————— I added “pix” here to make it to work

make a multipage plot in pdf format

import matplotlib import matplotlib.pyplot as plt from matplotlib.backends.backend_pdf import PdfPages pp = PdfPages('radial_profiles.pdf') for star in plot_data: plt.clf() plt.figure(figsize=(10.5, 8), dpi=100) plt.xlabel('Radius (pixels)') plt.ylabel('Flux') plt.title('Rad. Prof for {}'.format(star))

plt.plot(plot_data[star][0],plot_data[star][1]). <——————————Had to comment this to make it to work for some reason

plt.tight_layout()
pp.savefig()
plt.close(plt.gcf())

pp.close()

———————————————————————————————————————————— I check the data_x and data_y values and they are correctly read from the txt file .

Also again if you loop though like below , It plot the final graph in the loop and it is correct ( screen shoe is attached )

plot_data={} for y,x in zip(data_y, data_x):

print y, x

plot_data[(x,y)]=plots.radial_profile(x,y, pix)

On Nov 8, 2017, at 2:41 PM, Megan Sosey <notifications@github.com mailto:notifications@github.com> wrote:

I think that the plotting issue is specific to jupyter notebooks, it should only display the last plot for the cell. You can have it display as you go, but if you want all of them to display it's probably better to save the data and use matplotlib to create a plot which has all of them ordered in an NxN matrix.

You can also run the plotting in a loop and save to a single file, here's an example that saves to a multipage PDF file, you could also save single files:

save the data to a dictionary, this one gets indexed by the

center location, but you can index by id as well

you can also save from the loop that creates the radial_profile data

by adding the plotting commands below to that loop.

plot_data={} for y,x in zip(data_y, data_x): plot_data[(x,y)]=plots.radial_profile(x,y, genplot=False) <-- returns the data to create the plot

make a multipage plot in pdf format

pp = PdfPages('radial_profiles.pdf') for star in plot_data: plt.clf() plt.figure(figsize=(10.5, 8), dpi=100) plt.xlabel('Radius (pixels)') plt.ylabel('Flux') plt.title('Rad. Prof for {}'.format(star)) plt.plot(plot_data[star][0],plot_data[star][1]) plt.tight_layout() pp.savefig() plt.close(plt.gcf()) pp.close()

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/spacetelescope/imexam/issues/119#issuecomment-342952424, or mute the thread https://github.com/notifications/unsubscribe-auth/AfkQMe3ZYv-DUxzomJBO49qervvOEu5Gks5s0hHjgaJpZM4QGYZZ.

sanast commented 6 years ago

Hi

It basically doesn’t print the plots in the order I have them in the text file .

There is nothing wrong with the code . It would be nice if it pains in the order I have them in the text file .

Thank you again for helping me with this .

One thing I can suggest ,

  1. it will be nice if I can see the same exact radial plot with FWHM values in the x axis ( as it is shown in IRAF).

  2. A way that I can fit a MOFFAT or Gaussian type fitted line instead of scattered data points for these graphs .

The reason is , my aim is to make sure that all these are stars and not galaxies . So having FWHM with these will be a nice way to make sure they are stars and not galaxies .

Thank you .

On Nov 8, 2017, at 10:46 PM, sandanuwan prasadh kvsprasadh@gmail.com wrote:

Just to update you ,

I tried this in a separate python program and it worked . I was able to print all the graphs in to a pdf file .

Only issue I have for now is with this line

plt.title('Rad. Prof for {}'.format(star))

Because the the title I see in each graph, the coordinates are complete different and not sure where it come from. I was expecting the x,y coordinates

to print there from the file ( that come out from the plot_data function ).

For. Example when x= 5661 and y = 262 graph title says Rad. Prof for (6308, 3754).

I still couldn’t find how this happens.

I will update you if I fix it .

Thank you .

On Nov 8, 2017, at 8:42 PM, sandanuwan prasadh <kvsprasadh@gmail.com mailto:kvsprasadh@gmail.com> wrote:

HI

For some reason, it reads completely different coordinates and out put pdf file has empty set of graphs . ( Attached here )

I had to include another argument before genplot=False to get it to work for the following function.

for y,x in zip(data_y, data_x): plot_data[(x,y)]=plots.radial_profile(x,y, genplot=False) <-- returns the data to create the plot

I guess that is to identify the pixel s in the image .

My code is like this

import numpy as np import pyfits from astropy.io http://astropy.io/ import fits f = pyfits.open('A496RBCG.fits') pix = f[0].data. <———————————————————————read pixel data in my image

data_x = np.loadtxt('A496_179.ref',dtype=int,skiprows=1,usecols=(1))
data_y = np.loadtxt('A496_179.ref',dtype=int,skiprows=1,usecols=(2)) <—————————read x and Y data from a txt file

from imexam.imexamine import Imexamine plots=Imexamine()

plot_data={} for y,x in zip(data_y, data_x): plots.radial_profile_pars['center'][0] = False plot_data[(x,y)]=plots.radial_profile(x,y,pix,genplot=False) <——————————— I added “pix” here to make it to work

make a multipage plot in pdf format

import matplotlib import matplotlib.pyplot as plt from matplotlib.backends.backend_pdf import PdfPages pp = PdfPages('radial_profiles.pdf') for star in plot_data: plt.clf() plt.figure(figsize=(10.5, 8), dpi=100) plt.xlabel('Radius (pixels)') plt.ylabel('Flux') plt.title('Rad. Prof for {}'.format(star))

plt.plot(plot_data[star][0],plot_data[star][1]). <——————————Had to comment this to make it to work for some reason

plt.tight_layout()
pp.savefig()
plt.close(plt.gcf())

pp.close()

———————————————————————————————————————————— I check the data_x and data_y values and they are correctly read from the txt file .

Also again if you loop though like below , It plot the final graph in the loop and it is correct ( screen shoe is attached )

plot_data={} for y,x in zip(data_y, data_x):

print y, x

plot_data[(x,y)]=plots.radial_profile(x,y, pix)

On Nov 8, 2017, at 2:41 PM, Megan Sosey <notifications@github.com mailto:notifications@github.com> wrote:

I think that the plotting issue is specific to jupyter notebooks, it should only display the last plot for the cell. You can have it display as you go, but if you want all of them to display it's probably better to save the data and use matplotlib to create a plot which has all of them ordered in an NxN matrix.

You can also run the plotting in a loop and save to a single file, here's an example that saves to a multipage PDF file, you could also save single files:

save the data to a dictionary, this one gets indexed by the

center location, but you can index by id as well

you can also save from the loop that creates the radial_profile data

by adding the plotting commands below to that loop.

plot_data={} for y,x in zip(data_y, data_x): plot_data[(x,y)]=plots.radial_profile(x,y, genplot=False) <-- returns the data to create the plot

make a multipage plot in pdf format

pp = PdfPages('radial_profiles.pdf') for star in plot_data: plt.clf() plt.figure(figsize=(10.5, 8), dpi=100) plt.xlabel('Radius (pixels)') plt.ylabel('Flux') plt.title('Rad. Prof for {}'.format(star)) plt.plot(plot_data[star][0],plot_data[star][1]) plt.tight_layout() pp.savefig() plt.close(plt.gcf()) pp.close()

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/spacetelescope/imexam/issues/119#issuecomment-342952424, or mute the thread https://github.com/notifications/unsubscribe-auth/AfkQMe3ZYv-DUxzomJBO49qervvOEu5Gks5s0hHjgaJpZM4QGYZZ.