Tools for making image cutouts from sets of TESS full frame images

Overview

Cutout tools for astronomical images

Powered by Astropy Badge PyPi Status Documentation Status

Astrocut provides tools for making cutouts from sets of astronomical images with shared footprints. It is under active development.

Three main areas of functionality are included:

  • Solving the specific problem of creating image cutouts from sectors of Transiting Exoplanet Survey Satellite (TESS) full-frame images.
  • General fits file cutouts incuding from single images and sets of images with the shared WCS/pixel scale.
  • Cutout post-processing functionality, including centering cutouts along a path (for moving targets) and combining cutouts.

Documentation is at https://astrocut.readthedocs.io.

Project Status

Github actions CI status Codecov coverage status

Developer Documentation

Installation

$ git clone https://github.com/spacetelescope/astrocut.git
$ cd astrocut
$ pip install .

For active developement intall in develop mode

$ pip install -e .

Testing

Testing is now run with tox (pip install tox). Tests can be found in astrocut/tests/.

$ tox -e test

Tests can also be run directly with pytest:

$ pip install -e .[test]
$ pytest

Documentation

Documentation files are found in docs/.

We now build the documentation with tox (pip install tox):

$ tox -e build_docs

You can also build the documentation with Sphinx directly using:

$ pip install -e .[docs]
$ cd docs
$ make html

The built docs will be in docs/_build/html/, to view them go to file:///path/to/astrocut/repo/docs/_build/html/index.html in the browser of your choice.

Release Protocol

Follow the Astropy template release instructions.

Requirements:

  • build (pip install build)
  • twine (pip install twine)

Notes:

  • Astrocut uses setuptools_scm to manage version numbers.
  • Astrocut does have a pyproject.toml file
  • If the given twine command doesn't work you likely need python -m twine upload dist/*
  • You shouldn't have trigger a readthedocs build manually, it should run on it's own in ~20 min.

Contributing

We love contributions! Astrocut is open source, built on open source, and we'd love to have you hang out in our community.

Imposter syndrome disclaimer: We want your help. No, really.

There may be a little voice inside your head that is telling you that you're not ready to be an open source contributor; that your skills aren't nearly good enough to contribute. What could you possibly offer a project like this one?

We assure you - the little voice in your head is wrong. If you can write code at all, you can contribute code to open source. Contributing to open source projects is a fantastic way to advance one's coding skills. Writing perfect code isn't the measure of a good developer (that would disqualify all of us!); it's trying to create something, making mistakes, and learning from those mistakes. That's how we all improve, and we are happy to help others learn.

Being an open source contributor doesn't just mean writing code, either. You can help out by writing documentation, tests, or even giving feedback about the project (and yes - that includes giving feedback about the contribution process). Some of these contributions may be the most valuable to the project as a whole, because you're coming to the project with fresh eyes, so you can see the errors and assumptions that seasoned contributors have glossed over.

Note: This disclaimer was originally written by Adrienne Lowe for a PyCon talk, and was adapted by Astrocut based on its use in the README file for the MetPy project.

License

This project is Copyright (c) MAST Archive Developers and licensed under the terms of the BSD 3-Clause license. This package is based upon the Astropy package template which is licensed under the BSD 3-clause licence. See the licenses folder for more information.

