<p>After a lot of research, I found the answer to the second question, since the FITS files in sdss Images have more than 1 primary hdus, you have to pass the following fits images like an array *.fits[0] to the swarp program, where the first hdu in the fits file contains the image pixel. solution <a href="https://www.astromatic.net/forum/showthread.php?tid=760" rel="nofollow noreferrer">here</a></p>

<p>For the first question, yes the method to do that is correct. I also found that in order to get a re-sampled image that has the pixel of the galaxy at the center. You have to find the galactic coordinates in hmsdms format and feed it to the swarp tool by altering the following parameters in the swarp cofiguration file. </p>

<p>CENTER_TYPE: MANUAL<br>
CENTER: HH:MM:SS.SS, <span class="math-container">$\pm$</span>DD:MM:SS.SS  </p>

<p>For the conversion, I used the astropy python library. I hope this helps.</p>

CC BY-SA 4.0
2019-08-11T23:19:04.427Z
2019-08-14T15:30:36.780Z
2019-08-14T15:30:36.780Z
Umesh Timalsina
<p>In the CASJOBS Server, I created the following query for galaxies(DR12)</p>

<pre><code>SELECT za.specObjID, za.bestObjID, za.class, za.subClass, za.z, za.zErr,
  po.objID, po.type, po.flags, po.ra, po.dec, po.run, po.rerun, po.field, po.camcol,
  (po.petroMag_r-po.extinction_r) as dered_petro_r,
  zp.z as zphot, zp.zErr as dzphot,
  zi.e_bv_sfd,zi.primtarget, zi.sectarget,zi.targettype,zi.spectrotype,zi.subclass

INTO MyDB.SDSS_DR12
FROM SpecObjAll za
  JOIN PhotoObjAll po ON (po.objID = za.bestObjID)
  JOIN Photoz zp ON (zp.objID = za.bestObjID)
  JOIN galSpecInfo zi ON (zi.SpecObjID = za.specObjID)
WHERE
  (za.z&gt;0 AND za.zWarning=0)
    AND (za.targetType='SCIENCE' AND za.survey='sdss')
    AND (za.class='GALAXY' AND zi.primtarget&gt;=64 AND zi.targettype='GALAXY')
    AND (po.clean=1 AND po.insideMask=0)
  AND ((po.petroMag_r-po.extinction_r)&lt;=17.8)
  AND za.z &lt;= 0.4;
</code></pre>

<p>My Target is to get all the images related to this query. So, in the data release 12 of the SAS server, using the following <a href="https://dr12.sdss.org/sas/dr12/boss/photoObj/frames/301/" rel="nofollow noreferrer">link</a>, I started downloading all the corrected frames for galaxies that I got (From the photoobj, I got the run number, rerun number, camcol,field no. etc)... The code to do that is <a href="https://github.com/umesh-timalsina/redshift/blob/master/preprocessing/image_getter.py" rel="nofollow noreferrer">here</a>. 
Then for each galaxy, I got 'u', 'g', 'r', 'i', 'z' images as compressed fitz files. 
Finally, after getting the fits files, I wanted to resample the images using the swarp tool. with output size of 64. I ran the swarp tool in few sample images, the resulting image is all zeros in each and every pixel values(if we can call it that).</p>

<p>I have a couple of questions:
1. Is the method of downloading frames related to a galaxy based on run, rerun, field and camcol of the PhotoObjAll table in the SDSS casjobs server correct? 
2. Why is the output of swarp tool always zero matrix regardless of which sample I give?</p>

<p>Here's my swarp.conf file:</p>

<pre><code># Default configuration file for SWarp 2.38.0
# EB 2019-08-08
#
#----------------------------------- Output -----------------------------------
IMAGEOUT_NAME          coadd.fits      # Output filename
WEIGHTOUT_NAME       coadd.weight.fits # Output weight-map filename

HEADER_ONLY            N               # Only a header as an output file (Y/N)?
HEADER_SUFFIX          .head           # Filename extension for additional headers

#------------------------------- Input Weights --------------------------------

