<p>I don't know about WCS headers, but I had a similar question regarding FITS headers when cropping astronomical FITS images. The program MaxIm DL provides a Batch Process option for automatically cropping multiple images. The FTS headers are preserved.</p>

CC BY-SA 4.0
2022-11-25T20:00:38.450Z
2022-11-25T20:00:38.450Z
David Daiku Trowbridge
<p><a href="http://www.eso.org/sci/observing/tools/skycat.html" rel="nofollow noreferrer">Skycat</a> also stores the WCS information when selecting an image region from a fits file. Not sure how exactly this can be done in non-interactive mode but many features can in fact be &quot;batched&quot;. Give it a try. Best luck!</p>

CC BY-SA 4.0
2020-09-03T01:10:39.497Z
2020-09-03T02:40:56.183Z
2020-09-03T02:40:56.183Z
Matias G.
<p>While my question is similar to <a href="https://stackoverflow.com/questions/32728218/cropping-very-large-fits-files-using-specified-boundaries">this</a> one, the suggestions offered there won't work for my specific situation.  For over a month I've been trying to find software capable of this but it's been an unsuccessful search.  I don't think the software exists; however, I haven't asked this group yet. I sure hope I'm wrong.</p>
<h2>The Problem</h2>
<ul>
<li>if I crop a fits image, the WCS is lost (which makes sense, the image has changed) but the cropping software won't recompute the WCS for the new area and add it back into the new header</li>
</ul>
<h2>The Data Set</h2>
<ul>
<li>a collection of .fits image files created by a CCD (not tables or any
other kind of .fits file)</li>
<li>each individual image is large in terms of degrees of sky</li>
<li>minimum number of files in set: ~1,150 and max number is: ~15,000</li>
<li>each image has the WCS info in the header</li>
<li>each image is registered on a sub pixel level to the others</li>
</ul>
<h2>Software Requirements</h2>
<ul>
<li>IS NOT PYTHON <em>unless</em> it has a GUI interface hiding all evidence of Python code</li>
<li>runs in local Windows environment, not cloud based</li>
<li>works in a batch or bulk mode</li>
<li>copies the header from the original but updates the WCS entries</li>
<li>updates the other headers as necessary such as NAXIS1</li>
</ul>
<h2>Additional info: why standard methods don't work</h2>
<ul>
<li>the images can't be plate solved by astrometry dot net (they are very out of focus (on purpose with a diffuser) or the plate scale is extreme at over 20 arc-secs per pixel which looks out of focus but isn't)</li>
<li>while the crop with WCS update could be done in Python, this project requires a GUI</li>
</ul>
<p>I've tried SAOimageDS9, AstroImajeJ, PixInsight, Mira, and MaxIm DL 6 Pro but they don't recompute the WCS entries. My goal is to create a procedure to do aperture photometry on special data sets <em>without</em> using Python but first I need to determine if it's possible.  A crop is required before all else due to the size of the data.</p>
<p>When working with other data sets, cropping issue isn't a problem.  The images are registered, then the crop is performed (as well as any 'rotate 180 deg' or mirror left/right/top/bottom).  It removes the WSC headers but plate solving the new, smaller, postage stamp image puts the corrected ones back in.</p>
<p>If anyone knows of software to crop fits images and return correct WCS headers, it would help tremendously.</p>

