Commit 7e1a3a68 authored by Moreau Nicolas's avatar Moreau Nicolas
Browse files

changes to display 1D spectrum in 3D interface

parent 0d368557
......@@ -38,6 +38,8 @@ def cmap2palette (palette_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)]
from result import Result
from typing import Dict
......@@ -885,7 +887,7 @@ class DataBlock:
if(not np.nanmax(spectrum)):
hdu.header['DATAMAX'] = np.max(spectrum)
if (header["CTYPE3"]=="FREQ"):
if (header["CTYPE3"].startswith("FREQ")):
hdu.header['RESTFRQ'] = 0.
hdu.header['RESTFREQ'] = 0.
hdu.header['SPECSYS'] = self.__dVal(header, 'SPECSYS', 'UNKNOWN')
......@@ -1187,7 +1189,7 @@ class DataBlock:
# else:
# hdu.header["BUNIT"]="Jy.km/s"
if (Header["CTYPE3"]=="FREQ"):
if (Header["CTYPE3"].startswith("FREQ")):
iFreqMin=min(iFREQ0,iFREQ1)
iFreqMax=max(iFREQ0,iFREQ1)
iMid=iFreqMin+int((iFreqMax-iFreqMin)/2.)
......@@ -1247,7 +1249,7 @@ class DataBlock:
hdu.header['RESTFREQ'] = Header['RESTFREQ']-(Dv/const.c.value)*Header['RESTFREQ']
hdu.header['CRVAL3']=Dv
if (Header["CTYPE3"]=="FREQ"):
if (Header["CTYPE3"].startswith("FREQ")):
hdu.header['RESTFRQ'] = Header["CRVAL3"]+(iFREQ-1)*Header["CDELT3"]
hdu.header['CRVAL3'] = hdu.header['RESTFRQ']
......@@ -1510,7 +1512,7 @@ class DataBlock:
return result
def getAverageSpectrum(self, iDEC0=None, iDEC1=None, iRA0=None, iRA1=None) -> Result:
self.__logger.debug("getAverageSpectrum: entering")
self.__logger.debug("### getAverageSpectrum: entering")
if iRA0 == None:
iRA0 = 0
if iRA1 == None:
......@@ -1520,14 +1522,27 @@ class DataBlock:
if iDEC1 == None:
iDEC1 = self.__data.shape[1]
# special case when there is only one pixel
# selection will be [iRA0, iRA1[ [iDEC0, iDEC1[
if iRA0 == iRA1 and iDEC0 == iDEC1:
iRA1 = iRA0+1
iDEC1 = iDEC0+1
averageSpectrum = None
averageSpectrumFits = None
with_dask=True
if with_dask:
if with_dask:
if self.__header["BUNIT"] == "Jy/beam":
self.__logger.debug("### Jy/beam")
averageSpectrum = (dask.array.nansum(dask.array.nan_to_num(self.__data[:, iDEC0:iDEC1, iRA0:iRA1]), (1,2)) / self.__convert * self.__cdelt).compute().tolist()
averageSpectrumFits = self.__createFITSSpectrumFromData(iRA0,iRA1,"averageSpectrum",iDEC0,iDEC1,averageSpectrum, "Jy")
elif self.__header["BUNIT"].startswith("K"):
elif self.__header["BUNIT"].startswith("K"):
self.__logger.debug("### K")
self.__logger.debug(self.__data)
self.__logger.debug("self.__convert")
self.__logger.debug(self.__convert)
self.__logger.debug("self.__cdelt")
self.__logger.debug(self.__cdelt)
# print pour verifier que convert et cdelt == 1
# afficher IDEC0, IDEC1, iRA0, iRA1
# spectre scalé à 1.5 au dessus
......@@ -1536,16 +1551,18 @@ class DataBlock:
averageSpectrum = (dask.array.nanmean(dask.array.nan_to_num(self.__data[:, iDEC0:iDEC1, iRA0:iRA1]), (1,2)) / self.__convert * self.__cdelt).compute().tolist()
averageSpectrumFits = self.__createFITSSpectrumFromData(iRA0,iRA1,"averageSpectrum",iDEC0,iDEC1,averageSpectrum, self.__header["BUNIT"])
else:
self.__logger.debug("### else")
averageSpectrum = (dask.array.nanmean(dask.array.nan_to_num(self.__data[:, iDEC0:iDEC1, iRA0:iRA1]), (1,2)) / self.__convert * self.__cdelt).compute().tolist()
#averageSpectrumFits = self.__createFITSSpectrumFromData(iRA0,iRA1,"averageSpectrum",iDEC0,iDEC1,averageSpectrum, self.__header["BUNIT"])
averageSpectrumFits = None
else:
self.__logger.debug("### no dask")
averageSpectrum = np.nansum(np.nan_to_num(self.__data[:, iDEC0:iDEC1, iRA0:iRA1]), (1,2)) / self.__convert * self.__cdelt
averageSpectrumFits = self.__createFITSSpectrumFromData(iRA0,iRA1,"averageSpectrum",iDEC0,iDEC1,averageSpectrum, self.__header["BUNIT"])
#averageSpectrumFits = self.__createFITSSpectrumFromData(iRA0,iRA1,"averageSpectrum",iDEC0,iDEC1,averageSpectrum, "Jy")
result0 = {"averageSpectrum": averageSpectrum, "averageSpectrumFits": averageSpectrumFits}
self.__logger.debug(result0)
result = Result().ok(result0)
self.__logger.debug("getAverageSpectrum: exiting")
return result
......
......@@ -41,7 +41,10 @@ class FitsHeader {
// name of nth axis
this.ctype1 = "CTYPE1" in header ? header["CTYPE1"].toUpperCase().trim() : undefined;
this.ctype2 = "CTYPE2" in header ? header["CTYPE2"].toUpperCase().trim() : undefined;
this.ctype3 = "CTYPE3" in header ? header["CTYPE3"].toUpperCase().trim() : undefined;
if(this.ctype3 === 'FREQUENCY')
this.ctype3 = 'FREQ';
if(this.ctype1 !== undefined){
this.projectionType = this.ctype1.slice(-3);
......
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