Esempio n. 1
0
def from_xml_2(cls, ui_holder, xml_root, prefix=None):
    sed = module_xpath(xml_root, '//workflow/sed', text=False)
    apply_sed = sed is not None
    params = {prefix+'-apply_sed': apply_sed}
    if apply_sed:
        sspm_name = module_xpath(xml_root, '//sed/single-stellar-population-model')
        sspm = datasets.stellar_model_find_from_xml(sspm_name)
        if sspm is not None:
            params.update({prefix+'-single_stellar_population_model': sspm.id})
        bp_filters = []
        for filter_item in module_xpath_iterate(xml_root, '//filter/bandpass-filters/item', text=False):
            filter_id = filter_item.text
            filter_extension_list = filter_item.get('selected').split(',')
            filter = datasets.band_pass_filter_find_from_xml(filter_id)
            if filter is not None:
                for filter_extension in filter_extension_list:
                    bp_filters.append(str(filter.id) + '_' + filter_extension)
        if len(bp_filters) > 0:
            params.update({prefix+'-band_pass_filters': bp_filters})
        dust = module_xpath(xml_root, '//dust/model')
        apply_dust = dust is not None
        if apply_dust:
            dust_model = datasets.dust_model_find_from_xml(dust)
            if dust_model is not None:
                params.update({prefix+'-apply_dust': True})
                params.update({prefix+'-select_dust_model': dust_model.id})
            else:
                params.update({prefix+'-apply_dust': False})
        else:
            params.update({prefix+'-apply_dust': False})
    return cls(ui_holder, params, prefix=prefix)
def from_xml_2(cls, ui_holder, xml_root, prefix=None):
    params = {prefix+'-supported_formats': 'csv'}
    for fmt in configured_output_formats():
        supported_format = module_xpath(xml_root, '//' + fmt['value'], text=False)
        if supported_format is not None:
            params.update({prefix+'-supported_formats': fmt['value']})
    return cls(ui_holder, params, prefix=prefix)
Esempio n. 3
0
def from_xml_2(cls, ui_holder, xml_root, prefix=None):
    mi = module_xpath(xml_root, '//workflow/skymaker', False)
    apply_mock_image = mi is not None
    params = {'mock_image-apply_mock_image': apply_mock_image}
    if apply_mock_image:

        # Find the images and setup the management form.
        imgs = list(module_xpath_iterate(xml_root, '//skymaker/images/item', False))
        params[prefix + '-TOTAL_FORMS'] = len(imgs)
        params[prefix + '-INITIAL_FORMS'] = len(imgs)
        params[prefix + '-MAX_NUM_FORMS'] = 1000

        # Process each image.
        for ii, img in enumerate(imgs):
            pre = prefix + '-' + str(ii) + '-'
            for field in img:
                tag = strip_namespace(field.tag)
                if tag == 'mag_field':
                    id, ext = field.text.rsplit('_', 1)
                    filter = datasets.band_pass_filter_find_from_xml(id)
                    if filter is not None:
                        params[pre + tag] = str(filter.id) + '_' + ext
                else:
                    params[pre + tag] = field.text if field.text != 'None' else ''

    # Create the class.
    return cls(ui_holder, params, prefix=prefix)
def from_xml_2(cls, ui_holder, xml_root, prefix=None):
    query = module_xpath(xml_root, '//sql/query')
    simulation_name = module_xpath(xml_root, '//sql/simulation')
    galaxy_model_name = module_xpath(xml_root, '//sql/galaxy-model')
    simulation = datasets.simulation_from_xml(simulation_name)
    galaxy_model = datasets.galaxy_model_from_xml(galaxy_model_name)
    data_set = datasets.dataset_find_from_xml(simulation, galaxy_model)
    output_properties = [dsp for dsp in SQLJobForm._map_elems(xml_root)]
    if data_set is not None: query = query.replace('-table-', data_set.database)
    simulation_id = None
    if simulation is not None: simulation_id = simulation.id
    galaxy_model_id = None
    if galaxy_model is not None: galaxy_model_id = galaxy_model.id
    params = {
        prefix+'-galaxy_model': galaxy_model_id,
        prefix+'-dark_matter_simulation': simulation_id,
        prefix+'-query': query,
        prefix+'-output_properties': output_properties,
        }
    return cls(ui_holder, params, prefix=prefix)
Esempio n. 5
0
 def __init__(self, method, param=None):
     # forms are created _and_stored_ one by one so later forms can use data in first ones via self._dict = {}
     self._forms = []
     self._dict = {}
     self._errors = None
     self._dataset = None
     
     classes = UIModulesHolder.form_classes
     self.job_type = UIModulesHolder.LIGHT_CONE_JOB
     
     if method == UIModulesHolder.XML and module_xpath(param, '//workflow', attribute='name') == 'sql-job':
         classes = UIModulesHolder.sql_classes
         self.job_type = UIModulesHolder.SQL_JOB
         
     for klass, module_name in classes:
         form = method(self, klass, module_name, param)
         self._forms.append(form)
         self._dict[module_name] = form
