Simple conversion model not working with dark frames
When photon array is just zeros, the created charge data frame is empty, this is when the bug appears in charge.py
in add_charge_dataframe
, line 167: last_id = new_frame.index[-1]
.
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
C:\Work\tools\Anaconda3\envs\pyxel-dev\lib\site-packages\pandas\core\indexes\range.py in __getitem__(self, key)
825 try:
--> 826 return self._range[new_key]
827 except IndexError as err:
IndexError: range object index out of range
The above exception was the direct cause of the following exception:
IndexError Traceback (most recent call last)
<ipython-input-4-7911c78b6f1d> in <module>
----> 1 result_ds2 = exposure_mode(exposure=exposure, detector=detector, pipeline=pipeline)
c:\work\dev\pyxel\pyxel\run.py in exposure_mode(exposure, detector, pipeline)
65 processor = Processor(detector=detector, pipeline=pipeline)
66
---> 67 result = exposure.run_exposure(processor=processor)
68
69 if exposure_outputs.save_exposure_data:
c:\work\dev\pyxel\pyxel\exposure\exposure.py in run_exposure(self, processor)
75
76 # Unpure changing of processor
---> 77 _ = run_exposure_pipeline(
78 processor=processor,
79 readout=self.readout,
c:\work\dev\pyxel\pyxel\exposure\exposure.py in run_exposure_pipeline(processor, readout, outputs, progressbar, result_type)
163 detector.empty(empty_all=True)
164
--> 165 processor.run_pipeline()
166 detector.pipeline_count = i
167
c:\work\dev\pyxel\pyxel\pipelines\processor.py in run_pipeline(self, abort_before)
207 self._log.info("Processing group: %r", group_name)
208
--> 209 abort_flag = models_grp.run(
210 detector=self.detector,
211 pipeline=self.pipeline,
c:\work\dev\pyxel\pyxel\pipelines\model_group.py in run(self, detector, pipeline, abort_model)
93 # TODO: Display here information about the executed model
94 # self._log.info("Model: %r", model.name)
---> 95 model(detector)
96
97 return False
c:\work\dev\pyxel\pyxel\pipelines\model_function.py in __call__(self, detector)
216 func = functools.partial(self._func, **self.arguments)
217
--> 218 result = func(detector) # type: T
219
220 return result
c:\work\dev\pyxel\pyxel\models\charge_generation\photoelectrons.py in simple_conversion(detector)
44 init_hor_pix_position = geo.horizontal_pixel_center_pos_list()[where_non_zero]
45
---> 46 detector.charge.add_charge(
47 particle_type="e",
48 particles_per_cluster=charge_number,
c:\work\dev\pyxel\pyxel\data_structure\charge.py in add_charge(self, particle_type, particles_per_cluster, init_energy, init_ver_position, init_hor_position, init_z_position, init_ver_velocity, init_hor_velocity, init_z_velocity)
212
213 # Add charge(s)
--> 214 self.add_charge_dataframe(new_charges=new_charges)
c:\work\dev\pyxel\pyxel\data_structure\charge.py in add_charge_dataframe(self, new_charges)
165
166 # Get last 'id'
--> 167 last_id = new_frame.index[-1] # type: int
168
169 self.frame = new_frame
C:\Work\tools\Anaconda3\envs\pyxel-dev\lib\site-packages\pandas\core\indexes\range.py in __getitem__(self, key)
826 return self._range[new_key]
827 except IndexError as err:
--> 828 raise IndexError(
829 f"index {key} is out of bounds for axis 0 with size {len(self)}"
830 ) from err
IndexError: index -1 is out of bounds for axis 0 with size 0
Edited by Matej Arko