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 Jul 7, 2023
1 parent 5055f52 commit c65401a
Show file tree
Hide file tree
Showing 15 changed files with 172 additions and 6 deletions.
4 changes: 3 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ 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|tools.json",
"filename_pattern": r".*\.py",
"promote_jupyter_magic": True,
}


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
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
18 changes: 18 additions & 0 deletions examples/examples/core/Tools.py
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,6 +99,7 @@ class TelescopeWiseComponent(TelescopeComponent):
subarray = SubarrayDescription.read(GAMMA_FILE)
subarray.info()

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


Expand Down Expand Up @@ -184,6 +188,7 @@ def finish(self):
tool = MyTool()
tool

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


Expand Down Expand Up @@ -219,6 +224,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 +308,41 @@ def finish(self):

tool2 = MyTool()

######################################################################
try:
tool2.run(argv=["--config", "Tools.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 +353,7 @@ def finish(self):

tool.get_current_config()

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

Expand Down
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))
9 changes: 9 additions & 0 deletions examples/examples/core/table_writer_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from ctapipe.io import HDF5TableReader, HDF5TableWriter, read_table


######################################################################
class VariousTypesContainer(Container):

a_int = Field(int, "some int value")
Expand Down Expand Up @@ -72,6 +73,7 @@ def create_stream(n_event):
yield data


######################################################################
for data in create_stream(2):

for key, val in data.items():
Expand Down Expand Up @@ -103,6 +105,7 @@ def create_stream(n_event):

h5_table.h5file.isopen == False

######################################################################
print(os.listdir())

######################################################################
Expand All @@ -129,6 +132,7 @@ def create_stream(n_event):

print(h5_table.h5file)

######################################################################
os.remove("container.h5")

######################################################################
Expand Down Expand Up @@ -204,6 +208,7 @@ def create_stream(n_event):
table = read_table("container.h5", "/data_0/table")
table[:5]

######################################################################
table.meta


Expand Down Expand Up @@ -271,10 +276,14 @@ def read(mode):
print(data.as_dict())


######################################################################
read("r")

######################################################################
read("r+")

######################################################################
read("a")

######################################################################
read("w")
1 change: 1 addition & 0 deletions examples/examples/visualization/array_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

plt.rcParams["figure.figsize"] = (8, 6)

######################################################################
tel_ids = list(range(1, 5)) + list(range(5, 20)) # just LSTs + one set of MSTs

subarray = SubarrayDescription.read(
Expand Down
Loading

0 comments on commit c65401a

Please sign in to comment.