示例#1
0
def box_geometry_xml(xml_parameters):
    return stripped_joined_lines("""
                    <light-cone id="%(light_cone_id)s">
                        <!-- Module Version Number -->
                        <module-version>1</module-version>

                        <!-- Is the query a light-cone or box? -->
                        <geometry>box</geometry>

                        <!-- Selected Simuation -->
                        <simulation>%(dark_matter_simulation)s</simulation>

                        <!-- Selected Galaxy Model -->
                        <galaxy-model>%(galaxy_model)s</galaxy-model>

                        <redshift>%(redshift)s</redshift>
                        <query-box-size units="Mpc">%(box_size)f</query-box-size>

                        <!-- List of fields to be included in the output file -->
                        <output-fields>
                            <item label="%(output_properties_1_label)s" units="%(output_properties_1_units)s">%(output_properties_1_name)s</item>
                            <item label="%(output_properties_2_label)s">%(output_properties_2_name)s</item>
                        </output-fields>

                        <!-- RNG Seed -->
                        <!-- This will be added by the workflow after the job has been completed
                             to enable the job to be repeated.
                             The information stored may change, the intent is to store whatever is
                             required to re-run the job and obtain the same results.
                        <rng-seed>12345678901234567890</rng-seed> -->

                    </light-cone>
    """) % xml_parameters
示例#2
0
def light_cone_geometry_xml(xml_parameters):
    return stripped_joined_lines("""
                    <light-cone id="%(light_cone_id)s">
                        <!-- Module Version Number -->
                        <module-version>1</module-version>

                        <!-- Is the query a light-cone or box? -->
                        <geometry>light-cone</geometry>

                        <!-- Selected Simuation -->
                        <simulation>%(dark_matter_simulation)s</simulation>

                        <!-- Selected Galaxy Model -->
                        <galaxy-model>%(galaxy_model)s</galaxy-model>

                        <!-- The number of light-cones to generate  -->
                        <box-repetition>%(light_cone_type)s</box-repetition>
                        <num-cones>%(number_of_light_cones)d</num-cones>

                        <!-- The min and max redshifts to filter by -->
                        <redshift-min>%(redshift_min).1f</redshift-min>
                        <redshift-max>%(redshift_max).1f</redshift-max>

                        <!-- RA/Dec range for limiting the light-cone -->
                        <ra-min units="deg">0.0</ra-min>
                        <ra-max units="deg">%(ra_opening_angle).3f</ra-max>
                        <dec-min units="deg">0.0</dec-min>
                        <dec-max units="deg">%(dec_opening_angle).3f</dec-max>

                        <!-- List of fields to be included in the output file -->
                        <output-fields>
                            <item description="%(output_properties_1_description)s" label="%(output_properties_1_label)s" units="%(output_properties_1_units)s">%(output_properties_1_name)s</item>
                            <item description="%(output_properties_2_description)s" label="%(output_properties_2_label)s">%(output_properties_2_name)s</item>
                        </output-fields>

                        <!-- RNG Seed -->
                        <!-- This will be added by the workflow after the job has been completed
                             to enable the job to be repeated.
                             The information stored may change, the intent is to store whatever is
                             required to re-run the job and obtain the same results.
                        <rng-seed>12345678901234567890</rng-seed> -->

                    </light-cone>
    """) % xml_parameters
