<p>What they did was the following: for each individual filter, they assembled overlapping frames into a combined, <em>single-filter</em> image. E.g., they combined several <em>g</em>-band images into a single <em>g</em>-band image, combined several <em>r</em>-band images into a single <em>r</em>-band image, etc. (So they ran SWarp five times, once for each filter.) They then put each combined single-filter image into a separate layer to create a five-layer &quot;datacube&quot;; this is their &quot;64x64x5 pixel datacube&quot;.</p>
<p>What you are telling SWarp to do is something different: combine five individual-filter images into a single &quot;<span class="math-container">$u+g+r+i+z$</span>&quot; image. (People do sometimes do this sort of thing, though with SDSS images they would normally just use the <em>g</em>, <em>r</em>, and <em>i</em> images, since the <em>u</em> and <em>z</em> images are so low-S/N that they mainly just add noise to the result. And in any case this isn't what the paper you're interested in was doing.)</p>

CC BY-SA 4.0
2020-10-26T10:53:23.153Z
Thanks for the clarification. I understand that the command that I've entered will not give me what I want. However, I'm new to this and have been using SWARP in many different combinations. I've also tried `swarp frame-z.fits[0] -SUBTRACT_BACK N -RESAMPLE Y -RESAMPLING_TYPE LANCZOS3 -IMAGE_SIZE 64,64`. It does not give the expected result when extracted through astropy, please view [here](https://drive.google.com/file/d/13qNGc1nQZEbmxeDnVBnorY0zbpPqSRWd/view?usp=sharing). Would you know why? Thanks once again.
Hiba Jamal
CC BY-SA 4.0
2020-10-26T14:14:36.933Z
I'm afraid I don't really use SWarp (the last time was six or eight years ago), so I probably can't help very much. SWarp is designed to combine two or more images (usually in the same filter), so giving it just one image is a little odd. I just tried using your command on a random SDSS image I had, and it seems to extract the central 64x64 pixels from the image, rotate it so the North is up, and that's the output. I'm guessing that if you looked at the central 64x64 pixels of your input image, they would look similar to your output image (SDSS z-band images are noisy).
Peter Erwin
CC BY-SA 4.0
2020-10-26T14:20:12.330Z
If you want to extract a particular 64x64 pixels from your input image, you need to tell SWarp this, via one of the center-related parameters (I assume). I'm guessing that SWarp defaulted to the center of the image because you didn't tell it what the output center should be.
Peter Erwin
CC BY-SA 4.0
2020-10-27T06:03:53.537Z
Aah, thank you, I understand, I was expecting SWARP to give me an output like the one mentioned in the [paper](https://arxiv.org/pdf/1806.06607.pdf) (mentioned on p. 4, Fig. 3). The center is indeed what I need, but I see now how my command would not give that output. So basically, I would need to query out multiple images of the same frame for each equatorial coordinate that I give as input to the query?
Hiba Jamal
CC BY-SA 4.0
2020-10-27T16:07:42.670Z
I think so... (I'd say go ahead and experiment!)
Peter Erwin
CC BY-SA 4.0
2020-11-09T07:45:33.653Z
Hey! So I got my expected output but I got it without using SWARP. Just one last question, when you mentioned here that they are rotated up North, how am I to know which direction is 'up North' in each fits file? Thank you so much for your guidance!
Hiba Jamal
CC BY-SA 4.0
2020-11-11T11:42:12.133Z
The following Python code snippet should work with SDSS images. It computes the same rotation angle as the "north" task from the IRAF STSDAS package, which is the angle of the image +y axis in degrees CCW from N. (If you display the image in SAOImage DS9, the inset "panner" display near the top helpfully shows both x-y and N-E axes on top of the image, which may make it easier to understand the rotation.)
Peter Erwin
CC BY-SA 4.0
2020-11-11T11:42:41.127Z
```hdr = astropy.io.fits.getheader("/path/to/image.fits")```
Peter Erwin
CC BY-SA 4.0
2020-11-11T11:45:41.157Z
```cd1_1,cd1_2,cd2_1,cd2_2 = hdr['CD1_1'],hdr['CD1_2'],hdr['CD2_1'],hdr['CD2_2']
```
Peter Erwin
CC BY-SA 4.0
2020-11-11T11:45:58.113Z
```rot = math.degrees(math.atan2(math.radians(cd2_1), math.radians(cd1_1)))```
Peter Erwin
CC BY-SA 4.0
2020-11-11T11:46:33.163Z
(Apologies for abusing the comment system this way; I couldn't figure out how to get good code formatting in a single comment.)
Peter Erwin
CC BY-SA 4.0
2020-10-24T10:38:13.863Z
2020-10-24T10:38:13.863Z
Peter Erwin
<p>I am following this <a href="https://arxiv.org/abs/1806.06607" rel="nofollow noreferrer" title="Photometric redshifts from SDSS images using a Convolutional Neural Network">paper</a> to extract the u,g,r,i,z image frames from the SDSS image fits files. I have the fits files downloaded (using the bulk data download option from SDSS) and tried to run the <a href="http://www.astromatic.net/software/swarp" rel="nofollow noreferrer">SWARP</a> tool to get the resampled image as output, which I will access through astropy. I am still unclear on the exact parameters that will make up the entire SWARP command. So far I have:</p>
<pre><code>swarp frame-i.fits[0] frame-r.fits[0] frame-g.fits[0] frame-u.fits[0] frame-z.fits[0] -SUBTRACT_BACK N -RESAMPLE Y -RESAMPLING_TYPE LANCZOS3 -IMAGE_SIZE 64,64 -IMAGEOUT_NAME attempt.fits
</code></pre>
<p>This is written with the description of it in the paper, which is:</p>
<p><a href="https://i.sstatic.net/SsIkt.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/SsIkt.png" alt="Description of command from the aforementioned paper" /></a></p>
<p>With the command that has been run, I am getting quite noisy images as output that do not relay any sort of information. What am I doing wrong in this process?</p>

<galaxy-center><astropy><sloan-dss>
SDSS - getting separate u, g, r, i, z frames from SWARP tool and astropy
Hiba Jamal
# SDSS - getting separate u, g, r, i, z frames from SWARP tool and astropy

(Asked by: username_0 on 2020-10-24)

I am following this [paper](https://arxiv.org/abs/1806.06607 "Photometric redshifts from SDSS images using a Convolutional Neural Network") to extract the u,g,r,i,z image frames from the SDSS image fits files. I have the fits files downloaded (using the bulk data download option from SDSS) and tried to run the [SWARP](http://www.astromatic.net/software/swarp) tool to get the resampled image as output, which I will access through astropy. I am still unclear on the exact parameters that will make up the entire SWARP command. So far I have:

```
swarp frame-i.fits[0] frame-r.fits[0] frame-g.fits[0] frame-u.fits[0] frame-z.fits[0] -SUBTRACT_BACK N -RESAMPLE Y -RESAMPLING_TYPE LANCZOS3 -IMAGE_SIZE 64,64 -IMAGEOUT_NAME attempt.fits

```

This is written with the description of it in the paper, which is:

[![Description of command from the aforementioned paper](https://i.sstatic.net/SsIkt.png)](https://i.sstatic.net/SsIkt.png)

With the command that has been run, I am getting quite noisy images as output that do not relay any sort of information. What am I doing wrong in this process?

**Tags:** galaxy-center, astropy, sloan-dss


---

## 1 answers

### Answer by username_1 on 2020-10-24. Score: 3

What they did was the following: for each individual filter, they assembled overlapping frames into a combined, *single-filter* image. E.g., they combined several *g*-band images into a single *g*-band image, combined several *r*-band images into a single *r*-band image, etc. (So they ran SWarp five times, once for each filter.) They then put each combined single-filter image into a separate layer to create a five-layer "datacube"; this is their "64x64x5 pixel datacube".

What you are telling SWarp to do is something different: combine five individual-filter images into a single "$u+g+r+i+z$" image. (People do sometimes do this sort of thing, though with SDSS images they would normally just use the *g*, *r*, and *i* images, since the *u* and *z* images are so low-S/N that they mainly just add noise to the result. And in any case this isn't what the paper you're interested in was doing.)

> **Comments:**
> **username_0**: Thanks for the clarification. I understand that the command that I've entered will not give me what I want. However, I'm new to this and have been using SWARP in many different combinations. I've also tried `swarp frame-z.fits[0] -SUBTRACT_BACK N -RESAMPLE Y -RESAMPLING_TYPE LANCZOS3 -IMAGE_SIZE 64,64`. It does not give the expected result when extracted through astropy, please view [here](https://drive.google.com/file/d/13qNGc1nQZEbmxeDnVBnorY0zbpPqSRWd/view?usp=sharing). Would you know why? Thanks once again.  
> **username_1**: I'm afraid I don't really use SWarp (the last time was six or eight years ago), so I probably can't help very much. SWarp is designed to combine two or more images (usually in the same filter), so giving it just one image is a little odd. I just tried using your command on a random SDSS image I had, and it seems to extract the central 64x64 pixels from the image, rotate it so the North is up, and that's the output. I'm guessing that if you looked at the central 64x64 pixels of your input image, they would look similar to your output image (SDSS z-band images are noisy).  
> **username_1**: If you want to extract a particular 64x64 pixels from your input image, you need to tell SWarp this, via one of the center-related parameters (I assume). I'm guessing that SWarp defaulted to the center of the image because you didn't tell it what the output center should be.  
> **username_0**: Aah, thank you, I understand, I was expecting SWARP to give me an output like the one mentioned in the [paper](https://arxiv.org/pdf/1806.06607.pdf) (mentioned on p. 4, Fig. 3). The center is indeed what I need, but I see now how my command would not give that output. So basically, I would need to query out multiple images of the same frame for each equatorial coordinate that I give as input to the query?  
> **username_1**: I think so... (I'd say go ahead and experiment!)  
> **username_0**: Hey! So I got my expected output but I got it without using SWARP. Just one last question, when you mentioned here that they are rotated up North, how am I to know which direction is 'up North' in each fits file? Thank you so much for your guidance!  
> **username_1**: The following Python code snippet should work with SDSS images. It computes the same rotation angle as the "north" task from the IRAF STSDAS package, which is the angle of the image +y axis in degrees CCW from N. (If you display the image in SAOImage DS9, the inset "panner" display near the top helpfully shows both x-y and N-E axes on top of the image, which may make it easier to understand the rotation.)  
> **username_1**: ```hdr = astropy.io.fits.getheader("/path/to/image.fits")```  
> **username_1**: ```cd1_1,cd1_2,cd2_1,cd2_2 = hdr['CD1_1'],hdr['CD1_2'],hdr['CD2_1'],hdr['CD2_2'] ```  
> **username_1**: ```rot = math.degrees(math.atan2(math.radians(cd2_1), math.radians(cd1_1)))```  
> **username_1**: (Apologies for abusing the comment system this way; I couldn't figure out how to get good code formatting in a single comment.)  

---