def from_xml_2(cls, ui_holder, xml_root, prefix=None):
   simulation = module_xpath(xml_root, '//light-cone/simulation')
   galaxy_model = module_xpath(xml_root, '//light-cone/galaxy-model')
   data_set = datasets.dataset_find_from_xml(simulation, galaxy_model)
   filter_attribute = module_xpath(xml_root, '//record-filter/filter/filter-attribute')
   filter_min = module_xpath(xml_root, '//record-filter/filter/filter-min')
   filter_max = module_xpath(xml_root, '//record-filter/filter/filter-max')
   filter_units = module_xpath(xml_root, '//record-filter/filter/filter-min', attribute='units')
   if filter_min == 'None': filter_min = None
   if filter_max == 'None': filter_max = None
   data_set_id = 0
   if data_set is not None: data_set_id = data_set.id
   kind, record_id = datasets.filter_find_from_xml(data_set_id, filter_attribute, filter_units)
   if filter_attribute == None:
       kind = 'X'
       record_id = NO_FILTER
   attrs = {prefix+'-filter': kind + '-' + str(record_id),
            prefix+'-min': filter_min,
            prefix+'-max': filter_max,
            }
   return cls(ui_holder, attrs, prefix=prefix)
 def from_xml(cls, ui_holder, xml_root, prefix=None):
     version = module_xpath(xml_root, '//workflow/schema-version')
     if version == '2.0':
         return from_xml_2(cls, ui_holder, xml_root, prefix=prefix)
     else:
         return cls(ui_holder, {}, prefix=prefix)
Esempio n. 8
0
def from_xml_2(cls, ui_holder, xml_root, prefix=None):
    simulation_name = module_xpath(xml_root, '//light-cone/simulation')
    galaxy_model_name = module_xpath(xml_root, '//light-cone/galaxy-model')
    simulation = datasets.simulation_from_xml(simulation_name)
    galaxy_model = datasets.galaxy_model_from_xml(galaxy_model_name)
    data_set = datasets.dataset_find_from_xml(simulation_name, galaxy_model_name)
    geometry = module_xpath(xml_root, '//light-cone/geometry')
    simulation_id = None
    if simulation is not None: simulation_id = simulation.id
    galaxy_model_id = None
    if galaxy_model is not None: galaxy_model_id = galaxy_model.id
    if not (geometry in [Form.CONE, Form.BOX]):
        geometry = None
    params = {
        prefix+'-catalogue_geometry': geometry,
        prefix+'-galaxy_model': galaxy_model_id,
        prefix+'-dark_matter_simulation': simulation_id,
        }

    if geometry == Form.BOX:

        redshift = module_xpath(xml_root, '//light-cone/redshift')
        snapshot = datasets.snapshot_from_xml(data_set, redshift)
        if snapshot is not None:
            params.update({prefix+'-snapshot':snapshot.id})
        box_size = module_xpath(xml_root, '//light-cone/query-box-size')
        params.update({prefix+'-box_size': box_size})
        rng_seed_param = module_xpath(xml_root, '//light-cone/rng-seed')
        rng_seed = rng_seed_param if rng_seed_param else ''
        params.update({prefix + '-rng_seed': rng_seed})


    else: ## == Form.CONE

        light_cone_type = module_xpath(xml_root, '//light-cone/box-repetition')
        num_cones = module_xpath(xml_root, '//light-cone/num-cones')
        redshift_min = module_xpath(xml_root, '//light-cone/redshift-min')
        redshift_max = module_xpath(xml_root, '//light-cone/redshift-max')
        ra_max = module_xpath(xml_root, '//light-cone/ra-max')
        dec_max = module_xpath(xml_root, '//light-cone/dec-max')
        if light_cone_type == 'random':
            rng_seeds = []
            rng_seeds_params = [elem for elem in module_xpath_iterate(xml_root, '//light-cone/rng-seeds/*', False)]
            if rng_seeds_params:
                rng_seeds_dict = dict((rng_seed.tag.split('}')[1], rng_seed.text) for rng_seed in rng_seeds_params)
                rng_seeds = rng_seeds_dict
            params.update({prefix + '-rng_seeds': rng_seeds})
        params.update({
            prefix+'-light_cone_type': light_cone_type,
            prefix+'-number_of_light_cones': num_cones,
            prefix+'-redshift_min': redshift_min,
            prefix+'-redshift_max': redshift_max,
            prefix+'-ra_opening_angle': ra_max,
            prefix+'-dec_opening_angle': dec_max,
            })
    params.update({prefix+'-output_properties': [dsp.id for dsp in Form._map_elems(xml_root, data_set)]})
    return cls(ui_holder, params, prefix=prefix)