Skip to content

Commit

Permalink
fix output of cells
Browse files Browse the repository at this point in the history
  • Loading branch information
StFroese committed Sep 8, 2023
1 parent f543881 commit 837bacb
Show file tree
Hide file tree
Showing 19 changed files with 196 additions and 68 deletions.
8 changes: 7 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,13 @@ def setup(app):
"tutorials",
], # path to where to save gallery generated output
"nested_sections": True,
"copyfile_regex": r"index.rst|.*\.png",
"copyfile_regex": r"index.rst|.*\.png|.*\.json",
"filename_pattern": r".*\.py",
"promote_jupyter_magic": True,
"line_numbers": True,
"default_thumb_file": "ctapipe_logo.png",
"pypandoc": True,
"matplotlib_animations": True,
}


Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies:
- numpy>=1.22
- numpydoc
- pandas
- pypandoc
- pre-commit
- psutil
- pytables
Expand Down
9 changes: 9 additions & 0 deletions examples/examples/algorithms/convert_images_to_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from ctapipe.instrument import SubarrayDescription
from ctapipe.visualization import CameraDisplay

######################################################################
# get the subarray from an example file
subarray = SubarrayDescription.read("dataset://gamma_prod5.simtel.zst")

Expand All @@ -32,6 +33,7 @@
)
_, image, _ = model.generate_image(geom, intensity=500, nsb_level_pe=3)

######################################################################
CameraDisplay(geom, image)


Expand All @@ -42,10 +44,13 @@

image_square = geom.image_to_cartesian_representation(image)

######################################################################
plt.imshow(image_square)

######################################################################
image_1d = geom.image_from_cartesian_representation(image_square)

######################################################################
CameraDisplay(geom, image_1d)


Expand All @@ -66,8 +71,10 @@
)
_, image, _ = model.generate_image(geom, intensity=5000)

######################################################################
CameraDisplay(geom, image)

######################################################################
image_square = geom.image_to_cartesian_representation(image)


Expand All @@ -82,6 +89,8 @@

plt.imshow(image_square)

######################################################################
image_1d = geom.image_from_cartesian_representation(image_square)

######################################################################
disp = CameraDisplay(geom, image_1d)
1 change: 1 addition & 0 deletions examples/examples/algorithms/dilate_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def show_dilate(mask, times=1):
)


######################################################################
plt.figure(figsize=(18, 3))

for ii in range(0, 6):
Expand Down
8 changes: 3 additions & 5 deletions examples/examples/algorithms/nd_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@
######################################################################
# In the high-stats central region, we get a nice smooth interpolation
# function. Of course we can see that there are a few more steps to take
# before using this table: \* need to deal with cases where the table had
# low stats near the edges (smooth or extrapolate, or set bounds) \* may
# need to smooth the table even where there are sufficient stats, to avoid
# wiggles
#
# before using this table: \*
# - need to deal with cases where the table had low stats near the edges (smooth or extrapolate, or set bounds)
# - may need to smooth the table even where there are sufficient stats, to avoid wiggles
16 changes: 16 additions & 0 deletions examples/examples/core/InstrumentDescription.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

subarray.info()

######################################################################
subarray.to_table()


Expand Down Expand Up @@ -61,20 +62,27 @@
tel = subarray.tel[1]
tel

######################################################################
tel.optics.mirror_area

######################################################################
tel.optics.n_mirror_tiles

######################################################################
tel.optics.equivalent_focal_length

######################################################################
tel.camera

######################################################################
tel.camera.geometry.pix_x

######################################################################
# %matplotlib inline

CameraDisplay(tel.camera.geometry)

######################################################################
CameraDisplay(subarray.tel[98].camera.geometry)


Expand All @@ -92,6 +100,7 @@

subarray.peek()

######################################################################
subarray.footprint


Expand All @@ -102,11 +111,14 @@

subarray.telescope_types

######################################################################
subarray.camera_types

######################################################################
subarray.optics_types


######################################################################
center = SkyCoord("10.0 m", "2.0 m", "0.0 m", frame="groundframe")
coords = subarray.tel_coords # a flat list of coordinates by tel_index
coords.separation(center)
Expand Down Expand Up @@ -134,18 +146,22 @@

subarray.tel_index_array

######################################################################
subarray.tel_index_array[[1, 5, 23]]

######################################################################
subarray.tel_indices[
1
] # this is a dict of tel_id -> tel_index, so we can only do one at once

ids = subarray.get_tel_ids_for_type(subarray.telescope_types[0])
ids

######################################################################
idx = subarray.tel_ids_to_indices(ids)
idx

