Skip to content

Commit 64a2951

Browse files
authored
Merge pull request #7 from Caltech-IPAC/raen/patch/installs
Simplify the install cell (cloud-access-intro.md)
2 parents 959aaad + 566f74c commit 64a2951

File tree

1 file changed

+23
-30
lines changed

1 file changed

+23
-30
lines changed

tutorials/cloud_access/cloud-access-intro.md

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -71,34 +71,22 @@ It can be used to substitute values for the following variables, which are used
7171

7272
## 3. Imports
7373

74-
Libraries are imported at the top of each section when used.
74+
The following libraries will be used:
75+
76+
- astropy: perform image cutouts
77+
- hpgeom: map sky location to catalog partition
78+
- matplotlib: view results
79+
- pandas: query Parquet datasets
80+
- pyarrow: work with Parquet datasets
81+
- pyvo: locate images in the cloud (pyvo>=1.5 required)
82+
- s3fs: browse buckets
83+
84+
Libraries are imported at the top of each section where used.
7585
This cell will install them if needed:
7686

7787
```{code-cell} ipython3
78-
try:
79-
import astropy # perform image cutouts
80-
import hpgeom # map sky location to catalog partition
81-
import matplotlib # view results
82-
import pandas # query Parquet datasets
83-
import pyarrow # work with Parquet datasets
84-
import pyvo # locate images in the cloud (pyvo>=1.5 required)
85-
import s3fs # browse buckets
86-
except ImportError:
87-
%pip install astropy
88-
%pip install hpgeom
89-
%pip install pandas
90-
%pip install pyarrow
91-
%pip install pyvo>=1.5
92-
%pip install s3fs
93-
%pip install -U matplotlib
94-
95-
# check for pyvo>=1.5 (required for SIA2Service)
96-
try:
97-
import pyvo
98-
pyvo.dal.SIA2Service("https://irsa.ipac.caltech.edu/SIA")
99-
except AttributeError:
100-
%pip install --upgrade pyvo
101-
# note that you may need to restart the kernel to use the updated package
88+
# Uncomment the next line to install dependencies if needed.
89+
# !pip install astropy hpgeom pandas pyarrow pyvo>=1.5 s3fs matplotlib
10290
```
10391

10492
## 4. Browse buckets
@@ -199,7 +187,8 @@ seip_results["cloud_access"][:5]
199187
```{code-cell} ipython3
200188
# find the first mosaic file in the results
201189
# use json to convert the string containing the cloud info to a dictionary
202-
seip_mosaic_cloud_info = json.loads([i for i in seip_results["cloud_access"] if ".mosaic.fits" in i][0])
190+
mosaics = [i for i in seip_results["cloud_access"] if ".mosaic.fits" in i]
191+
seip_mosaic_cloud_info = json.loads(mosaics[0])
203192
204193
# extract
205194
BUCKET_NAME = seip_mosaic_cloud_info["aws"]["bucket_name"]
@@ -230,7 +219,8 @@ In addition, use the HDU `section` method in place of the usual `data` to avoid
230219
(See [Obtaining subsets from cloud-hosted FITS files](https://docs.astropy.org/en/stable/io/fits/usage/cloud.html#fits-io-cloud).)
231220

232221
```{code-cell} ipython3
233-
with astropy.io.fits.open(f"s3://{BUCKET_NAME}/{image_key}", fsspec_kwargs={"anon": True}) as hdul:
222+
s3_image_path = f"s3://{BUCKET_NAME}/{image_key}"
223+
with astropy.io.fits.open(s3_image_path, fsspec_kwargs={"anon": True}) as hdul:
234224
cutout = Cutout2D(hdul[0].section, position=coords, size=size, wcs=WCS(hdul[0].header))
235225
```
236226

@@ -273,7 +263,8 @@ fs = pyarrow.fs.S3FileSystem(region=BUCKET_REGION, anonymous=True)
273263

274264
```{code-cell} ipython3
275265
# load the schema from the "_common_metadata" file
276-
schema = pyarrow.dataset.parquet_dataset(f"{parquet_root}/_common_metadata", filesystem=fs).schema
266+
s3_schema_path = f"{parquet_root}/_common_metadata"
267+
schema = pyarrow.dataset.parquet_dataset(s3_schema_path, filesystem=fs).schema
277268
278269
# the full schema can be quite large since catalogs often have hundreds of columns
279270
# but if you do want to look at the entire schema, uncomment the next line
@@ -316,7 +307,9 @@ Find the partitions (HEALPix pixel indexes) that overlap the polygon:
316307

317308
```{code-cell} ipython3
318309
k = 5
319-
polygon_pixels = hpgeom.query_polygon(a=corners[0], b=corners[1], nside=hpgeom.order_to_nside(k), inclusive=True)
310+
polygon_pixels = hpgeom.query_polygon(
311+
a=corners[0], b=corners[1], nside=hpgeom.order_to_nside(k), inclusive=True
312+
)
320313
```
321314

322315
Query:
@@ -353,5 +346,5 @@ results_df.plot.hexbin("W2-W3", "W1-W2", norm=colors.LogNorm(vmin=1, vmax=500))
353346
## About this notebook
354347

355348
- Author: Troy Raen (IRSA Developer) in conjunction with Brigitta Sipőcz, Jessica Krick and the IPAC Science Platform team
356-
- Updated: 2023-12-22
357349
- Contact: https://irsa.ipac.caltech.edu/docs/help_desk.html
350+
- Updated: 2024-07-29

0 commit comments

Comments
 (0)