[AstroPy] AstroPy Digest, Vol 112, Issue 4

Roberts, Michael michael.roberts.15 at ucl.ac.uk
Sun Jan 17 06:16:35 EST 2016


Hi Domink,

Not sure I follow you on that. Could you give an example of what you think I may need to do?

I was hoping that this would work as it was given to me as a working script....surely it must be permissions for the files I am trying to modify?

Michael

________________________________________
From: AstroPy <astropy-bounces at scipy.org> on behalf of astropy-request at scipy.org <astropy-request at scipy.org>
Sent: Sunday, January 17, 2016 11:03 AM
To: astropy at scipy.org
Subject: AstroPy Digest, Vol 112, Issue 4

Send AstroPy mailing list submissions to
        astropy at scipy.org

To subscribe or unsubscribe via the World Wide Web, visit
        https://mail.scipy.org/mailman/listinfo/astropy
or, via email, send a message with subject or body 'help' to
        astropy-request at scipy.org

You can reach the person managing the list at
        astropy-owner at scipy.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of AstroPy digest..."


Today's Topics:

   1. Re: IOError: [Errno 2] No such file or directory when using
      satrapy fits moduel in IPython environment (Dominik Klaes)


----------------------------------------------------------------------

Message: 1
Date: Sun, 17 Jan 2016 12:03:01 +0100
From: Dominik Klaes <dklaes at astro.uni-bonn.de>
To: Astronomical Python mailing list <astropy at scipy.org>
Subject: Re: [AstroPy] IOError: [Errno 2] No such file or directory
        when using satrapy fits moduel in IPython environment
Message-ID:
        <CAAc-CLQ7v+7NXBRY7eQgRh-0CYuRTT+otsoBH6K7rG4wq45+Ww at mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi Michael,

I think what you are trying is to open this file before you create it with
fits.open(). If you create a FITS file from scratch, which is I think what
you want to do, then you don't need this command, just as you do in the end
hdu.writeto().

Cheers,

Dominik

2016-01-17 11:43 GMT+01:00 Roberts, Michael <michael.roberts.15 at ucl.ac.uk>:

> Dear Astropy community,
>
>
> I'm having a little problem with a script that I am using. The parts of
> the script which is giving me the problems are as follows:
>
>
> #Function to replace all NaNs in the exposure map by 0s and to replace the corresponding pixels in the sky and large scale sensitivity map by 0s.def replace_nan(filename):
>     #Print that all NaNs will be replaced by 0s in the exposure map and that the corresponding pixels in the sky and large scale sensitivity map will also be replaced by 0s.
>     print "All NaNs will be replaced by 0s in " + filename + " and the corresponding pixels in the sky and large scale sensitivity map will also be replaced by 0s."
>     #Open the exposure map, the corresponding sky and large scale sensitivity map and copy the primary headers (extension 0 of hdulist) to new hdulists.
>     hdulist_ex = fits.open(filename)
>     new_hdu_header_ex = fits.PrimaryHDU(header=hdulist_ex[0].header)
>     new_hdulist_ex = fits.HDUList([new_hdu_header_ex])
>     hdulist_sk = fits.open(filename.replace("ex","sk_corrected"))
>     new_hdu_header_sk = fits.PrimaryHDU(header=hdulist_sk[0].header)
>     new_hdulist_sk = fits.HDUList([new_hdu_header_sk])
>     hdulist_lss = fits.open(filename.replace("ex","lss_m"))
>     new_hdu_header_lss = fits.PrimaryHDU(header=hdulist_lss[0].header)
>     new_hdulist_lss = fits.HDUList([new_hdu_header_lss])
>
>     #For all frames in the image: Create the mask and run the function replace_pix.
>     for i in range(1,len(hdulist_ex)):
>         mask = np.isnan(hdulist_ex[i].data)
>         replace_pix(hdulist_ex[i],mask,new_hdulist_ex)
>         replace_pix(hdulist_sk[i],mask,new_hdulist_sk)
>         replace_pix(hdulist_lss[i],mask,new_hdulist_lss)
>
>     #Write the new hdulists to new images.
>     new_hdulist_ex.writeto(filename.replace(".img","_new.img"))
>     new_hdulist_sk.writeto(filename.replace("ex.img","sk_new.img"))
>     new_hdulist_lss.writeto(filename.replace("ex.img","lss_new.img"))
>
>     #Print that all NaNs are replaced by 0s in the exposure map and that the corresponding pixels in the sky and large scale sensitivity map are also replaced by 0s.
>     print "All NaNs are replaced by 0s in " + filename + " and the corresponding pixels in the sky and large scale sensitivity map are also replaced by 0s."
>
>
> When running:
>
>
> replace_nan("/Users/.../sw00031048001uw1_ex.img")
>
> (where I have dotted out my path for convenience.) it is failing on
> (traceback) is hdulist_sk = fits.open(filename.replace("ex","sk_corrected"
> ))
>
>
> The error is simply
>
>
> IOError: [Errno 2] No such file or directory: '/Users/.../sw00031048001uw1_sk_corrected.img'
>
> But this is the file I am attempting to create by replacing
> '/Users/.../sw00031048001uw1_ex.img'
>
>
> I'm within the iPython development environment (if that helps, or if that
> is relevant). I'm guessing at this stage that maybe I don't have
> permissions to be messing around with files from the iPython console? Or I
> need some extra arguments for this to work...
>
>
> Any suggestions would be warmly welcomed.
>
>
> Many thanks,
>
>
> Michael Roberts
>
>
>
>
>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> https://mail.scipy.org/mailman/listinfo/astropy
>
>


--
Dominik Klaes
Argelander-Institut f?r Astronomie
Room 2.027a
Auf dem H?gel 71
53121 Bonn

Telefon: 0228/73-5773
E-Mail: dklaes at astro.uni-bonn.de <dklaes at astro.uni-bonn.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.scipy.org/pipermail/astropy/attachments/20160117/99a706c7/attachment.html>

------------------------------

Subject: Digest Footer

_______________________________________________
AstroPy mailing list
AstroPy at scipy.org
https://mail.scipy.org/mailman/listinfo/astropy


------------------------------

End of AstroPy Digest, Vol 112, Issue 4
***************************************



More information about the AstroPy mailing list