CC BY-SA 4.0
2020-07-23T00:17:17.787Z
Surely the easiest thing would be for you to write a thin gui wrapper around the astropy function.  It is, as I understand it, a file picker, a couple of sliders and a "crop" button.
James K
CC BY-SA 4.0
2020-07-23T00:37:48.090Z
You say both that you want it to have a GUI *and* that you want it to work in batch mode (which is understandable for processing thousands of images).  Could you clarify what needs to happen in the GUI and what would happen non-interactively?   I’m trying to understand better what your use case is here, and especially what the role of the GUI is.
Eric Jensen
CC BY-SA 4.0
2020-07-23T02:18:04.107Z
I should have included more info in my original post but my posts are always too long.  I'm writing a paper and a few weeks ago I came to the conclusion there isn't any software available for astronomers to crop fits files and keep the WCS info correct - but how does one "prove" software doesn't exist?  My searches yielding nothing except "use Python" so I'm asking in as many forums as I can find. I don't mind using Python. But I don't want to publish a paper with a faulty premise only to have someone say, "You could have used SomeProgram.exe".  The GUI explanation will be in the next comment.
AstroShannon
CC BY-SA 4.0
2020-07-23T02:31:07.797Z
The GUI would consist of what @JamesK said.  There would be a way to view individual fits images, maybe a slider moving through the stack, with zoom and pan.  My hypothetical stack is already registered, so one crop applies to them all.  I'd want to pick an output folder and add a keyword line to the header with the original filename as a string so I know where my cropped image came from.  I'd draw a rectangle on one of the images and hit "crop" and all would be cropped, original filename added to header, and saved in the dir I selected. I'm surprised it doesn't exist as an exe yet.
AstroShannon
CC BY-SA 4.0
2020-07-23T02:35:30.347Z
Most importantly the recalculation of the WCS would take place.  If I wanted to get really fancy, my GUI would even let me select which WCS I wanted to save in the new cropped images. For almost every situation I've encountered where I needed to crop, PIPP has worked for me.  It's the Swiss Army Knife for working with huge numbers of fits files but it won't open the data sets I'm trying to crop due to the headers having the image info in the first extension HDU instead of the primary HDU. PIPP = Planetary Imaging PreProcesor, not to be confused with "pip" install
AstroShannon
CC BY-SA 4.0
2020-07-23T13:18:02.197Z
Just to correct something from the question, AstroImageJ *does* have a crop option, including for a stack of images.  Just choose the rectangle tool, drag, and then choose Image->Crop. It doesn't save the WCS, though apparently that is [on the development roadmap](https://www.astro.louisville.edu/software/astroimagej/updates/release_notes.html).  SAOImage ds9 also has a crop option in the menus, though I couldn't figure out how to make it work, at least on the Mac version - it kept reverting to the original image.
Eric Jensen
CC BY-SA 4.0
2020-07-23T14:41:57.380Z
"not use python..."  port the python code to the language of your choice.  Your ground rules here don't seem to make any sense.
Carl Witthoft
CC BY-SA 4.0
2020-07-23T14:43:16.783Z
For obvious reasons you can't "prove" some code doesn't exist.  In the meantime, you seem to know what you want, so write it in the language of your choice.  The FITS format is well-defined.
Carl Witthoft
CC BY-SA 4.0
2020-07-23T15:26:02.660Z
Python doesn't mean "no GUI." See Tkinter, PyQt, wxPython...
Mike G
CC BY-SA 4.0
2020-07-24T01:36:54.967Z
@ELNJ I saw it is in the works for AIJ to crop and keep the WCS so when that gets released it'll solve a vast majority of the issues I'm noticing.
AstroShannon
CC BY-SA 4.0
2020-07-24T01:56:13.030Z
@CarlWitthoft I'm working with variable star observers to develop a procedure which will allow both professional and advanced amateurs to do data mining on difficult data sets.  There are more than you'd think who don't use Python and don't have the time to learn it.  The limitations I've listed are the limitations these observers are dealing with.  They want to work with specific data and they can't for the reasons I listed, so I thought I pose the question here to see if I was overlooking software which already existed.
AstroShannon
CC BY-SA 4.0
2020-07-24T01:58:43.853Z
@MikeG A Python based solution with a GUI would be fine as I stated in one of the first few comments.  I haven't been able to find a solution which already exists, though.
AstroShannon
CC BY-SA 4.0
2020-07-24T02:06:32.750Z
As a new user of Stack Exchange, it would be helpful to know why my question was down voted. Since this is the first question I've asked, I went over the info on "how to ask a question" very carefully.  Perhaps if I knew why it was down voted, I could learn more about what's acceptable and what isn't so I don't make the same mistake again.
AstroShannon
CC BY-SA 4.0
2020-07-27T14:58:59.953Z
saods9 can recompute the WCS. You got to File->Save Image->FITS. This writes the displayed image as a new FITS file, complete with any cropping and zooming included in the WCS. If you change your window size to be what you want to crop, this will do the cropping (if zoom=1). You can do Match->Frame->WCS to match each image before you do the saving. Of course it's easier to just crop the FITS table then decrement CRPIX1 and CRPIX2 headers by how much you have chopped off the side.
xioxox
CC BY-SA 4.0
2020-07-27T15:17:43.017Z
Aladin (https://aladin.u-strasbg.fr/) does cropping. You can load the FITS images as separate planes. Then go to Image->Crop Image Area. Draw a rectangle. Then you can save the loaded images ("planes") by going to File->Export Planes.
xioxox
CC BY-SA 4.0
2020-07-27T17:34:07.200Z
@xioxox I didn't know Aladin could crop uploaded images, I'll try this feature and see how it handles the headers (for example, does it write a newly calculated WCS and allow for different epochs to be used while retaining the rest of the original header).  This is an interesting way to solve the cropping issue, but it'd be cumbersome with data sets 20GB - multiple TBs in size.  Thank you for the info - I'm looking for solutions anyone can use and even if it doesn't work for the data sets I'm interested in it might work for smaller ones.
AstroShannon
CC BY-SA 4.0
2020-07-27T17:44:54.267Z
@xioxox Do you know how to load multiple images (thousands) at once in DS9? I see I can open each image individually to slowly build up the data set but I'm struggling to find the way I can open or import them all at once.  This would be the perfect solution - anyone could use it without having to upload the large sets to a service like Aladin. Thanks again!
AstroShannon
CC BY-SA 4.0
2020-07-27T20:47:54.767Z
@AstroShannon Aladin isn't an online service (though it can use them) and can work easily with local files. For ds9, it's probably difficult to load lots of files through the GUI. It can be scripted to load lots through the command line or via XPA: http://ds9.si.edu/doc/user/scripts/ (SAMP is a possibility for more complex things). I believe it's also possible to write TCL plugins to add things onti to the GUI, though I've never tried this (I believe that actions in ds9 are tcl commands).
xioxox
CC BY-SA 4.0
2020-07-28T17:25:45.333Z
@xioxox I forgot Aladin can be run locally, I'll install it and see what it can do. I'll also take a look at scripting and plugins with DS9 and see how it handles loading a large data set (~20GB). Thanks for your suggestions, these are the kinds of solutions I was hoping to find.
AstroShannon
<fits><wcs>
How can I crop a fits file and get correct WCS header info without a new plate solve and WITHOUT USING PYTHON?
AstroShannon
# How can I crop a fits file and get correct WCS header info without a new plate solve and WITHOUT USING PYTHON?

(Asked by: username_0 on 2020-07-23)

While my question is similar to [this](https://stackoverflow.com/questions/32728218/cropping-very-large-fits-files-using-specified-boundaries) one, the suggestions offered there won't work for my specific situation. For over a month I've been trying to find software capable of this but it's been an unsuccessful search. I don't think the software exists; however, I haven't asked this group yet. I sure hope I'm wrong.

## The Problem

* if I crop a fits image, the WCS is lost (which makes sense, the image has changed) but the cropping software won't recompute the WCS for the new area and add it back into the new header

## The Data Set

* a collection of .fits image files created by a CCD (not tables or any
  other kind of .fits file)
* each individual image is large in terms of degrees of sky
* minimum number of files in set: ~1,150 and max number is: ~15,000
* each image has the WCS info in the header
* each image is registered on a sub pixel level to the others

## Software Requirements

* IS NOT PYTHON *unless* it has a GUI interface hiding all evidence of Python code
* runs in local Windows environment, not cloud based
* works in a batch or bulk mode
* copies the header from the original but updates the WCS entries
* updates the other headers as necessary such as NAXIS1

## Additional info: why standard methods don't work

* the images can't be plate solved by astrometry dot net (they are very out of focus (on purpose with a diffuser) or the plate scale is extreme at over 20 arc-secs per pixel which looks out of focus but isn't)
* while the crop with WCS update could be done in Python, this project requires a GUI

I've tried SAOimageDS9, AstroImajeJ, PixInsight, Mira, and MaxIm DL 6 Pro but they don't recompute the WCS entries. My goal is to create a procedure to do aperture photometry on special data sets *without* using Python but first I need to determine if it's possible. A crop is required before all else due to the size of the data.

When working with other data sets, cropping issue isn't a problem. The images are registered, then the crop is performed (as well as any 'rotate 180 deg' or mirror left/right/top/bottom). It removes the WSC headers but plate solving the new, smaller, postage stamp image puts the corrected ones back in.

If anyone knows of software to crop fits images and return correct WCS headers, it would help tremendously.

**Tags:** fits, wcs

> **Comments:**
> **username_1**: Surely the easiest thing would be for you to write a thin gui wrapper around the astropy function.  It is, as I understand it, a file picker, a couple of sliders and a "crop" button.  
> **username_2**: You say both that you want it to have a GUI *and* that you want it to work in batch mode (which is understandable for processing thousands of images).  Could you clarify what needs to happen in the GUI and what would happen non-interactively?   I’m trying to understand better what your use case is here, and especially what the role of the GUI is.  
> **username_0**: I should have included more info in my original post but my posts are always too long.  I'm writing a paper and a few weeks ago I came to the conclusion there isn't any software available for astronomers to crop fits files and keep the WCS info correct - but how does one "prove" software doesn't exist?  My searches yielding nothing except "use Python" so I'm asking in as many forums as I can find. I don't mind using Python. But I don't want to publish a paper with a faulty premise only to have someone say, "You could have used SomeProgram.exe".  The GUI explanation will be in the next comment.  
> **username_0**: The GUI would consist of what @JamesK said.  There would be a way to view individual fits images, maybe a slider moving through the stack, with zoom and pan.  My hypothetical stack is already registered, so one crop applies to them all.  I'd want to pick an output folder and add a keyword line to the header with the original filename as a string so I know where my cropped image came from.  I'd draw a rectangle on one of the images and hit "crop" and all would be cropped, original filename added to header, and saved in the dir I selected. I'm surprised it doesn't exist as an exe yet.  
> **username_0**: Most importantly the recalculation of the WCS would take place.  If I wanted to get really fancy, my GUI would even let me select which WCS I wanted to save in the new cropped images. For almost every situation I've encountered where I needed to crop, PIPP has worked for me.  It's the Swiss Army Knife for working with huge numbers of fits files but it won't open the data sets I'm trying to crop due to the headers having the image info in the first extension HDU instead of the primary HDU. PIPP = Planetary Imaging PreProcesor, not to be confused with "pip" install  
> **username_2**: Just to correct something from the question, AstroImageJ *does* have a crop option, including for a stack of images.  Just choose the rectangle tool, drag, and then choose Image->Crop. It doesn't save the WCS, though apparently that is [on the development roadmap](https://www.astro.louisville.edu/software/astroimagej/updates/release_notes.html).  SAOImage ds9 also has a crop option in the menus, though I couldn't figure out how to make it work, at least on the Mac version - it kept reverting to the original image.  
> **username_3**: "not use python..."  port the python code to the language of your choice.  Your ground rules here don't seem to make any sense.  
> **username_3**: For obvious reasons you can't "prove" some code doesn't exist.  In the meantime, you seem to know what you want, so write it in the language of your choice.  The FITS format is well-defined.  
> **username_4**: Python doesn't mean "no GUI." See Tkinter, PyQt, wxPython...  
> **username_0**: @ELNJ I saw it is in the works for AIJ to crop and keep the WCS so when that gets released it'll solve a vast majority of the issues I'm noticing.  
> **username_0**: @CarlWitthoft I'm working with variable star observers to develop a procedure which will allow both professional and advanced amateurs to do data mining on difficult data sets.  There are more than you'd think who don't use Python and don't have the time to learn it.  The limitations I've listed are the limitations these observers are dealing with.  They want to work with specific data and they can't for the reasons I listed, so I thought I pose the question here to see if I was overlooking software which already existed.  
> **username_0**: @MikeG A Python based solution with a GUI would be fine as I stated in one of the first few comments.  I haven't been able to find a solution which already exists, though.  
> **username_0**: As a new user of Stack Exchange, it would be helpful to know why my question was down voted. Since this is the first question I've asked, I went over the info on "how to ask a question" very carefully.  Perhaps if I knew why it was down voted, I could learn more about what's acceptable and what isn't so I don't make the same mistake again.  
> **username_5**: saods9 can recompute the WCS. You got to File->Save Image->FITS. This writes the displayed image as a new FITS file, complete with any cropping and zooming included in the WCS. If you change your window size to be what you want to crop, this will do the cropping (if zoom=1). You can do Match->Frame->WCS to match each image before you do the saving. Of course it's easier to just crop the FITS table then decrement CRPIX1 and CRPIX2 headers by how much you have chopped off the side.  
> **username_5**: Aladin (https://aladin.u-strasbg.fr/) does cropping. You can load the FITS images as separate planes. Then go to Image->Crop Image Area. Draw a rectangle. Then you can save the loaded images ("planes") by going to File->Export Planes.  
> **username_0**: @username_5 I didn't know Aladin could crop uploaded images, I'll try this feature and see how it handles the headers (for example, does it write a newly calculated WCS and allow for different epochs to be used while retaining the rest of the original header).  This is an interesting way to solve the cropping issue, but it'd be cumbersome with data sets 20GB - multiple TBs in size.  Thank you for the info - I'm looking for solutions anyone can use and even if it doesn't work for the data sets I'm interested in it might work for smaller ones.  
> **username_0**: @username_5 Do you know how to load multiple images (thousands) at once in DS9? I see I can open each image individually to slowly build up the data set but I'm struggling to find the way I can open or import them all at once.  This would be the perfect solution - anyone could use it without having to upload the large sets to a service like Aladin. Thanks again!  
> **username_5**: @username_0 Aladin isn't an online service (though it can use them) and can work easily with local files. For ds9, it's probably difficult to load lots of files through the GUI. It can be scripted to load lots through the command line or via XPA: http://ds9.si.edu/doc/user/scripts/ (SAMP is a possibility for more complex things). I believe it's also possible to write TCL plugins to add things onti to the GUI, though I've never tried this (I believe that actions in ds9 are tcl commands).  
> **username_0**: @username_5 I forgot Aladin can be run locally, I'll install it and see what it can do. I'll also take a look at scripting and plugins with DS9 and see how it handles loading a large data set (~20GB). Thanks for your suggestions, these are the kinds of solutions I was hoping to find.  

---

## 2 answers

### Answer by username_6 on 2022-11-25. Score: 3

I don't know about WCS headers, but I had a similar question regarding FITS headers when cropping astronomical FITS images. The program MaxIm DL provides a Batch Process option for automatically cropping multiple images. The FTS headers are preserved.


---

### Answer by username_7 on 2020-09-03. Score: 2

[Skycat](http://www.eso.org/sci/observing/tools/skycat.html) also stores the WCS information when selecting an image region from a fits file. Not sure how exactly this can be done in non-interactive mode but many features can in fact be "batched". Give it a try. Best luck!


---

