Added image healpix map into the json response of UpperLimitView; altered the Survey field into a PositiveSmallIntegerField
This commit is contained in:
parent
6154679dd2
commit
cf3213a0f9
@ -13,7 +13,7 @@ class Pixel(models.Model):
|
|||||||
# WILL ONLY HOLD 10 SURVEYS AS AN AUTOFIELD (IntegerField, ~2 billion limit)
|
# WILL ONLY HOLD 10 SURVEYS AS AN AUTOFIELD (IntegerField, ~2 billion limit)
|
||||||
# BIGAUTOFIELD WILL BE REQUIRED FOR MORE!
|
# BIGAUTOFIELD WILL BE REQUIRED FOR MORE!
|
||||||
|
|
||||||
survey = models.SmallIntegerField()
|
survey = models.PositiveSmallIntegerField()
|
||||||
|
|
||||||
hpid = models.IntegerField(db_index=True) # up to over 200 million
|
hpid = models.IntegerField(db_index=True) # up to over 200 million
|
||||||
|
|
||||||
|
@ -2,5 +2,6 @@ astropy
|
|||||||
numpy
|
numpy
|
||||||
healpy
|
healpy
|
||||||
scipy
|
scipy
|
||||||
|
mpmath
|
||||||
django
|
django
|
||||||
djangorestframework
|
djangorestframework
|
||||||
|
64
views.py
64
views.py
@ -363,38 +363,86 @@ class UpperLimitView(APIView):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# SQUARE REGION IMAGE SERVING
|
||||||
|
# ****************************************************************
|
||||||
|
|
||||||
|
# get hpids within a circle of radius sqrt(2) * outer annulus radius
|
||||||
|
map_radius = annulus_outer * np.sqrt(2)
|
||||||
|
|
||||||
|
map_pixel_list = hp.query_disc(
|
||||||
|
nside = 4096,
|
||||||
|
vec = src_vec,
|
||||||
|
inclusive = False,
|
||||||
|
nest = False,
|
||||||
|
radius = (map_radius * u.arcsecond).to(u.radian).value
|
||||||
|
)
|
||||||
|
|
||||||
|
# fetch those pixels for the requested surveys
|
||||||
|
# summing counts and sorting by hpid
|
||||||
|
|
||||||
|
map_pixels_qs = (
|
||||||
|
Pixel.objects
|
||||||
|
.filter(hpid__in = map_pixel_list, survey__in = survey_numbers)
|
||||||
|
.values('hpid')
|
||||||
|
.annotate(counts=Sum('counts'))
|
||||||
|
.order_by('hpid')
|
||||||
|
)
|
||||||
|
|
||||||
|
# turn the queryset to a list
|
||||||
|
map_pixels_list = list(map_pixels_qs)
|
||||||
|
|
||||||
|
# get lists of healpix indices and count values
|
||||||
|
map_healpix_list = [d['hpid'] for d in map_pixels_list]
|
||||||
|
map_counts_list = [d['counts'] for d in map_pixels_list]
|
||||||
|
|
||||||
|
# set map nside
|
||||||
|
map_nside = 4096
|
||||||
|
|
||||||
|
# set map order
|
||||||
|
map_order = 'ring'
|
||||||
|
|
||||||
|
# assemble the result dict
|
||||||
|
map_dict = {
|
||||||
|
'healpix' : map_healpix_list,
|
||||||
|
'counts' : map_counts_list,
|
||||||
|
'nside' : map_nside,
|
||||||
|
'order' : map_order,
|
||||||
|
'radius_as' : map_radius
|
||||||
|
}
|
||||||
|
|
||||||
# RESULT JSON
|
# RESULT JSON
|
||||||
# ****************************************************************
|
# ****************************************************************
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
|
# frequentist limits
|
||||||
'ClassicUpperLimit' : classic_count_ul,
|
'ClassicUpperLimit' : classic_count_ul,
|
||||||
'ClassicLowerLimit' : classic_count_ll,
|
'ClassicLowerLimit' : classic_count_ll,
|
||||||
'ClassicCountRateUpperLimit' : classic_rate_ul,
|
'ClassicCountRateUpperLimit' : classic_rate_ul,
|
||||||
'ClassicCountRateLowerLimit' : classic_rate_ll,
|
'ClassicCountRateLowerLimit' : classic_rate_ll,
|
||||||
'ClassicFluxUpperLimit' : classic_flux_ul,
|
'ClassicFluxUpperLimit' : classic_flux_ul,
|
||||||
'ClassicFluxLowerLimit' : classic_flux_ll,
|
'ClassicFluxLowerLimit' : classic_flux_ll,
|
||||||
|
# bayesian limits
|
||||||
'BayesianUpperLimit' : bayesian_count_ul,
|
'BayesianUpperLimit' : bayesian_count_ul,
|
||||||
'BayesianLowerLimit' : bayesian_count_ll,
|
'BayesianLowerLimit' : bayesian_count_ll,
|
||||||
'BayesianCountRateUpperLimit' : bayesian_rate_ul,
|
'BayesianCountRateUpperLimit' : bayesian_rate_ul,
|
||||||
'BayesianCountRateLowerLimit' : bayesian_rate_ll,
|
'BayesianCountRateLowerLimit' : bayesian_rate_ll,
|
||||||
'BayesianFluxUpperLimit' : bayesian_flux_ul,
|
'BayesianFluxUpperLimit' : bayesian_flux_ul,
|
||||||
'BayesianFluxLowerLimit' : bayesian_flux_ll,
|
'BayesianFluxLowerLimit' : bayesian_flux_ll,
|
||||||
|
# flux 'center value' estimate
|
||||||
'FluxEstimate' : Flux,
|
'FluxEstimate' : Flux,
|
||||||
|
# raw data
|
||||||
'ApertureCounts' : N,
|
'ApertureCounts' : N,
|
||||||
'ApertureBackgroundCounts' : B,
|
'ApertureBackgroundCounts' : B,
|
||||||
'SourceCounts' : S,
|
'SourceCounts' : S,
|
||||||
'Exposure' : t,
|
'Exposure' : t,
|
||||||
|
# count rates
|
||||||
'SourceRate' : CR,
|
'SourceRate' : CR,
|
||||||
'BackgroundRate' : BR,
|
'BackgroundRate' : BR,
|
||||||
|
# contamination
|
||||||
'Contamination' : contamination,
|
'Contamination' : contamination,
|
||||||
'NearbySources' : nearby_sources
|
'NearbySources' : nearby_sources,
|
||||||
|
# count map for the frontend image
|
||||||
|
'CountMap' : map_dict
|
||||||
}
|
}
|
||||||
|
|
||||||
clean = sanitize(result) # calling sanitize() to convert NaN to null
|
clean = sanitize(result) # calling sanitize() to convert NaN to null
|
||||||
|
Loading…
x
Reference in New Issue
Block a user