def fixup_old_data(data): for m in [ 'beamEvolutionAnimation', 'bunch', 'bunchAnimation', 'bunchTwiss', 'simulationSettings', 'turnComparisonAnimation', 'twissReport', 'twissReport2', ]: if m not in data['models']: data['models'][m] = {} template_common.update_model_defaults(data['models'][m], m, _SCHEMA) if 'bunchReport' in data['models']: del data['models']['bunchReport'] for i in range(4): m = 'bunchReport{}'.format(i + 1) model = data['models'][m] = {} template_common.update_model_defaults(data['models'][m], 'bunchReport', _SCHEMA) if i == 0: model['y'] = 'xp' elif i == 1: model['x'] = 'y' model['y'] = 'yp' elif i == 3: model['x'] = 'z' model['y'] = 'zp' template_common.organize_example(data)
def fixup_old_data(data): for m in [ 'bunch', 'bunchAnimation', 'bunchAnimation2', 'energyAnimation', 'particle', 'particleCoordinate', 'simulationSettings', 'opticsReport', 'twissReport', 'twissReport2', 'twissSummaryReport', ]: if m not in data.models: data.models[m] = pkcollections.Dict({}) template_common.update_model_defaults(data.models[m], m, _SCHEMA) if 'coordinates' not in data.models.bunch: data.models.bunch.coordinates = [] if 'spntrk' in data.models.simulationSettings: for f in ('spntrk', 'S_X', 'S_Y', 'S_Z'): if f in data.models.simulationSettings: data.models.bunch[f] = data.models.simulationSettings[f] del data.models.simulationSettings[f] template_common.organize_example(data)
def fixup_old_data(data): for m in _SCHEMA.model: # don't include beamline element models (all uppercase) if m != m.upper(): if m not in data.models: data.models[m] = pkcollections.Dict({}) template_common.update_model_defaults(data.models[m], m, _SCHEMA) for m in ('analysisAnimation', 'fitter', 'fitReport'): if m in data.models: del data.models[m] if 'history' not in data.models.analysisReport: data.models.analysisReport.history = [] if 'subreports' not in data.models.hiddenReport: data.models.hiddenReport.subreports = [] if 'beamlines' not in data.models: _init_default_beamline(data) for el in data.models.elements: # create a watchpointReport for each WATCH element if el['type'] == 'WATCH': name = 'watchpointReport{}'.format(el['_id']) if name not in data.models: m = pkcollections.Dict({ '_id': el['_id'], }) data.models[name] = m template_common.update_model_defaults(m, 'watchpointReport', _SCHEMA) template_common.organize_example(data)
def fixup_old_data(data): for m in [ 'bunchSource', 'twissReport', ]: if m not in data['models']: data['models'][m] = {} template_common.update_model_defaults(data['models'][m], m, _SCHEMA) if 'bunchFile' not in data['models']: data['models']['bunchFile'] = { 'sourceFile': None, } if 'folder' not in data['models']['simulation']: data['models']['simulation']['folder'] = '/' if 'simulationMode' not in data['models']['simulation']: data['models']['simulation']['simulationMode'] = 'parallel' if 'rpnVariables' not in data['models']: data['models']['rpnVariables'] = [] if 'commands' not in data['models']: data['models']['commands'] = _create_default_commands(data) for m in data['models']['elements']: model_schema = _SCHEMA['model'][m['type']] for k in m: if k in model_schema and model_schema[k][ 1] == 'OutputFile' and m[k]: m[k] = "1" for m in data['models']['elements']: if m['type'] == 'WATCH': m['filename'] = '1' if m['mode'] == 'coordinates' or m['mode'] == 'coord': m['mode'] = 'coordinate' template_common.update_model_defaults(m, m['type'], _SCHEMA) if 'centroid' not in data['models']['bunch']: bunch = data['models']['bunch'] for f in ('emit_x', 'emit_y', 'emit_z'): if bunch[f] and not isinstance(bunch[f], basestring): bunch[f] /= 1e9 if bunch['sigma_s'] and not isinstance(bunch['sigma_s'], basestring): bunch['sigma_s'] /= 1e6 first_bunch_command = _find_first_bunch_command(data) # first_bunch_command may not exist if the elegant sim has no bunched_beam command if first_bunch_command: first_bunch_command['symmetrize'] = str( first_bunch_command['symmetrize']) for f in _SCHEMA['model']['bunch']: if f not in bunch and f in first_bunch_command: bunch[f] = first_bunch_command[f] else: bunch['centroid'] = '0,0,0,0,0,0' for m in data['models']['commands']: template_common.update_model_defaults(m, 'command_{}'.format(m['_type']), _SCHEMA) template_common.organize_example(data)
def fixup_old_data(data): for m in _SCHEMA.model: if m not in data.models: data.models[m] = pkcollections.Dict({}) template_common.update_model_defaults(data.models[m], m, _SCHEMA) for m in ('analysisAnimation', 'fitter', 'fitReport'): if m in data.models: del data.models[m] if 'history' not in data.models.analysisReport: data.models.analysisReport.history = [] if 'subreports' not in data.models.hiddenReport: data.models.hiddenReport.subreports = [] template_common.organize_example(data)
def fixup_old_data(data): if 'optimizer' not in data['models'] or 'enabledFields' not in data[ 'models']['optimizer']: data['models']['optimizer'] = { 'constraints': [], 'enabledFields': {}, 'fields': [], } for m in [ 'egunCurrentAnimation', 'fieldReport', 'impactDensityAnimation', 'optimizer', 'optimizerAnimation', 'optimizerStatus', 'particle3d', 'particleAnimation', 'simulation', 'simulationGrid', ]: if m not in data.models: data.models[m] = {} template_common.update_model_defaults(data.models[m], m, _SCHEMA) if 'joinEvery' in data.models.particle3d: del data.models.particle3d['joinEvery'] types = data.models.conductorTypes if 'conductorTypes' in data.models else {} for c in types: if c is None: continue if 'isConductor' not in c: c.isConductor = '1' if c.voltage > 0 else '0' template_common.update_model_defaults(c, c.type if 'type' in c else 'box', _SCHEMA) for c in data.models.conductors: template_common.update_model_defaults(c, 'conductorPosition', _SCHEMA) if 'fieldComparisonReport' not in data.models: grid = data.models.simulationGrid data.models.fieldComparisonReport = { 'dimension': 'x', 'xCell1': int(grid.num_x / 3.), 'xCell2': int(grid.num_x / 2.), 'xCell3': int(grid.num_x * 2. / 3), 'zCell1': int(grid.num_z / 2.), 'zCell2': int(grid.num_z * 2. / 3), 'zCell3': int(grid.num_z * 4. / 5), } template_common.organize_example(data)
def fixup_old_data(data): for m in ('beamAnimation', 'beamHistogramAnimation', 'parameterAnimation', 'particleAnimation'): if m not in data.models: data.models[m] = pkcollections.Dict({}) template_common.update_model_defaults(data.models[m], m, _SCHEMA) if 'solenoidFile' not in data['models']['solenoid']: data['models']['solenoid']['solenoidFile'] = '' if 'beamDefinition' not in data['models']['beam']: beam = data['models']['beam'] beam['beamDefinition'] = 'transverse_longitude' beam['cstCompress'] = '0' beam['transversalFile2d'] = '' beam['transversalFile4d'] = '' beam['longitudinalFile1d'] = '' beam['longitudinalFile2d'] = '' beam['cstFile'] = '' template_common.organize_example(data)
def fixup_old_data(data): if (float(data.fixup_old_version) < 20170703.000001 and 'geometricSource' in data.models): g = data.models.geometricSource x = g.cone_max g.cone_max = g.cone_min g.cone_min = x for m in [ 'initialIntensityReport', 'plotXYReport', ]: if m not in data.models: data.models[m] = pkcollections.Dict({}) template_common.update_model_defaults(data.models[m], m, _SCHEMA) for m in data.models: if template_common.is_watchpoint(m): template_common.update_model_defaults(data.models[m], 'watchpointReport', _SCHEMA) template_common.organize_example(data)
def fixup_old_data(data): for m in ('ring', 'particleAnimation', 'twissReport'): if m not in data['models']: data['models'][m] = {} template_common.update_model_defaults(data['models'][m], m, _SCHEMA) if 'coolingRatesAnimation' not in data['models']: for m in ('beamEvolutionAnimation', 'coolingRatesAnimation'): data['models'][m] = {} template_common.update_model_defaults(data['models'][m], m, _SCHEMA) if 'beam_type' not in data['models']['ionBeam']: ion_beam = data['models']['ionBeam'] ion_beam['beam_type'] = 'bunched' if ion_beam[ 'rms_bunch_length'] > 0 else 'continuous' if 'beam_type' not in data['models']['electronBeam']: ebeam = data['models']['electronBeam'] ebeam['beam_type'] = 'continuous' if ebeam[ 'shape'] == 'dc_uniform' else 'bunched' ebeam['rh'] = ebeam['rv'] = 0.004 settings = data['models']['simulationSettings'] if settings['model'] == 'model_beam': settings['model'] = 'particle' if 'ibs' not in settings: settings['ibs'] = '1' settings['e_cool'] = '1' if 'ref_bet_x' not in settings or not settings['ref_bet_x']: settings['ref_bet_x'] = settings['ref_bet_y'] = 10 for f in ('ref_alf_x', 'ref_disp_x', 'ref_disp_dx', 'ref_alf_y', 'ref_disp_y', 'ref_disp_dy'): settings[f] = 0 # if model field value is less than min, set to default value for m in data['models']: model = data['models'][m] if m in _SCHEMA['model']: for f in _SCHEMA['model'][m]: field_def = _SCHEMA['model'][m][f] if len(field_def) > 4 and model[f] < field_def[4]: model[f] = field_def[2] template_common.organize_example(data)
def fixup_old_data(data): if 'laserPreviewReport' not in data['models']: data['models']['laserPreviewReport'] = {} if 'particleAnimation' not in data['models']: data['models']['particleAnimation'] = { 'x': 'z', 'y': 'x', 'histogramBins': 100, } if 'simulationStatus' not in data['models']: data['models']['simulationStatus'] = {} if 'histogramBins' not in data['models']['particleAnimation']: data['models']['particleAnimation']['histogramBins'] = 100 if 'framesPerSecond' not in data['models']['fieldAnimation']: data['models']['fieldAnimation']['framesPerSecond'] = 20 data['models']['particleAnimation']['framesPerSecond'] = 20 if 'rScale' not in data['models']['simulationGrid']: grid = data['models']['simulationGrid'] grid['rScale'] = 4 grid['rLength'] = '20.324980154380' grid['rMin'] = 0 grid['rMax'] = '20.324980154380' grid['rCellsPerSpotSize'] = 8 grid['rCount'] = 32 grid['zScale'] = 2 grid['zLength'] = '20.324980154631' grid['zMin'] = '-20.324980154631' grid['zMax'] = '1.60' grid['zCellsPerWavelength'] = 8 grid['zCount'] = 214 del grid['xMin'] del grid['xMax'] del grid['xCount'] del grid['zLambda'] if 'rParticlesPerCell' not in data['models']['simulationGrid']: data['models']['simulationGrid']['rParticlesPerCell'] = 1 data['models']['simulationGrid']['zParticlesPerCell'] = 2 if 'field' not in data['models']['laserPreviewReport']: laserPreview = data['models']['laserPreviewReport'] laserPreview['field'] = 'E' laserPreview['coordinate'] = 'y' laserPreview['mode'] = '1' if 'sourceType' not in data['models']['simulation']: data['models']['simulation']['sourceType'] = 'laserPulse' if 'electronBeam' not in data['models']: data['models']['electronBeam'] = { 'charge': 1.0e-08, 'energy': 23, } if 'beamPreviewReport' not in data['models']: data['models']['beamPreviewReport'] = { 'x': 'z', 'y': 'x', 'histogramBins': 100 } if 'beamAnimation' not in data['models']: data['models']['beamAnimation'] = data['models'][ 'particleAnimation'].copy() if 'rCellResolution' not in data['models']['simulationGrid']: grid = data['models']['simulationGrid'] grid['rCellResolution'] = 40 grid['zCellResolution'] = 40 if 'rmsLength' not in data['models']['electronBeam']: beam = data['models']['electronBeam'] beam['rmsLength'] = 0 beam['rmsRadius'] = 0 beam['bunchLength'] = 0 beam['transverseEmittance'] = 0 if 'xMin' not in data['models']['particleAnimation']: animation = data['models']['particleAnimation'] for v in ('x', 'y', 'z'): animation['{}Min'.format(v)] = 0 animation['{}Max'.format(v)] = 0 animation['u{}Min'.format(v)] = 0 animation['u{}Max'.format(v)] = 0 if 'beamRadiusMethod' not in data['models']['electronBeam']: beam = data['models']['electronBeam'] beam['beamRadiusMethod'] = 'a' beam['transverseEmittance'] = 0.00001 beam['rmsRadius'] = 15 beam['beamBunchLengthMethod'] = 's' if 'folder' not in data['models']['simulation']: data['models']['simulation']['folder'] = '/' for m in ('beamAnimation', 'fieldAnimation', 'particleAnimation'): template_common.update_model_defaults(data['models'][m], m, _SCHEMA) template_common.organize_example(data)