Commit 2a50b3fb authored by Caillat Michel's avatar Caillat Michel
Browse files

Adopt the notations conventions

parent 26d8f6bf
......@@ -944,38 +944,27 @@ class DataBlock:
self.__logger.debug("RADECRangeInDegrees: exiting")
return result
def degToHMSDMS(self, ra, dec):
def degToHMSDMS(self, RAinDD, DECinDD):
self.__logger.debug("degToHMSDMS: entering")
w = wcs.WCS(self.__header)
pixcrd = np.array([[ra, dec, 0, 0]], np.float_)
pixcrd = np.array([[RAinDD, DECinDD, 0, 0]], np.float_)
world = w.all_pix2world(pixcrd, 0)
result = SkyCoord(world[0][0], world[0][1], unit="deg").to_string('hmsdms')
self.__logger.debug("degToHMSDMS: exiting")
return {"status": True, "message": "", "result": result}
def rangeToHMS(self, start, end, step):
def rangeToHMS(self, iRA0, iRA1, iRAstep):
self.__logger.debug("rangeToHMS: entering")
start = int(start)
end = int(end)
step = int(step)
self.__logger.debug( "Getting HMS range.")
self.__logger.debug("%d %d %d" % (start, end, step))
result = []
for i in range(start, end, step):
self.__logger.debug( "i: %d" % i)
for i in range(iRA0, iRA1, iRAstep):
result.append(self.degToHMSDMS(i, 0)["result"])
self.__logger.debug("rangeToHMS: exiting")
return {"status": True, "message": "", "result": result}
def rangeToDMS(self, start, end, step):
def rangeToDMS(self, iDEC0, iDEC1, iDECstep):
self.__logger.debug("rangeToDMS: entering")
start = int(start)
end = int(end)
step = int(step)
self.__logger.debug( "Getting DMS range from input parameters '%d %d %d'" % (start, end, step))
result = []
for i in range(start, end, step):
self.__logger.debug( "i: %d" % i)
for i in range(iDEC0, iDEC1, iDECstep):
result.append(self.degToHMSDMS(0, i)["result"])
self.__logger.debug("rangeToDMS: exiting")
return {"status": True, "message": "", "result": result}
......
#!/usr/bin/env python
from astropy.io import fits
from astropy import units as u
from astropy import wcs
from astropy.coordinates import SkyCoord
import numpy as np
import sys
import getopt
import os
import subprocess
import collections
import math
import socket
import psutil
import json
#import StringIO
from io import StringIO
from io import BytesIO
import matplotlib as mpl
import png
from PIL import Image, PngImagePlugin
import math
import dask
import dask.array as da
from datetime import datetime
import traceback
from DataBlock import DataBlock
mpl.use('Agg') # to avoid problem when DISPLAY isn't defined.
#from matplotlib import pyplot as pp
DataRoot = "dataroot"
FITSFilePrefix = DataRoot + '/FITS/'
PNGFilePrefix = DataRoot + '/PNG/'
DataRoot = "dataroot"
FITSFilePrefix = DataRoot + '/FITS/'
PNGFilePrefix = DataRoot + '/PNG/'
#
#
......@@ -46,36 +24,6 @@ DataBlock.setFITSFilePrefix(FITSFilePrefix)
# The PNG files
DataBlock.setPNGFilePrefix(PNGFilePrefix)
# def __cmap2palette (name):
# x = pp.get_cmap(palette_name)
# return [tuple(map(lambda x: int(round(x*255)), x(i)[0:3])) for i in range(x.N)]
#
# __palette_names = ["Greys", "RdYlBu", "hsv", "gist_ncar", "gist_rainbow", "gist_gray", "Spectral", "jet", "plasma", "inferno", "magma", "afmhot", "gist_heat"]
# __palette = dict()
# for palette_name in __palette_names:
# __palette[palette_name] = __cmap2palette(palette_name)
#
# __default_palette_name = "Greys"
#
# def getPaletteFromName (name ):
# return __palette[name] if name in __palette_names else __palette[__default_palette_name]
#
# __transformation_names = ["minmax", "percent98"]
#
# __video_mode_names = ["direct", "inverse"]
#
# def getRenderingCapabilities():
# return {
# "itts" : __transformation_names,
# "default_itt_index" : 0,
# "luts" : __palette_names,
# "default_lut_index" : 2,
# "vmodes" : __video_mode_names,
# "default_vmode_index" : 0
# }
#
#
# An implementation of the class used in the serverWsgi-ish server.
#
......@@ -219,7 +167,6 @@ class DataManagerImpl :
result = self.__checkPresence(relFITSFilePath)
if result["status"]:
result = self.__dataBlocks[relFITSFilePath].getHeader()
self.__logger.debug("About to return %r" % result)
self.__logger.debug("getHeader : exiting")
return result
......@@ -228,31 +175,30 @@ class DataManagerImpl :
result = self.__checkPresence(relFITSFilePath)
if result["status"]:
result = self.__dataBlocks[relFITSFilePath].RADECRangeInDegrees()
self.__logger.debug("About to return %s " % repr(result))
self.__logger.debug("RADECRangeInDegrees : exiting")
return result
def degToHMSDMS(self, ra, dec, relFITSFilePath):
def degToHMSDMS(self, relFITSFilePath, RAinDD, DECinDD):
self.__logger.debug("degToHMSDMS : entering")
result = self.__checkPresence(relFITSFilePath)
if result["status"]:
result=self.__dataBlocks[relFITSFilePath].degToHMSDMS(ra, dec)
result = self.__dataBlocks[relFITSFilePath].degToHMSDMS(RAinDD, DECinDD)
self.__logger.debug("degToHMSDMS : exiting")
return result
def rangeToHMS(self, start, end, step, relFITSFilePath):
def rangeToHMS(self, relFITSFilePath, iRA0, iRA1, iRAstep):
self.__logger.debug("degToHMSDMS : entering")
result = self.__checkPresence(relFITSFilePath)
if result["status"]:
result=self.__dataBlocks[relFITSFilePath].rangeToHMS(start, end, step)
result=self.__dataBlocks[relFITSFilePath].rangeToHMS(iRA0, iRA1, iRAstep)
self.__logger.debug("degToHMSDMS : exiting")
return result
def rangeToDMS(self, start, end, step, relFITSFilePath):
def rangeToDMS(self, relFITSFilePath, iDEC0, iDEC1, iDECstep):
self.__logger.debug("rangeToDMS : entering")
result = self.__checkPresence(relFITSFilePath)
if result["status"]:
result=self.__dataBlocks[relFITSFilePath].rangeToDMS(start, end, step)
result = self.__dataBlocks[relFITSFilePath].rangeToDMS(iDEC0, iDEC1, iDECstep)
self.__logger.debug("rangeToDMS : exiting")
return result
......
......@@ -33,21 +33,21 @@ import dataManager_michel as dataManager
# #
#####################################################################
""" enable cross domain ajax requests
"""
enable cross domain ajax requests
"""
def enable_cors(fn):
def _enable_cors(*args, **kwargs):
def _enable_cors(*args, **kwargs):
# set CORS headers
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, OPTIONS'
response.headers['Access-Control-Allow-Headers'] = 'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token'
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, OPTIONS'
response.headers['Access-Control-Allow-Headers'] = 'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token'
if request.method != 'OPTIONS':
# actual request; reply with the actual response
return fn(*args, **kwargs)
if request.method != 'OPTIONS':
# actual request; reply with the actual response
return fn(*args, **kwargs)
return _enable_cors
return _enable_cors
def getFloatValue(value):
if value is not None and str(value) != "null":
......@@ -68,11 +68,6 @@ def getBoolValue(value):
Replaces NaN values by None in array
"""
def cleanNanInList(arr):
# result = listToClean
# for i in range(0, len(result)):
# for j in range(0, len(result[i])):
# if np.isnan(result[i][j]):
# result[i][j] = None
result = arr
result[np.isnan(result)] = None
return result
......@@ -93,8 +88,6 @@ def rebuildFilename(filename):
"""
def byteify(input):
#logging.debug("byteify : entering")
#logging.debug("input = %r and itstype = %s" % (input, type(input)))
result = None
if isinstance(input, dict):
result = {byteify(key): byteify(value)
......@@ -123,8 +116,8 @@ def byteify(input):
@route(baseUrl+"/ping", name='upAnWaiting', method='GET')
@enable_cors
def upAnWaiting():
logger.debug("upAndWaiting : entering")
logger.debug("upAndWaiting : exiting")
logger.debug("upAndWaiting - wrapper : entering")
logger.debug("upAndWaiting - wrapper : exiting")
return "{status: %r, message : 'Up and waiting', 'result': %r}" % (True, request)
"""
......@@ -134,12 +127,19 @@ def upAnWaiting():
@route( baseUrl+'/degToHMSDMS', name='degToHMSDMS', method='GET')
@enable_cors
def degToHMSDMS():
relFITSFilePath = rebuildFilename(request.GET['relPNGFilePath'])
ra = getFloatValue(request.GET['ra'])
dec = getFloatValue(request.GET['dec'])
sessionID = request.GET['sessionID']
logger.debug("degToHMSDMS - wrapper : entering")
try:
relFITSFilePath = rebuildFilename(request.GET['relFITSFilePath'])
RAinDD = getFloatValue(request.GET['RAinDD'])
DECinDD = getFloatValue(request.GET['DECinDD'])
except Exception as e:
logger.debug(f'{e}')
raise
response.content_type = "application/json; charset=utf-8"
return json.dumps(dm.degToHMSDMS(ra, dec, relFITSFilePath))
logger.debug("degToHMSDMS - wrapper : exiting")
return json.dumps(dm.degToHMSDMS(relFITSFilePath, RAinDD, DECinDD))
"""
......@@ -150,15 +150,20 @@ def degToHMSDMS():
@route( baseUrl+'/rangeToHMS', name='rangeToHMS', method='GET')
@enable_cors
def rangeToHMS():
logger.debug("rangeToHMS - wrapper : entering")
try:
relFITSFilePath = rebuildFilename(request.GET['relFITSFilePath'])
iRA0 = getIntValue(request.GET['iRA0'])
iRA1 = getIntValue(request.GET['iRA1'])
iRAstep = getIntValue(request.GET['iRAstep'])
except Exception as e:
logger.debug(f'{e}')
raise
relFITSFilePath = rebuildFilename(request.GET['relFITSFilePath'])
sessionID = request.GET['sessionID']
start = getIntValue(request.GET['start'])
end = getIntValue(request.GET['end'])
step = getIntValue(request.GET['step'])
response.content_type = "application/json; charset=utf-8"
logger.debug("rangeToHMS - wrapper : exiting")
return json.dumps(dm.rangeToHMS(start, end, step, relFITSFilePath))
return json.dumps(dm.rangeToHMS(relFITSFilePath, iRA0, iRA1, iRAstep))
"""
Given a FITS filename and an interval of positive integers values and
......@@ -168,15 +173,18 @@ def rangeToHMS():
@route( baseUrl+'/rangeToDMS', name='rangeToDMS', method='GET')
@enable_cors
def rangeToDMS():
relFITSFilePath = rebuildFilename(request.GET['relFITSFilePath'])
sessionID = request.GET['sessionID']
start = getIntValue(request.GET['start'])
end = getIntValue(request.GET['end'])
step = getIntValue(request.GET['step'])
logger.debug("rangeToDMS - wrapper : entering")
try:
relFITSFilePath = rebuildFilename(request.GET['relFITSFilePath'])
iDEC0 = getIntValue(request.GET['iDEC0'])
iDEC1 = getIntValue(request.GET['iDEC1'])
iDECstep = getIntValue(request.GET['iDECstep'])
except Exception as e:
logger.debug(f'{e}')
response.content_type = "application/json; charset=utf-8"
logger.debug("rangeToDMS - wrapper : exiting")
return json.dumps(dm.rangeToDMS(start, end, step, relFITSFilePath))
return json.dumps(dm.rangeToDMS(relFITSFilePath, iDEC0, iDEC1, iDECstep))
"""
Given relFITSFilePath read corresponding the FITS file in memory
......@@ -185,12 +193,15 @@ def rangeToDMS():
@route( baseUrl+'/setData', name='setData', method='GET')
@enable_cors
def setData():
logger.debug("setData : entering")
relFITSFilePath = rebuildFilename(request.GET['relFITSFilePath'])
sessionID = request.GET['sessionID']
logger.debug("setData - wrapper : entering")
try:
relFITSFilePath = rebuildFilename(request.GET['relFITSFilePath'])
except Exception as e:
logger.debug(f'{e}')
raise
response.content_type = "application/json; charset=utf-8"
result = dm.setData(relFITSFilePath)
logger.debug("setData : exiting")
logger.debug("setData - wrapper : exiting")
return json.dumps(result)
"""
......@@ -200,10 +211,14 @@ def setData():
@route( baseUrl+'/getDimensions', name='getDimensions', method='GET')
@enable_cors
def getDimensions():
relFITSFilePath = rebuildFilename(request.GET['relFITSFilePath'])
sessionID = request.GET['sessionID']
logger.debug("getDimensions - wrapper : entering")
try:
relFITSFilePath = rebuildFilename(request.GET['relFITSFilePath'])
except Exception as e:
logger.debug(f'{e}')
raise
response.content_type = "application/json; charset=utf-8"
logger.debug("getDimensions - wrapper : exiting")
return json.dumps(dm.getDimensions(relFITSFilePath))
......@@ -230,7 +245,6 @@ def getPixelValueAtiFreqiRAiDEC():
logger.debug("getPixelValueAtiFreqiRAiDEC - wrapper : entering" )
relFITSFilePath = rebuildFilename(request.GET['relFITSFilePath'])
sessionID = request.GET['sessionID']
iFreq = getIntValue(request.GET['iFreq'])
iRA = getIntValue(request.GET['iRA'])
iDEC = getIntValue(request.GET['iDEC'])
......@@ -252,7 +266,6 @@ def getSlice():
logger.debug("getSlice - wrapper : entering" )
relFITSFilePath = rebuildFilename(request.GET['relFITSFilePath'])
sessionID = request.GET['sessionID']
sliceNumb = int(request.GET['sliceNumb'])
step = int(request.GET['step'])
result = dm.getSlice(sliceNumb, step, relFITSFilePath)
......@@ -272,7 +285,6 @@ def getFreq():
logger.debug("getFreq - wrapper : entering" )
relFITSFilePath = rebuildFilename(request.GET['relFITSFilePath'])
sessionID = request.GET['sessionID']
x = getIntValue(request.GET['x'])
y = getIntValue(request.GET['y'])
startZ = getIntValue(request.GET['startZ'])
......@@ -386,14 +398,15 @@ def createFits():
@route( baseUrl+'/getHeader', name='getHeader', method='GET')
@enable_cors
def getHeader():
global logger
global dm
logger.debug("getHeader : entering")
relFITSFilePath = rebuildFilename(request.GET['relFITSFilePath'])
logger.debug(f"relFITSFilePath = {relFITSFilePath}")
logger.debug("getHeader - wrapper : entering")
try:
relFITSFilePath = rebuildFilename(request.GET['relFITSFilePath'])
except Exception as e:
logger.debug(f'{e}')
raise
response.content_type = "application/json; charset=utf-8"
result = json.dumps(dm.getHeader(relFITSFilePath))
logger.debug("getHeader : exiting")
logger.debug("getHeader - wrapper : exiting")
return result
"""
......@@ -404,9 +417,15 @@ def getHeader():
@route( baseUrl+'/RADECRangeInDegrees', name='RADECRangeInDegrees', method='GET')
@enable_cors
def RADECRangeInDegrees():
relFITSFilePath = rebuildFilename(request.GET['relFITSFilePath'])
sessionID = request.GET['sessionID']
logger.debug("RADECRangeInDegrees - wrapper : entering")
try :
relFITSFilePath = rebuildFilename(request.GET['relFITSFilePath'])
except Exception as e:
logger.debug(f'{e}')
raise
response.content_type = "application/json; charset=utf-8"
logger.debug("RADECRangeInDegrees - wrapper : exiting")
return json.dumps(dm.RADECRangeInDegrees(relFITSFilePath))
"""
......@@ -572,7 +591,7 @@ def purgeDataBlocks():
#
# HTTP server error handling
#
@error(500)
# @error(500)
def error500(error):
stack_str=''.join(traceback.format_stack())
global logger
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment