Skip to content
This repository was archived by the owner on Apr 6, 2025. It is now read-only.

Commit 0fb0ea8

Browse files
committed
Add support for loading info images
1 parent 36ee9d4 commit 0fb0ea8

File tree

4 files changed

+41
-44
lines changed

4 files changed

+41
-44
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import requests, json
2222
url = "http://quickanalysis.photonranch.org/lineprofile"
2323
body = json.dumps({
2424
"full_filename": "tst-test-20201112-00000058-EX10.fits.bz2",
25+
"s3_directory": "data",
2526
# return the intensity profile for the line spanning the top left to bottom right corners.
2627
"start": {
2728
"x": 0,

application.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
class LineProfileInput(Schema):
2828
""" Parse and validate input for the line profile endpoint """
2929
full_filename = fields.Str(required=True)
30+
s3_directory = fields.Str(required=True)
3031
start = fields.Dict(keys=fields.Str(), values=fields.Float(), required=True)
3132
end = fields.Dict(keys=fields.Str(), values=fields.Float(), required=True)
3233

@@ -54,12 +55,13 @@ def home():
5455
def plotView():
5556
""" This is a route to visualize the line requested for the line profile."""
5657
filename = request.args.get('filename')
58+
s3_directory = request.args.get('s3_directory')
5759
x0 = float(request.args.get('x0'))
5860
x1 = float(request.args.get('x1'))
5961
y0 = float(request.args.get('y0'))
6062
y1 = float(request.args.get('y1'))
6163

62-
data = get_image_data(filename)
64+
data = get_image_data(filename, s3_directory)
6365
start = (x0, y0)
6466
end = (x1, y1)
6567
profile = get_intensity_profile(data, start, end)
@@ -77,11 +79,12 @@ def lineprofile():
7779
start (dict): 'x' and 'y' values for the line start point, in [0, 1]
7880
end (dict): same as start
7981
full_filename (str): photon ranch filename in s3, including the extension.
82+
s3_directory (str): the 'folder' that the image resides in s3. [ data | info-images | allsky ]
8083
8184
Example post request:
8285
curl -X POST http://localhost:5000/lineprofile -F \
8386
'data={"start":{"x": 0, "y":0}, "end": {"x": 1, "y": 1},
84-
"full_filename": "tst-test-20201112-00000058-EX01.fits.bz2"}'
87+
"full_filename": "tst-test-20201112-00000058-EX01.fits.bz2", "s3_directory": "data"}'
8588
8689
"""
8790

@@ -91,16 +94,17 @@ def lineprofile():
9194
start = (args['start']['x'], args['start']['y'])
9295
end = (args['end']['x'], args['end']['y'])
9396
full_filename = args['full_filename']
97+
s3_directory = args['s3_directory']
9498

9599
# Make sure the requested file exists
96-
if not check_if_s3_image_exists(full_filename):
100+
if not check_if_s3_image_exists(full_filename, s3_directory):
97101
return jsonify({
98102
"success": False,
99-
"message": f"Image does not exist: {full_filename}."
103+
"message": f"Image does not exist: {s3_directory}/{full_filename}."
100104
}), 400
101105

102106
# Get the image data and compute a line profile
103-
data = get_image_data(full_filename)
107+
data = get_image_data(full_filename, s3_directory)
104108
profile = get_intensity_profile(data, start, end)
105109

106110
response = jsonify({
@@ -134,15 +138,16 @@ def image_statistics():
134138

135139
args = json.loads(request.data)
136140
full_filename = args['full_filename']
141+
s3_directory = args['s3_directory']
137142

138143
# Make sure the requested file exists
139-
if not check_if_s3_image_exists(full_filename):
144+
if not check_if_s3_image_exists(full_filename, s3_directory):
140145
return jsonify({
141146
"success": False,
142-
"message": f"Image does not exist: {full_filename}."
147+
"message": f"Image does not exist: {s3_directory}/{full_filename}."
143148
}), 400
144149

145-
image_data = get_image_data(full_filename)
150+
image_data = get_image_data(full_filename, s3_directory)
146151
if 'subregion' in args.keys():
147152
coords = args['subregion']
148153
image_data = get_subregion_rect(image_data, coords['x0'], coords['x1'], coords['y0'], coords['y1'] )
@@ -172,6 +177,7 @@ def histogram():
172177
173178
POST Args:
174179
full_filename (str): full file name for analysis, including the file extensions.
180+
s3_directory (str): the 'folder' that the image resides in s3. [ data | info-images | allsky ]
175181
clip_percent (float): percentile value of intensity to define min and max range of histogram
176182
subregion (dict): optional, analyze subregion of image
177183
subregion['shape'] (str): type of shape. Currently only supports 'rect'.
@@ -186,17 +192,18 @@ def histogram():
186192

187193
args = json.loads(request.data)
188194
full_filename = args['full_filename']
195+
s3_directory = args['s3_directory']
189196
clip_percent = args['clip_percent']
190197
print(full_filename, clip_percent)
191198

192199
# Make sure the requested file exists
193-
if not check_if_s3_image_exists(full_filename):
200+
if not check_if_s3_image_exists(full_filename, s3_directory):
194201
return jsonify({
195202
"success": False,
196-
"message": f"Image does not exist: {full_filename}."
203+
"message": f"Image does not exist: {s3_directory}/{full_filename}."
197204
}), 400
198205

199-
image_data = get_image_data(full_filename)
206+
image_data = get_image_data(full_filename, s3_directory)
200207
if 'subregion' in args.keys():
201208
coords = args['subregion']
202209
image_data = get_subregion_rect(image_data, coords['x0'], coords['x1'], coords['y0'], coords['y1'] )

dev_sandbox/example.ipynb

Lines changed: 16 additions & 28 deletions
Large diffs are not rendered by default.

quickanalysis/utils/load_data.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,23 @@
1111
URL_EXPIRATION = 3600
1212
MAX_CACHE_SIZE = 1e8 # the max `sys.getsizeof(x)` size for the cache
1313

14-
def check_if_s3_image_exists(full_filename):
14+
def check_if_s3_image_exists(full_filename, s3_directory):
1515
try:
1616
s3.head_object(
1717
Bucket=settings.S3_BUCKET,
18-
Key=f'data/{full_filename}'
18+
Key=f'{s3_directory}/{full_filename}'
1919
)
2020
except Exception as e:
2121
return False
2222
return True
2323

2424

25-
@cached(cache=TTLCache(maxsize=1024, ttl=URL_EXPIRATION))
26-
def get_image_data(full_filename):
25+
#@cached(cache=TTLCache(maxsize=1024, ttl=URL_EXPIRATION))
26+
def get_image_data(full_filename, s3_directory):
27+
print('FULL FILENAME: ',full_filename)
2728
params = {
2829
'Bucket': settings.S3_BUCKET,
29-
'Key': f'data/{full_filename}'
30+
'Key': f'{s3_directory}/{full_filename}'
3031
}
3132
url = s3.generate_presigned_url(
3233
ClientMethod='get_object',

0 commit comments

Comments
 (0)