Skip to content
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

Python3 migration and summary file #7

Merged
merged 1 commit into from
Feb 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions src/discosscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
logger = logging.getLogger(__name__)
from datetime import datetime
import sys

import glob
import numpy as np

from astropy.io import fits
Expand All @@ -34,7 +34,9 @@

from .scancycle import ScanCycle

SUMMARY = "summary.fits"

#SUMMARY = "summary.fits"

STOKES = "stokes"
CLIGHT = C.to("km / s").value
FILE_PREFIX = "class"
Expand All @@ -47,6 +49,7 @@ def __init__(self, message):

class DiscosScanConverter(object):
def __init__(self, path=None, duty_cycle={}, skip_calibration=False):
self.SUMMARY=glob.glob(path+'?um*.fits')
self.scan_path = path
self.got_summary = False
self.file_class_out = pyclassfiller.ClassFileOut()
Expand All @@ -60,7 +63,13 @@ def __init__(self, path=None, duty_cycle={}, skip_calibration=False):
def load_subscans(self):
for subscan_file in os.listdir(self.scan_path):
ext = os.path.splitext(subscan_file)[-1]
if not subscan_file == SUMMARY and ext == DATA_EXTENSION:
if subscan_file.lower().startswith('sum'):
self.SUMMARY=subscan_file
logger.debug("Summary File: %s" % self.SUMMARY)



if not subscan_file == self.SUMMARY and ext == DATA_EXTENSION:
subscan_path = os.path.join(self.scan_path, subscan_file)
with fits.open(subscan_path) as subscan:
self.subscans.append((subscan_path,
Expand All @@ -73,7 +82,7 @@ def load_subscans(self):
self.subscans.sort(key=lambda x:x[2])
logger.debug("ordered files: %s" % (str([filename for filename,_,_ in
self.subscans]),))
with fits.open(os.path.join(self.scan_path, SUMMARY)) as summary:
with fits.open(os.path.join(self.scan_path, self.SUMMARY)) as summary:
self.summary = summary[0].header

def convert_subscans(self, dest_dir=None):
Expand All @@ -87,10 +96,10 @@ def convert_subscans(self, dest_dir=None):
if not os.path.isdir(self.dest_dir):
logger.error("cannot create output dir: %s" % (self.dest_dir,))
sys.exit(1)
for i in range(len(self.subscans) / self.duty_cycle_size):
for i in range(int(len(self.subscans) / self.duty_cycle_size)):
self.n_cycles += 1
scan_cycle = self.convert_cycle(i * self.duty_cycle_size)
self.write_observation(scan_cycle, i * self.duty_cycle_size)
self.write_observation(scan_cycle, i * self.duty_cycle_size)

def convert_cycle(self, index):
current_index = index
Expand Down Expand Up @@ -278,7 +287,7 @@ def write_observation(self, scan_cycle, first_subscan_index):
on, off, cal = onoffcal[sec_id][pol]
if((not self.skip_calibration) and
(cal is not None)):
start_bin = self.bins / 3
start_bin = int(self.bins / 3)
stop_bin = 2 * start_bin
cal_mean = cal[start_bin:stop_bin].mean()
off_mean = off[start_bin:stop_bin].mean()
Expand All @@ -298,10 +307,10 @@ def write_observation(self, scan_cycle, first_subscan_index):
def load_summary_info(self, summary_file_path=None):
if not summary_file_path:
dir_name = self.scan_path
summary_file_path = os.path.join(dir_name, SUMMARY)
summary_file_path = os.path.join(dir_name, self.SUMMARY)
if not os.path.exists(summary_file_path):
raise DiscosScanException("scan %s does not conatain a %s" % (dir_name,
SUMMARY))
self.SUMMARY))
with fits.open(summary_file_path) as summary_file:
logger.debug("loading summary from %s" % (summary_file_path,))
summary_header = summary_file[0].header
Expand Down