WEIGHT_TYPE            NONE            # BACKGROUND,MAP_RMS,MAP_VARIANCE
                                       # or MAP_WEIGHT
RESCALE_WEIGHTS        Y               # Rescale input weights/variances (Y/N)?
WEIGHT_SUFFIX          .weight.fits    # Suffix to use for weight-maps
WEIGHT_IMAGE                           # Weightmap filename if suffix not used
                                       # (all or for each weight-map)
WEIGHT_THRESH                         # Bad pixel weight-threshold

#------------------------------- Co-addition ----------------------------------

COMBINE                Y               # Combine resampled images (Y/N)?
COMBINE_TYPE           MEDIAN          # MEDIAN,AVERAGE,MIN,MAX,WEIGHTED,CLIPPED
                                       # CHI-OLD,CHI-MODE,CHI-MEAN,SUM,
                                       # WEIGHTED_WEIGHT,MEDIAN_WEIGHT,
                                       # AND,NAND,OR or NOR
CLIP_AMPFRAC           0.3             # Fraction of flux variation allowed
                                       # with clipping
CLIP_SIGMA             4.0             # RMS error multiple variation allowed
                                       # with clipping
CLIP_WRITELOG          N               # Write output file with coordinates of
                                       # clipped pixels (Y/N) 
CLIP_LOGNAME           clipped.log     # Name of output file with coordinates
                                       # of clipped pixels
BLANK_BADPIXELS        N               # Set to 0 pixels having a weight of 0

#-------------------------------- Astrometry ----------------------------------

CELESTIAL_TYPE         NATIVE          # NATIVE, PIXEL, EQUATORIAL,
                                       # GALACTIC,ECLIPTIC, or SUPERGALACTIC
PROJECTION_TYPE        TAN             # Any WCS projection code or NONE
PROJECTION_ERR         0.001           # Maximum projection error (in output
                                       # pixels), or 0 for no approximation
CENTER_TYPE            ALL             # MANUAL, ALL or MOST
CENTER         00:00:00.0, +00:00:00.0 # Coordinates of the image center
PIXELSCALE_TYPE        MEDIAN          # MANUAL,FIT,MIN,MAX or MEDIAN
PIXEL_SCALE            0.0             # Pixel scale
IMAGE_SIZE             64               # Image size (0 = AUTOMATIC)

#-------------------------------- Resampling ----------------------------------

RESAMPLE               Y               # Resample input images (Y/N)?
RESAMPLE_DIR           .               # Directory path for resampled images
RESAMPLE_SUFFIX        .resamp.fits    # filename extension for resampled images

RESAMPLING_TYPE        LANCZOS3        # NEAREST,BILINEAR,LANCZOS2,LANCZOS3
                                       # LANCZOS4 (1 per axis) or FLAGS
OVERSAMPLING           0               # Oversampling in each dimension
                                       # (0 = automatic)
INTERPOLATE            N               # Interpolate bad input pixels (Y/N)?
                                       # (all or for each image)

FSCALASTRO_TYPE        FIXED           # NONE,FIXED, or VARIABLE
FSCALE_KEYWORD         FLXSCALE        # FITS keyword for the multiplicative
                                       # factor applied to each input image
FSCALE_DEFAULT         1.0             # Default FSCALE value if not in header

GAIN_KEYWORD           GAIN            # FITS keyword for effect. gain (e-/ADU)
GAIN_DEFAULT           0.0             # Default gain if no FITS keyword found
                                       # 0 = infinity (all or for each image)
SATLEV_KEYWORD         SATURATE        # FITS keyword for saturation level (ADU)
SATLEV_DEFAULT         50000.0         # Default saturation if no FITS keyword

#--------------------------- Background subtraction ---------------------------

SUBTRACT_BACK          N               # Subtraction sky background (Y/N)?
                                       # (all or for each image)

BACK_TYPE              AUTO            # AUTO or MANUAL
                                       # (all or for each image)
BACK_DEFAULT           0.0             # Default background value in MANUAL
                                       # (all or for each image)
