-
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
Open
skhrg
wants to merge
10
commits into
more_ml_mapmaker
Choose a base branch
from
mlm_fixes
base: more_ml_mapmaker
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
ML Mapmaker fixes #1404
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1801342
fix: pass recenter to srcsamp, adjust quaternion for hor recenter, de…
skhrg a709bba
feat: dont reprocess observations that were cut in previous passes
skhrg e1e8c7b
fix: dont error out if some procs have no surviving tods
skhrg e5e8aca
fix: dont call finalize explicitly
skhrg 98cb943
feat: add OT filter to ml mapmaker
skhrg 2494a7e
feat: add option to null out some flags when finding usable detectors…
skhrg cc558cb
fix: dont error if we are missing expected flags and some minor chang…
skhrg 8aec14f
fix: move MPI pruning to function and fix typos
skhrg e71ef6a
fix: pass mapmaker to pruning func
skhrg 74716e0
fix: move mapmaker comm replacements back to script
skhrg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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,27 @@ def atomic_db_aux(atomic_db, info: list[AtomicInfo]): | |
| session.commit() | ||
| except exc.IntegrityError: | ||
| session.rollback() | ||
|
|
||
|
|
||
| def prune_mpi(comm, ranks_to_keep): | ||
| """ | ||
| 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. | ||
|
|
||
| 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 | ||
|
|
||
| return comm | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.