######################################################################
subarray.tel_coords[idx]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from ctapipe.instrument import SubarrayDescription
from ctapipe.utils import get_dataset_path

######################################################################
GAMMA_FILE = get_dataset_path("gamma_prod5.simtel.zst")


Expand Down Expand Up @@ -80,8 +81,10 @@ class TelescopeWiseComponent(TelescopeComponent):
).tag(config=True)


######################################################################
MyComponent()

######################################################################
AdvancedComponent(infile="test.foo", outfile="out.foo")


Expand All @@ -96,24 +99,19 @@ class TelescopeWiseComponent(TelescopeComponent):
subarray = SubarrayDescription.read(GAMMA_FILE)
subarray.info()

######################################################################
TelescopeWiseComponent(subarray=subarray)


######################################################################
# This TelescopeParameters can then be set using a list of patterns like:
#
# .. code:: python
#
# component.param = [
# ("type", "LST*",3.0),
# ("type", "MST*", 2.0),
# (id, 25, 4.0)
# ]
# component.param = [("type", "LST*",3.0),("type", "MST*", 2.0),(id, 25, 4.0)]
#
# These get translated into per-telescope-id values once the subarray is
# registered. After that one acccess the per-telescope id values via:
#
# .. code:: python
#
# component.param.tel[tel_id]
#
Expand Down Expand Up @@ -184,6 +182,7 @@ def finish(self):
tool = MyTool()
tool

######################################################################
tool.print_help()


Expand All @@ -202,7 +201,6 @@ def finish(self):
# specified it’s read from ``sys.argv``, so the following is the same as
# running:
#
# .. code:: sh
#
# mytool --log_level=INFO --infile gamma_test.simtel.gz --iterations=3
#
Expand All @@ -219,6 +217,7 @@ def finish(self):
tool.log_format = "%(asctime)s : %(levelname)s [%(name)s %(funcName)s] %(message)s"


######################################################################
try:
tool.run(
argv=[
Expand Down Expand Up @@ -302,30 +301,41 @@ def finish(self):

tool2 = MyTool()

######################################################################
try:
tool2.run(argv=["--config", "Tools.json"])
tool2.run(argv=["--config", "config.json"])
except SystemExit as e:
assert e.code == 0, f"Tool returned with error status {e}"

######################################################################
print(tool2.advanced.infile)

######################################################################
print(tool2.config)

######################################################################
tool2.is_setup

######################################################################
tool3 = MyTool()

######################################################################
tool3.is_setup

######################################################################
tool3.initialize(argv=[])

######################################################################
tool3.is_setup

######################################################################
tool3

######################################################################
tool.setup()
tool

######################################################################
tool.comp2


Expand All @@ -336,6 +346,7 @@ def finish(self):

tool.get_current_config()

######################################################################
tool.iterations = 12
tool.get_current_config()

Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions examples/examples/core/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class EventContainer(Container):
#
help(EventContainer)

######################################################################
help(SubContainer)

######################################################################
Expand All @@ -100,8 +101,10 @@ class EventContainer(Container):
ev.event_id = 100
ev.event_id

######################################################################
ev.as_dict() # by default only shows the bare items, not sub-containers (See later)

######################################################################
ev.as_dict(recursive=True)


Expand All @@ -114,6 +117,7 @@ class EventContainer(Container):
ev.tel[5] = TelContainer()
ev.tel[42] = TelContainer()

######################################################################
# because we are using a default_factory to handle mutable defaults, the images are actually different:
ev.tel[42].image is ev.tel[32]

Expand Down Expand Up @@ -142,6 +146,7 @@ class DangerousContainer(Container):
print(c2.image)
print(c1.image is c2.image)

######################################################################
ev.tel


Expand All @@ -152,6 +157,7 @@ class DangerousContainer(Container):

ev.as_dict()

######################################################################
ev.as_dict(recursive=True, flatten=False)


Expand All @@ -171,6 +177,7 @@ class DangerousContainer(Container):
ev.tel[5].image[:] = 9
print(ev)

######################################################################
ev.reset()
ev.as_dict(recursive=True)

Expand All @@ -183,6 +190,7 @@ class DangerousContainer(Container):

help(SimulatedShowerContainer)

######################################################################
shower = SimulatedShowerContainer()
shower

Expand Down
3 changes: 3 additions & 0 deletions examples/examples/core/provenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

p.finish_activity()

######################################################################
p.finished_activity_names


Expand Down Expand Up @@ -110,6 +111,8 @@ def flatten(x, name=""):
return out


######################################################################
d = dict(activity=p.provenance)

######################################################################
pprint(flatten_dict(d))
Loading

0 comments on commit 837bacb

Please sign in to comment.