Skip to content

Commit a3b8383

Browse files
authored
Merge pull request #24 from sdss/offset_func_v1
Offset function v1
2 parents d25e0b6 + 86b0a52 commit a3b8383

File tree

1 file changed

+63
-42
lines changed

1 file changed

+63
-42
lines changed

src/coordio/utils.py

Lines changed: 63 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,22 @@ def func_magloss(self):
642642
return magloss
643643

644644

645+
def default_Moffat_params():
646+
"""
647+
Returns the dict of default parameters for
648+
the Moffat profile base don observator and lunation
649+
"""
650+
# set beta
651+
beta = {}
652+
beta['bright'] = {'APO': 1.6, 'LCO': 1.7}
653+
beta['dark'] = {'APO': 1.9, 'LCO': 1.8}
654+
# set FWHM
655+
FWHM = {}
656+
FWHM['bright'] = {'APO': 0.5, 'LCO': 0.8}
657+
FWHM['dark'] = {'APO': 1.4, 'LCO': 1.1}
658+
return beta, FWHM
659+
660+
645661
class Moffat2dInterp(object):
646662
"""
647663
Create the dict of 1D interpolations function
@@ -653,33 +669,45 @@ def __init__(self, Noffset=None, FWHM=None, beta=None):
653669
if Noffset is None:
654670
Noffset = 1500
655671
if FWHM is None:
656-
FWHM = [1., 1.3, 1.5, 1.7, 1.9]
672+
defualt = default_Moffat_params()[1]
673+
FWHM = [defualt[l][o] for l in ['bright', 'dark'] for o in ['APO', 'LCO']]
657674
if beta is None:
658-
beta = {'APO': 5., 'LCO': 2.}
675+
beta = default_Moffat_params()[0]
659676
rfibers = {'APO': 1., 'LCO': 1.33 / 2}
660677
offsets = numpy.zeros((len(FWHM), Noffset))
661678
FWHMs = numpy.zeros((len(FWHM), Noffset))
662679
for i, f in enumerate(FWHM):
663680
FWHMs[i, :] = f
664-
offsets[i, :] = numpy.linspace(0, 30, Noffset)
681+
offsets[i, :] = numpy.linspace(0, 50, Noffset)
665682

666683
magloss = numpy.zeros((FWHMs.shape[0], Noffset))
667684

668685
fmagloss = {}
669-
for obs, rfiber in zip(rfibers.keys(), rfibers.values()):
670-
fmagloss[obs] = {}
671-
if isinstance(beta, dict):
672-
b = beta[obs]
673-
else:
674-
b = beta
675-
for i, f in enumerate(FWHMs[:, 0]):
676-
magloss[i, :] = MoffatLossProfile(offsets[i, :], b, f, rfiber=rfiber).func_magloss()
677-
fmagloss[obs][f] = interp1d(magloss[i, :], offsets[i, :])
686+
# this is for default case to have it by lunation as well
687+
if isinstance(beta, dict) and 'bright' in beta.keys():
688+
for lunation, beta_lun in zip(beta.keys(), beta.values()):
689+
fmagloss[lunation] = {}
690+
for obs, rfiber in zip(rfibers.keys(), rfibers.values()):
691+
fmagloss[lunation][obs] = {}
692+
b = beta_lun[obs]
693+
for i, f in enumerate(FWHMs[:, 0]):
694+
magloss[i, :] = MoffatLossProfile(offsets[i, :], b, f, rfiber=rfiber).func_magloss()
695+
fmagloss[lunation][obs][f] = interp1d(magloss[i, :], offsets[i, :])
696+
else:
697+
for obs, rfiber in zip(rfibers.keys(), rfibers.values()):
698+
fmagloss[obs] = {}
699+
if isinstance(beta, dict):
700+
b = beta[obs]
701+
else:
702+
b = beta
703+
for i, f in enumerate(FWHMs[:, 0]):
704+
magloss[i, :] = MoffatLossProfile(offsets[i, :], b, f, rfiber=rfiber).func_magloss()
705+
fmagloss[obs][f] = interp1d(magloss[i, :], offsets[i, :])
678706
self.fmagloss = fmagloss
679707
self.beta_interp2d = beta
680708
self.FWHM_interp2d = FWHM
681709

682-
def __call__(self, magloss, FWHM, obsSite):
710+
def __call__(self, magloss, FWHM, obsSite, lunation=None):
683711
"""
684712
The cal to return the offset value based on the desired
685713
magloss.
@@ -697,12 +725,21 @@ def __call__(self, magloss, FWHM, obsSite):
697725
The observatory of the observation. Should either be
698726
'APO' or 'LCO'.
699727
728+
lunation: str
729+
If the designmode is bright time ('bright') or dark
730+
time ('dark'). Required if set up using default params.
731+
700732
Returns
701733
-------
702734
r: float or numpy.array
703735
The offset to get the desired magloss in arcseconds.
704736
"""
705-
r = self.fmagloss[obsSite][FWHM](magloss)
737+
if 'bright' in self.fmagloss.keys():
738+
if lunation is None:
739+
raise ValueError('Must provide lunation for default function!')
740+
r = self.fmagloss[lunation][obsSite][FWHM](magloss)
741+
else:
742+
r = self.fmagloss[obsSite][FWHM](magloss)
706743
return r
707744

708745

@@ -827,19 +864,14 @@ def offset_definition(mag, mag_limits, lunation, waveName, obsSite, fmagloss=Non
827864
offset_bright_limit = 13.
828865
else:
829866
offset_bright_limit = 1.
830-
# get magloss function
831-
if fmagloss is None:
832-
fmagloss = Moffat2dInterp(beta=beta, FWHM=[FWHM])
833867
# assign correct FWHM
834868
if FWHM is None:
835-
if obsSite == 'APO':
836-
FWHM = 1.7
837-
elif obsSite == 'LCO':
838-
FWHM = 1.
839-
else:
840-
raise ValueError('obsSite must be APO or LCO.')
869+
FWHM = default_Moffat_params()[1][lunation][obsSite]
841870
if beta is None:
842-
beta = {'APO': 5., 'LCO': 2.}
871+
beta = default_Moffat_params()[0]
872+
# get magloss function
873+
if fmagloss is None:
874+
fmagloss = Moffat2dInterp(beta=beta, FWHM=[FWHM])
843875
if isinstance(mag, float) or isinstance(mag, int):
844876
# make can_offset always True if not supplied
845877
if can_offset is None:
@@ -848,18 +880,16 @@ def offset_definition(mag, mag_limits, lunation, waveName, obsSite, fmagloss=Non
848880
if mag <= mag_limit and mag not in cases and can_offset and mag > offset_bright_limit:
849881
# linear portion in the wings
850882
r_wings = ((mag_limit + safety_factor) - mag - 8.2) / 0.05
851-
# linear portion in transition area
852-
r_trans = ((mag_limit + safety_factor) - mag - 4.5) / 0.25
853883
# core area
854884
if beta != fmagloss.beta_interp2d or FWHM not in fmagloss.FWHM_interp2d:
855885
fmagloss = Moffat2dInterp(beta=beta, FWHM=[FWHM])
856-
r_core = fmagloss((mag_limit + safety_factor) - mag, FWHM, obsSite)
886+
r_core = fmagloss((mag_limit + safety_factor) - mag, FWHM, obsSite, lunation=lunation)
857887
else:
858-
r_core = fmagloss((mag_limit + safety_factor) - mag, FWHM, obsSite)
888+
r_core = fmagloss((mag_limit + safety_factor) - mag, FWHM, obsSite, lunation=lunation)
859889
# tom's old conservative core function
860890
# r_core = 1.5 * ((mag_limit + safety_factor) - mag) ** 0.8
861891
# exlusion radius is the max of each section
862-
r = numpy.nanmax([r_wings, r_trans, r_core])
892+
r = numpy.nanmax([r_wings, r_core])
863893
else:
864894
r = 0.
865895
if mag > mag_limit:
@@ -880,7 +910,6 @@ def offset_definition(mag, mag_limits, lunation, waveName, obsSite, fmagloss=Non
880910
can_offset = numpy.zeros(mag.shape, dtype=bool) + True
881911
# create empty arrays for each portion
882912
r_wings = numpy.zeros(mag.shape)
883-
r_trans = numpy.zeros(mag.shape)
884913
r_core = numpy.zeros(mag.shape)
885914
# only do calc for valid mags and can_offsets for offset
886915
# to avoid warning
@@ -894,21 +923,18 @@ def offset_definition(mag, mag_limits, lunation, waveName, obsSite, fmagloss=Non
894923
offset_flag[(mag <= offset_bright_limit) & ~((numpy.isin(mag, cases)) | (numpy.isnan(mag)))] += 32
895924
# linear portion in the wings
896925
r_wings[mag_valid] = ((mag_limit + safety_factor) - mag[mag_valid] - 8.2) / 0.05
897-
# linear portion in transition area
898-
r_trans[mag_valid] = ((mag_limit + safety_factor) - mag[mag_valid] - 4.5) / 0.25
899926
# core area
900927
if beta != fmagloss.beta_interp2d or FWHM not in fmagloss.FWHM_interp2d:
901928
fmagloss = Moffat2dInterp(beta=beta, FWHM=[FWHM])
902929
r_core[mag_valid] = fmagloss((mag_limit + safety_factor) - mag[mag_valid],
903-
FWHM, obsSite)
930+
FWHM, obsSite, lunation=lunation)
904931
else:
905932
r_core[mag_valid] = fmagloss((mag_limit + safety_factor) - mag[mag_valid],
906-
FWHM, obsSite)
933+
FWHM, obsSite, lunation=lunation)
907934
# tom's old conservative core function
908935
# r_core[mag_valid] = 1.5 * ((mag_limit + safety_factor) - mag[mag_valid]) ** 0.8
909936
# exlusion radius is the max of each section
910937
r = numpy.nanmax(numpy.column_stack((r_wings,
911-
r_trans,
912938
r_core)),
913939
axis=1)
914940
if skybrightness is not None and offset_min_skybrightness is not None:
@@ -1017,14 +1043,9 @@ def object_offset(mags, mag_limits, lunation, waveName, obsSite, fmagloss=None,
10171043
else:
10181044
safety_factor = 1.0
10191045
if FWHM is None:
1020-
if obsSite == 'APO':
1021-
FWHM = 1.7
1022-
elif obsSite == 'LCO':
1023-
FWHM = 1.
1024-
else:
1025-
raise ValueError('obsSite must be APO or LCO.')
1046+
FWHM = default_Moffat_params()[1][lunation][obsSite]
10261047
if beta is None:
1027-
beta = {'APO': 5., 'LCO': 2.}
1048+
beta = default_Moffat_params()[0]
10281049
delta_ras = numpy.zeros(mags.shape)
10291050
offset_flags = numpy.zeros(mags.shape)
10301051
for i in range(len(mag_limits)):

0 commit comments

Comments
 (0)