BACK_SIZE              128             # Background mesh size (pixels)
                                       # (all or for each image)
BACK_FILTERSIZE        3               # Background map filter range (meshes)
                                       # (all or for each image)
BACK_FILTTHRESH        0.0             # Threshold above which the background-
                                       # map filter operates

#------------------------------ Memory management -----------------------------

VMEM_DIR               .               # Directory path for swap files
VMEM_MAX               2047            # Maximum amount of virtual memory (MB)
MEM_MAX                2048             # Maximum amount of usable RAM (MB)
COMBINE_BUFSIZE        2048             # RAM dedicated to co-addition(MB)

#------------------------------ Miscellaneous ---------------------------------

DELETE_TMPFILES        Y               # Delete temporary resampled FITS files
                                       # (Y/N)?
COPY_KEYWORDS          OBJECT          # List of FITS keywords to propagate
                                       # from the input to the output headers
WRITE_FILEINFO         N               # Write information about each input
                                       # file in the output image header?
WRITE_XML              N               # Write XML file (Y/N)?
XML_NAME               swarp.xml       # Filename for XML output
XSL_URL                file:///usr/local/share/swarp/swarp.xsl
                                       # Filename for XSL style-sheet
VERBOSE_TYPE           NORMAL          # QUIET,LOG,NORMAL, or FULL
NNODES                 1               # Number of nodes (for clusters)
NODE_INDEX             0               # Node index (for clusters)

NTHREADS               0               # Number of simultaneous threads for
                                       # the SMP version of SWarp
                                       # 0 = automatic
NOPENFILES_MAX         512             # Maximum number of files opened by SWarp

