
extend-gwpy
by tatsuki-washimi
gwpy expansions for experiments
SKILL.md
name: extend_gwpy description: GWpy/Astropyクラスの安全な継承と拡張のためのガイドライン
Extend GWpy Class
This skill provides guidelines and patterns for safely inheriting from and extending GWpy/Astropy classes (TimeSeries, FrequencySeries, Spectrogram, etc.).
Common Pitfalls & Solutions
1. __new__ and Metadata
GWpy uses __new__ to preserve units and metadata. When subclassing, ensure metadata is propagated.
class MyTimeSeries(TimeSeries):
def __new__(cls, data, *args, **kwargs):
obj = super().__new__(cls, data, *args, **kwargs)
return obj
2. Unit Preservation
Always ensure that mathematical operations preserve units.
4. Metadata Preservation in __array_finalize__
When using NumPy ufuncs (like +, *) or arithmetic operations, NumPy creates new instances and calls __array_finalize__(self, obj). obj is the original instance. You must copy your custom metadata from obj to preserve it.
def __array_finalize__(self, obj):
super().__array_finalize__(obj)
if obj is None:
return
# Preserve custom attributes
for attr in ["_my_meta", "_domain_label"]:
val = getattr(obj, attr, None)
if val is not None:
setattr(self, attr, val)
CRITICAL PITFALL: If __new__ sets default values (e.g., self.attr = "default"), then __array_finalize__ might see those defaults and decide not to copy from obj.
- Solution: Initialize custom attributes to
Nonein__new__and handle default logic within__array_finalize__. - Reference: See
gwexpy/types/array4d.pyfor how it handles_axis0_index. It defers setting thearangedefault until after it fails to find an index onobj.
Note: Be careful if the metadata depends on the axis names or shape, which might have changed (though ufuncs usually preserve these). Use the pattern in Array4D and FieldBase as a reference.
5. Type Preservation in Collections
When implementing batch methods in collection classes (like FieldList or FieldDict), use self.__class__ to ensure that subclasses return instances of their own type.
def map_all(self, func):
return self.__class__([func(item) for item in self])
スコア
総合スコア
リポジトリの品質指標に基づく評価
SKILL.mdファイルが含まれている
ライセンスが設定されている
100文字以上の説明がある
GitHub Stars 100以上
3ヶ月以内に更新がある
10回以上フォークされている
オープンIssueが50未満
プログラミング言語が設定されている
1つ以上のタグが設定されている
レビュー
レビュー機能は近日公開予定です