diff --git a/models.py b/models.py index 5abfcbd..2c19b02 100644 --- a/models.py +++ b/models.py @@ -13,7 +13,7 @@ class Pixel(models.Model): # WILL ONLY HOLD 10 SURVEYS AS AN AUTOFIELD (IntegerField, ~2 billion limit) # BIGAUTOFIELD WILL BE REQUIRED FOR MORE! - survey = models.SmallIntegerField() + survey = models.PositiveSmallIntegerField() hpid = models.IntegerField(db_index=True) # up to over 200 million diff --git a/requirements.txt b/requirements.txt index f23852f..7b143be 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,5 +2,6 @@ astropy numpy healpy scipy +mpmath django djangorestframework diff --git a/views.py b/views.py index 114ec44..68b5eba 100644 --- a/views.py +++ b/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 = { - + # frequentist limits 'ClassicUpperLimit' : classic_count_ul, 'ClassicLowerLimit' : classic_count_ll, 'ClassicCountRateUpperLimit' : classic_rate_ul, 'ClassicCountRateLowerLimit' : classic_rate_ll, 'ClassicFluxUpperLimit' : classic_flux_ul, 'ClassicFluxLowerLimit' : classic_flux_ll, - + # bayesian limits 'BayesianUpperLimit' : bayesian_count_ul, 'BayesianLowerLimit' : bayesian_count_ll, 'BayesianCountRateUpperLimit' : bayesian_rate_ul, 'BayesianCountRateLowerLimit' : bayesian_rate_ll, 'BayesianFluxUpperLimit' : bayesian_flux_ul, 'BayesianFluxLowerLimit' : bayesian_flux_ll, - + # flux 'center value' estimate 'FluxEstimate' : Flux, - + # raw data 'ApertureCounts' : N, 'ApertureBackgroundCounts' : B, 'SourceCounts' : S, 'Exposure' : t, - + # count rates 'SourceRate' : CR, 'BackgroundRate' : BR, - + # 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