Skip to content

Commit

Permalink
From Ken: ruff check --fix --extend-select=I pmd_beamphysics/
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherMayes committed Oct 18, 2024
1 parent bb5547b commit 38db1d8
Show file tree
Hide file tree
Showing 22 changed files with 84 additions and 95 deletions.
4 changes: 2 additions & 2 deletions pmd_beamphysics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .particles import ParticleGroup, single_particle
from .status import ParticleStatus
from .fields.fieldmesh import FieldMesh
from .particles import ParticleGroup, single_particle
from .readers import particle_paths
from .status import ParticleStatus
from .writers import pmd_init

try:
Expand Down
7 changes: 3 additions & 4 deletions pmd_beamphysics/fields/analysis.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from pmd_beamphysics.units import mec2, c_light
from pmd_beamphysics.species import charge_state, mass_of

import numpy as np
from scipy import interpolate
from scipy.integrate import solve_ivp
from scipy.optimize import brent, brentq
import numpy as np

from pmd_beamphysics.species import charge_state, mass_of
from pmd_beamphysics.units import c_light, mec2

# Numpy migration per https://numpy.org/doc/stable/numpy_2_0_migration_guide.html
if np.lib.NumpyVersion(np.__version__) >= "2.0.0":
Expand Down
5 changes: 2 additions & 3 deletions pmd_beamphysics/fields/corrector_modeling.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import numpy as np
from matplotlib import pyplot as plt
from scipy.constants import mu_0 as u0
from scipy.constants import pi

from matplotlib import pyplot as plt
import numpy as np

from pmd_beamphysics import FieldMesh


Expand Down
5 changes: 3 additions & 2 deletions pmd_beamphysics/fields/expansion.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from scipy.interpolate import UnivariateSpline
from scipy import fft
import numpy as np
from scipy import fft
from scipy.interpolate import UnivariateSpline

from pmd_beamphysics.units import c_light


Expand Down
66 changes: 29 additions & 37 deletions pmd_beamphysics/fields/fieldmesh.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,48 @@
from pmd_beamphysics.units import pg_units

from pmd_beamphysics.readers import (
component_data,
expected_record_unit_dimension,
field_record_components,
field_paths,
component_from_alias,
load_field_attrs,
component_alias,
)
import functools
import os
from copy import deepcopy

from pmd_beamphysics.writers import write_pmd_field, pmd_field_init
import numpy as np
from h5py import File
from scipy.interpolate import RegularGridInterpolator

from pmd_beamphysics import tools