<span class="math-container">```</span>
</code></pre>

CC BY-SA 4.0
2019-08-10T02:06:45.683Z
After a lot of research, I found the answer to the second question, since the FITS files in sdss Images have more than 1 primary hdus, you have to pass the following fits images like an array *.fits[0] to the swarp program, where the first hdu in the fits file contains the image pixel. solution [here](https://www.astromatic.net/forum/showthread.php?tid=760)
Umesh Timalsina
CC BY-SA 4.0
2019-08-10T16:08:54.830Z
This will be more helpful to others with the same problem if you post it as an answer.
Bit Chaser
<observational-astronomy><redshift><spectroscopy>
SDSS Image Download: Swarp returns all zeros
Umesh Timalsina
# SDSS Image Download: Swarp returns all zeros

(Asked by: username_0 on 2019-08-08)

In the CASJOBS Server, I created the following query for galaxies(DR12)
SELECT za.specObjID, za.bestObjID, za.class, za.subClass, za.z, za.zErr,
  po.objID, po.type, po.flags, po.ra, po.dec, po.run, po.rerun, po.field, po.camcol,
  (po.petroMag_r-po.extinction_r) as dered_petro_r,
  zp.z as zphot, zp.zErr as dzphot,
  zi.e_bv_sfd,zi.primtarget, zi.sectarget,zi.targettype,zi.spectrotype,zi.subclass

INTO MyDB.SDSS_DR12
FROM SpecObjAll za
  JOIN PhotoObjAll po ON (po.objID = za.bestObjID)
  JOIN Photoz zp ON (zp.objID = za.bestObjID)
  JOIN galSpecInfo zi ON (zi.SpecObjID = za.specObjID)
WHERE
  (za.z>0 AND za.zWarning=0)
    AND (za.targetType='SCIENCE' AND za.survey='sdss')
    AND (za.class='GALAXY' AND zi.primtarget>=64 AND zi.targettype='GALAXY')
    AND (po.clean=1 AND po.insideMask=0)
  AND ((po.petroMag_r-po.extinction_r)<=17.8)
  AND za.z <= 0.4;

My Target is to get all the images related to this query. So, in the data release 12 of the SAS server, using the following link, I started downloading all the corrected frames for galaxies that I got (From the photoobj, I got the run number, rerun number, camcol,field no. etc)... The code to do that is here. 
Then for each galaxy, I got 'u', 'g', 'r', 'i', 'z' images as compressed fitz files. 
Finally, after getting the fits files, I wanted to resample the images using the swarp tool. with output size of 64. I ran the swarp tool in few sample images, the resulting image is all zeros in each and every pixel values(if we can call it that).
I have a couple of questions:
1. Is the method of downloading frames related to a galaxy based on run, rerun, field and camcol of the PhotoObjAll table in the SDSS casjobs server correct? 
2. Why is the output of swarp tool always zero matrix regardless of which sample I give?
Here's my swarp.conf file:
# Default configuration file for SWarp 2.38.0
# EB 2019-08-08
#
#----------------------------------- Output -----------------------------------
IMAGEOUT_NAME          coadd.fits      # Output filename
WEIGHTOUT_NAME       coadd.weight.fits # Output weight-map filename

HEADER_ONLY            N               # Only a header as an output file (Y/N)?
HEADER_SUFFIX          .head           # Filename extension for additional headers

#------------------------------- Input Weights --------------------------------

WEIGHT_TYPE            NONE            # BACKGROUND,MAP_RMS,MAP_VARIANCE
                                       # or MAP_WEIGHT
RESCALE_WEIGHTS        Y               # Rescale input weights/variances (Y/N)?
WEIGHT_SUFFIX          .weight.fits    # Suffix to use for weight-maps
WEIGHT_IMAGE                           # Weightmap filename if suffix not used
                                       # (all or for each weight-map)
WEIGHT_THRESH                         # Bad pixel weight-threshold

#------------------------------- Co-addition ----------------------------------

COMBINE                Y               # Combine resampled images (Y/N)?
COMBINE_TYPE           MEDIAN          # MEDIAN,AVERAGE,MIN,MAX,WEIGHTED,CLIPPED
                                       # CHI-OLD,CHI-MODE,CHI-MEAN,SUM,
                                       # WEIGHTED_WEIGHT,MEDIAN_WEIGHT,
                                       # AND,NAND,OR or NOR
CLIP_AMPFRAC           0.3             # Fraction of flux variation allowed
                                       # with clipping
CLIP_SIGMA             4.0             # RMS error multiple variation allowed
                                       # with clipping
CLIP_WRITELOG          N               # Write output file with coordinates of
                                       # clipped pixels (Y/N) 
CLIP_LOGNAME           clipped.log     # Name of output file with coordinates
                                       # of clipped pixels
BLANK_BADPIXELS        N               # Set to 0 pixels having a weight of 0

#-------------------------------- Astrometry ----------------------------------

CELESTIAL_TYPE         NATIVE          # NATIVE, PIXEL, EQUATORIAL,
                                       # GALACTIC,ECLIPTIC, or SUPERGALACTIC
PROJECTION_TYPE        TAN             # Any WCS projection code or NONE
PROJECTION_ERR         0.001           # Maximum projection error (in output
                                       # pixels), or 0 for no approximation
CENTER_TYPE            ALL             # MANUAL, ALL or MOST
CENTER         00:00:00.0, +00:00:00.0 # Coordinates of the image center
PIXELSCALE_TYPE        MEDIAN          # MANUAL,FIT,MIN,MAX or MEDIAN
PIXEL_SCALE            0.0             # Pixel scale
IMAGE_SIZE             64               # Image size (0 = AUTOMATIC)

#-------------------------------- Resampling ----------------------------------

RESAMPLE               Y               # Resample input images (Y/N)?
RESAMPLE_DIR           .               # Directory path for resampled images
RESAMPLE_SUFFIX        .resamp.fits    # filename extension for resampled images

RESAMPLING_TYPE        LANCZOS3        # NEAREST,BILINEAR,LANCZOS2,LANCZOS3
                                       # LANCZOS4 (1 per axis) or FLAGS
OVERSAMPLING           0               # Oversampling in each dimension
                                       # (0 = automatic)
INTERPOLATE            N               # Interpolate bad input pixels (Y/N)?
                                       # (all or for each image)

FSCALASTRO_TYPE        FIXED           # NONE,FIXED, or VARIABLE
FSCALE_KEYWORD         FLXSCALE        # FITS keyword for the multiplicative
                                       # factor applied to each input image
FSCALE_DEFAULT         1.0             # Default FSCALE value if not in header

GAIN_KEYWORD           GAIN            # FITS keyword for effect. gain (e-/ADU)
GAIN_DEFAULT           0.0             # Default gain if no FITS keyword found
                                       # 0 = infinity (all or for each image)
SATLEV_KEYWORD         SATURATE        # FITS keyword for saturation level (ADU)
SATLEV_DEFAULT         50000.0         # Default saturation if no FITS keyword

#--------------------------- Background subtraction ---------------------------

SUBTRACT_BACK          N               # Subtraction sky background (Y/N)?
                                       # (all or for each image)

BACK_TYPE              AUTO            # AUTO or MANUAL
                                       # (all or for each image)
BACK_DEFAULT           0.0             # Default background value in MANUAL
                                       # (all or for each image)
BACK_SIZE              128             # Background mesh size (pixels)
                                       # (all or for each image)
BACK_FILTERSIZE        3               # Background map filter range (meshes)
                                       # (all or for each image)
BACK_FILTTHRESH        0.0             # Threshold above which the background-
                                       # map filter operates

#------------------------------ Memory management -----------------------------

VMEM_DIR               .               # Directory path for swap files
VMEM_MAX               2047            # Maximum amount of virtual memory (MB)
MEM_MAX                2048             # Maximum amount of usable RAM (MB)
COMBINE_BUFSIZE        2048             # RAM dedicated to co-addition(MB)

#------------------------------ Miscellaneous ---------------------------------

DELETE_TMPFILES        Y               # Delete temporary resampled FITS files
                                       # (Y/N)?
COPY_KEYWORDS          OBJECT          # List of FITS keywords to propagate
                                       # from the input to the output headers
WRITE_FILEINFO         N               # Write information about each input
                                       # file in the output image header?
WRITE_XML              N               # Write XML file (Y/N)?
XML_NAME               swarp.xml       # Filename for XML output
XSL_URL                file:///usr/local/share/swarp/swarp.xsl
                                       # Filename for XSL style-sheet
VERBOSE_TYPE           NORMAL          # QUIET,LOG,NORMAL, or FULL
NNODES                 1               # Number of nodes (for clusters)
NODE_INDEX             0               # Node index (for clusters)

NTHREADS               0               # Number of simultaneous threads for
                                       # the SMP version of SWarp
                                       # 0 = automatic
NOPENFILES_MAX         512             # Maximum number of files opened by SWarp

```