示例#3
0
def fits_output_format_xml(xml_parameters):
    if xml_parameters['catalogue_geometry'] == 'box':
        geometry_fragment = box_geometry_xml(xml_parameters)
    else:
        geometry_fragment = light_cone_geometry_xml(xml_parameters)
    xml_parameters.update({'geometry_fragment': geometry_fragment})
    if 'band_pass_filter_description' not in xml_parameters:
        xml_parameters.update({'band_pass_filter_description': ''})
    xml = stripped_joined_lines("""<?xml version="1.0" encoding="UTF-8"?>
            <!-- Using the XML namespace provides a version for future modifiability.  The timestamp allows
                 a researcher to know when this parameter file was generated.  -->
            <tao xmlns="http://tao.asvo.org.au/schema/module-parameters-v1" timestamp="2012-12-20T13:55:36+10:00">

                <!-- Username submitting the job -->
                <username>%(username)s</username>

                <!-- Workflow name identifies which workflow is to be executed.
                     This is currently a placeholder, the name is ignored. -->
                <workflow name="alpha-light-cone-image">

                    <!-- Global Configuration Parameters -->
                    <schema-version>2.0</schema-version>


                    <!-- File output module -->
                    <fits id="%(csv_dump_id)s">
                        <fields>
                            <item label="%(output_properties_1_label)s" units="%(output_properties_1_units)s">%(output_properties_1_name)s</item>
                            <item label="%(output_properties_2_label)s">%(output_properties_2_name)s</item>
                            <!-- <item label="bandpass (Absolute)">%(band_pass_filter_name)s_absolute</item> -->
                            <item label="bandpass (Apparent)">%(band_pass_filter_name)s_apparent</item>
                        </fields>

                        <!-- Module Version Number -->
                        <module-version>1</module-version>

                        <!-- Output file format -->
                        <filename>tao.output.csv</filename>

                        <parents>
                            <item>%(bandpass_filter_id)s</item>
                        </parents>

                    </fits>

                    <!-- Optional: Spectral Energy Distribution parameters -->
                    <sed id="%(sed_id)s">
                        <!-- Module Version Number -->
                        <module-version>1</module-version>

                        <parents>
                            <item>%(light_cone_id)s</item>
                        </parents>

                        %(ssp_encoding)s
                    </sed>

                    <filter id="%(bandpass_filter_id)s">
                        <module-version>1</module-version>
                        <parents>
                            <item>%(dust_id)s</item>
                        </parents>

                        <!-- Bandpass Filters) -->
                        <bandpass-filters>
                            <item description="%(band_pass_filter_description)s" label="%(band_pass_filter_label)s" selected="apparent">%(band_pass_filter_id)s</item>
                        </bandpass-filters>
                    </filter>

                    <dust id="%(dust_id)s">
                        <!-- Module Version Number -->
                        <module-version>1</module-version>
                        <parents>
                            <item>%(sed_id)s</item>
                        </parents>
                        <model>%(dust_model_name)s</model>
                    </dust>

                    <!-- Record Filter -->
                    <record-filter>
                        <!-- Module Version Number -->
                        <module-version>1</module-version>

                        <!-- Note that the units are for readability,
                             no unit conversion is supported.  The consumer of the
                             parameter file should check that the expected units are provided. -->
                        <filter>
                            <filter-attribute>%(filter)s</filter-attribute>
                            <filter-min units="Msun/h">%(filter_min)s</filter-min>
                            <filter-max units="Msun/h">%(filter_max)s</filter-max>
                        </filter>
                    </record-filter>

                    <!-- Image generation module parameters
                    <image-generator>
                        <!- Module Version Number ->
                        <module-version>1</module-version>

                        <!- Image size parameters ->
                        <image-width units="px">1024</image-width>
                        <image-height units="px">1024</image-height>

                        <!- Focal scale parameters ->
                        <focalx units="??">1024</focalx>
                        <focaly units="??">1024</focaly>

                        <!- Image offset parameters ->
                        <image-offsetx units="??">512</image-offsetx>
                        <image-offsety units="??">0</image-offsety>
                    </image-generator> -->

                </workflow>

                <!-- The signature is automatically generated and is intended to be used when running
                     old versions of the science modules (to remove the need for the UI to parse and check
                     every version. -->
                <signature>base64encodedsignature</signature>

            </tao>
        """) % xml_parameters
    return xml
    def test_no_dust(self):
        form_parameters = {
            'catalogue_geometry': 'box',
            'dark_matter_simulation': self.simulation.id,
            'galaxy_model': self.dataset.id,
            'output_properties' : [self.filter.id],
            'snapshot': self.snapshot.id,
            'box_size': 20,
            'rng_seed': 12345678901234567890
            }
        xml_parameters = form_parameters.copy()
        xml_parameters.update({
            'username' : self.user.username,
            'dark_matter_simulation': self.simulation.name,
            'galaxy_model': self.galaxy_model.name,
            'output_properties_1_name' : self.filter.name,
            'output_properties_1_label' : self.filter.label,
            'output_properties_1_units' : self.filter.units,
            'output_properties_1_description' : self.filter.description,
            'redshift' : float(self.snapshot.redshift),
            })
        xml_parameters.update({
            'filter': self.filter.name,
            'filter_min' : 'None',
            'filter_max' : '1000000',
            })
        # TODO: there are commented out elements which are not implemented yet
        xml_parameters.update({
            'ssp_encoding': self.stellar_model.encoding,
            'band_pass_filter_label': self.band_pass_filter.label,
            'band_pass_filter_id': self.band_pass_filter.filter_id,
            'band_pass_filter_name': self.band_pass_filter.filter_id,
            'band_pass_filter_description': self.band_pass_filter.description,
            'band_pass_extension': 'absolute',
            })
        xml_parameters.update({
            'light_cone_id': FormsGraph.LIGHT_CONE_ID,
            'csv_dump_id': FormsGraph.OUTPUT_ID,
            'bandpass_filter_id': FormsGraph.BANDPASS_FILTER_ID,
            'sed_id': FormsGraph.SED_ID,
            'dust_id': FormsGraph.DUST_ID,
            })
        # comments are ignored by assertXmlEqual
        expected_parameter_xml = stripped_joined_lines("""<?xml version="1.0"?>
            <!-- Using the XML namespace provides a version for future modifiability.  The timestamp allows
                 a researcher to know when this parameter file was generated.  -->
            <tao xmlns="http://tao.asvo.org.au/schema/module-parameters-v1" timestamp="2012-12-20T13:55:36+10:00">

                <!-- Username submitting the job -->
                <username>%(username)s</username>

                <!-- Workflow name identifies which workflow is to be executed.
                     This is currently a placeholder, the name is ignored. -->
                <workflow name="alpha-light-cone-image">

                    <!-- Global Configuration Parameters -->
                    <schema-version>2.0</schema-version>

                    <!-- Light-cone module parameters -->
                    <light-cone id="%(light_cone_id)s">
                        <!-- Module Version Number -->
                        <module-version>1</module-version>

                        <!-- Is the query a light-cone or box? -->
                        <geometry>box</geometry>

                        <!-- Selected Simuation -->
                        <simulation>%(dark_matter_simulation)s</simulation>

                        <!-- Selected Galaxy Model -->
                        <galaxy-model>%(galaxy_model)s</galaxy-model>

                        <!-- The number of light-cones to generate
                        <box-repetition>unique | random</box-repetition>
                        <num-cones>1</num-cones> -->

                        <!-- The min and max redshifts to filter by -->
                        <redshift>%(redshift).10f</redshift>

                        <!-- Size of box to return -->
                        <query-box-size units="Mpc">%(box_size)d</query-box-size>

                        <!-- RNG Seed -->
                        <!-- This will be added by the workflow after the job has been completed
                             to enable the job to be repeated.
                             The information stored may change, the intent is to store whatever is
                             required to re-run the job and obtain the same results.-->
                        <rng-seed>12345678901234567890</rng-seed> 

                        <!-- List of fields to be included in the output file -->
                        <output-fields>
                            <item description="%(output_properties_1_description)s" label="%(output_properties_1_label)s" units="%(output_properties_1_units)s">%(output_properties_1_name)s</item>
                        </output-fields>

                    </light-cone>

                    <!-- File output module -->
                    <csv id="%(csv_dump_id)s">
                        <fields>
                            <item label="%(output_properties_1_label)s" units="%(output_properties_1_units)s">%(output_properties_1_name)s</item>
                            <item label="bandpass (Absolute)">%(band_pass_filter_name)s_absolute</item>
                            <!-- <item label="bandpass (Apparent)">%(band_pass_filter_name)s_apparent</item> -->
                        </fields>

                        <!-- Module Version Number -->
                        <module-version>1</module-version>

                        <!-- Output file format -->
                        <filename>tao.output.csv</filename>

                        <parents>
                            <item>%(bandpass_filter_id)s</item>
                        </parents>

                    </csv>

                    <!-- Optional: Spectral Energy Distribution parameters -->
                    <sed id="%(sed_id)s">
                        <!-- Module Version Number -->
                        <module-version>1</module-version>

                        <parents>
                            <item>%(light_cone_id)s</item>
                        </parents>

                        %(ssp_encoding)s
                    </sed>

                    <filter id="%(bandpass_filter_id)s">
                        <module-version>1</module-version>
                        <parents>
                            <item>%(sed_id)s</item>
                        </parents>

                        <!-- Bandpass Filters) -->
                        <bandpass-filters>
                            <item description="%(band_pass_filter_description)s" label="%(band_pass_filter_label)s" selected="%(band_pass_extension)s">%(band_pass_filter_id)s</item>
                        </bandpass-filters>
                    </filter>

                    <!-- Record Filter -->
                    <record-filter>
                        <!-- Module Version Number -->
                        <module-version>1</module-version>

                        <!-- Note that the units are for readability,
                             no unit conversion is supported.  The consumer of the
                             parameter file should check that the expected units are provided. -->
                        <filter>
                            <filter-attribute>%(filter)s</filter-attribute>
                            <filter-min units="Msun/h">%(filter_min)s</filter-min>
                            <filter-max units="Msun/h">%(filter_max)s</filter-max>
                        </filter>
                    </record-filter>

                    <!-- Image generation module parameters
                    <image-generator>
                        <!- Module Version Number ->
                        <module-version>1</module-version>

                        <!- Image size parameters ->
                        <image-width units="px">1024</image-width>
                        <image-height units="px">1024</image-height>

                        <!- Focal scale parameters ->
                        <focalx units="??">1024</focalx>
                        <focaly units="??">1024</focaly>

                        <!- Image offset parameters ->
                        <image-offsetx units="??">512</image-offsetx>
                        <image-offsety units="??">0</image-offsety>
                    </image-generator> -->

                </workflow>

                <!-- The signature is automatically generated and is intended to be used when running
                     old versions of the science modules (to remove the need for the UI to parse and check
                     every version. -->
                <signature>base64encodedsignature</signature>

            </tao>
        """) % xml_parameters
        
        mock_ui_holder = MockUIHolder()
        light_cone_form = make_form({}, LightConeForm, form_parameters, ui_holder=mock_ui_holder, prefix='light_cone')
        sed_form = make_form({}, SEDForm, self.sed_parameters_no_dust, ui_holder=mock_ui_holder, prefix='sed')
        output_form = make_form({}, OutputFormatForm, {'supported_formats': 'csv'}, ui_holder=mock_ui_holder, prefix='output_format')
        mock_ui_holder.update(light_cone = light_cone_form, sed = sed_form, output_format = output_form)
        mock_ui_holder.dataset = self.dataset
        record_filter_form = make_form({}, RecordFilterForm, {'filter':'D-'+str(self.filter.id),'max':str(1000000)},
                                           ui_holder=mock_ui_holder, prefix='record_filter')
        self.assertEqual({}, light_cone_form.errors)
        self.assertEqual({}, sed_form.errors)
        self.assertEqual({}, record_filter_form.errors)
        self.assertEqual({}, output_form.errors)

        mock_ui_holder.update(record_filter = record_filter_form)
        job = workflow.save(self.user, mock_ui_holder)
        actual_parameter_xml = job.parameters

        self.assertXmlEqual(expected_parameter_xml, actual_parameter_xml)
        self.assertEqual(self.dataset.database, job.database)