예제 #1
0
def parsed_dict(v, op):
    std_options = Struct(**list2dict(srwl_uti_std_options()))

    beamline_elements = get_beamline(op.arOpt, v.op_r)

    # Since the rotation angle cannot be passed from SRW object, we update the angle here:
    beamline_elements = _update_crystals(beamline_elements, v)

    def _default_value(parm, obj, std, def_val=None):
        if not hasattr(obj, parm):
            try:
                return getattr(std, parm)
            except:
                if def_val is not None:
                    return def_val
                else:
                    return ''
        try:
            return getattr(obj, parm)
        except:
            if def_val is not None:
                return def_val
            else:
                return ''

    # This dictionary will is used for both initial intensity report and for watch point:
    initialIntensityReport = {
        'characteristic': v.si_type,
        'fieldUnits': 2,
        'polarization': v.si_pol,
        'precision': v.w_prec,
        'sampleFactor': 0,
    }

    # Default electron beam:
    if hasattr(v, 'ebm_nm'):
        source_type = 'u'

        electronBeam = {
            'beamSelector':
            v.ebm_nm,
            'current':
            v.ebm_i,
            'energy':
            _default_value('ueb_e', v, std_options, 3.0),
            'energyDeviation':
            _default_value('ebm_de', v, std_options, 0.0),
            'horizontalAlpha':
            _default_value('ueb_alpha_x', v, std_options, 0.0),
            'horizontalBeta':
            _default_value('ueb_beta_x', v, std_options, 2.02),
            'horizontalDispersion':
            _default_value('ueb_eta_x', v, std_options, 0.0),
            'horizontalDispersionDerivative':
            _default_value('ueb_eta_x_pr', v, std_options, 0.0),
            'horizontalEmittance':
            _default_value('ueb_emit_x', v, std_options, 9e-10) * 1e9,
            'horizontalPosition':
            v.ebm_x,
            'isReadOnly':
            False,
            'name':
            v.ebm_nm,
            'rmsSpread':
            _default_value('ueb_sig_e', v, std_options, 0.00089),
            'verticalAlpha':
            _default_value('ueb_alpha_y', v, std_options, 0.0),
            'verticalBeta':
            _default_value('ueb_beta_y', v, std_options, 1.06),
            'verticalDispersion':
            _default_value('ueb_eta_y', v, std_options, 0.0),
            'verticalDispersionDerivative':
            _default_value('ueb_eta_y_pr', v, std_options, 0.0),
            'verticalEmittance':
            _default_value('ueb_emit_y', v, std_options, 8e-12) * 1e9,
            'verticalPosition':
            v.ebm_y,
        }

        undulator = {
            'horizontalAmplitude':
            _default_value('und_bx', v, std_options, 0.0),
            'horizontalInitialPhase':
            _default_value('und_phx', v, std_options, 0.0),
            'horizontalSymmetry':
            _default_value('und_sx', v, std_options, 1.0),
            'length':
            _default_value('und_len', v, std_options, 1.5),
            'longitudinalPosition':
            _default_value('und_zc', v, std_options, 1.305),
            'period':
            _default_value('und_per', v, std_options, 0.021) * 1e3,
            'verticalAmplitude':
            _default_value('und_by', v, std_options, 0.88770981),
            'verticalInitialPhase':
            _default_value('und_phy', v, std_options, 0.0),
            'verticalSymmetry':
            _default_value('und_sy', v, std_options, -1),
        }

        gaussianBeam = {
            'energyPerPulse': None,
            'polarization': 1,
            'rmsPulseDuration': None,
            'rmsSizeX': None,
            'rmsSizeY': None,
            'waistAngleX': None,
            'waistAngleY': None,
            'waistX': None,
            'waistY': None,
            'waistZ': None,
        }

    else:
        source_type = 'g'
        electronBeam = {
            'beamSelector': None,
            'current': None,
            'energy': None,
            'energyDeviation': None,
            'horizontalAlpha': None,
            'horizontalBeta': 1.0,
            'horizontalDispersion': None,
            'horizontalDispersionDerivative': None,
            'horizontalEmittance': None,
            'horizontalPosition': None,
            'isReadOnly': False,
            'name': None,
            'rmsSpread': None,
            'verticalAlpha': None,
            'verticalBeta': 1.0,
            'verticalDispersion': None,
            'verticalDispersionDerivative': None,
            'verticalEmittance': None,
            'verticalPosition': None,
        }
        undulator = {
            'horizontalAmplitude': None,
            'horizontalInitialPhase': None,
            'horizontalSymmetry': 1,
            'length': None,
            'longitudinalPosition': None,
            'period': None,
            'verticalAmplitude': None,
            'verticalInitialPhase': None,
            'verticalSymmetry': 1,
        }

        gaussianBeam = {
            'energyPerPulse': _default_value('gbm_pen', v, std_options),
            'polarization': _default_value('gbm_pol', v, std_options),
            'rmsPulseDuration':
            _default_value('gbm_st', v, std_options) * 1e12,
            'rmsSizeX': _default_value('gbm_sx', v, std_options) * 1e6,
            'rmsSizeY': _default_value('gbm_sy', v, std_options) * 1e6,
            'waistAngleX': _default_value('gbm_xp', v, std_options),
            'waistAngleY': _default_value('gbm_yp', v, std_options),
            'waistX': _default_value('gbm_x', v, std_options),
            'waistY': _default_value('gbm_y', v, std_options),
            'waistZ': _default_value('gbm_z', v, std_options),
        }

    python_dict = {
        'models': {
            'beamline': beamline_elements,
            'electronBeam': electronBeam,
            'electronBeams': [],
            'fluxReport': {
                'azimuthalPrecision': v.sm_pra,
                'distanceFromSource': v.op_r,
                'finalEnergy': v.sm_ef,
                'fluxType': v.sm_type,
                'horizontalApertureSize': v.sm_rx * 1e3,
                'horizontalPosition': v.sm_x,
                'initialEnergy': v.sm_ei,
                'longitudinalPrecision': v.sm_prl,
                'photonEnergyPointCount': v.sm_ne,
                'polarization': v.sm_pol,
                'verticalApertureSize': v.sm_ry * 1e3,
                'verticalPosition': v.sm_y,
            },
            'initialIntensityReport': initialIntensityReport,
            'intensityReport': {
                'distanceFromSource': v.op_r,
                'fieldUnits': 1,
                'finalEnergy': v.ss_ef,
                'horizontalPosition': v.ss_x,
                'initialEnergy': v.ss_ei,
                'photonEnergyPointCount': v.ss_ne,
                'polarization': v.ss_pol,
                'precision': v.ss_prec,
                'verticalPosition': v.ss_y,
            },
            'multiElectronAnimation': {
                'horizontalPosition': 0,
                'horizontalRange': v.w_rx * 1e3,
                'stokesParameter': '0',
                'verticalPosition': 0,
                'verticalRange': v.w_ry * 1e3,
            },
            'multipole': {
                'distribution': 'n',
                'field': 0,
                'length': 0,
                'order': 1,
            },
            'postPropagation': op.arProp[-1],
            'powerDensityReport': {
                'distanceFromSource': v.op_r,
                'horizontalPointCount': v.pw_nx,
                'horizontalPosition': v.pw_x,
                'horizontalRange': v.pw_rx * 1e3,
                'method': v.pw_meth,
                'precision': v.pw_pr,
                'verticalPointCount': v.pw_ny,
                'verticalPosition': v.pw_y,
                'verticalRange': v.pw_ry * 1e3,
            },
            'propagation': get_propagation(op),
            'simulation': {
                'facility': 'Import',
                'horizontalPointCount': v.w_nx,
                'horizontalPosition': v.w_x,
                'horizontalRange': v.w_rx * 1e3,
                'isExample': 0,
                'name': '',
                'photonEnergy': v.w_e,
                'sampleFactor': v.w_smpf,
                'samplingMethod': 1,
                'simulationId': '',
                'sourceType': source_type,
                'verticalPointCount': v.w_ny,
                'verticalPosition': v.w_y,
                'verticalRange': v.w_ry * 1e3,
            },
            'sourceIntensityReport': {
                'characteristic': v.si_type,  # 0,
                'distanceFromSource': v.op_r,
                'fieldUnits': 2,
                'polarization': v.si_pol,
            },
            'undulator': undulator,
            'gaussianBeam': gaussianBeam,
        },
        'report': '',
        'simulationType': 'srw',
        'version': '',
    }

    # Format the key name to be consistent with Sirepo:
    for i in range(len(beamline_elements)):
        if beamline_elements[i]['type'] == 'watch':
            idx = beamline_elements[i]['id']
            python_dict['models']['watchpointReport{}'.format(
                idx)] = initialIntensityReport

    return python_dict
