Ejemplo n.º 1
0
def test_OctreeRayTracer_OpenCL():  #{{{
    misc.init_OpenCl()
    if misc.OpenCL_initialized:
        #if True:
        octree_dset = pymses.sources.ramses.octree.CameraOctreeDataset.\
              from_hdf5(os.path.join(PWD, "test_amr_dset.h5"))
        rho_op = ScalarOperator(lambda dset: dset["rho"])
        # camera center small shift is still with OctreeRayTracer to avoid grid limit pb
        cam  = Camera(center=[0.501, 0.501, 0.501], line_of_sight_axis='z', region_size=[.3, .3],\
               distance=0.3, far_cut_depth=0.3,\
         up_vector='y', map_max_size=3, log_sensitive=True)

        rt = OctreeRayTracer(octree_dset)
        # print rt.process(rho_op, cam, rgb=False, use_C_code=True)
        map, lvlmax_map = rt.process(rho_op, cam, rgb=False, use_openCL=True)

        map = apply_log_scale(map)
        print("map :")
        print(map)
        print("asserted_rt_map :")
        print(asserted_rt_map)
        assert (abs(map - asserted_rt_map) < 1e-3).all()
        print(lvlmax_map)
        print(asserted_lvlmax_map)
        assert (lvlmax_map == asserted_lvlmax_map).all()
Ejemplo n.º 2
0
def test_OctreeRayTracer_RGB():  #{{{
    octree_dset = pymses.sources.ramses.octree.CameraOctreeDataset.\
          from_hdf5(os.path.join(PWD, "test_amr_dset.h5"))
    rho_op = ScalarOperator(lambda dset: dset["rho"])
    cam  = Camera(center=[0.5, 0.5, 0.5], line_of_sight_axis='z', region_size=[.3, .3],\
           distance=0.3, far_cut_depth=0.3,\
     up_vector='y', map_max_size=3, log_sensitive=True)

    cltf = ColorLinesTransferFunction((-5.0, 2.0))
    cltf.add_line(-2.0, 0.1)
    cltf.add_line(.0, 0.1)
    cltf.add_line(2., 0.1)
    cam.set_color_transfer_function(cltf)

    rt = OctreeRayTracer(octree_dset)
    map = rt.process(rho_op, cam, return_image=False)

    print(map[0])
    asserted_map = numpy.array([[0.12494199, 0., 0.57994005],
                                [0.12494199, 0., 0.57994005],
                                [0.12446702, 0., 0.57773542]])
    print(asserted_map)
    assert (abs(map[0] - asserted_map) < 1e-6).all()


#}}}
Ejemplo n.º 3
0
def test_OctreeRayTracer_rotated():  #{{{
    octree_dset = pymses.sources.ramses.octree.CameraOctreeDataset.\
          from_hdf5(os.path.join(PWD, "test_amr_dset.h5"))
    rho_op = ScalarOperator(lambda dset: dset["rho"])
    # camera center small shift is still with OctreeRayTracer to avoid grid limit pb
    cam  = Camera(center=[0.501, 0.501, 0.501], line_of_sight_axis=[0.401, 0.601, -0.701], region_size=[.3, .3],\
           distance=0.3, far_cut_depth=0.3,\
     up_vector='y', map_max_size=3, log_sensitive=False)

    rt = OctreeRayTracer(octree_dset)
    map, lvlmax_map = rt.process(rho_op, cam, rgb=False, use_C_code=False)
    print("map :")
    print(map)
    print("asserted_rt_map :")
    print(asserted_rotated_rt_map)
    assert (abs(map - asserted_rotated_rt_map) < 1e-3).all()
    print(lvlmax_map)
    print(asserted_lvlmax_map)
    assert (lvlmax_map == asserted_lvlmax_map).all()
    print("Coherence with C Code... :")
    mapC, lvlmax_mapC = rt.process(rho_op, cam, rgb=False, use_C_code=True)
    assert (abs(map - mapC) < 1e-3).all()
    assert (lvlmax_map == lvlmax_mapC).all()
    print("Coherence with RayTracer... :")

    class EmptyOutput(object):
        def __init__(self):
            self.info = {}
            self.info["levelmin"] = 3
            self.info["dom_decomp"] = None
            self.output_repos = None
            self.iout = None

    ro = EmptyOutput()
    top_down_rt = RayTracer(ro, ["rho"])
    mapRayT = top_down_rt.process(rho_op, cam, source=octree_dset)
    assert (abs(map - mapRayT) < 1e-3).all()
    misc.init_OpenCl()
    if misc.OpenCL_initialized:
        mapO, lvlmax_mapO = rt.process(rho_op, cam, rgb=False, use_openCL=True)
        print("OK\nCoherence with OpenCl Code... :")
        print(lvlmax_mapC, numpy.min(lvlmax_mapC))
        print(lvlmax_mapO, numpy.min(lvlmax_mapO))
        assert (abs(mapC - mapO) < 1e-3).all()
        assert (lvlmax_mapC == lvlmax_mapO).all()
