Skip to content

Commit

Permalink
classes take Tables, work with QTables internally
Browse files Browse the repository at this point in the history
  • Loading branch information
gschwefer committed Feb 23, 2024
1 parent 1567fcf commit edffd2f
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/ctapipe/atmosphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import numpy as np
from astropy import units as u
from astropy.table import QTable
from astropy.table import QTable, Table
from scipy.interpolate import interp1d

__all__ = [
Expand Down Expand Up @@ -180,10 +180,12 @@ def peek(self):
return fig, axis

@classmethod
def from_table(cls, table: QTable):
def from_table(cls, table: Table):
"""return a subclass of AtmosphereDensityProfile from a serialized
table"""

table = QTable(table, copy=False)

if "TAB_TYPE" not in table.meta:
raise ValueError("expected a TAB_TYPE metadata field")

Expand Down Expand Up @@ -294,11 +296,11 @@ class TableAtmosphereDensityProfile(AtmosphereDensityProfile):
load a TableAtmosphereDensityProfile from a supported EventSource
"""

def __init__(self, table: QTable):
def __init__(self, table: Table):
"""
Parameters
----------
table : QTable
table : Table
Table with columns `height`, `density`, and `column_density`
"""

Expand All @@ -307,9 +309,9 @@ def __init__(self, table: QTable):
raise ValueError(f"Missing expected column: {col} in table")

valid = (
(table["height"].value >= 0)
& (table["density"].value > 0)
& (table["column_density"].value > 0)
(table["height"] >= 0)
& (table["density"] > 0)
& (table["column_density"] > 0)
)
self.table = QTable(table[valid], copy=False)

Expand Down Expand Up @@ -416,8 +418,9 @@ class FiveLayerAtmosphereDensityProfile(AtmosphereDensityProfile):
A User’s Guide", 2021, Appendix F
"""

def __init__(self, table: QTable):
self.table = table
def __init__(self, table: Table):

self.table = QTable(table, copy=False)

param_a = self.table["a"].to(GRAMMAGE_UNIT)
param_b = self.table["b"].to(GRAMMAGE_UNIT)
Expand Down

0 comments on commit edffd2f

Please sign in to comment.