예제 #2
0
def _parsed_dict(v, op):
    import sirepo.template.srw
    std_options = Struct(**_list2dict(srwl_uti_std_options()))

    beamline_elements = _get_beamline(op.arOpt, v.op_r)

    # Since the rotation angle cannot be passed from SRW object, we update the angle here:
    beamline_elements = _update_crystals(beamline_elements, v)

    def _default_value(parm, obj, std, def_val=None):
        if not hasattr(obj, parm):
            try:
                return getattr(std, parm)
            except Exception:
                if def_val is not None:
                    return def_val
                else:
                    return ''
        try:
            return getattr(obj, parm)
        except Exception:
            if def_val is not None:
                return def_val
            else:
                return ''

    # This dictionary will is used for both initial intensity report and for watch point:
    initialIntensityReport = pkcollections.Dict({
        'characteristic': v.si_type,
        'fieldUnits': 1,
        'polarization': v.si_pol,
        'precision': v.w_prec,
        'sampleFactor': 0,
    })

    predefined_beams = sirepo.template.srw.get_predefined_beams()

    # Default electron beam:
    if (hasattr(v, 'source_type') and v.source_type == 'u') or (hasattr(v, 'ebm_nm') and not hasattr(v, 'gbm_pen')):
        source_type = 'u'
        if v.ebm_nms == 'Day1':
            v.ebm_nms = 'Day 1'
        full_beam_name = '{}{}'.format(v.ebm_nm, v.ebm_nms)
        electronBeam = pkcollections.Dict()
        for b in predefined_beams:
            if b['name'] == full_beam_name:
                electronBeam = b
                electronBeam['beamSelector'] = full_beam_name
                break
        if not electronBeam:
            electronBeam = pkcollections.Dict({
                'beamSelector': full_beam_name,
                'current': v.ebm_i,
                'energy': _default_value('ebm_e', v, std_options, 3.0),
                'energyDeviation': _default_value('ebm_de', v, std_options, 0.0),
                'horizontalAlpha': _default_value('ebm_alphax', v, std_options, 0.0),
                'horizontalBeta': _default_value('ebm_betay', v, std_options, 2.02),
                'horizontalDispersion': _default_value('ebm_etax', v, std_options, 0.0),
                'horizontalDispersionDerivative': _default_value('ebm_etaxp', v, std_options, 0.0),
                'horizontalEmittance': _default_value('ebm_emx', v, std_options, 9e-10) * 1e9,
                'horizontalPosition': v.ebm_x,
                'isReadOnly': False,
                'name': full_beam_name,
                'rmsSpread': _default_value('ebm_ens', v, std_options, 0.00089),
                'verticalAlpha': _default_value('ebm_alphay', v, std_options, 0.0),
                'verticalBeta': _default_value('ebm_betay', v, std_options, 1.06),
                'verticalDispersion': _default_value('ebm_etay', v, std_options, 0.0),
                'verticalDispersionDerivative': _default_value('ebm_etaxp', v, std_options, 0.0),
                'verticalEmittance': _default_value('ebm_emy', v, std_options, 8e-12) * 1e9,
                'verticalPosition': v.ebm_y,
            })

        undulator = pkcollections.Dict({
            'horizontalAmplitude': _default_value('und_bx', v, std_options, 0.0),
            'horizontalInitialPhase': _default_value('und_phx', v, std_options, 0.0),
            'horizontalSymmetry': _default_value('und_sx', v, std_options, 1.0),
            'length': _default_value('und_len', v, std_options, 1.5),
            'longitudinalPosition': _default_value('und_zc', v, std_options, 1.305),
            'period': _default_value('und_per', v, std_options, 0.021) * 1e3,
            'verticalAmplitude': _default_value('und_by', v, std_options, 0.88770981) if hasattr(v, 'und_by') else _default_value('und_b', v, std_options, 0.88770981),
            'verticalInitialPhase': _default_value('und_phy', v, std_options, 0.0),
            'verticalSymmetry': _default_value('und_sy', v, std_options, -1),
        })

        gaussianBeam = pkcollections.Dict({
            'energyPerPulse': None,
            'polarization': 1,
            'rmsPulseDuration': None,
            'rmsSizeX': None,
            'rmsSizeY': None,
            'waistAngleX': None,
            'waistAngleY': None,
            'waistX': None,
            'waistY': None,
            'waistZ': None,
        })

    else:
        source_type = 'g'
        electronBeam = pkcollections.Dict()
        default_ebeam_name = 'NSLS-II Low Beta Final'
        for beam in predefined_beams:
            if beam['name'] == default_ebeam_name:
                electronBeam = beam
                electronBeam['beamSelector'] = default_ebeam_name
                break
        if not electronBeam:
            raise ValueError('Electron beam is not set during import')
        undulator = pkcollections.Dict({
            "horizontalAmplitude": "0",
            "horizontalInitialPhase": 0,
            "horizontalSymmetry": 1,
            "length": 3,
            "longitudinalPosition": 0,
            "period": "20",
            "undulatorParameter": 1.65776086,
            "verticalAmplitude": "0.88770981",
            "verticalInitialPhase": 0,
            "verticalSymmetry": -1,
        })

        gaussianBeam = pkcollections.Dict({
            'energyPerPulse': _default_value('gbm_pen', v, std_options),
            'polarization': _default_value('gbm_pol', v, std_options),
            'rmsPulseDuration': _default_value('gbm_st', v, std_options) * 1e12,
            'rmsSizeX': _default_value('gbm_sx', v, std_options) * 1e6,
            'rmsSizeY': _default_value('gbm_sy', v, std_options) * 1e6,
            'waistAngleX': _default_value('gbm_xp', v, std_options),
            'waistAngleY': _default_value('gbm_yp', v, std_options),
            'waistX': _default_value('gbm_x', v, std_options),
            'waistY': _default_value('gbm_y', v, std_options),
            'waistZ': _default_value('gbm_z', v, std_options),
        })

    python_dict = pkcollections.Dict({
        'models': pkcollections.Dict({
            'beamline': beamline_elements,
            'electronBeam': electronBeam,
            'electronBeams': [],
            'fluxReport': pkcollections.Dict({
                'azimuthalPrecision': v.sm_pra,
                'distanceFromSource': v.op_r,
                'finalEnergy': v.sm_ef,
                'fluxType': v.sm_type,
                'horizontalApertureSize': v.sm_rx * 1e3,
                'horizontalPosition': v.sm_x,
                'initialEnergy': v.sm_ei,
                'longitudinalPrecision': v.sm_prl,
                'photonEnergyPointCount': v.sm_ne,
                'polarization': v.sm_pol,
                'verticalApertureSize': v.sm_ry * 1e3,
                'verticalPosition': v.sm_y,
            }),
            'initialIntensityReport': initialIntensityReport,
            'intensityReport': pkcollections.Dict({
                'distanceFromSource': v.op_r,
                'fieldUnits': 1,
                'finalEnergy': v.ss_ef,
                'horizontalPosition': v.ss_x,
                'initialEnergy': v.ss_ei,
                'photonEnergyPointCount': v.ss_ne,
                'polarization': v.ss_pol,
                'precision': v.ss_prec,
                'verticalPosition': v.ss_y,
            }),
            'multiElectronAnimation': pkcollections.Dict({
                'horizontalPosition': 0,
                'horizontalRange': v.w_rx * 1e3,
                'stokesParameter': '0',
                'verticalPosition': 0,
                'verticalRange': v.w_ry * 1e3,
            }),
            'multipole': pkcollections.Dict({
                'distribution': 'n',
                'field': 0,
                'length': 0,
                'order': 1,
            }),
            'postPropagation': op.arProp[-1],
            'powerDensityReport': pkcollections.Dict({
                'distanceFromSource': v.op_r,
                'horizontalPointCount': v.pw_nx,
                'horizontalPosition': v.pw_x,
                'horizontalRange': v.pw_rx * 1e3,
                'method': v.pw_meth,
                'precision': v.pw_pr,
                'verticalPointCount': v.pw_ny,
                'verticalPosition': v.pw_y,
                'verticalRange': v.pw_ry * 1e3,
            }),
            'propagation': _get_propagation(op),
            'simulation': pkcollections.Dict({
                'horizontalPointCount': v.w_nx,
                'horizontalPosition': v.w_x,
                'horizontalRange': v.w_rx * 1e3,
                'isExample': 0,
                'name': '',
                'photonEnergy': v.w_e,
                'sampleFactor': v.w_smpf,
                'samplingMethod': 1,
                'simulationId': '',
                'sourceType': source_type,
                'verticalPointCount': v.w_ny,
                'verticalPosition': v.w_y,
                'verticalRange': v.w_ry * 1e3,
            }),
            'sourceIntensityReport': pkcollections.Dict({
                'characteristic': v.si_type,  # 0,
                'distanceFromSource': v.op_r,
                'fieldUnits': 1,
                'polarization': v.si_pol,
            }),
            'undulator': undulator,
            'gaussianBeam': gaussianBeam,
        }),
        'simulationType': 'srw',
        'version': '',
    })

    # Format the key name to be consistent with Sirepo:
    for i in range(len(beamline_elements)):
        if beamline_elements[i]['type'] == 'watch':
            idx = beamline_elements[i]['id']
            python_dict['models']['watchpointReport{}'.format(idx)] = initialIntensityReport

    return python_dict