cltf = ColorLinesTransferFunction((-5.0, 2.0))
cltf.add_line(-2.0, 0.1)
cltf.add_line(.0, 0.1)
cltf.add_line(2., 0.1)
cam.set_color_transfer_function(cltf)
# We add 1e-8 to avoid NaN and -Inf log result problems with approximative null values
op = ScalarOperator(lambda dset: log10(dset["rho"] + 1e-8))
###### Option A : Create OctreeRayTracer = implicit OctreeDataSource creation #######
#OctreeRT = OctreeRayTracer(ro, ["rho"])
###### Option B : Explicit OctreeDataSource creation (can be explicitly reused) #####
######### fullOctreeDataSource = Build a local octree for this aera #################
fullOctreeDataSource = CameraOctreeDatasource(cam, esize, source).dset
# Here is how to save and load local octree option for faster reuse if wanted :
#fullOctreeDataSource.write_hdf5("myDset")
#fullOctreeDataSource = CameraOctreeDataset.from_hdf5("myDset")
OctreeRT = OctreeRayTracer(fullOctreeDataSource)
#########            Start OctreeRayTracer process :                 ################
img = OctreeRT.process(op, cam)
#img.show()
img.save("rt_tf_%s.png" % outNumber)
print("rt_tf_%s.png saved" % outNumber)

#####################################################################################
######## 2) RayTracer with PyMSES Classic Operator definition #######################
#####################################################################################
#op = ScalarOperator(lambda dset: dset["rho"])
op = FractionOperator(lambda dset: (dset["rho"]**2), lambda dset:
                      (dset["rho"]))
######### Option A : Create RayTracer = multiprocessing on data #####################
#rt = RayTracer(ro, ["rho"])
##map = rt.process(op, cam) # multiprocessing cpu on data files loaded
             map_max_size=mms)

# Octree source creation :
source = ro.amr_source(["rho"])
# We need to add an extension to the octree box loaded in memory,
# or not (if min(distance,far_cut_depth) > max(region_size))
# as the rotation is around the "y" axis,
# to allow rotation without empty starting point ray bugs
esize = 0.5**(ro.info["levelmin"] + 1) + max(region_size)
camOctSource = cam.copy()
fullOctreeDataSource = CameraOctreeDatasource(camOctSource,
                                              esize,
                                              source,
                                              ngrid_max=ngrid_max,
                                              include_split_cells=True).dset
OctreeRT = OctreeRayTracer(fullOctreeDataSource)

t0 = time()
map, levelmax_map = OctreeRT.process(op, cam, rgb=False, use_openCL=use_openCL)
t1 = time()
print("rt total time = %.1f s"%(t1-t0), "mms = ", mms, "max AMR read = ", \
 cam.get_required_resolution())
save_map_HDF5(map, cam, map_name="img%s" % (i))
# ran used to fix the colormap during the movie
# (= use first frame colormap for each frame)
ran = save_HDF5_to_img("./img%s.h5" % (i),
                       cmap="jet",
                       img_path="./",
                       ramses_output=ro,
                       drawStarsParam=sinkParams)
for i in range(1, nbImgRot):