**Tags:** observational-astronomy, redshift, spectroscopy
> **Comments:**
> **username_0**: After a lot of research, I found the answer to the second question, since the FITS files in sdss Images have more than 1 primary hdus, you have to pass the following fits images like an array *.fits[0] to the swarp program, where the first hdu in the fits file contains the image pixel. solution [here](https://www.astromatic.net/forum/showthread.php?tid=760)  
> **username_1**: This will be more helpful to others with the same problem if you post it as an answer.  

---

## 1 answers

### Answer by username_0 on 2019-08-11. Score: 1

After a lot of research, I found the answer to the second question, since the FITS files in sdss Images have more than 1 primary hdus, you have to pass the following fits images like an array \*.fits[0] to the swarp program, where the first hdu in the fits file contains the image pixel. solution [here](https://www.astromatic.net/forum/showthread.php?tid=760)

For the first question, yes the method to do that is correct. I also found that in order to get a re-sampled image that has the pixel of the galaxy at the center. You have to find the galactic coordinates in hmsdms format and feed it to the swarp tool by altering the following parameters in the swarp cofiguration file.

CENTER\_TYPE: MANUAL  
CENTER: HH:MM:SS.SS, $\pm$DD:MM:SS.SS

For the conversion, I used the astropy python library. I hope this helps.


---