def parsed_dict(v, op, fname=None):
    std_options = Struct(**list2dict(srwl_uti_std_options()))

    beamlines_list = get_beamline(op.arOpt, v.op_r)

    def _default_value(parm, obj, std, def_val=None):
        if not hasattr(obj, parm):
            try:
                return getattr(std, parm)
            except:
                if def_val is not None:
                    return def_val
                else:
                    return ''
        try:
            return getattr(obj, parm)
        except:
            if def_val is not None:
                return def_val
            else:
                return ''

    # This dictionary will is used for both initial intensity report and for watch point:
    initialIntensityReport = {
        u'characteristic': v.si_type,
        u'fieldUnits': 2,
        u'polarization': v.si_pol,
        u'precision': v.w_prec,
        u'sampleFactor': 0,
    }

    # Default electron beam:
    if hasattr(v, 'ebm_nm'):
        source_type = u'u'

        electronBeam = {
            u'beamSelector': unicode(v.ebm_nm),
            u'current': v.ebm_i,
            u'energy': _default_value('ueb_e', v, std_options, 3.0),
            u'energyDeviation': _default_value('ebm_de', v, std_options, 0.0),
            u'horizontalAlpha': _default_value('ueb_alpha_x', v, std_options, 0.0),
            u'horizontalBeta': _default_value('ueb_beta_x', v, std_options, 2.02),
            u'horizontalDispersion': _default_value('ueb_eta_x', v, std_options, 0.0),
            u'horizontalDispersionDerivative': _default_value('ueb_eta_x_pr', v, std_options, 0.0),
            u'horizontalEmittance': _default_value('ueb_emit_x', v, std_options, 9e-10) * 1e9,
            u'horizontalPosition': v.ebm_x,
            u'isReadOnly': False,
            u'name': unicode(v.ebm_nm),
            u'rmsSpread': _default_value('ueb_sig_e', v, std_options, 0.00089),
            u'verticalAlpha': _default_value('ueb_alpha_y', v, std_options, 0.0),
            u'verticalBeta': _default_value('ueb_beta_y', v, std_options, 1.06),
            u'verticalDispersion': _default_value('ueb_eta_y', v, std_options, 0.0),
            u'verticalDispersionDerivative': _default_value('ueb_eta_y_pr', v, std_options, 0.0),
            u'verticalEmittance': _default_value('ueb_emit_y', v, std_options, 8e-12) * 1e9,
            u'verticalPosition': v.ebm_y,
        }

        undulator = {
            u'horizontalAmplitude': _default_value('und_bx', v, std_options, 0.0),
            u'horizontalInitialPhase': _default_value('und_phx', v, std_options, 0.0),
            u'horizontalSymmetry': v.und_sx,
            u'length': v.und_len,
            u'longitudinalPosition': v.und_zc,
            u'period': v.und_per * 1e3,
            u'verticalAmplitude': _default_value('und_by', v, std_options, 0.88770981),
            u'verticalInitialPhase': _default_value('und_phy', v, std_options, 0.0),
            u'verticalSymmetry': v.und_sy,
        }

        gaussianBeam = {
            u'energyPerPulse': None,
            u'polarization': 1,
            u'rmsPulseDuration': None,
            u'rmsSizeX': None,
            u'rmsSizeY': None,
            u'waistAngleX': None,
            u'waistAngleY': None,
            u'waistX': None,
            u'waistY': None,
            u'waistZ': None,
        }

    else:
        source_type = u'g'
        electronBeam = {
            u'beamSelector': None,
            u'current': None,
            u'energy': None,
            u'energyDeviation': None,
            u'horizontalAlpha': None,
            u'horizontalBeta': 1.0,
            u'horizontalDispersion': None,
            u'horizontalDispersionDerivative': None,
            u'horizontalEmittance': None,
            u'horizontalPosition': None,
            u'isReadOnly': False,
            u'name': None,
            u'rmsSpread': None,
            u'verticalAlpha': None,
            u'verticalBeta': 1.0,
            u'verticalDispersion': None,
            u'verticalDispersionDerivative': None,
            u'verticalEmittance': None,
            u'verticalPosition': None,
        }
        undulator = {
            u'horizontalAmplitude': None,
            u'horizontalInitialPhase': None,
            u'horizontalSymmetry': 1,
            u'length': None,
            u'longitudinalPosition': None,
            u'period': None,
            u'verticalAmplitude': None,
            u'verticalInitialPhase': None,
            u'verticalSymmetry': 1,
        }

        gaussianBeam = {
            u'energyPerPulse': _default_value('gbm_pen', v, std_options),
            u'polarization': _default_value('gbm_pol', v, std_options),
            u'rmsPulseDuration': _default_value('gbm_st', v, std_options) * 1e12,
            u'rmsSizeX': _default_value('gbm_sx', v, std_options) * 1e6,
            u'rmsSizeY': _default_value('gbm_sy', v, std_options) * 1e6,
            u'waistAngleX': _default_value('gbm_xp', v, std_options),
            u'waistAngleY': _default_value('gbm_yp', v, std_options),
            u'waistX': _default_value('gbm_x', v, std_options),
            u'waistY': _default_value('gbm_y', v, std_options),
            u'waistZ': _default_value('gbm_z', v, std_options),
        }

    import_datetime = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S')
    if fname:
        name = 'Imported file <{}> ({})'.format(fname, import_datetime)
    else:
        name = 'Imported file ({})'.format(import_datetime)

    python_dict = {
        u'models': {
            u'beamline': beamlines_list,
            u'electronBeam': electronBeam,
            u'electronBeams': [],
            u'fluxReport': {
                u'azimuthalPrecision': v.sm_pra,
                u'distanceFromSource': v.op_r,
                u'finalEnergy': v.sm_ef,
                u'fluxType': v.sm_type,
                u'horizontalApertureSize': v.sm_rx * 1e3,
                u'horizontalPosition': v.sm_x,
                u'initialEnergy': v.sm_ei,
                u'longitudinalPrecision': v.sm_prl,
                u'photonEnergyPointCount': v.sm_ne,
                u'polarization': v.sm_pol,
                u'verticalApertureSize': v.sm_ry * 1e3,
                u'verticalPosition': v.sm_y,
            },
            u'initialIntensityReport': initialIntensityReport,
            u'intensityReport': {
                u'distanceFromSource': v.op_r,
                u'fieldUnits': 1,
                u'finalEnergy': v.ss_ef,
                u'horizontalPosition': v.ss_x,
                u'initialEnergy': v.ss_ei,
                u'photonEnergyPointCount': v.ss_ne,
                u'polarization': v.ss_pol,
                u'precision': v.ss_prec,
                u'verticalPosition': v.ss_y,
            },
            u'multiElectronAnimation': {
                u'horizontalPosition': 0,
                u'horizontalRange': v.w_rx * 1e3,
                u'stokesParameter': '0',
                u'verticalPosition': 0,
                u'verticalRange': v.w_ry * 1e3,
            },
            u'multipole': {
                u'distribution': 'n',
                u'field': 0,
                u'length': 0,
                u'order': 1,
            },
            u'postPropagation': op.arProp[-1],
            u'powerDensityReport': {
                u'distanceFromSource': v.op_r,
                u'horizontalPointCount': v.pw_nx,
                u'horizontalPosition': v.pw_x,
                u'horizontalRange': v.pw_rx * 1e3,
                u'method': v.pw_meth,
                u'precision': v.pw_pr,
                u'verticalPointCount': v.pw_ny,
                u'verticalPosition': v.pw_y,
                u'verticalRange': v.pw_ry * 1e3,
            },
            u'propagation': get_propagation(op),
            u'simulation': {
                u'facility': 'Import',  # unicode(v.ebm_nm.split()[0]),
                u'horizontalPointCount': v.w_nx,
                u'horizontalPosition': v.w_x,
                u'horizontalRange': v.w_rx * 1e3,
                u'isExample': 0,
                u'name': name,  # unicode(v.ebm_nm),  # unicode(v.name),
                u'photonEnergy': v.w_e,
                u'sampleFactor': v.w_smpf,
                u'samplingMethod': 1,
                u'simulationId': '',
                u'sourceType': source_type,
                u'verticalPointCount': v.w_ny,
                u'verticalPosition': v.w_y,
                u'verticalRange': v.w_ry * 1e3,
            },
            u'sourceIntensityReport': {
                u'characteristic': v.si_type,  # 0,
                u'distanceFromSource': v.op_r,
                u'fieldUnits': 2,
                u'polarization': v.si_pol,
            },
            # get_json(static_json_url + '/srw-default.json')['models']['sourceIntensityReport'],
            u'undulator': undulator,
            u'gaussianBeam': gaussianBeam,
        },
        u'report': u'',
        u'simulationType': u'srw',
        u'version': unicode(get_json(static_json_url + '/schema-common.json')['version']),
    }

    # Format the key name to be consistent with Sirepo:
    for i in range(len(beamlines_list)):
        if beamlines_list[i]['type'] == 'watch':
            idx = beamlines_list[i]['id']
            python_dict['models'][u'watchpointReport{}'.format(idx)] = initialIntensityReport

    return python_dict
