Commit 20a42954 authored by ba yaye-awa's avatar ba yaye-awa
Browse files

add the obj directory in the docker configuration

parent dd2f65fc
......@@ -6,6 +6,11 @@ import socket
import psutil
import json
import math
import numpy as np
import yt
from spectral_cube import SpectralCube
from astropy.io import fits
from astropy.stats import sigma_clip
from datetime import datetime
from DataBlock import DataBlock
......@@ -13,6 +18,7 @@ from DataBlock import DataBlock
DataRoot = "dataroot"
FITSFilePrefix = DataRoot + '/FITS/'
PNGFilePrefix = DataRoot + '/PNG/'
OBJFilePrefix = DataRoot + '/OBJ/'
#
#
......@@ -24,6 +30,9 @@ DataBlock.setFITSFilePrefix(FITSFilePrefix)
# The PNG files
DataBlock.setPNGFilePrefix(PNGFilePrefix)
# The PNG files
DataBlock.setOBJFilePrefix(OBJFilePrefix)
#
# An implementation of the class used in the serverWsgi-ish server.
#
......@@ -349,6 +358,54 @@ class DataManagerImpl :
del self.__dataBlocks[db]
self.__logger.debug("purgeDataBlocks : exiting")
return {"status": True, "message": f"{len(tobePurged)} data set(s) erased.", "result": tobePurged}
#
#
#
def getYtObj(self):
self.__logger.debug("ytObj : entering")
name = "Abell1795.CO.image.pbcor"
filename = FITSFilePrefix+"Abell1795.CO.image.pbcor.fits"
fileout = OBJFilePrefix+"Abell1795.CO.image.pbcor"
#create cube by extracting data from the fits
cube= fits.getdata(filename)
cube = cube.squeeze()
cube[np.isnan(cube)] = np.nanmin(cube)
cube.shape
Nsigma = 0.1
#define the delimeter
reduce=0.4 # 20% of the nb of x and y channels (to avoid the edge noise)
schrink = 1 # velocity axis: new v-axis size is RA/DEC-axis size / schrink
chan_min = 86 # 0 #121 # 24
chan_max = 100# len(cube[:,1,1]) #233 # 86
cube.shape
rms=cube.std()
maxi=cube.max()
mini=cube.max()
cube.clip(Nsigma*rms)
subcube = cube[chan_min:chan_max,:,:]
print(subcube.shape)
print(maxi)
print(rms)
max_shape=max(subcube.shape)
data = dict(density = subcube)
ytds = yt.load_uniform_grid(data, subcube.shape)
print("Dim")
print(ytds.domain_dimensions)
ytds.periodicity = (True,)*3
dd = ytds.all_data()
region = ytds.r[:,:,:]
surf = ytds.surface(region, "density", Nsigma*rms)
surf.export_obj(fileout)
self.__logger.debug("ytObj : exiting")
return {"status": True, "message": "", "result": name}
#
#
# End of the DataManagerImpl class
......
......@@ -754,6 +754,36 @@ def purgeDataBlocks():
@route('/static/<filepath:path>')
def server_static(filepath):
return static_file(filepath, root=dataManager.PNGFilePrefix)
"""
Given relObjFilePath
produces a Obj file representing the surface of the fits image created by yt
returns a dictionary { "path_to_obj": relOBJFilePath} where :
* relOBJFilePath a path to the OBJ file relative to the root directory of OBJ files.
"""
@route( baseUrl+'/getYtObj', name='getYtObj', method='POST')
@enable_cors
def getYtObj():
logger.debug("getYtObj - wrapper : entering")
try:
#body = byteify(json.loads(request.body.read()))
result = dm.getYtObj()
except Exception as e:
exc_type, exc_value, exc_traceback = sys.exc_info()
traceback.print_exc()
message = "%s ! %s" % (repr(e), "".join(traceback.format_list(traceback.extract_tb(exc_traceback))))
result = {"status": False, "message": message}
response.content_type = "application/json; charset=utf-8"
logger.debug("getYtObj - wrapper : exiting")
return json.dumps(result)
#
# End of the class
#
......
......@@ -58,15 +58,22 @@ RUN npm install
# The root directory of the PNG files (read/write). It'll have to be bound to an host directory.
RUN mkdir -p /home/partemix/dataroot/PNG
# The root directory of the OBJ files (read/write). It'll have to be bound to an host directory.
RUN mkdir -p /home/partemix/dataroot/OBJ
# The root directory of the SAMP spectrum files (read/write). It'll have to be bound to an host directory.
RUN mkdir -p /home/partemix/dataroot/SAMP
# The directory for log files (read/write). It'll have to be bound to an host directory.
RUN mkdir /home/partemix/log
#create link for the server PNG directory
RUN ln -sf /home/partemix/dataroot/PNG /home/partemix/yafitsv/png
#create link for the server PNG directory
RUN ln -sf /home/partemix/dataroot/OBJ /home/partemix/yafitsv/obj
# Copy app source to image _after_ npm install so that
# application code changes don't bust the docker cache of npm install step
COPY --chown=partemix:partemix . /home/partemix/yafitsv
......
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