[AstroPy] IOError: [Errno 2] No such file or directory when using satrapy fits moduel in IPython environment

Dominik Klaes dklaes at astro.uni-bonn.de
Sun Jan 17 06:03:01 EST 2016


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: <http://mail.python.org/pipermail/astropy/attachments/20160117/99a706c7/attachment.html>


More information about the AstroPy mailing list