-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add footprint finder code #127
Conversation
My initial reaction is to say let's setup a single |
b842116
to
9e51987
Compare
I added unit tests for the module, but there seems to be a problem with accessing the public footprint files on S3 in the runners. From what I can find online, this is a permissions issue. The odd thing is, we have other tests that access S3 resources and work fine.
|
fix type annotation
Use json.load() documentation, set threads to 8 for cube_cut
9e51987
to
735112e
Compare
I added a fixture to mock opening the footprint files with |
Marking as ready as tests and documentation have been added. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an issue with accessing the footprint files in the bucket -- I have a ticket to work on that next week.
Since we're having a delay in opening up the cached footprint files on S3, another approach could be to download the footprint directly from CAOM through vo-tap interface on the first cutout. This query gets the SPOC footprint table from CAOM and can be run from anywhere: And this gets the TICA footprint (takes a bit longer since it's HLSP) We manipulate that response in tesscut to create the footprint JSON file we store in S3 with a small bit of code but we could add that into astrocut as well. Taking advantage of the cached footprint file in S3 is likely better long term, but we could use this method initially, for this PR |
Do we want to revisit any of the mocking now that we can access the footprints? |
|
||
from .utils.utils import parse_size_input | ||
|
||
TESS_ARCSEC_PER_PX = 21 # Number of arcseconds per pixel in a TESS image |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we may want to make an issue or note to come back to this and generalize this somehow so it could be used for other missions. i think it could wait for now though, as I think TESS is the only mission we'd do this for.
astrocut/footprint_cutouts.py
Outdated
|
||
def _s_region_to_polygon(s_region: Column): | ||
""" | ||
Takes in a s_region string of type POLYGON or CIRCLE and returns it as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think this docstring is correct -- this function as currently written only supports POLYGON
, not CIRCLE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this docstring is still referring to CIRCLE but that doesn't look supported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you looking at the most recent commit? I do see the change on that docstring.
astrocut/footprint_cutouts.py
Outdated
@cached(cache=FFI_TTLCACHE, lock=Lock()) | ||
def _get_s3_ffis(s3_uri, as_table: bool = False, load_polys: bool = False): | ||
""" | ||
Fetch the S3 footprint file containing a dict of all FFIs and a polygon column | ||
that holds the s_regions as polygon points and vectors. | ||
Optional Parameters: | ||
as_table: Return the footprint file as an Astropy Table | ||
load_polys: Convert the s_region column to an array of SphericalPolygon objects | ||
""" | ||
# Open footprint file with fsspec | ||
with fsspec.open(s3_uri, s3={'anon': True}) as f: | ||
ffis = json.load(f) | ||
|
||
if load_polys: | ||
ffis['polygon'] = _s_region_to_polygon(ffis['s_region']) | ||
|
||
if as_table: | ||
ffis = Table(ffis) | ||
|
||
return ffis |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this function be removed, for now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured that we could leave it in since we'll need it shortly, but it's true that we don't want users trying to call it while the bucket isn't accessible. I'll remove it for now.
I was looking for the coverage results. Doesn't need to be handled in this PR, but it looks like there's a problem with codecov upload in the github action. From Python 3.10 with numpy 1.23 and full coverage job: [2024-10-03T16:46:10.843Z] ['info'] => Project root located at: /home/runner/work/astrocut/astrocut
[2024-10-03T16:46:10.846Z] ['info'] -> No token specified or token is empty
[2024-10-03T16:46:10.936Z] ['info'] Searching for coverage files...
[2024-10-03T16:46:10.973Z] ['info'] => Found 1 possible coverage files:
./coverage.xml
[2024-10-03T16:46:10.973Z] ['info'] Processing ./coverage.xml...
[2024-10-03T16:46:10.976Z] ['info'] Detected GitHub Actions as the CI provider.
[2024-10-03T16:46:11.306Z] ['info'] Pinging Codecov: https://codecov.io/upload/v4?package=github-action-2.1.0-uploader-0.8.0&token=*******&branch=footprint-finder&build=11166073335&build_url=https%3A%2F%2Fgithub.com%2Fspacetelescope%2Fastrocut%2Factions%2Fruns%2F11166073335&commit=9552cbb9116481980b67cbea56921b10ebb327db&job=CI&pr=127&service=github-actions&slug=spacetelescope%2Fastrocut&name=&tag=&flags=&parent=
[2024-10-03T16:46:11.478Z] ['error'] There was an error running the uploader: Error uploading to [https://codecov.io:](https://codecov.io/) Error: There was an error fetching the storage URL during POST: 429 - {"message":"Rate limit reached. Please upload with the Codecov repository upload token to resolve issue. Expected time to availability: 366s."}
[2024-10-03T16:46:11.479Z] ['info'] Codecov will exit with status code 0. If you are expecting a non-zero exit code, please pass in the `-Z` flag Anyways, coverage looks pretty good:
|
Made an issue here: https://jira.stsci.edu/browse/ASB-29119 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all looks reasonable to me. I only had a few small comments on some tests.
astrocut/tests/test_utils.py
Outdated
def test_parse_size_input(): | ||
"""Test that different types of input are accurately parsed into cutout sizes""" | ||
# With scalar as input | ||
cutout_size = utils.parse_size_input(5) | ||
assert np.array_equal(cutout_size, np.array((5, 5))) | ||
|
||
# With astropy quantity as input | ||
cutout_size = utils.parse_size_input(10 * u.pix) | ||
assert np.array_equal(cutout_size, np.array((10, 10)) * u.pix) | ||
|
||
# With tuple as input | ||
cutout_size = utils.parse_size_input((5, 10)) | ||
assert np.array_equal(cutout_size, np.array((5, 10))) | ||
|
||
# With list as input | ||
cutout_size = utils.parse_size_input([10, 5]) | ||
assert np.array_equal(cutout_size, np.array((10, 5))) | ||
|
||
# With array as input | ||
cutout_size = utils.parse_size_input(np.array((5, 10))) | ||
assert np.array_equal(cutout_size, np.array((5, 10))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can probably simplify this test by parametrizing over the inputs/outputs using @pytest.mark.parametrize
"""Test that FFI intersection with cutout outputs proper results""" | ||
# SphericalPolygon object for cutout | ||
cutout_sp = SphericalPolygon.from_radec(lon=(350, 10, 10, 350), | ||
lat=(-10, -10, 10, 10), | ||
center=(0, 0)) | ||
|
||
# Intersecting object | ||
intersecting = SphericalPolygon.from_radec(lon=(345, 355, 355, 345), | ||
lat=(-15, -15, -5, -5), | ||
center=(350, -10)) | ||
|
||
# Non-intersecting object | ||
nonintersecting = SphericalPolygon.from_radec(lon=(335, 345, 345, 335), | ||
lat=(-15, -15, -5, -5), | ||
center=(340, -10)) | ||
|
||
# Edge object that intersects | ||
edge_intersect = SphericalPolygon.from_radec(lon=(340, 350, 350, 340), | ||
lat=(-15, -15, -5, -5), | ||
center=(345, -10)) | ||
|
||
# Edge object that does not intersect | ||
edge_nonintersect = SphericalPolygon.from_radec(lon=(340, 349, 349, 340), | ||
lat=(-15, -15, -5, -5), | ||
center=(345, -10)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could probably parametrize this test as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not much exposure to this codebase yet so can't comfortably comment on the details but this looks good on the overview to me. Ran the test suite last night (after changes) and it all came back good.
This is a draft PR that adds the footprint finder code from TESScut. Leaving as draft since I haven't added tests yet, but I'd welcome any feedback on the actual implementation.
I tried to make things as general as possible in terms of functions and variable names, but some things are more TESS specific and will need to be pulled out into a wrapper later when we generalize. Namely,
_extract_sequence_information
,_create_sequence_list
, and_get_cube_files_from_sequence_obs
are more TESS-specific as of now. The same is true about certain parts ofcube_cut_from_footprint
, mainly variables.Something I was unsure about is how to best handle multiprocessing. The
cube_cut_from_footprint
function takes athreads
parameter to use asmax_workers
when usingcube_cut
on the gathered cube files. However, thecube_cut
function also takes its ownthreads
parameter. Should these be two separate parameters tocube_cut_from_footprint
, or the same? Shouldthreads
incube_cut
just be set to'auto'
?