Esempio n. 1
0
def renderin_the_file(objectGeo, fileNameTosave, patheNameTOSave, scad_flag):
    """
                  creating the xml file of the object geometry based on if the xml file will be
                  rendering to cad file or will be using to run the simulation
                  using mcvine

                  Parameters
                  ----------
                  objectGeo: object
                     the geometry of the body
                  fileNameTosave: string
                        name of the xml geometry file to be saved
                  patheNameTOSave: string
                        name of the path where the xml geometry file will be saved
                  scad_flag: boolen
                        to indicate if the xml file will be used to render cad file

                  Returns: object
                  -------
                  xml file of the object geometry
                  """
    filename_withExtension = '%s.xml' % (fileNameTosave, )
    outputfile = os.path.join(patheNameTOSave, filename_withExtension)
    with open(outputfile, 'wt') as file_h:
        if scad_flag:
            weave(objectGeo, file_h, print_docs=False)
        else:
            weave(objectGeo,
                  file_h,
                  print_docs=False,
                  renderer=File_inc_Renderer(),
                  author='')
Esempio n. 2
0
def write_file(fl_name, geom, scad_flag):
    with open(fl_name, 'wt') as file_h:
        if scad_flag:
            weave(geom, file_h, print_docs=False)
        else:
            weave(geom,
                  file_h,
                  print_docs=False,
                  renderer=File_inc_Renderer(),
                  author='')
    def test(self):
        """
        instrument.geometry.pml.render
        """
        import numpy as np
        from instrument.geometry.pml import weave
        from instrument.geometry import shapes, operations
        pyramid = shapes.pyramid(thickness="20.*mm",
                                 width="20.*mm",
                                 height="110.*mm")
        pyramid_along_beam = operations.rotate(pyramid,
                                               transversal="1",
                                               angle="90.*deg")
        angles = np.arange(-160, 0., 15.)
        pyramids = [
            operations.rotate(pyramid_along_beam,
                              vertical="1",
                              angle='%s*deg' % a) for a in angles
        ]
        channels = operations.unite(*pyramids)

        hollow_cylinder = operations.subtract(
            shapes.cylinder(radius="55.*mm", height="50.*mm"),
            shapes.cylinder(radius="25.*mm", height="60.*mm"),
        )
        half_cylinder = operations.subtract(
            hollow_cylinder,
            operations.translate(
                shapes.block(height="110*mm",
                             width="110*mm",
                             thickness="110*mm"),
                transversal="-55.*mm",
            ))
        all = operations.subtract(half_cylinder, channels)

        # use a special renderer
        from instrument.geometry.pml.Renderer import Renderer as base

        class Renderer(base):
            def _renderDocument(self, body):
                self.onGeometry(body)
                return

            def header(self):
                return []

            def footer(self):
                return []

            def end(self):
                return

        text = weave(all,
                     open('collimator.xml', 'wt'),
                     print_docs=False,
                     renderer=Renderer(),
                     author='')
        return
