Пример #1
0
def make_experiment_xml(prefix,xml_doc,params,restarts,ic_start,ic_end,start_umid,batch):
	# Set start umid  
	anc = ANC()
        anc.Start(start_umid) # next set

        ######## Make expts ##########
	end_umid=CreatePertExpts(xml_doc,params,restarts,ic_start,ic_end,anc)


	# Add the batch info
	batch['first_start_year']=params['model_start_year']
        batch['last_start_year']=params['model_start_year']
        batch['umid_start']=start_umid
        batch['umid_end']=end_umid
        AddBatchDict(xml_doc,batch)

        ######## Write out the file ########
	xml_filename=prefix + str(params['model_start_year']) + "_" +\
                          start_umid + '_' + end_umid + '.xml'
        #define the xml filename
        fh = open(xml_filename, 'w')
        print 'Writing to:',xml_filename,'...'
        remove_whitespace_nodes(xml_doc)
        xml_doc.writexml(fh,newl='\n',addindent='\t')
#xml_doc.writexml(fh)
        fh.close()
	
	count = xml_doc.getElementsByTagName("experiment").length

	print "Number of workunits: ",count
    root = xml_doc.documentElement

    make_header(xml_doc, args.site, upload_loc, app_config, stash_files,
                pack_files)

    # Set up number of perturbations
    pert_start = 0
    pert_end = 5
    npert = pert_end - pert_start

    first_year = 2013
    last_year = 2013

    # Set start umid
    start_umid = "a000"
    anc = ANC()
    anc.Start(start_umid)  # next set

    print("Creating experiments... ")

    for year in range(first_year, last_year + 1):
        params['model_start_year'] = year
        params['file_atmos'] = 'xpaef.start'
        end_umid = CreatePertExpts2(xml_doc, params, pert_start, pert_end, anc,
                                    args.resolution)

    # Add in batch tags:
    batch = {}
    batch['name'] = "HadSM4 test experiment"
    batch['desc'] = "Test simulation for HadSM4 for CMIP6 forcings"
    batch[
def create_xml(batch, params, ifs_data, climate_data, dates, n_analysis, n_ens,
               upload_loc, start_umid, model_class, model_config,
               fullpos_namelist):
    print "Creating experiments... "
    ic_ancil = {}
    # Start the xml document
    outtreeroot = Element('batch')
    outtree = ElementTree(outtreeroot)

    # Add in the model config
    SubElement(outtreeroot, 'model_class').text = str(model_class)
    SubElement(outtreeroot, 'model_config').text = str(model_config)
    SubElement(outtreeroot, 'fullpos_namelist').text = str(fullpos_namelist)

    # Add in the upload information
    upload_handler, upload_template = get_upload_info(upload_loc)
    ul_info = Element('upload_info')
    ul_tree = ElementTree(ul_info)
    SubElement(ul_info, 'upload_handler').text = str(upload_handler)
    SubElement(ul_info, 'result_template_prefix').text = str(upload_template)
    outtreeroot.append(ul_info)

    # Create the workunits section
    WUs = Element('workunits')
    WUs_tree = ElementTree(WUs)

    # Setup the umid counter
    anc = ANC()
    anc.Start(start_umid)  # next set

    count = 0
    for date in dates:
        params['start_year'] = date[0:4]
        params['start_month'] = date[4:6]
        params['start_day'] = date[6:8]
        params['start_hour'] = date[-2:]

        for ia in range(0, n_analysis):
            ic_ancil['ic_ancil_zip'] = 'ic_' + params[
                'exptid'] + '_' + date + '_' + str(ia).zfill(3) + '.zip'
            params['analysis_member_number'] = str(ia).zfill(3)
            for iens in range(1, n_ens + 1):
                params['ensemble_member_number'] = str(iens).zfill(3)
                params['unique_member_id'] = anc.Get()

                wu = CreateWorkunit(params, ic_ancil, ifs_data, climate_data)
                WUs.append(wu)
                anc.Next()
                count += 1
    # Add the workunits to the xml
    outtreeroot.append(WUs)

    end_umid = params['unique_member_id']

    # Add in start and end umid to batch tags:
    batch['umid_start'] = start_umid
    batch['umid_end'] = end_umid
    binf = AddBatchInfo(batch)
    outtreeroot.append(binf)

    ######## Write out the file ########
    #Write overall tree stucture to output xml


    xml_out='wu_oifs_'+batch['name'].replace(" ","")+"_" +\
                      start_umid + '_' + end_umid + '.xml'
    if not os.path.exists('xmls'):
        os.makedirs('xmls')
    print 'Writing to:', xml_out, '...'
    #outtree.write('xmls/'+xml_out)

    xmlstr = minidom.parseString(
        ET.tostring(outtreeroot)).toprettyxml(indent="   ")
    with open("xmls/" + xml_out, "w") as f:
        f.write(xmlstr)

# Print out the number of xmls
    print "Number of workunits: ", count