Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sacc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def numpy_to_vanilla(x):
Parameters
----------
x : numpy scalar
A NumPy scalar value (e.g., np.str_, np.int64, np.float64, np.bool).
A NumPy scalar value (e.g., np.str_, np.int64, np.float64, np.bool_).

Returns
-------
Expand All @@ -207,6 +207,6 @@ def numpy_to_vanilla(x):
x = int(x)
elif type(x) == np.float64:
x = float(x)
elif type(x) == np.bool:
elif type(x) == np.bool_:
x = bool(x)
return x
47 changes: 47 additions & 0 deletions test/test_load_fits.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python

import numpy as np
import sacc

def create_simple_sacc():
# Create a new Sacc object
s = sacc.Sacc()

# --- 1️⃣ Define tracers ---
# Add a survey tracer (usually represents the data source)
s.add_tracer("survey", "my_mock_survey", 100.0) # 100 deg^2 area, for example

# Add two bin tracers (e.g., redshift and richness bins)
s.add_tracer("bin_z", "zbin_0", 0.2, 0.4)
s.add_tracer("bin_z", "zbin_1", 0.4, 0.6)
s.add_tracer("bin_richness", "rich_0", 10, 20)
s.add_tracer("bin_richness", "rich_1", 20, 40)
print(type(s.tracers["zbin_0"]))

# --- 2️⃣ Add mock data ---
# We’ll use a standard type — cluster counts
cluster_count = sacc.standard_types.cluster_counts

# reproducible random numbers
rng = np.random.default_rng(42)

for zbin in ["zbin_0", "zbin_1"]:
for rbin in ["rich_0", "rich_1"]:
count_value = rng.integers(50, 150) # random counts
s.add_data_point(cluster_count, ("my_mock_survey", zbin, rbin), count_value)

# --- 3️⃣ Add covariance ---
# Create a simple diagonal covariance matrix (variance = 10 for each data point)
ndata = len(s.data)
covariance = np.diag(np.ones(ndata) * 10)
s.add_covariance(covariance)

# --- 4️⃣ Save the SACC file ---
s.to_canonical_order()
s.save_fits("test/data/simple_mock_clusters.sacc", overwrite=True)

print(f"SACC file saved with {ndata} data points: test/data/simple_mock_clusters.sacc")

def test_bool_numpy_error():
create_simple_sacc()
t2 = sacc.Sacc.load_fits("test/data/simple_mock_clusters.sacc")