Esempio n. 4
0
def create (coll_front_end_from_center,max_coll_len=60., Snap_angle=False, vertical_number_channels=20, horizontal_number_channels=20,
            detector_angles=[-45,-135],multiple_collimator=False, collimator_Nosupport=True, scad_flag=False,
            outputfile=coll_geo_file):

    length_of_each_part = max_coll_len
    coll_last_height_detector=150.
    coll_last_width_detector=60*2.
    min_channel_wall_thickness =1

    coll_last_front_end_from_center=coll_front_end_from_center+(2.*length_of_each_part)

    coll_last_back_end_from_center =coll_last_front_end_from_center+length_of_each_part

    coll_first=Collimator_geom()

    coll_first_inner_radius = coll_front_end_from_center + (0. * length_of_each_part)
    coll_first_outer_radius = coll_first_inner_radius + length_of_each_part

    coll_first_height_detector = (coll_last_height_detector / coll_last_back_end_from_center) * coll_first_outer_radius

    coll_first_width_detector = (coll_last_width_detector / coll_last_back_end_from_center) * coll_first_outer_radius  # half part


    coll_first.set_constraints(max_coll_height_detector=coll_first_height_detector,
                          max_coll_width_detector=coll_first_width_detector,
                          min_channel_wall_thickness=min_channel_wall_thickness,
                          max_coll_length=length_of_each_part,
                          min_channel_size=3,
                          collimator_front_end_from_center=coll_first_inner_radius,
                          collimator_parts=False,
                          no_right_border=False,
                          no_top_border=False,
                          horizontal_odd_blades=False,
                          vertical_odd_blades=False,
                          )

    fist_vertical_number_blades = 3
    fist_horizontal_number_blades = 3

    coll_first.set_parameters(vertical_number_channels=fist_vertical_number_blades,
                         horizontal_number_channels=fist_horizontal_number_blades,
                         channel_length=length_of_each_part)


    coll_middle = Collimator_geom()

    coll_middle_inner_radius = coll_front_end_from_center + (1. * length_of_each_part)

    coll_middle_outer_radius = length_of_each_part + coll_middle_inner_radius


    coll_middle_height_detector = (coll_last_height_detector / coll_last_back_end_from_center) * coll_middle_outer_radius

    coll_middle_width_detector = (coll_last_width_detector / coll_last_back_end_from_center) * coll_middle_outer_radius

    coll_middle.set_constraints(max_coll_height_detector=coll_middle_height_detector,
                          max_coll_width_detector=coll_middle_width_detector,
                          min_channel_wall_thickness=min_channel_wall_thickness,
                          max_coll_length=length_of_each_part,
                          min_channel_size=3,
                          collimator_front_end_from_center=coll_middle_inner_radius,
                          collimator_parts=True,
                          initial_collimator_horizontal_channel_angle=0.0,
                          initial_collimator_vertical_channel_angle=0.0,
                          remove_vertical_blades_manually=True,
                          vertical_blade_index_list_toRemove=[2, 5],
                          remove_horizontal_blades_manually=True,
                          horizontal_blade_index_list_toRemove=[2, 5],
                          no_right_border=False,
                          no_top_border=False,
                          vertical_even_blades=False,
                          horizontal_even_blades=False)

    coll_middle.set_parameters(vertical_number_channels=(fist_vertical_number_blades) * 3,
                         horizontal_number_channels=(fist_horizontal_number_blades) * 3,
                         channel_length=length_of_each_part)

    col_last = Collimator_geom()

    col_last.set_constraints(max_coll_height_detector=coll_last_height_detector,
                                  max_coll_width_detector=coll_last_width_detector,
                                  min_channel_wall_thickness=min_channel_wall_thickness,
                                  max_coll_length=length_of_each_part,
                                  min_channel_size=3.,
                                  collimator_front_end_from_center=coll_last_front_end_from_center,
                                  remove_horizontal_blades_manually=True,
                                  horizontal_blade_index_list_toRemove=[2, 5, 11, 14, 20, 23],
                                  remove_vertical_blades_manually=True,
                                  vertical_blade_index_list_toRemove=[2, 5, 11, 14, 20, 23],
                                  collimator_parts=True,
                                  no_right_border=False,
                                  no_top_border=False,
                                  vertical_odd_blades=False,
                                  horizontal_odd_blades=False)


    col_last.set_parameters(vertical_number_channels=fist_vertical_number_blades * 9,
                                 horizontal_number_channels=fist_horizontal_number_blades * 9,
                                 channel_length=length_of_each_part)

    coliFirst = coll_first.gen_collimators(detector_angles=detector_angles, multiple_collimator=False,
                                             collimator_Nosupport=True)
    coliMiddle = coll_middle.gen_collimators(detector_angles=detector_angles, multiple_collimator=False,
                                        collimator_Nosupport=True)
    colilast =col_last.gen_collimators(detector_angles=detector_angles, multiple_collimator=False,collimator_Nosupport=True)


    whole = operations.unite(operations.unite(coliFirst, coliMiddle),colilast)

    with open (outputfile,'wt') as file_h:
        weave(whole,file_h, print_docs = False,renderer=File_inc_Renderer(), author='')
Esempio n. 5
0
# with open ('Al_largest_cone.xml','wt') as file_h:
#     weave(Al_largest_cone,file_h, print_docs = False)
# with open ("Al_largest_cone_widertip.xml",'wt') as file_h:
#     weave(Al_largest_cone_widertip,file_h, print_docs = False)
# with open ("Al_tapered_cylinder.xml",'wt') as file_h:
#     weave(Al_tapered_cylinder,file_h, print_docs = False)
# with open("Al_centered_taperedCylinder.xml", 'wt') as file_h:
#     weave(Al_centered_taperedCylinder, file_h, print_docs=False)
# with open ("outer_Al.xml",'wt') as file_h:
#     weave(outer_Al,file_h, print_docs = False)
#
#
#
# with open ("CuBe_largest_cone.xml",'wt') as file_h:
#     weave(CuBe_largest_cone,file_h, print_docs = False)
# with open ("CuBe_largest_cone_widertip.xml",'wt') as file_h:
#     weave(CuBe_largest_cone_widertip,file_h, print_docs = False)
# with open ("CuBe_tapered_cylinder.xml",'wt') as file_h:
#     weave(CuBe_tapered_cylinder,file_h, print_docs = False)
# with open("CuBe_centered_taperedCylinder.xml", 'wt') as file_h:
#     weave(CuBe_centered_taperedCylinder, file_h, print_docs=False)
# with open ("CuBe_innerSleeve.xml",'wt') as file_h:
#     weave(CuBe_innerSleeve,file_h, print_docs = False)
#
# with open ("sample.xml",'wt') as file_h:
#     weave(sample,file_h, print_docs = False)
#collimator_4channels_22mm_fr_smpl

with open("collimator_support_ed2.xml", 'wt') as file_h:
    weave(sample_assemblyCad, file_h, print_docs=False)