1717from astropy .modeling import models
1818
1919
20- def _get_cloud_http (s3_uri : Union [str , S3Path ], verbose : bool = False ) -> str :
20+ def _get_cloud_http (s3_uri : Union [str , S3Path ], key : str = None , secret : str = None ,
21+ token : str = None , verbose : bool = False ) -> str :
2122 """
2223 Get the HTTP URI of a cloud resource from an S3 URI.
2324
2425 Parameters
2526 ----------
2627 s3_uri : string | S3Path
2728 the S3 URI of the cloud resource
29+ key : string
30+ Default None. Access key ID for S3 file system.
31+ secret : string
32+ Default None. Secret access key for S3 file system.
33+ token : string
34+ Default None. Security token for S3 file system.
2835 verbose : bool
2936 Default False. If true intermediate information is printed.
3037 """
@@ -38,7 +45,7 @@ def _get_cloud_http(s3_uri: Union[str, S3Path], verbose: bool = False) -> str:
3845 print (f'Attempting to access private S3 bucket: { s3_path .bucket } ' )
3946
4047 # create file system and get URL of file
41- fs = s3fs .S3FileSystem (anon = is_anon )
48+ fs = s3fs .S3FileSystem (anon = is_anon , key = key , secret = secret , token = token )
4249 with fs .open (s3_uri , 'rb' ) as f :
4350 return f .url ()
4451
@@ -252,8 +259,8 @@ def _write_asdf(cutout: astropy.nddata.Cutout2D, gwcsobj: gwcs.wcs.WCS, outfile:
252259
253260def asdf_cut (input_file : Union [str , pathlib .Path , S3Path ], ra : float , dec : float , cutout_size : int = 20 ,
254261 output_file : Union [str , pathlib .Path ] = "example_roman_cutout.fits" ,
255- write_file : bool = True , fill_value : Union [int , float ] = np .nan ,
256- verbose : bool = False ) -> astropy .nddata .Cutout2D :
262+ write_file : bool = True , fill_value : Union [int , float ] = np .nan , key : str = None ,
263+ secret : str = None , token : str = None , verbose : bool = False ) -> astropy .nddata .Cutout2D :
257264 """
258265 Takes a single ASDF input file (`input_file`) and generates a cutout of designated size `cutout_size`
259266 around the given coordinates (`coordinates`).
@@ -276,8 +283,17 @@ def asdf_cut(input_file: Union[str, pathlib.Path, S3Path], ra: float, dec: float
276283 Optional, default True. Flag to write the cutout to a file or not.
277284 fill_value: int | float
278285 Optional, default `np.nan`. The fill value for pixels outside the original image.
286+ key : string
287+ Default None. Access key ID for S3 file system. Only applicable if `input_file` is a
288+ cloud resource.
289+ secret : string
290+ Default None. Secret access key for S3 file system. Only applicable if `input_file` is a
291+ cloud resource.
292+ token : string
293+ Default None. Security token for S3 file system. Only applicable if `input_file` is a
294+ cloud resource.
279295 verbose : bool
280- Default False. If true intermediate information is printed.
296+ Default False. If True, intermediate information is printed.
281297
282298 Returns
283299 -------
@@ -288,7 +304,7 @@ def asdf_cut(input_file: Union[str, pathlib.Path, S3Path], ra: float, dec: float
288304 # if file comes from AWS cloud bucket, get HTTP URL to open with asdf
289305 file = input_file
290306 if (isinstance (input_file , str ) and input_file .startswith ('s3://' )) or isinstance (input_file , S3Path ):
291- file = _get_cloud_http (input_file , verbose )
307+ file = _get_cloud_http (input_file , key , secret , token , verbose )
292308
293309 # get the 2d image data
294310 with asdf .open (file ) as f :
0 commit comments