def schrep(values, entries, index, marker, start, stop, day, year): global group, repeat if s.schcon.debug: s.wlog(0, "SCHREP starting.") # if we get a repeat request, store it such that we can execute it when # the requested number of scan (group) has been parsed if marker == -1: repeat = int(values["repeat"]) group = int(values["group"]) if repeat != 0: marker = index elif values["repeat"] > 1: s.errlog("SCHREP: Cannot do nested or overlapping loops.") if s.schcon.debug: s.wlog( 0, "SCHREP: Scan - {} Repeat and group: {} {}".format( index + 1, repeat, group)) if (marker != -1) and (index + 1 >= group + marker): for r in range(repeat - 1): for g in range(group): index += 1 scndup(index, marker, False, "SCHREP", use_direct_access=False) start[index] = parameter.unset stop[index] = parameter.unset day[index] = day[marker] year[index] = year[marker] marker += 1 marker = -1 return index, marker
def check_mode_change(scans, scan_offset, stations, scan_mode): """ scan_mode: {index in scans: mode name} Returns whether any scan failed the mode change gap check. """ stations = [s for s in stations if is_field_system_station(s)] any_warning = False scan_pairs = zip(scans[:-1], scans[1:]) for scan_index, (scan, next_scan) in enumerate(scan_pairs, scan_offset): if any(station.stascn[scan_index] and station.stascn[scan_index + 1] for station in stations) \ and (scan_mode[scan_index - scan_offset] != scan_mode[scan_index - scan_offset + 1]) \ and ((next_scan.startj - scan.stopj) * secpday < minimum_mode_change_gap_seconds): stations_string = ", ".join( station.station for station in stations if station.stascn[scan_index] and station.stascn[scan_index + 1]) # print warning for next scan, +1 for next, +1 for FORTRAN indexing s.prtscn(scan_index + 2, "VXSCHK") s.wlog( 1, "WARNING: Mode setup <= {l}s for station(s) {s}.\n" " FS Stations once needed {l}s for any mode " "change, incl frequency shift.".format( s=stations_string, l=minimum_mode_change_gap_seconds)) s.wlog( 1, " This may no longer be true but the new value " "is not yet clear.") any_warning = True return any_warning
def sttant(tantsta1, tantsta2): s.schn1.tants1[:s.schn1.nsta] = False s.schn1.tants2[:s.schn1.nsta] = False tantsta1 = set( tant.ljust(s.schc1.staname.itemsize).encode() for tant in tantsta1) tantsta2 = set( tant.ljust(s.schc1.staname.itemsize).encode() for tant in tantsta2) s.schn1.tants1 = [station in tantsta1 for station in s.schc1.staname] s.schn1.tants2 = [station in tantsta2 for station in s.schc1.staname] tant1or2 = np.logical_or(s.schn1.tants1, s.schn1.tants2) control = set(("SNAP", "SN50", "VEX", "NRAO")) for index in range(s.schn1.nsta): if (s.schn1.tants1[index] or s.schn1.tants2[index]) and \ (s.schcst.control[s.schn1.stanum[index]-1].decode().strip() in control): s.wlog( 1, "SCHIN: TANT request for {} will be ignored.".format( s.schcst.station[s.schn1.stanum[index] - 1].decode().strip())) if not (s.schn1.tants1[:s.schn1.nsta].any() or \ s.schn1.tants2[:s.schn1.nsta].any()): mask = (s.schc1.staname[:s.schn1.nsta] == "EFLSBERG".ljust( s.schc1.staname.itemsize).encode()) s.schn1.tants1[:s.schn1.nsta][mask] = True
def ifdbbc(dbbc_version, e_firmware): if s.schcon.debug: s.wlog(1, "IFDBBC: Starting") max_bbc = 16 max_if = 4 ifbbc = np.zeros((max_bbc, max_if)) if dbbc_version == "ASTRO": mif = 4 for if_ in range(mif): ifbbc[if_ * 4:(if_ + 1) * 4, if_] = 1 elif dbbc_version == "GEO": mif = 2 for if_ in range(mif): ifbbc[if_ * 8:(if_ + 1) * 8, if_] = 1 elif dbbc_version == "HYBRID": mif = 3 ifbbc[0:4, 0] = 1 ifbbc[4:8, 1] = 1 ifbbc[8:16, 2] = 1 else: s.wlog(1, "IFDBBC: DBBCVER not recognised: {}".format(dbbc_version)) s.errlog("catalog error") if e_firmware: # 32 MHz (only in E) DDC mode can only do odd (count starting at 1) BBCs ifbbc[1::2, :] = 0 return ifbbc, mif
def pcread(input_iterator): global record_defaults record_defaults = { "name": ["", util.noop], "sources": [[], util.foreach(util.upper)], "endcent": [None, util.noop], } input_iterator.set_defaults(record_defaults, {}) attribute_to_key = {"ctrname": "name", "ctrsrcn": "sources"} if s.schcon.debug: s.wlog(0, "PCREAD: Starting to read groups of phase centers") catalog = PhaseCenterCatalog() start = int(s.schsou.ncent) index = start for record in input_iterator: values, present = util.merge_record_with_defaults( record, record_defaults, {}) if "endcent" in present: break entry = catalog.entries[index] entry.set_keyin_values(values, attribute_to_key) index += 1 s.schsou.ncent = index catalog.write(range(start, index))
def update_catalogs(): try: if not os.path.exists(checkout_dir): s.wlog(1, "Downloading catalogs to {}".format(checkout_dir)) # clone a shallow, single branch version to reduce data usage repo = git.Repo.clone_from(git_repository, checkout_dir, depth=1, branch=branch, progress=Spinner()) print() else: repo = git.Repo(checkout_dir) # make sure the required branch is in the local repo if branch not in {b.name for b in repo.branches}: repo.git.remote("set-branches", "origin", branch) repo.git.fetch("origin", branch, depth=1) repo.git.checkout(branch) s.wlog(1, "Updating catalogs in {}".format(checkout_dir)) repo.git.pull() s.wlog(1, "Catalogs in {} are up-to-date.".format(checkout_dir)) except git.exc.GitError as e: s.wlog(1, "Warning, failed to update catalogs.") s.wlog(0, "Update failed with error: {}".format(e))
def resize_string(text, size, attr): ret = text.ljust(size) if len(ret) > size: ret = ret[:size] s.wlog(1, ("Warning, maximum string length exceeded for {attr}, " "truncating '{text}' to '{ret}'").format(attr=attr, text=text, ret=ret)) return ret
def ifdbbc3(): if s.schcon.debug: s.wlog(1, "IFDBBC3: Starting") max_bbc = 64 max_if = 8 ifbbc = np.zeros((max_bbc, max_if)) for if_ in range(max_if): ifbbc[if_ * 8:(if_ + 1) * 8, if_] = 1 return ifbbc, max_if
def check_emerlin(setup, station): bits = max(setup.bits) expected_samprate = 256 // bits if setup.samprate != expected_samprate: s.wlog( 1, "Check eMERLIN: Invalid SAMPRATE specified for station {}: " "{} for DAR=eMERL. Must be {} Msamp/s for {} bits.".format( station.station, setup.samprate, expected_samprate, bits)) return True return False
def check_ifchan(): somebad = False for ifchan in setup_entry.ifchan: if (ifchan[0] not in ifnam) or \ ((len(ifchan) > 1) and (ifchan[1] not in "1234 ")): if_descriptors = [c + "[1-4]" for c in ifnam] ifnam_text = ", ".join(if_descriptors[:-1]) + \ " or " + if_descriptors[-1] s.wlog(1, "CHKDBBC: IFCHAN '{}' not {}".format( ifchan, ifnam_text)) somebad = True return somebad
def addgeo(last_scan_index, scan_index, geo_opt, scans, stations): global j_scan, n_seg, seg_sources, geo_stascn, geo_startj if s.schcon.debug: s.wlog(0, "ADDGEO starting.") if geo_opt == 0: j_scan = scans[scan_index - 1].geoiscn seg_sources, n_seg, geo_stascn, geo_startj = geomake( last_scan_index, j_scan, scan_index, n_seg, geo_stascn, geo_startj, stations, scans) geo_opt = n_seg if geo_opt != 0: seg_index = n_seg - geo_opt scan_stascn = geo_stascn[seg_index, :] approx_time = geo_startj[seg_index] seg_source_index = seg_sources[seg_index] n_good, ok_sta, scan_stascn = gmkscn( last_scan_index, scan_index, j_scan, s.schsou.geosrci[seg_source_index - 1], s.schcsc.geosrc[seg_source_index - 1], approx_time, scans[j_scan - 1].opminel, 0, scan_stascn, "FORCE") geo_opt -= 1 scan = scans[scan_index - 1] scan.origen = 3 if s.schsou.geoprt >= 0: if scan_index == s.schn1.scan1: s_gap = 0. else: s_gap = (scan.startj - scans[scan_index - 2].stopj) * secpday msg = "{:4d} {:8.0f} {:<12}".format( seg_source_index, s_gap, f2str(s.schcsc.geosrc[seg_source_index - 1])) msg += " ".join( " {:4.0f} ".format(s.el1[scan_index - 1]) if s. stascn[scan_index - 1] else "({:4.0f})".format(s.el1[scan_index - 1]) for s in stations[:20]) s.wlog(0, msg) return geo_opt, True
def optnone(k_scan, scan_index): """ Copies scan indexed by k_scan to scan indexed by scan_index, if the indices differ and not done already yet. Return tuple of booleans (adjust, keep, done) """ if s.schcon.debug and (k_scan <= 3): s.wlog(0, "OPTNONE: Starting.") done = (k_scan > s.schn1.nscans) if (not done) and (k_scan != scan_index): scndup(scan_index - 1, k_scan - 1, True, "OPTNONE") # duronly, 1 means only start times, 4 only stop times specified adjust = (s.schn1.dwells and (scan_index > s.schn1.scan1)) and \ (scan_catalog.direct_access_entries[scan_index - 1].duronly in {1, 4}) return (adjust, True, done)
def p_chunk(self): entries = [] self.p_skip_newline() if self.tok.type_ == "EOF": raise EOFBeforeFirstItem() # create items until the token iterator is on a value starting with a / while not ((self.tok.type_ == "value") and self.tok.value.startswith("/")): entries.append(self.p_item()) self.p_skip_newline() # read until a newline or EOF while self.tok.type_ not in ("newline", "EOF"): self.tok = next(self.tokIt) logging.debug("p_chunk %s", str(self.tok)) if len(entries) == 0: schedlib.wlog( 1, "Warning: empty record in {} line {}.".format( self.tok.file_.name, self.tok.line)) return dict(entries)
def rfreq(input_iterator): if s.schcon.debug: s.wlog(0, "RFREQ: Starting to read line frequencies") maxlch = s.schlin.restfreq.shape[0] record_defaults = { "lineset": ["", util.upper], "restfreq": [[0.], util.extend_to(maxlch)], "endlines": [None, util.noop], } input_iterator.set_defaults(record_defaults, {}) attribute_to_key = { "linename": "lineset", "restfreq": "restfreq", } catalog = LineRestFrequencyCatalog() start = int(s.schlin.nlgp) index = start found_end = False for record in input_iterator: values, present = util.merge_record_with_defaults( record, record_defaults, {}) if "endlines" in present: found_end = True break if index >= catalog.maxlgp: s.errlog(" SCHED only set up to use {} rest frequency groups.".\ format(catalog.maxlgp)) entry = catalog.entries[index] entry.set_keyin_values(values, attribute_to_key) index += 1 if not found_end: s.errlog("RFREQ: Input data ended while reading spectral line rest " "frequencies.") catalog.write(range(start, index)) s.schlin.nlgp = index
def check_recording_sizes(scans, scan_offset, stations): """ Print warnings for large continuous recordings. """ # gather the scan indices that trigger the warnings scan_warnings = set() for station in ( s for s in stations if is_field_system_station(s) and s.disk != "LBADR" and s.usedisk): previous_scan_index = None previous_gbytes = 0 for scan_index, scan in ((i, s) for i, s in enumerate(scans, scan_offset) if station.stascn[i]): if previous_scan_index is not None: previous_scan = scans[previous_scan_index - scan_offset] if (scan.startj - previous_scan.stopj) * secpday > gap_seconds: previous_gbytes = station.gbytes[previous_scan_index] gbytes = station.gbytes[scan_index] if gbytes - previous_gbytes > max_disk_unit: scan_warnings.add(scan_index) previous_scan_index = scan_index # print messages, do not print a new message for consecutive scans previous_scan_index = -42 # any value that triggers the check below for scan_index in sorted(scan_warnings): if scan_index != previous_scan_index + 1: s.wlog( 0, "The scan detailed below has exceeded the limit for " "continuous recording. Insert a gap before this scan, or " "reduce its length if necessary:") s.prtscn(scan_index + 1, "VXSCH") s.wlog(0, " ") previous_scan_index = scan_index if len(scan_warnings) > 0: s.wrtmsg(1, "VXSCH", "warnbank")
def input_(stdin): if s.schcon.debug: s.wlog(0, "INPUT starting") schin(stdin) rdpeak_open(stdin) s.accsrc(True) s.schcsc.srver = " --- ".ljust(s.schcsc.srver.itemsize) s.schcsc.srver2 = " --- ".ljust(s.schcsc.srver2.itemsize) srread_open(util.f2str(s.schcsc.srcfile), stdin, True, '1') srcfile2 = util.f2str(s.schcsc.srcfile2) if (srcfile2 != "NONE"): srread_open(srcfile2, stdin, True, '3') if (s.schpeakn.dopoint): srread_open(util.f2str(s.schpeakc.psrcfile), stdin, True, '2') if (not s.schcon.noset): getset() if (not s.schcon.noset): getfreq() s.wlog(0, "INPUT: Found {:5d} input scans.".format(int(s.schn1.nscans)))
def makescn(last_scan_index, scan_index, j_scan, source_index, source_name, approx_time, min_elevation, use_time): if s.schcon.debug: s.wlog(0, "MAKESCN starting.") scndup(scan_index - 1, j_scan - 1, False, "MAKESCN") scans = scan_catalog.direct_access_entries scans[scan_index - 1].srcnum = source_index scans[scan_index - 1].scnsrc = source_name.ljust(s.schc2b.scnsrc.itemsize) stations = station_catalog.used(use_direct_access=True) n_good = 0 ok_sta = np.full(fill_value=False, dtype=bool, shape=(len(stations),)) for i, station in enumerate(stations): if station.stascn[j_scan - 1]: last_time, available_time = s.stageo(scan_index, i + 1, approx_time, last_scan_index[i], "MAKESCN") if (f2str(station.up1[scan_index - 1]) == "") and \ (f2str(station.up2[scan_index - 1]) == "") and \ (station.el1[scan_index - 1] > min_elevation) and \ (station.el2[scan_index - 1] > min_elevation): ok_sta[i] = True n_good += 1 for i, station in enumerate(stations): station.stascn[scan_index - 1] = station.stascn[scan_index - 1] and \ ok_sta[i] if n_good >= 1: scans[scan_index - 1].startj = approx_time s.opttim(last_scan_index, last_scan_index, scan_index, True, use_time, False) n_good = s.scngeo(last_scan_index, scan_index) return n_good
def check_scan_overlap(scans, scan_offset, stations): """ Returns whether any scan failed the scan overlap check. """ any_warning = False scan_pairs = zip(scans[:-1], scans[1:]) for scan_index, (scan, next_scan) in enumerate(scan_pairs, scan_offset): if any(station.stascn[scan_index] and station.stascn[scan_index + 1] for station in stations) \ and (next_scan.startj < scan.stopj): stations_string = ", ".join( station.station for station in stations if station.stascn[scan_index] and station.stascn[scan_index + 1]) # print warning for next scan, +1 for next, +1 for FORTRAN indexing s.prtscn(scan_index + 2, "VXSCHK") s.wlog(1, "WARNING: Tape early start failed for stations(s) {}.".\ format(s=stations_string)) s.wlog( 1, " Early tape starts only work if there are " "sufficient gaps.") any_warning = True return any_warning
def check_minimum_scan_duration(scans, scan_offset, stations): """ Returns whether any scan failed the minimum duration check. """ # only check certain stations, mimic SCHED here stations = [ s for s in stations if is_field_system_station(s) and s.disk != "LBADR" and s.usedisk ] any_warning = False for scan_index, scan in enumerate(scans, scan_offset): if any(station.stascn[scan_index] for station in stations) \ and ((scan.stopj - scan.startj) * secpday < minimum_scan_seconds): stations_string = ", ".join(station.station for station in stations if station.stascn[scan_index]) s.prtscn(scan_index + 1, "VXSCHK") s.wlog( 1, "WARNING: Scan length < {l}s for station(s) {s}.\n" " Currently FS supports minimal " "scan length of {l}s".format(s=stations_string, l=minimum_scan_seconds)) any_warning = True return any_warning
def getset(): if s.schcon.debug: s.wlog(0, "GETSET: Starting.") for index, entry in enumerate(SetupFileCatalog().read()): setfilename = entry.setfile if setfilename in {"DUMMY", "DEFAULT"}: s.errlog(" SETUP file required. ") else: if setfilename not in \ (entry.setname for entry in SetupCatalog().read()): try: f = open(setfilename, "r") except Exception as e: s.wlog(1, str(e)) s.errlog("RDSET: Problem opening setup file") with f: input_iterator = key.KeyfileLister(f) rdset(setfilename, input_iterator, index + 1) s.setn2a.fifmin[:, :s.setn1.nset].setfield(0., dtype=s.setn2a.fifmin.dtype) s.setn2a.fifmax[:, :s.setn1.nset].setfield(1e15, dtype=s.setn2a.fifmax.dtype) s.setn2a.corinv[:, :s.setn1.nset].setfield(0., dtype=s.setn2a.corinv.dtype)
def setbbc(ks, setup_catalog, frequency_entries, station_entries): if s.setn1.sdebug: s.wlog(0, "SETBBC: Starting.") setup_entry = setup_catalog.entries[ks - 1] for ich, channel in enumerate(setup_entry.channel): if channel.ifreqnum >= 1: if channel.ifchan == "": channel.ifchan = frequency_entries[channel.ifreqnum-1].\ fifnam[channel.ifreqif-1] else: if channel.ifchan == "": s.wlog( 1, "SETBBC: Cannot set IFCHANs. First bad channel: " "{} of {} total.".format(ich + 1, len(setup_entry.channel))) s.errset(ks) setup_catalog.write(range(ks - 1, ks)) station_entry = station_entries[setup_entry.isetsta - 1] if (station_entry.recorder == "S2") and \ (station_entry.dar in ("VLBA", "VLBAG", "VLBA4")): s.bbcvs2(ks) else: def handle_func(f): def handle(ks): f(ks, setup_entry, station_entry) setup_catalog.write(range(ks - 1, ks)) return handle bbc_func = { "VLBA": s.bbcvlba, "RDBE": s.bbcrdbe, "RDBE2": s.bbcrdbe, "WIDAR": s.bbcwidar, "VLBAG": s.bbcgeo, "VLBA4": s.bbcgeo, "MKIV": s.bbcm4, "DBBC": handle_func(bbcdbbc), "DBBC3": handle_func(bbcdbbc), "CDAS": s.bbccdas, "R1002": s.bbckvsr, "LBA": s.bbclba, "eMERL": handle_func(bbc_emerlin) }.get(station_entry.dar, None) if bbc_func is not None: bbc_func(ks) elif station_entry.dar != "NONE": s.wlog( 1, "SETBBC: SCHED does not set default BBCs for format: {}, " "DAR type: {}".format(setup_entry.format, station_entry.dar)) s.errset(ks)
def check_channels(): somebad = False for ich, channel in enumerate(setup_entry.channel): iif = ifnam.find(channel.ifchan[0]) bbc = channel.bbc if (iif == -1) or (not ifbbc[bbc-1, iif]): s.wlog(1, "CHKDBBC: Illegal IF input {} for DBBC, channel " "{} BBC {}".format(channel.ifchan, ich+1, bbc)) s.wlog(1, " Allowed IF index and first character " "for this BBC are: {}".format( "".join("({}, {})".format(i+1, ifnam[i]) for i in np.where(ifbbc[bbc-1] == 1)[0]) )) somebad = True if somebad: s.wlog(1, " Be careful of special wiring restrictions " "for these DARs.") return somebad
def bbc_emerlin(ks, setup_entry, station_entry): """ ks: Fortran index into setups setup_entry: changes will be written to catalog station_entry: read only """ if s.schcon.debug: s.wlog(1, "BBCEMERLIN: Starting") ifbbc, mif = ifdbbc("GEO", False) ifnam = list("AB") max_bbc = ifbbc.shape[0] if station_entry.nbbc > max_bbc: s.wlog( 1, "BBCDBBC: Number of VCs at {} Larger than maximum expected: " "{}".format(setup_entry.setsta[0], max_bbc)) s.wlog(1, " Catalog or programming problem ") s.errset(ks) ubbc = bbcalt(ks, setup_entry, ifbbc, ifnam, "eMERL", "BBCEMERLIN")
def invla(values, present, entries, index, case): warn = True if s.schcon.debug and ((index < 2) or (case != 1)): s.wlog(0, "INVLA: Starting with case: {}".format(case)) if case == 1: entry = entries[index] default = False if index > 0: default = (entries[index - 1].vlatsys == "T") entry.vlatsys = "T" if toggle(values, present, "vlantsys", "vlatsys", default) \ else " " if entry.vlaphs == "": entry.vlaphs = entry.scnsrc if warn and (("vlabw" in present) or ("vlaband" in present)): s.wlog( 1, "INVLA: -- WARNING -- VLABW or VLABAND specified in " "main schedule.") s.wlog(1, "INVLA: They will be ignored.") s.wlog(1, "INVLA: Specify them in the setup files.") warn = False elif case == 2: s.schc3.vlatype = util.resize_string(values["vlatype"], s.schc3.vlatype.itemsize, "vlatype") s.schn3.vlausern = values["vlausern"] s.schn1.iatutc = values["iatutc"] if not s.schcon.noset: if [station[:3] for station in s.schc1.staname[:s.schn1.nsta]].\ count(b"VLA") >= 2: s.wrtmsg(1, "INVLA", "multipleVLA") else: s.errlog("INVLA: Bad case.") s.schn3.vlarfant = values["vlarfant"]
def bbcdbbc(ks, setup_entry, station_entry): """ ks: Fortran index into setups setup_entry: changes will be written to catalog station_entry: read only """ if s.schcon.debug: s.wlog(1, "BBCDBBC: Starting") if station_entry.dar == "DBBC3": ifbbc, mif = ifdbbc3() ifnam = list("ABCDEFGH") else: e_firmware = SetupCatalog.is_dbbc_e_firmware(setup_entry) ifbbc, mif = ifdbbc(station_entry.dbbcver, e_firmware) ifnam = list("ABCD") max_bbc = ifbbc.shape[0] if station_entry.nbbc > max_bbc: s.wlog( 1, "BBCDBBC: Number of VCs at {} Larger than maximum expected: " "{}".format(setup_entry.setsta[0], max_bbc)) s.wlog(1, " Catalog or programming problem ") s.errset(ks) ubbc = bbcalt(ks, setup_entry, ifbbc, ifnam, "DBBC", "BBCDBBC")
def getcov(values): s.schco.schver = values["version"] for attribute in [ "piname", "phone", "email", "fax", "obsphone", "obsmode" ]: setattr( s.schsco, attribute, util.resize_string(values[attribute], getattr(s.schsco, attribute).itemsize, attribute)) for i in range(4): address = "address" + str(i + 1) s.schsco.address[i] = util.resize_string(values[address], s.schsco.address.itemsize, address) note = "note" + str(i + 1) s.schsco.note[i] = util.resize_string(values[note], s.schsco.note.itemsize, note) if s.schcon.debug: s.wlog(0, "GETCOV: Checking cover information.") missing = False if s.schco.schver == 0.: s.wlog(1, " Schedule version is missing. ") missing = True if values["piname"] == "": s.wlog(1, " No PINAME given. ") missing = True if values["address1"] == "": s.wlog(1, " No address specified.") missing = True if values["phone"] == "": s.wlog(1, " No PI phone number specified.") missing = True if (values["email"] == "") and (values["fax"] == ""): s.wlog(1, " No email address or fax number specified.") missing = True if missing: s.wlog(1, "GETCOV: Cover information incomplete or missing.") if not s.schn1.notape and not s.schcon.plot: s.errlog("GETCOV: Cover information is required for VLBI " "observations.") if s.schcon.plot: s.wlog( 1, "GETCOV: Sched will plot, but not write telescope " "control files.") text = [ "Schedule Version: {:10.2f}".format(float(s.schco.schver)), "Processed by SCHED version: {:6.2f} {}".format( float(s.vern.vernum), bytes(s.verc.version).decode()), "PI: {}".format( values["piname"]), "Address: {}".format(values["address1"]), " {}".format(values["address2"]), " {}".format( values["address3"]), " {}".format(values["address4"]), "Phone: {}".format(values["phone"]), "EMAIL: {}".format( values["email"]), "Fax: {}".format(values["fax"]), "Phone during observation: {}".format(values["obsphone"]), "Observing mode: {}".format(values["obsmode"]), "Notes: {}".format( values["note1"]), " {}".format(values["note2"]), " {}".format(values["note3"]), " {}".format(values["note4"]) ] line = next((line for line in text if line.find("!") != -1), None) if line is not None: s.wlog( 1, "GETCOV: Please do not use exclamation marks in the cover " "information.") s.wlog( 1, " They mess up the parsing of the CRD files at the " "VLBA stations.") s.wlog(1, " One was found in the line: ") s.wlog(1, line) s.errlog("SCHIN: Remove exclamation marks.") for index, line in enumerate(text): s.schsco.cover[index] = util.resize_string(line, s.schsco.cover.itemsize, "cover")
def rdpeak_open(stdin): if (s.schcon.debug): s.wlog(0, "RDPEAK starting") s.schpeakn.dopoint = s.schcon.autopeak or \ (s.schn2a.point[:s.schn1.nscans] >= 0).any() peakfile = bytes(s.schsco.peakfile).decode().strip() if (peakfile.upper() == "NONE") or not s.schpeakn.dopoint: return try: f = open(peakfile, "r") except Exception as e: s.wlog(1, str(e)) s.wlog(1, "RDPEAK: Automatic insertion and/or conversion of scans " "was requested.") s.wlog(1, " PEAKFILE needed, but could not be opened.") s.wlog(1, " Problem is with file: ") s.wlog(1, peakfile) s.wlog(1, " Note that file peak.cmd could be used") s.wlog(1, " It is with the standard catalogs.") s.errlog(" Fix PEAKFILE or do not invoke AUTOPEAK or POINT.") with f: rdpeak_implementation(key.KeyfileIterator(f), stdin)
def rdpeak_implementation(input_iterator, stdin): global first_call if first_call: s.schpeakn.pkgroup.fill(0) s.schpeakn.npkgrp = 0 first_call = False input_name = "Program input" if input_iterator.input_ is stdin \ else input_iterator.input_.name state_defaults = { "srcfile": [schdefs("refpointing"), util.noop], "setup": ["", util.expand_file_name], "setupl": ["", util.expand_file_name], "minfreq": [60e3, util.noop], "minel": [30., util.noop], "dwell": [60., util.multiply_by(1 / 86400.)], "linename": ["", util.upper], "vlamode": ["", util.upper], } record_defaults = { "stations": [[], util.foreach(util.upper)], "sources": [[], util.foreach(util.upper)], "lineinit": [None, util.noop], "endpeak": [None, util.noop], } input_iterator.set_defaults(record_defaults, state_defaults) # map from catalog entry attributes to keyin keywords attribute_to_key = { "pklines": "linename", "pvlamode": "vlamode", "pkdwell": "dwell", "pkminfq": "minfreq", "pkminel": "minel", "psetfile": "setup", "plsetfil": "setupl", "pksta": "stations", "pksrc": "sources", } catalog = PeakCatalog() start = int(s.schpeakn.npkgrp) index = start for record in input_iterator: values, present = util.merge_record_with_defaults( record, record_defaults, state_defaults) if "endpeak" in present: break if "lineinit" in present: rfreq(input_iterator) continue if index >= catalog.maxpeak: s.errlog("RDPEAK: Too many reference pointing groups (Max {}) " "in: {}".format(catalog.maxpeak, input_name)) entry = catalog.entries[index] entry.set_keyin_values(values, attribute_to_key) if entry.plsetfil == "": entry.plsetfil = entry.psetfile s.wlog(1, "RDPEAK: WARNING: Your peak command file does not " "have a separate setup file") s.wlog(1, " for spectral line (narrow band) sources. " "You may encounter errors" ) s.wlog(1, " because the digital backends require " "sample rate = 2 times bandwidth ") s.wlog(1, " and the sample rate can only be changed " "with a new setup file.") def check_pointing_setup(filename): return SetupFileCatalog.extend_with( filename, "RDPEAK: Exceeded limit on number of setup files while adding " "ones needed for reference pointing.") entry.pklset = check_pointing_setup(entry.psetfile) entry.pklsetl = check_pointing_setup(entry.plsetfil) if (len(entry.pksta) == 0) and index > 0: entry.pksta = catalog.entries[index-1].pksta elif len(entry.pksta) == 0: s.errlog("RDPEAK: First peak group has no stations.") if (len(entry.pksrc) == 0) and index > 0: entry.pksrc = catalog.entries[index-1].pksrc elif len(entry.pksrc) == 0: s.errlog("RDPEAK: First peak group has no sources.") index += 1 if index == 0: s.wlog(0, "RDPEAK: No pointing instruction groups found in ") s.wlog(0, input_name) s.schpeakn.npkgrp = index s.schpeakc.psrcfile = util.resize_string(util.expand_file_name( state_defaults["srcfile"][0]), s.schpeakc.psrcfile.itemsize, "srcfile") catalog.write(range(start, index))
def rdpeak(input_iterator, stdin): if (s.schcon.debug): s.wlog(0, "RDPEAK starting") s.schpeakn.dopoint = True rdpeak_implementation(input_iterator, stdin)
def getsta(stdin, values, index, gotvex, mjd1): global last_station_file maxsta = StationCatalog.maxcat if s.schcon.debug and (index < 2): s.wlog(1, "GETSTA: starting.") if index == 0: last_station_file = "" station_file = util.expand_file_name(values["stafile"]) s.schcst.stafile = util.resize_string(station_file, s.schcst.stafile.itemsize, "stafile") s.schcst.locafile = util.resize_string( util.expand_file_name(values["locfile"]), s.schcst.locafile.itemsize, "locfile") if (station_file.upper() != "NONE") and (station_file != last_station_file): try: f = open(station_file, "r") except Exception as e: s.putout(str(e)) s.error("Station catalog: {} not opened".format(station_file)) else: with f: input_iterator = key.KeyfileLister(f) stread(input_iterator, stdin, mjd1) last_station_file = station_file if (index == 0) and (len(values["stations"]) == 0): s.errlog("GETSTA: No stations specified!") elif len(values["stations"]) == 0: s.schn2a.stascn[index] = s.schn2a.stascn[index - 1] else: s.schn2a.stascn[index] = False for station in values["stations"]: ksta, ista, doit = s.stano(station) if doit: if ksta == 0: s.wlog(1, "GETSTA: Station {} not found in catalogs".\ format(station)) s.errlog("GETSTA: Note -- specify station catalog " "before end of first scan input") if ista == 0: s.schn1.nsta += 1 if s.schn1.nsta > maxsta: s.errlog("'SCHIN: Too many stations!") ista = s.schn1.nsta s.schc1.staname[ista - 1] = s.schcst.station[ksta - 1] s.schn1.stanum[ista - 1] = ksta s.schsta.ischsta[ksta - 1] = ista control = bytes(s.schcst.control[s.schn1.stanum[ista-1]]).\ decode().strip() if control == "VEX ": gotvex = True if control == "VSOP": s.schcon.dovsop = True if s.schc1.staname[ista - 1][:4] != b"VLBA": s.schn5.allvlba = False else: s.schn1.gotvlba = True s.schn2a.stascn[index][ista - 1] = True return gotvex