Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create format for Shapelets #13

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
33 changes: 30 additions & 3 deletions Tigger/Models/Formats/ASCII.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,19 @@ def get_ang_field(name, units=ANGULAR_UNITS):
def getval(num, scale=1):
return None if (num is None or len(fields) <= num) else float(fields[num]) * scale

def getval_list(num, scale=1):
return None if (num is None or len(fields) <= num) else [float(x) * scale for x in fields[num].split(',')]

def triangular_index(val):
print("IN TRIANGULAR INDEX")
n = 1
x = n
print("n, x", n, x)
while x < val:
n += 1
x += n
return n

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use np.tril_indices here

# now process file line-by-line
linenum = 0
format_str = ''
Expand Down Expand Up @@ -315,17 +328,31 @@ def getval(num, scale=1):
ex, ey, pa = [(getval(x[0], x[1]) or 0) for x in extent_fields]
extent_errors = [getval(x[2], x[3]) for x in extent_fields]
elif shapelet_fields:
(scoeffsl_field, _), (scoeffsm_field, _) = get_field("scoeffsl"), get_field("scoeffsm")
(scoeffs_field, _) = get_field("shapelet_coeffs")
beta_l, beta_m = [(getval(s[0]) or 0) for s in shapelet_fields]
shapelet_coeffs_l, shapelet_coeffs_m = getval(scoeffsl_field), getval(scoeffsm_field)
shapelet_coeffs_list = [float(x) for x in fields[scoeffs_field].split(',')] #getval_list(scoeffs_field)

list_len = triangular_index(len(shapelet_coeffs_list))
shapelet_coeffs = [[0.0 for _ in range(list_len)] for _ in range(list_len)]
max_val = 1
i_ind = 0
j_ind = 0
for val in shapelet_coeffs_list:
shapelet_coeffs[i_ind][j_ind] = val
i_ind -= 1
j_ind += 1
if i_ind < 0:
i_ind = max_val
j_ind = 0
max_val += 1
# form up shape object
if (ex or ey) and max(ex, ey) >= min_extent:
shape = ModelClasses.Gaussian(ex, ey, pa)
for ifield, field in enumerate(['ex', 'ey', 'pa']):
if extent_errors[ifield] is not None:
shape.setAttribute(field + "_err", extent_errors[ifield])
if (beta_l or beta_m or shapelet_coeffs_l or shapelet_coeffs_m):
shape = ModelClasses.Shapelet(beta_l, beta_m, shapelet_coeffs_l, shapelet_coeffs_m)
shape = ModelClasses.Shapelet(beta_l, beta_m, shapelet_coeffs)
else:
shape = None
# get tags
Expand Down
2 changes: 1 addition & 1 deletion Tigger/Models/ModelClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def strDescErr(self, delimiters=('"', "x", "@", "deg"), **kw):
class Shapelet(Shape):
typecode = "Sha"

mandatory_attrs = ["sbetal", "sbetam", "scoeffsl", "scoeffsm"]
mandatory_attrs = ["sbetal", "sbetam", "shapelet_coeffs"]
optional_attrs = dict(ex_err=None, ey_err=None, pa_err=None)

def getShape(self):
Expand Down