from pmd_beamphysics.plot import (
plot_fieldmesh_cylindrical_2d,
plot_fieldmesh_cylindrical_1d,
plot_fieldmesh_rectangular_1d,
plot_fieldmesh_rectangular_2d,
from pmd_beamphysics.fields.conversion import (
fieldmesh_rectangular_to_cylindrically_symmetric_data,
)

from pmd_beamphysics.fields.expansion import expand_fieldmesh_from_onaxis
from pmd_beamphysics.interfaces.ansys import read_ansys_ascii_3d_fields
from pmd_beamphysics.interfaces.astra import (
write_astra_1d_fieldmap,
astra_1d_fieldmap_data,
read_astra_3d_fieldmaps,
write_astra_1d_fieldmap,
write_astra_3d_fieldmaps,
astra_1d_fieldmap_data,
)
from pmd_beamphysics.interfaces.gpt import write_gpt_fieldmesh
from pmd_beamphysics.interfaces.impact import (
create_impact_emfield_cartesian_ele,
create_impact_solrf_ele,
parse_impact_emfield_cartesian,
write_impact_emfield_cartesian,
create_impact_emfield_cartesian_ele,
)
from pmd_beamphysics.interfaces.superfish import write_superfish_t7, read_superfish_t7

from pmd_beamphysics.fields.expansion import expand_fieldmesh_from_onaxis
from pmd_beamphysics.fields.conversion import (
fieldmesh_rectangular_to_cylindrically_symmetric_data,
from pmd_beamphysics.interfaces.superfish import read_superfish_t7, write_superfish_t7
from pmd_beamphysics.plot import (
plot_fieldmesh_cylindrical_1d,
plot_fieldmesh_cylindrical_2d,
plot_fieldmesh_rectangular_1d,
plot_fieldmesh_rectangular_2d,
)

import functools

from scipy.interpolate import RegularGridInterpolator

from h5py import File
import numpy as np
from copy import deepcopy
import os

from pmd_beamphysics.readers import (
component_alias,
component_data,
component_from_alias,
expected_record_unit_dimension,
field_paths,
field_record_components,
load_field_attrs,
)
from pmd_beamphysics.units import pg_units
from pmd_beamphysics.writers import pmd_field_init, write_pmd_field

# -----------------------------------------
# Classes
Expand Down
1 change: 1 addition & 0 deletions pmd_beamphysics/interfaces/ansys.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np

from pmd_beamphysics.units import mu_0


Expand Down
7 changes: 4 additions & 3 deletions pmd_beamphysics/interfaces/astra.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import numpy as np
from pmd_beamphysics.status import ParticleStatus
from pmd_beamphysics.readers import component_alias
import os

import numpy as np

from pmd_beamphysics.readers import component_alias
from pmd_beamphysics.status import ParticleStatus

astra_species_name = {1: "electron", 2: "positron", 3: "proton", 4: "hydrogen"}
astra_species_index = {v: k for k, v in astra_species_name.items()} # Inverse mapping
Expand Down
3 changes: 2 additions & 1 deletion pmd_beamphysics/interfaces/bmad.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
from pmd_beamphysics.units import c_light

from pmd_beamphysics.species import mass_of
from pmd_beamphysics.units import c_light


# Remove from below, because this docstring is used directly in ParticleGroup
Expand Down
8 changes: 4 additions & 4 deletions pmd_beamphysics/interfaces/elegant.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from pmd_beamphysics.units import mec2

import numpy as np
import subprocess
import os
import subprocess

import numpy as np
from h5py import File

from pmd_beamphysics.units import mec2


def write_elegant(particle_group, outfile, verbose=False):
"""
Expand Down
4 changes: 2 additions & 2 deletions pmd_beamphysics/interfaces/genesis.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os

import numpy as np
from h5py import File

from pmd_beamphysics.statistics import twiss_calc
from pmd_beamphysics.units import mec2, c_light, write_unit_h5, unit

from pmd_beamphysics.units import c_light, mec2, unit, write_unit_h5

# Genesis 1.3
# -------------
Expand Down
9 changes: 5 additions & 4 deletions pmd_beamphysics/interfaces/gpt.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from pmd_beamphysics.units import e_charge, c_light
from pmd_beamphysics.interfaces.superfish import fish_complex_to_real_fields
import os
import subprocess

import numpy as np
import subprocess
import os

from pmd_beamphysics.interfaces.superfish import fish_complex_to_real_fields
from pmd_beamphysics.units import c_light, e_charge


def write_gpt(particle_group, outfile, asci2gdf_bin=None, verbose=False):
Expand Down
1 change: 1 addition & 0 deletions pmd_beamphysics/interfaces/impact.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import re

import numpy as np
from numpy import pi
from scipy import fft
Expand Down
3 changes: 2 additions & 1 deletion pmd_beamphysics/interfaces/litrack.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pmd_beamphysics.units import c_light
import numpy as np

from pmd_beamphysics.units import c_light


def write_litrack(particle_group, outfile="litrack.zd", p0c=None, verbose=False):
"""
Expand Down
2 changes: 1 addition & 1 deletion pmd_beamphysics/interfaces/lucretia.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import scipy.io as sio
import numpy as np
import scipy.io as sio


def lucretia_to_data(
Expand Down
5 changes: 2 additions & 3 deletions pmd_beamphysics/interfaces/simion.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import numpy as np

from pmd_beamphysics.species import mec2, e_charge

from scipy.constants import physical_constants

from pmd_beamphysics.species import e_charge, mec2

amu_to_rest_mass_energy = (
physical_constants["atomic mass constant energy equivalent in MeV"][0] * 1e6
)
Expand Down
2 changes: 1 addition & 1 deletion pmd_beamphysics/interfaces/superfish.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import scipy.constants
import numpy as np
import scipy.constants

mu_0 = scipy.constants.mu_0

Expand Down
3 changes: 1 addition & 2 deletions pmd_beamphysics/labels.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from pmd_beamphysics.units import parse_bunching_str, nice_array

from pmd_beamphysics.units import nice_array, parse_bunching_str

TEXLABEL = {
# 'status'
Expand Down
31 changes: 13 additions & 18 deletions pmd_beamphysics/particles.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,40 @@
from pmd_beamphysics.units import pg_units, c_light, parse_bunching_str
import functools
import os
from copy import deepcopy

import numpy as np
from h5py import File

from pmd_beamphysics.interfaces.astra import write_astra
import pmd_beamphysics.interfaces.bmad as bmad
import pmd_beamphysics.statistics as statistics
from pmd_beamphysics.interfaces.astra import write_astra
from pmd_beamphysics.interfaces.elegant import write_elegant
from pmd_beamphysics.interfaces.genesis import (
write_genesis4_distribution,
genesis2_beam_data,
write_genesis2_beam_file,
write_genesis4_beam,
write_genesis4_distribution,
)
from pmd_beamphysics.interfaces.gpt import write_gpt
from pmd_beamphysics.interfaces.impact import write_impact
from pmd_beamphysics.interfaces.litrack import write_litrack
from pmd_beamphysics.interfaces.lucretia import write_lucretia
from pmd_beamphysics.interfaces.opal import write_opal
from pmd_beamphysics.interfaces.simion import write_simion
from pmd_beamphysics.interfaces.elegant import write_elegant

from pmd_beamphysics.plot import density_plot, marginal_plot, slice_plot

from pmd_beamphysics.readers import particle_array, particle_paths
from pmd_beamphysics.species import charge_of, mass_of

from pmd_beamphysics.statistics import (
matched_particles,
norm_emit_calc,
normalized_particle_coordinate,
particle_amplitude,
particle_twiss_dispersion,
matched_particles,
resample_particles,
slice_statistics,
)
import pmd_beamphysics.statistics as statistics

from pmd_beamphysics.writers import write_pmd_bunch, pmd_init

from h5py import File
import numpy as np
from copy import deepcopy
import functools
import os

from pmd_beamphysics.units import c_light, parse_bunching_str, pg_units
from pmd_beamphysics.writers import pmd_init, write_pmd_bunch

# -----------------------------------------
# Classes
Expand Down
1 change: 0 additions & 1 deletion pmd_beamphysics/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# For field legends
from mpl_toolkits.axes_grid1 import make_axes_locatable


from pmd_beamphysics.labels import mathlabel
from pmd_beamphysics.units import nice_array, nice_scale_prefix, plottable_array

Expand Down
7 changes: 3 additions & 4 deletions pmd_beamphysics/readers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from .units import dimension, dimension_name, SI_symbol, c_light, e_charge
from .tools import decode_attrs, decode_attr


import numpy as np

from .tools import decode_attr, decode_attrs
from .units import SI_symbol, c_light, dimension, dimension_name, e_charge

# -----------------------------------------
# General Utilities

Expand Down
1 change: 1 addition & 0 deletions pmd_beamphysics/tools.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime

import numpy as np


Expand Down
4 changes: 2 additions & 2 deletions pmd_beamphysics/writers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numpy as np

from .units import pg_units
from .readers import component_from_alias, load_field_attrs
from .tools import fstr, encode_attrs
from .tools import encode_attrs, fstr
from .units import pg_units


def pmd_init(h5, basePath="/data/%T/", particlesPath="./"):
Expand Down

0 comments on commit 38db1d8

Please sign in to comment.