Comments
  • Enable `CutoutFactory.cube_cut()` to use S3-hosted files

    Enable `CutoutFactory.cube_cut()` to use S3-hosted files

    Summary

    This PR documents a working prototype which enables the CutoutFactory.cube_cut() method to read TESS cube files directly from AWS S3 storage, by-passing the need for users to download the large cubes locally. (TESS cubes amount to ~110 GB per CCD in Sector 35!)

    Example use:

    Screen Shot 2021-06-01 at 10 41 46 PM

    The motivation for this change is to enable fast cloud-based analyses of TESS FFI data, i.e., this feature would enable users to obtain thousands of TESS cut-outs concurrently, limited only by the throughput of S3.

    This PR is rough and not ready for review -- it lacks tests, docstrings, etc. I also haven't investigated whether this change would be compatible with @ceb8's awesome recent work on moving cut-outs. However I am happy to prepare a proper PR if we think this is a good idea!

    Technical details

    This prototype defines two compatible classes, LocalCubeFile and S3CubeFile, which encapsulate two different data access patterns:

    • LocalCubeFile uses astropy.io.fits.open() to access a cube as normal.
    • S3CubeFile uses the boto3 and asyncio libraries to asynchronously extract slices from the cube using Byte-range GET requests. The number of requests scales with the vertical size of the cutout (requests = n_rows + 3), leveraging the smart columnar way in which the cubes are organized for this purpose.

    The S3CubeFile will only work with astrocut-produced cubes at this time. In the future we can hopefully integrate cloud streaming features in a more generic way into astropy.io.fits, but that would be a much more expensive project. See existing discussions at https://github.com/astropy/astropy/issues/3446 and https://github.com/jbcurtin/astro-cloud/issues/1.

    Inspiration

    The idea to stream partial FITS files from the cloud is not mine and has been explored by many others before me, including:

    • @astrofrog, cf. https://gist.github.com/astrofrog/404a5682311bae221fd5308c1498da94
    • @pllim & @mustaric, cf. https://github.com/mustaric/lambda-tess-search/blob/master/sandbox/aws_remote_fits.py
    • @jbcurtin, cf. https://github.com/jbcurtin/astro-cloud/
    • and others, no doubt!

    Verification

    Click here to see the code snippet I used to verify that S3-based cutouts match local cutouts:
    from astrocut import CutoutFactory
    path = "/Users/gb/tmp/tess-s0035-1-1-cube.fits"
    CutoutFactory().cube_cut(path, "147 -7.5", 10, "local-cutout.fits")
    uri = "s3://stpubdata/tess/public/mast/tess-s0035-1-1-cube.fits"
    CutoutFactory().cube_cut(uri, "147 -7.5", 10, "s3-cutout.fits")
    
    import lightkurve as lk
    lk.read("local-cutout.fits").plot(title="Local Cube");
    lk.read("s3-cutout.fits").plot(title="S3 Cube");
    
    Screen Shot 2021-06-01 at 11 02 33 PM
    opened by barentsen 20
  • Make cubes out of TICA FFIs

    Make cubes out of TICA FFIs

    Implements a class based off the existing CubeFactory class that can generate cubes out of TICA FFIs.

    Note: This is one of the core four projects for MAST Q3 and must be implemented before June 30.

    • [x] Implement TICACubeFactory
    • [x] Verify file structural similarity between TICA and TESS Cubes
    • [x] Verify image similarity between TICA and TESS Cubes
    • [x] Add functionality to append incoming FFIs to existing cubes (starting in Sept we get new ones every week, EM1 we get them ever 2 weeks...?)
    • [x] Fix truncated string issue: StringTruncateWarning: truncated right side string(s) longer than 9 character(s) during assignment self.info_table[kwd][i] = ffi_data[0].header.get(kwd, nulval)
    • [x] First test that the duplicate columns issue is still an issue in delivery 1 of future sectors - so far I think I've only seen it in sector 27. ~Fix duplicate columns issue in build_info_table(). For some reason there are duplicate columns in the order 1 deliveries for keywords: TESS_X, TESS_Y, TESS_VX, TESS_VY etc~
    • [x] Code cleanup: Make sure class variables are under init so they get reset for every run. There was an issue with cube_shape being too small, that would get fixed when I reinitialized the class, investigate that.
    • [x] Unit test(s)

    UPDATE: After investigating TruncatedString warning, I found the source of the issue being under _build_info_table where the default length of a string keyword value is set based on the length of the string keyword value in the designated template_file . In the event that the string kwd value in one FFI is longer than the string kwd value in the template file, a stringTruncated Warning will pop up. I fixed the default value and compared the generated info_table with the info_table before fixing, and it doesn't seem to clip off the kwd value the way I expected it would. So I'm going to leave this error alone and avoid fiddling with the string column length in case that creates a memory issue. The Warning will be noted here for future reference in case I need to revisit.

    Screenshot below shows the DATASUM values for 2 FFIs in an info table where one value is 9 characters and the other is 10. This is the string column causing the Warnings. image



    TICA vs SPOC Cube Analysis

    HDU Lists for SPOC and TICA cubes (respectively)

    image

    Image comparison between SPOC and TICA FFis within the cubes

    Sector 27, Camera 1, CCD 2

    image

    Normalized (Array/MEDIAN(Array))

    image

    Using this star as a reference point to verify alignment between two FFIs within the respective cubes

    image

    Ratio image (TESS/TICA) between exact cutouts of that star for both SPOC and TICA

    image

    Verifying time-cadence between SPOC and TESS. Start time between consecutive FFIs lapsed for 10 minutes. Consistent with the EM1 protocol.

    image enhancement Priority: High 
    opened by jaymedina 7
  • fixing error resulting from forward slash in target name

    fixing error resulting from forward slash in target name

    Fixing an error originating from having forward slashes and spaces in the target name (e.g. C/2014 UN271). This edit catches any / or spaces in the name of the target and replaces them accordingly, which allows the script to continue writing the output Target Pixel File.

    This closes https://github.com/spacetelescope/astrocut/issues/50

    bug no-changelog-entry-needed 
    opened by jaymedina 7
  • Addition of check for cutout existing before continuing

    Addition of check for cutout existing before continuing

    With the previous updates, the check confirming that the file exists was removed. Unfortunately, there appears to be edge cases where the file may be empty and this causes an index error. This work adds a check prior to looping through the cutout file dictionary. Also correcting a minor spelling mistake.

    FYI: Due to mission freezes, we will have to coordinate the timing of the merging and promotion to PyPi.

    opened by phicc 5
  • Make cutouts out of TICA cubes

    Make cutouts out of TICA cubes

    Implements a class based off the existing CutoutFactory class that can generate TPFs out of TICA cubes.

    Note: This is one of the core four projects for MAST Q3 and must be implemented before June.

    • [x] Implement TICACutoutFactory
    • [x] Verify file structural similarity between TICA and TESS TPFs
    • [x] Verify image similarity between TICA and TESS TPFs
    • [x] Ensure TPF header keywords should be the same between TICA and TESS
    • [x] Ensure TICA header keyword values are unique from TESS and accurate
    • [x] Add new header keyword in TPF that lets users know what FFIs were used to make the TPF (TICA or TESS?)
    • [x] Unit test(s)
    opened by jaymedina 4
  • Documentation revamp

    Documentation revamp

    The PR includes a major update to the look and feel of the Astrocut documentation, as well as added information in the output file formats for various functionalities.

    A live version of the new docs can be viewed here: https://astrocut.readthedocs.io/en/doc_updates/

    opened by ceb8 4
  • `tesscut` does not appear to work right now

    `tesscut` does not appear to work right now

    I appear to be experiencing issues with TESScut. For example, requesting a cut-out for Pi Men in sector 1 yields a Cutout Error: No FFIs found for input target. Cutout not performed..

    Example: Screenshot from 2019-07-17 09-50-57

    opened by barentsen 4
  • cutout error on s3-support branch

    cutout error on s3-support branch

    On the s3-support branch for making direct s3 cutouts, seeing an error with this set of input data:

    from astrocut import CutoutFactory
    
    astrocut_cutter = CutoutFactory()
    
    cube_file = 's3://stpubdata/tess/public/mast/tess-s0030-4-3-cube.fits'
    coordinates = '102.7 -70.5'
    cutout_size = (3, 3)
    output_path = '/tmp'
    
    astrocut_cutter.cube_cut(cube_file, coordinates, cutout_size, output_path=output_path)
    

    Traceback:

    Traceback (most recent call last):
      File "/Users/bfalk/repos/astrocut/astrocut/tests/test_small_s3_cutout.py", line 12, in <module>
        astrocut_cutter.cube_cut(cube_file, coordinates, cutout_size, output_path=output_path)
      File "/Users/bfalk/repos/astrocut/astrocut/cube_cut.py", line 736, in cube_cut
        self._parse_table_info(cube.table.data, verbose)
      File "/Users/bfalk/repos/astrocut/astrocut/cube_cut.py", line 930, in table
        return self.loop.run_until_complete(self.cube_async.table)
      File "/Users/bfalk/miniconda3/envs/astrocut/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
        return future.result()
      File "/Users/bfalk/repos/astrocut/astrocut/cube_cut.py", line 1018, in table
        self._table = await self.read_table()
      File "/Users/bfalk/repos/astrocut/astrocut/cube_cut.py", line 1032, in read_table
        hdu2_str = await self._read_block(hdu2_offset, length=None)
      File "/Users/bfalk/repos/astrocut/astrocut/cube_cut.py", line 1064, in _read_block
        resp = await self.s3_client.get_object(
      File "/Users/bfalk/miniconda3/envs/astrocut/lib/python3.9/site-packages/aiobotocore/client.py", line 187, in _make_api_call
        raise error_class(parsed_response, operation_name)
    botocore.exceptions.ClientError: An error occurred (InvalidRange) when calling the GetObject operation: The requested range is not satisfiable
    

    Specifying a local file for the cube_file, I don't see this error, and the cutout succeeds.

    I'm wondering if this particular sector/file needs some special casing when reading in the table information?

    @barentsen wondering if you might be able to take a look at this at some point?

    opened by falkben 3
  • MNT: Update codecov-action version to v2

    MNT: Update codecov-action version to v2

    You are using a deprecated version of codecov-action, see https://github.com/codecov/codecov-action for more details. xref astropy/astropy#12245

    This is an automated update made by the batchpr tool :robot: - feel free to close if it doesn't look good! You can report issues to @pllim.

    opened by pllim 3
  • MNT: Stop using ci-helpers in appveyor.yml

    MNT: Stop using ci-helpers in appveyor.yml

    To whom it may concern,

    If you are using https://github.com/astropy/ci-helpers in your appveyor.yml , please know that the Astropy project has dropped active development/support for Appveyor CI. If it still works, good for you, because we did not remove the relevant files (yet). But if it ever stops working, we have no plans to fix anything for Appveyor CI. Please consider using native Windows support other CI, e.g., Travis CI (see https://docs.travis-ci.com/user/reference/windows/). We apologize for any inconvenience caused.

    If this issue is opened in error or irrelevant to you, feel free to close. Thank you.

    xref astropy/ci-helpers#464

    opened by pllim 3
  • Error handling

    Error handling

    Adding error handling so that if one file in a list for fits_cut or image_cut raises an error, the user still gets a cutout with the rest of the files. A warning is raised showing which files caused a problem and what the error was.

    opened by ceb8 3
  • Add header keyword value quality checks to unit tests

    Add header keyword value quality checks to unit tests

    Add header keyword value quality checks to unit tests for make_cube.py.

    There was an incident where the EXT1 header keyword NAXIS2 did not reflect the correct number of FFIs that were added to the cube. We are still unsure of what happened, but as a preventative measure, it would be good to have some checks in place to verify the quality of the primary and image header keyword values.

    opened by jaymedina 0
  • Use class inheritance to merge `TicaCubeFactory` with `CubeFactory`

    Use class inheritance to merge `TicaCubeFactory` with `CubeFactory`

    Suggestion from @falkben RE: Pull Request #59

    "Can we use class inheritance here? It looks like most of the changes would just be in the class attributes. If we make those changes, I think we can make these changes much simpler and should be easier to maintain."

    Also some commentary I initially made in TicaCubeFactory class:

    NOTE: Later down the line 
            we might want to generalize CubeFactory so that we no longer need 
            a separate class for the TICA cubes. 
            
            Modifying the __init__ 
            in CubeFactory so that it can switch parameters based on whether 
            we want cubes for TICA or TESS will probably be the route I take.
            Or see how this is generalized when Zcut wraps CubeFactory?
    
    opened by jaymedina 0
  • Expand functionality to support ASDF file format

    Expand functionality to support ASDF file format

    Cutouts are able to be made on FITS Cut out of the box, but future mission like Roman will be housing data in ASDF files. Find a way to support this. ASDF Cut?

    opened by jaymedina 0
Owner
Space Telescope Science Institute
STScI is operated by AURA for NASA
Space Telescope Science Institute
Image enhancing model for making a blurred image to be somehow clearer than before

This is a very small prject which helps in enhancing the images by taking a Input images. This project has many features like detcting the faces and enhaning the faces itself and also a feature which enhances the whole image

null 3 Dec 3, 2021
Pixel art as well as various sets for hand crafting

Pixel art as well as various sets for hand crafting

null 1 Nov 9, 2021
Console images in 48 colors, 216 colors and full rgb

console_images Console images in 48 colors, 216 colors and full rgb Full RGB 216 colors 48 colors If it does not work maybe you should change color_fu

Урядов Алексей 5 Oct 11, 2022
Image Reading, Metadata Conversion, and Image Writing for Microscopy Images in Python

AICSImageIO Image Reading, Metadata Conversion, and Image Writing for Microscopy Images in Pure Python Features Supports reading metadata and imaging

Allen Institute for Cell Science - Modeling 137 Dec 14, 2022
Seaborn-image is a Python image visualization library based on matplotlib and provides a high-level API to draw attractive and informative images quickly and effectively.

seaborn-image: image data visualization Description Seaborn-image is a Python image visualization library based on matplotlib and provides a high-leve

null 48 Jan 5, 2023
This app finds duplicate to near duplicate images by generating a hash value for each image stored with a specialized data structure called VP-Tree which makes searching an image on a dataset of 100Ks almost instantanious

Offline Reverse Image Search Overview This app finds duplicate to near duplicate images by generating a hash value for each image stored with a specia

null 53 Nov 15, 2022
missing-pixel-filler is a python package that, given images that may contain missing data regions (like satellite imagery with swath gaps), returns these images with the regions filled.

Missing Pixel Filler This is the official code repository for the Missing Pixel Filler by SpaceML. missing-pixel-filler is a python package that, give

SpaceML 11 Jul 19, 2022
A tool for making simple-style text posters or wallpapers with high resolution.

PurePoster PurePoster is a fancy tool for making arbitrary-resolution, simple-style posters or wallpapers with text in center. Functionality PurePoste

Renyang Guan 4 Jul 9, 2022
impy is an all-in-one image analysis library, equipped with parallel processing, GPU support, GUI based tools and so on.

impy is All You Need in Image Analysis impy is an all-in-one image analysis library, equipped with parallel processing, GPU support, GUI based tools a

null 24 Dec 20, 2022
Kainat 13 Mar 7, 2022
Fast batch image resizer and rotator for JPEG and PNG images.

imgp is a command line image resizer and rotator for JPEG and PNG images.

Terminator X 921 Dec 25, 2022
Python Image Morpher (PIM) is a program that can take two images and blend them to whatever extent or precision that you like

Python Image Morpher (PIM) is a program that can take two images and blend them to whatever extent or precision that you like! It is designed to emulate some of Python's OpenCV image processing from scratch without reference.

David Dowd 108 Dec 19, 2022
Create a static HTML/CSS image gallery from a bunch of images.

gallerize Create a static HTML/CSS image gallery from a bunch of images.

Jochen Kupperschmidt 19 Aug 21, 2022
starfish is a Python library for processing images of image-based spatial transcriptomics.

starfish: scalable pipelines for image-based transcriptomics starfish is a Python library for processing images of image-based spatial transcriptomics

null 199 Dec 8, 2022
Image Processing - Make noise images clean

影像處理-影像降躁化(去躁化) (Image Processing - Make Noise Images Clean) 得力於電腦效能的大幅提升以及GPU的平行運算架構,讓我們能夠更快速且有效地訓練AI,並將AI技術應用於不同領域。本篇將帶給大家的是 「將深度學習應用於影像處理中的影像降躁化 」,

null 2 Aug 4, 2022
Png2Jpg tool will help you convert from png image format to jpg images format.

PNG 2 JPG All codes assume running from root directory. Please update the sys path at the beginning of the codes before running. Over View Png2Jpg too

Nguyễn Trường Lâu 2 Dec 27, 2021
A simple image-level annotation tool supporting multi-channel images for napari.

napari-labelimg4classification A simple image-level annotation tool supporting multi-channel images for napari. This napari plugin was generated with

null 4 May 16, 2022
An open source image editor which can manipulate an image in many ways!

Image Editor - An open source image editor which can manipulate an image in many ways! If you need any more modes in repo or I

TroJanzHEX 44 Nov 17, 2022