예제 #4
0
def _parsed_dict(v, op):
    import sirepo.template.srw
    std_options = Struct(**_list2dict(srwl_bl.srwl_uti_std_options()))

    beamline_elements = _get_beamline(op.arOpt, v.op_r)

    # Since the rotation angle cannot be passed from SRW object, we update the angle here:
    beamline_elements = _update_crystals(beamline_elements, v)

    def _default_value(parm, obj, std, def_val=None):
        if not hasattr(obj, parm):
            try:
                return getattr(std, parm)
            except Exception:
                if def_val is not None:
                    return def_val
                else:
                    return ''
        try:
            return getattr(obj, parm)
        except Exception:
            if def_val is not None:
                return def_val
            else:
                return ''

    # This dictionary will is used for both initial intensity report and for watch point:
    initialIntensityReport = pkcollections.Dict({
        'characteristic': v.si_type,
        'fieldUnits': 1,
        'polarization': v.si_pol,
        'precision': v.w_prec,
        'sampleFactor': 0,
    })

    predefined_beams = sirepo.template.srw.get_predefined_beams()

    # Default electron beam:
    if (hasattr(v, 'source_type')
            and v.source_type == 'u') or (hasattr(v, 'ebm_nm')
                                          and v.gbm_pen == 0):
        source_type = 'u'
        if v.ebm_nms == 'Day1':
            v.ebm_nms = 'Day 1'
        full_beam_name = '{}{}'.format(v.ebm_nm, v.ebm_nms)
        if not len(full_beam_name):
            full_beam_name = 'Electron Beam'
        electronBeam = pkcollections.Dict()
        for b in predefined_beams:
            if b['name'] == full_beam_name:
                electronBeam = b
                electronBeam['beamSelector'] = full_beam_name
                break
        if not electronBeam:
            electronBeam = pkcollections.Dict({
                'beamSelector':
                full_beam_name,
                'current':
                v.ebm_i,
                'energy':
                _default_value('ebm_e', v, std_options, 3.0),
                'energyDeviation':
                _default_value('ebm_de', v, std_options, 0.0),
                'horizontalAlpha':
                _default_value('ebm_alphax', v, std_options, 0.0),
                'horizontalBeta':
                _default_value('ebm_betay', v, std_options, 2.02),
                'horizontalDispersion':
                _default_value('ebm_etax', v, std_options, 0.0),
                'horizontalDispersionDerivative':
                _default_value('ebm_etaxp', v, std_options, 0.0),
                'horizontalEmittance':
                _default_value('ebm_emx', v, std_options, 9e-10) * 1e9,
                'horizontalPosition':
                v.ebm_x,
                'isReadOnly':
                False,
                'name':
                full_beam_name,
                'rmsSpread':
                _default_value('ebm_ens', v, std_options, 0.00089),
                'verticalAlpha':
                _default_value('ebm_alphay', v, std_options, 0.0),
                'verticalBeta':
                _default_value('ebm_betay', v, std_options, 1.06),
                'verticalDispersion':
                _default_value('ebm_etay', v, std_options, 0.0),
                'verticalDispersionDerivative':
                _default_value('ebm_etaxp', v, std_options, 0.0),
                'verticalEmittance':
                _default_value('ebm_emy', v, std_options, 8e-12) * 1e9,
                'verticalPosition':
                v.ebm_y,
            })

        undulator = pkcollections.Dict({
            'horizontalAmplitude':
            _default_value('und_bx', v, std_options, 0.0),
            'horizontalInitialPhase':
            _default_value('und_phx', v, std_options, 0.0),
            'horizontalSymmetry':
            str(int(_default_value('und_sx', v, std_options, 1.0))),
            'length':
            _default_value('und_len', v, std_options, 1.5),
            'longitudinalPosition':
            _default_value('und_zc', v, std_options, 1.305),
            'period':
            _default_value('und_per', v, std_options, 0.021) * 1e3,
            'verticalAmplitude':
            _default_value('und_by', v, std_options, 0.88770981)
            if hasattr(v, 'und_by') else _default_value(
                'und_b', v, std_options, 0.88770981),
            'verticalInitialPhase':
            _default_value('und_phy', v, std_options, 0.0),
            'verticalSymmetry':
            str(int(_default_value('und_sy', v, std_options, -1))),
        })

        gaussianBeam = pkcollections.Dict({
            'energyPerPulse': None,
            'polarization': 1,
            'rmsPulseDuration': None,
            'rmsSizeX': None,
            'rmsSizeY': None,
            'waistAngleX': None,
            'waistAngleY': None,
            'waistX': None,
            'waistY': None,
            'waistZ': None,
        })

    else:
        source_type = 'g'
        electronBeam = pkcollections.Dict()
        default_ebeam_name = 'NSLS-II Low Beta Final'
        for beam in predefined_beams:
            if beam['name'] == default_ebeam_name:
                electronBeam = beam
                electronBeam['beamSelector'] = default_ebeam_name
                break
        if not electronBeam:
            raise ValueError('Electron beam is not set during import')
        undulator = pkcollections.Dict({
            "horizontalAmplitude": "0",
            "horizontalInitialPhase": 0,
            "horizontalSymmetry": 1,
            "length": 3,
            "longitudinalPosition": 0,
            "period": "20",
            "undulatorParameter": 1.65776086,
            "verticalAmplitude": "0.88770981",
            "verticalInitialPhase": 0,
            "verticalSymmetry": -1,
        })

        gaussianBeam = pkcollections.Dict({
            'energyPerPulse':
            _default_value('gbm_pen', v, std_options),
            'polarization':
            _default_value('gbm_pol', v, std_options),
            'rmsPulseDuration':
            _default_value('gbm_st', v, std_options) * 1e12,
            'rmsSizeX':
            _default_value('gbm_sx', v, std_options) * 1e6,
            'rmsSizeY':
            _default_value('gbm_sy', v, std_options) * 1e6,
            'waistAngleX':
            _default_value('gbm_xp', v, std_options),
            'waistAngleY':
            _default_value('gbm_yp', v, std_options),
            'waistX':
            _default_value('gbm_x', v, std_options),
            'waistY':
            _default_value('gbm_y', v, std_options),
            'waistZ':
            _default_value('gbm_z', v, std_options),
        })

    python_dict = pkcollections.Dict({
        'models':
        pkcollections.Dict({
            'beamline':
            beamline_elements,
            'electronBeam':
            electronBeam,
            'electronBeams': [],
            'beamline3DReport':
            pkcollections.Dict({}),
            'fluxReport':
            pkcollections.Dict({
                'azimuthalPrecision': v.sm_pra,
                'distanceFromSource': v.op_r,
                'finalEnergy': v.sm_ef,
                'fluxType': v.sm_type,
                'horizontalApertureSize': v.sm_rx * 1e3,
                'horizontalPosition': v.sm_x,
                'initialEnergy': v.sm_ei,
                'longitudinalPrecision': v.sm_prl,
                'photonEnergyPointCount': v.sm_ne,
                'polarization': v.sm_pol,
                'verticalApertureSize': v.sm_ry * 1e3,
                'verticalPosition': v.sm_y,
            }),
            'initialIntensityReport':
            initialIntensityReport,
            'intensityReport':
            pkcollections.Dict({
                'distanceFromSource': v.op_r,
                'fieldUnits': 1,
                'finalEnergy': v.ss_ef,
                'horizontalPosition': v.ss_x,
                'initialEnergy': v.ss_ei,
                'photonEnergyPointCount': v.ss_ne,
                'polarization': v.ss_pol,
                'precision': v.ss_prec,
                'verticalPosition': v.ss_y,
            }),
            'multiElectronAnimation':
            pkcollections.Dict({
                'horizontalPosition': 0,
                'horizontalRange': v.w_rx * 1e3,
                'stokesParameter': '0',
                'verticalPosition': 0,
                'verticalRange': v.w_ry * 1e3,
            }),
            'multipole':
            pkcollections.Dict({
                'distribution': 'n',
                'field': 0,
                'length': 0,
                'order': 1,
            }),
            'postPropagation':
            op.arProp[-1],
            'powerDensityReport':
            pkcollections.Dict({
                'distanceFromSource': v.op_r,
                'horizontalPointCount': v.pw_nx,
                'horizontalPosition': v.pw_x,
                'horizontalRange': v.pw_rx * 1e3,
                'method': v.pw_meth,
                'precision': v.pw_pr,
                'verticalPointCount': v.pw_ny,
                'verticalPosition': v.pw_y,
                'verticalRange': v.pw_ry * 1e3,
            }),
            'propagation':
            _get_propagation(op),
            'simulation':
            pkcollections.Dict({
                'horizontalPointCount': v.w_nx,
                'horizontalPosition': v.w_x,
                'horizontalRange': v.w_rx * 1e3,
                'isExample': 0,
                'name': '',
                'photonEnergy': v.w_e,
                'sampleFactor': v.w_smpf,
                'samplingMethod': 1,
                'simulationId': '',
                'sourceType': source_type,
                'verticalPointCount': v.w_ny,
                'verticalPosition': v.w_y,
                'verticalRange': v.w_ry * 1e3,
            }),
            'sourceIntensityReport':
            pkcollections.Dict({
                'characteristic': v.si_type,  # 0,
                'distanceFromSource': v.op_r,
                'fieldUnits': 1,
                'polarization': v.si_pol,
            }),
            'undulator':
            undulator,
            'gaussianBeam':
            gaussianBeam,
        }),
        'simulationType':
        'srw',
        'version':
        '',
    })

    # Format the key name to be consistent with Sirepo:
    for i in range(len(beamline_elements)):
        if beamline_elements[i]['type'] == 'watch':
            idx = beamline_elements[i]['id']
            python_dict['models']['watchpointReport{}'.format(
                idx)] = initialIntensityReport

    return python_dict