Closed jacquelinegarrahan closed 2 years ago
Playing around a bit further, I found calling
G.configure()
after the assignment will get the xy_dist into the object params (G.params
). I still land with the same downstream error for the dimensions, though, and have no xy_distribution logging in the verbose output.
Interesting. Can you send full yaml file or string that you send to Generator so I can test?
I believe the blank xy_dist when using verbose is a minor bug, but does not effect particle generation:
I'm trying to understand how your example differs from the one in the examples_dist notebook:
generates:
I can manipulate the distribution (here I cut a rectangle out of the center and stretch the x scale):
Btw, did you install the package through conda or through Git?
Here is the yaml, with xy_dist set as file for placeholder then overwritten with the structure. I've found that if xy_dist is not included in this file, I get a key error when setting the structure.
n_particle: 1000000
random_type: hammersley
start:
type: cathode
MTE:
value: 414
units: meV
total_charge:
value: 250
units: pC
t_dist:
type: tukey
length:
value: 7.5
units: ps
ratio:
value: 0.8
units: ''
xy_dist:
type: file2d
file: laser.txt
transforms:
order:
- tx
- ty
tx:
avg_x:
units: mm
value: 0
type: set_avg x
ty:
avg_y:
units: mm
value: 0
type: set_avg y
Also, I installed via conda. Let me create a small toy example and report back.
Ok - I think I may understand the issue now. So the first time you run your code you use file2d for creating particles from an image file. And then you want to update that image. I think the issue that you are running into is this: in distgen the file2d object which reads in your file isn't created until you use gen.run() or gen.beam(). And even then, because it's expecting to always read the xy dist from the file, I don't think it ever creates gen['xy_dist:P'].
The fastest solution is as follows:
*Loading the Pxy data: I saw in your example you are loading the 2d data from a txt file. That's totally fine, and I think you could load that into python with something like Pxy = np.loadtxt(....). However, if that data comes from an original image file, typically png, tif, or jpeg, it can be loaded directly into python using distgen.tools.read_image_file. This will convert 3 or 4 channel image files into a grey scale 2d NumPy array ready to use.
Below is a python file implementing this solution, as well as an example image file. Note I couldn't attach the python code as .py (which is funny for Git?) so I made it .txt.
Sorry for the delay! This is working well with our packaged model workflow! Thank you for your patience and for helping me work through this :)
I've run into a follow up issue from https://github.com/ColwynGulliford/distgen/issues/7 with the set params being used in generating the beam.
After assigning the structure:
All items appear to be set correctly. However, running beam generation in verbose mode suggests that the configuration for the xy_dist is empty:
I'm using this as a replacement for a File2d dist type and, while this successfully generates particles, the dimensions are incorrect. I'm guessing the xy distribution type is defaulting to something other than image2d here?
Impact returns the below error:
Any thoughts?