-
Notifications
You must be signed in to change notification settings - Fork 21
ML mapmaker I/O #1234
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
base: master
Are you sure you want to change the base?
ML mapmaker I/O #1234
Changes from 124 commits
c0674dc
5ef5dca
cfbdc46
7699a8d
e9496ea
b857da6
69529f4
fc95de2
7e5fff0
60ca432
1f16024
f68260f
e727ee6
bda426f
c07083e
37818b7
2a87548
3b4e7dc
4ee564f
39d4eb2
c5a2dde
a92d55e
84542bc
20c298d
f8bde19
3b3e85e
a712097
1d9aa55
41c6c2c
5567fe5
c205068
125d7a7
022fec0
6c36a14
96538da
1e17f54
d8599b0
d313314
19b827b
99c51d2
a740669
c203f2a
da3c9f9
b6b5753
c6a8a14
9b2d327
44e5f61
37ddd9d
9108f72
03fa7e2
13a46fe
299ec4e
538c8c6
decaa06
a4faf06
36d16cf
321d936
2ae937c
c83a13e
2bab595
15ae506
f6b315d
d354b04
35052c0
33bedf9
4cb71b2
c45649c
d783157
2a8b743
d3709aa
2d831ca
5383c9c
902817a
5fb42ea
3a7572b
bbcf0b2
d49d9f0
c6f237b
5a7681a
6670d3f
bdb0126
8025030
95dcfc5
19bc5b6
172f63c
4d27633
7aa02b7
9cd9c28
6f16008
6e4d34b
024ac53
416691a
f7b8b30
553e470
13bd47b
7e2a429
4e15ef2
f8cfaff
ca0f8a8
150521b
6974e05
d774668
da6c258
f86e65f
cf2d411
0807626
f1954a3
898dfe8
71215cb
99584f3
8652e2a
caffebe
744f6e0
41cf648
0ec5a58
4980828
8c81629
043e8d8
5ec48b8
d00592a
620bea7
0f7ea34
9097e2d
855b937
3fad9c3
61b7340
1705c27
c8afb14
466a10d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import sys | ||
| import logging | ||
| import os | ||
| from typing import Optional, Any, Union | ||
|
|
@@ -322,6 +323,18 @@ def get_subids_file(fname, context=None): | |
| sub_ids = expand_ids(sub_ids, context=context) | ||
| return sub_ids | ||
|
|
||
| def get_obsinfo_subids(subids, context): | ||
| """Given a list of subids, return a ResultSet with one entry | ||
| from the obsdb for each subid. Ideally one would have this | ||
| from the original query that defined the subids, but since | ||
| subids are often read in directly from a file, we can't rely | ||
| on that. This function is a bit inefficient, since it starts | ||
| from the full obsdb and then looks up the subids from it""" | ||
| obsids = split_subids(subids)[0] | ||
| ids_str = ",".join(f"'{subid}'" for subid in obsids) | ||
| rs = context.obsdb.query("obs_id IN (%s)" % ids_str) | ||
| return rs | ||
|
|
||
| def expand_ids(obs_ids, context=None, bands=None): | ||
| """Given a list of ids that are either obs_ids or sub_ids, expand any obs_ids | ||
| into sub_ids and return the resulting list. | ||
|
|
@@ -380,14 +393,19 @@ def expand_ids(obs_ids, context=None, bands=None): | |
| sub_ids.append("%s:ws%d:%s" % (obs_id, si, band)) | ||
| return sub_ids | ||
|
|
||
| def filter_subids(subids, wafers=None, bands=None): | ||
| def filter_subids(subids, wafers=None, bands=None, ots=None): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this tested? |
||
| subids = np.asarray(subids) | ||
| if wafers is not None: | ||
| wafs = astr_tok(subids,":",1) | ||
| subids = subids[np.isin(wafs, wafers)] | ||
| if bands is not None: | ||
| bpass = astr_tok(subids,":",2) | ||
| subids = subids[np.isin(bpass, bands)] | ||
| if ots is not None: | ||
| # Somewhat hacky implementation | ||
| obs_ids = astr_tok(subids, ":",0) | ||
| has_ot = np.prod([np.char.find(obs_ids, ot) for ot in ots], 0) | ||
|
iparask marked this conversation as resolved.
|
||
| subids = subids[has_ot >= 0] | ||
| return subids | ||
|
|
||
| def astr_cat(*arrs): | ||
|
|
@@ -484,10 +502,16 @@ def get_pos(name, ctime, sys=None): | |
| elif name == "auto": | ||
| return np.array([0,0]) # would use geom here | ||
| else: | ||
| obj = getattr(ephem, name)() | ||
| djd = ctime/86400 + 40587.0 + 2400000.5 - 2415020 | ||
| obj.compute(djd) | ||
| return np.array([obj.a_ra, obj.a_dec]) | ||
| try: | ||
| planet = coords.planets.SlowSource.for_named_source( | ||
| name, ctime) | ||
| ra0, dec0 = planet.pos(np.mean(ctime)) | ||
| except: | ||
| obj = getattr(ephem, name)() | ||
| djd = ctime/86400 + 40587.0 + 2400000.5 - 2415020 | ||
| obj.compute(djd) | ||
| ra0, dec0 = obj.a_ra, obj.a_dec | ||
| return np.array([ra0, dec0]) | ||
| else: | ||
| return to_cel(name, sys, ctime, site, weather) | ||
| p1 = get_pos(info["from"], ctime, info["from_sys"]) | ||
|
|
@@ -569,8 +593,11 @@ def rangemat_sum(rangemat): | |
| res[i] = np.sum(ra[:,1]-ra[:,0]) | ||
| return res | ||
|
|
||
| def find_usable_detectors(obs, maxcut=0.1, glitch_flags: str = "flags.glitch_flags"): | ||
| ncut = rangemat_sum(obs[glitch_flags]) | ||
| def find_usable_detectors(obs, maxcut=0.1, glitch_flags: str = "flags.glitch_flags", to_null : str = "flags.expected_flags"): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a test? |
||
| flag = obs[glitch_flags] | ||
| if to_null and to_null in obs: | ||
| flag = flag*~obs[to_null] | ||
| ncut = rangemat_sum(flag) | ||
| good = ncut < obs.samps.count * maxcut | ||
| return obs.dets.vals[good] | ||
|
|
||
|
|
@@ -750,6 +777,33 @@ def setup_passes(downsample="1", maxiter="500", interpol="nearest", npass=None): | |
| passes.append(entry) | ||
| return passes | ||
|
|
||
| def distribute_tods_ra(obsinfo, nsplit, site="so", weather="typical"): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How would this work if
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is a perfect candidate for a unit test.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but we run it with so_lat in the ML mapmaker. This is a general function so it doesn't matter if the default is so. The difference is tiny.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aren't we supposed to support ACT data as well with SO tools? |
||
| """For each row in obsinfo, assign it to one of nsplit categories | ||
| such that each category is as compact in RA as possible, and each | ||
| category has as similar size as possible. Assumes that all obs | ||
| are at the same site.""" | ||
| owners = np.arange(nsplit,dtype=int)[:len(obsinfo)] | ||
| if len(obsinfo) > nsplit: | ||
| # Get a reprsentative RA per entry | ||
| az = obsinfo["az_center"] * putils.degree | ||
| el = obsinfo["el_center"] * putils.degree | ||
| ctime = (obsinfo["start_time"] + obsinfo["stop_time"])/2 | ||
| ra = so3g.proj.CelestialSightLine.az_el(ctime, az, el, site=site, weather=weather).coords()[:,0] | ||
| # Put everything on the same copy of the sky | ||
| ra = putils.rewind_compact(ra) | ||
| # Partition sorted ras equally by weight. Would ideally include | ||
| # ndet too, but the effective ndet depends on the cuts etc. | ||
| order = np.argsort(ra) | ||
| weight= obsinfo["n_samples"][order] | ||
| cum = putils.cumsum(weight) | ||
| wtot = cum[-1]+weight[-1] # = np.sum(weight) | ||
| owners[order] = putils.floor(cum*nsplit/wtot) | ||
| # Make sure none ended up empty. If they did, fall back to unweighted, | ||
| # which will always succeed | ||
| if np.any(np.bincount(owners, minlength=nsplit) == 0): | ||
| owners[order] = np.arange(len(obsinfo))*nsplit/len(obsinfo) | ||
| return owners | ||
|
|
||
| Base = declarative_base() | ||
|
|
||
| class AtomicInfo(Base): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have a test?