-
Notifications
You must be signed in to change notification settings - Fork 20
ML Mapmaker fixes #1404
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: more_ml_mapmaker
Are you sure you want to change the base?
ML Mapmaker fixes #1404
Changes from 9 commits
1801342
a709bba
e1e8c7b
e5e8aca
98cb943
2494a7e
cc558cb
8aec14f
e71ef6a
74716e0
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 | ||
| from typing import Optional, Any, Union | ||
| from sqlalchemy import create_engine, exc | ||
| from sqlalchemy.orm import declarative_base, Mapped, mapped_column, sessionmaker | ||
|
|
@@ -377,14 +378,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): | ||
| 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) | ||
| subids = subids[has_ot >= 0] | ||
| return subids | ||
|
|
||
| def astr_cat(*arrs): | ||
|
|
@@ -471,7 +477,7 @@ def to_cel(lonlat, sys, ctime=None, site=None, weather=None): | |
| if sys == "cel" or sys == "equ": | ||
| return lonlat | ||
| elif sys == "hor": | ||
| return so3g.proj.CelestialSightLine.az_el(ctime, lonlat[0], lonlat[1], site=site, weather=weather).coords()[0,:2] | ||
| return so3g.proj.CelestialSightLine.az_el(ctime, -1*lonlat[0], np.pi/2 - lonlat[1], site=site, weather=weather).coords()[0,:2] | ||
| else: | ||
| raise NotImplementedError | ||
| def get_pos(name, ctime, sys=None): | ||
|
|
@@ -481,10 +487,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(tod.timestamps.mean()) | ||
| except: | ||
| obj = getattr(ephem, name)() | ||
| djd = ctime/86400 + 40587.0 + 2400000.5 - 2415020 | ||
|
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. What are all these numbers? It would be better if you include them in variables or constants that we can import |
||
| 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"]) | ||
|
|
@@ -566,8 +578,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"): | ||
| flag = obs[glitch_flags] | ||
| if to_null != "" and to_null in obs._fields: | ||
| flag = flag*~obs[to_null] | ||
| ncut = rangemat_sum(flag) | ||
| good = ncut < obs.samps.count * maxcut | ||
| return obs.dets.vals[good] | ||
|
|
||
|
|
@@ -800,3 +815,36 @@ def atomic_db_aux(atomic_db, info: list[AtomicInfo]): | |
| session.commit() | ||
| except exc.IntegrityError: | ||
| session.rollback() | ||
|
|
||
|
|
||
| def prune_mpi(comm, ranks_to_keep, mapmaker=None): | ||
| """ | ||
| Prune unneeded MPI procs. | ||
|
|
||
| Arguments: | ||
|
|
||
| comm: The MPI communicator currently in use. | ||
|
|
||
| ranks_to_keep: List of current ranks to keep in the new communicator. | ||
|
|
||
| mapmaker: If mapmaker is provided then all comms will be swapped out | ||
| for the new communicator. Pass None to if you don't have a mapmaker | ||
| instance to modify. | ||
|
|
||
| Returns: | ||
|
|
||
| comm: Modified communicator with only the processes we want to keep. | ||
| """ | ||
| group = comm.Get_group() | ||
| new_group = group.Incl(ranks_to_keep) | ||
| new_comm = comm.Create(new_group) | ||
| if comm.rank not in ranks_to_keep: | ||
| sys.exit(0) | ||
| comm = new_comm | ||
|
|
||
| if mapmaker is not None: | ||
| for signal in mapmaker.signals: | ||
| if hasattr(signal, "comm"): | ||
| signal.comm = comm | ||
|
||
|
|
||
| return comm | ||
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.
The pi/2 - el still looks wrong, so run this by @amaurea or otherwise figure out what's up.