Commit 36189a3e authored by JX's avatar JX 😵
Browse files

Merge remote-tracking branch 'origin/develop'

parents dd26d370 27646bc4
Pipeline #4509 passed with stage
in 0 seconds
......@@ -4,7 +4,8 @@ from datetime import datetime
import argparse
from astropy.time import Time
from ObservationSim.Config import Pointing
from observation_sim.config import Pointing
def parse_args():
'''
......@@ -12,13 +13,19 @@ def parse_args():
can be set in the .yaml config file as well.
'''
parser = argparse.ArgumentParser()
parser.add_argument('--config_file', type=str, required=True, help='.yaml config file for simulation settings.')
parser.add_argument('--catalog', type=str, help='name of the catalog interface class to be loaded.')
parser.add_argument('-c', '--config_dir', type=str, help='Directory that houses the .yaml config file.')
parser.add_argument('-d', '--data_dir', type=str, help='Directory that houses the input data.')
parser.add_argument('-w', '--work_dir', type=str, help='The path for output.')
parser.add_argument('--config_file', type=str, required=True,
help='.yaml config file for simulation settings.')
parser.add_argument('--catalog', type=str,
help='name of the catalog interface class to be loaded.')
parser.add_argument('-c', '--config_dir', type=str,
help='Directory that houses the .yaml config file.')
parser.add_argument('-d', '--data_dir', type=str,
help='Directory that houses the input data.')
parser.add_argument('-w', '--work_dir', type=str,
help='The path for output.')
return parser.parse_args()
def generate_pointing_list(config, pointing_filename=None, data_dir=None):
pointing_list = []
......@@ -48,7 +55,7 @@ def generate_pointing_list(config, pointing_filename=None, data_dir=None):
# header = f.readline()
iline = 0
for line in f:
if len(line.strip()) == 0 or line[0]=='#':
if len(line.strip()) == 0 or line[0] == '#':
continue
if run_pointings and iline not in run_pointings:
iline += 1
......@@ -83,6 +90,7 @@ def generate_pointing_list(config, pointing_filename=None, data_dir=None):
ipoint += 1
return pointing_list
def make_run_dirs(work_dir, run_name, pointing_list):
if not os.path.exists(work_dir):
try:
......@@ -97,6 +105,7 @@ def make_run_dirs(work_dir, run_name, pointing_list):
pass
return imgDir
def make_output_pointing_dir(path_dict, config, pointing_ID=0):
imgDir = os.path.join(path_dict["work_dir"], config["run_name"])
if not os.path.exists(imgDir):
......@@ -113,6 +122,7 @@ def make_output_pointing_dir(path_dict, config, pointing_ID=0):
pass
return subImgdir, prefix
def get_shear_field(config):
if not config["shear_setting"]["shear_type"] in ["constant", "catalog"]:
raise ValueError("Please set a right 'shear_method' parameter.")
......
......@@ -7,18 +7,22 @@ except ImportError:
# Try backported to PY<37 'importlib_resources'
import importlib_resources as pkg_resources
def checkInputList(input_list, n):
if not isinstance(input_list, list):
raise TypeError("Input type is not list!", input_list)
for i in input_list:
if type(i) != type(1.1):
if type(i) != type(1):
raise TypeError("Input list's element is not float or int!", input_list)
raise TypeError(
"Input list's element is not float or int!", input_list)
if len(input_list) != n:
raise RuntimeError("Length of input list is not equal to stars' number!", input_list)
raise RuntimeError(
"Length of input list is not equal to stars' number!", input_list)
def on_orbit_obs_position(input_ra_list, input_dec_list, input_pmra_list, input_pmdec_list, input_rv_list, input_parallax_list, input_nstars, input_x, input_y, input_z, input_vx, input_vy, input_vz, input_epoch, input_date_str, input_time_str, lib_path=None):
#Check input parameters
# Check input parameters
if not isinstance(input_nstars, int):
raise TypeError("Parameter 7 is not int!", input_nstars)
......@@ -41,7 +45,7 @@ def on_orbit_obs_position(input_ra_list, input_dec_list, input_pmra_list, input_
raise TypeError("Parameter 12 is not double!", input_vy)
if not isinstance(input_vz, float):
raise TypeError("Parameter 13 is not double!", input_vz)
#Convert km -> m
# Convert km -> m
input_x = input_x*1000.0
input_y = input_y*1000.0
input_z = input_z*1000.0
......@@ -53,57 +57,65 @@ def on_orbit_obs_position(input_ra_list, input_dec_list, input_pmra_list, input_
raise TypeError("Parameter 15 is not string!", input_date_str)
else:
input_date_str = input_date_str.strip()
if not (input_date_str[4]=="-" and input_date_str[7]=="-"):
if not (input_date_str[4] == "-" and input_date_str[7] == "-"):
raise TypeError("Parameter 15 format error (1)!", input_date_str)
else:
tmp = input_date_str.split("-")
if len(tmp) != 3:
raise TypeError("Parameter 15 format error (2)!", input_date_str)
raise TypeError(
"Parameter 15 format error (2)!", input_date_str)
input_year = int(tmp[0])
input_month = int(tmp[1])
input_day = int(tmp[2])
if not (input_year>=1900 and input_year<=2100):
raise TypeError("Parameter 15 year range error [1900 ~ 2100]!", input_year)
if not (input_month>=1 and input_month<=12):
raise TypeError("Parameter 15 month range error [1 ~ 12]!", input_month)
if not (input_day>=1 and input_day<=31):
raise TypeError("Parameter 15 day range error [1 ~ 31]!", input_day)
if not (input_year >= 1900 and input_year <= 2100):
raise TypeError(
"Parameter 15 year range error [1900 ~ 2100]!", input_year)
if not (input_month >= 1 and input_month <= 12):
raise TypeError(
"Parameter 15 month range error [1 ~ 12]!", input_month)
if not (input_day >= 1 and input_day <= 31):
raise TypeError(
"Parameter 15 day range error [1 ~ 31]!", input_day)
if not isinstance(input_time_str, str):
raise TypeError("Parameter 16 is not string!", input_time_str)
else:
input_time_str = input_time_str.strip()
if not (input_time_str[2]==":" and input_time_str[5]==":"):
if not (input_time_str[2] == ":" and input_time_str[5] == ":"):
raise TypeError("Parameter 16 format error (1)!", input_time_str)
else:
tmp = input_time_str.split(":")
if len(tmp) != 3:
raise TypeError("Parameter 16 format error (2)!", input_time_str)
raise TypeError(
"Parameter 16 format error (2)!", input_time_str)
input_hour = int(tmp[0])
input_minute = int(tmp[1])
input_second = float(tmp[2])
if not (input_hour>=0 and input_hour<=23):
raise TypeError("Parameter 16 hour range error [0 ~ 23]!", input_hour)
if not (input_minute>=0 and input_minute<=59):
raise TypeError("Parameter 16 minute range error [0 ~ 59]!", input_minute)
if not (input_second>=0 and input_second<60.0):
raise TypeError("Parameter 16 second range error [0 ~ 60)!", input_second)
if not (input_hour >= 0 and input_hour <= 23):
raise TypeError(
"Parameter 16 hour range error [0 ~ 23]!", input_hour)
if not (input_minute >= 0 and input_minute <= 59):
raise TypeError(
"Parameter 16 minute range error [0 ~ 59]!", input_minute)
if not (input_second >= 0 and input_second < 60.0):
raise TypeError(
"Parameter 16 second range error [0 ~ 60)!", input_second)
#Inital dynamic lib
# Inital dynamic lib
try:
with pkg_resources.files('ObservationSim.Astrometry.lib').joinpath("libshao.so") as lib_path:
with pkg_resources.files('observation_sim.astrometry.lib').joinpath("libshao.so") as lib_path:
shao = cdll.LoadLibrary(lib_path)
except AttributeError:
with pkg_resources.path('ObservationSim.Astrometry.lib', "libshao.so") as lib_path:
with pkg_resources.path('observation_sim.astrometry.lib', "libshao.so") as lib_path:
shao = cdll.LoadLibrary(lib_path)
shao.onOrbitObs.restype = c_int
d3 = c_double * 3
shao.onOrbitObs.argtypes = [c_double, c_double, c_double, c_double, c_double, c_double, \
c_int, c_int, c_int, c_int, c_int, c_double, \
c_double, POINTER(d3), POINTER(d3), \
c_int, c_int, c_int, c_int, c_int, c_double, \
POINTER(c_double), POINTER(c_double) ]
shao.onOrbitObs.argtypes = [c_double, c_double, c_double, c_double, c_double, c_double,
c_int, c_int, c_int, c_int, c_int, c_double,
c_double, POINTER(d3), POINTER(d3),
c_int, c_int, c_int, c_int, c_int, c_double,
POINTER(c_double), POINTER(c_double)]
output_ra_list = list()
output_dec_list = list()
for i in range(input_nstars):
......@@ -125,10 +137,10 @@ def on_orbit_obs_position(input_ra_list, input_dec_list, input_pmra_list, input_
DAT = c_double(37.0)
output_ra = c_double(0.0)
output_dec = c_double(0.0)
rs = shao.onOrbitObs(input_ra, input_dec, input_parallax, input_pmra, input_pmdec, input_rv, \
input_year_c, input_month_c, input_day_c, input_hour_c, input_minute_c, input_second_c, \
DAT, byref(p3), byref(v3), \
input_year_c, input_month_c, input_day_c, input_hour_c, input_minute_c, input_second_c, \
rs = shao.onOrbitObs(input_ra, input_dec, input_parallax, input_pmra, input_pmdec, input_rv,
input_year_c, input_month_c, input_day_c, input_hour_c, input_minute_c, input_second_c,
DAT, byref(p3), byref(v3),
input_year_c, input_month_c, input_day_c, input_hour_c, input_minute_c, input_second_c,
byref(output_ra), byref(output_dec))
if rs != 0:
raise RuntimeError("Calculate error!")
......
import os
import logging
import ObservationSim.Config._util as _util
from ObservationSim.Config.Header import generatePrimaryHeader
import observation_sim.config._util as _util
from observation_sim.config.header import generatePrimaryHeader
class ChipOutput(object):
......
......@@ -5,11 +5,12 @@ import galsim
import numpy as np
from astropy.time import Time
from ObservationSim.Config._util import get_obs_id
import ObservationSim.Instrument._util as _util
from observation_sim.config._util import get_obs_id
import observation_sim.instruments._util as _util
class Pointing(object):
def __init__(self, id=0, ra=0., dec=0., img_pa=0., timestamp=1621915200, sat_x=0., sat_y=0., sat_z=0., sun_x=0., sun_y=0., sun_z=0., sat_vx=0., sat_vy=0., sat_vz=0., exp_time=150., pointing_type='SCI', pointing_type_code='101', pointing_id = '00000001', obs_config_file=None, t_shutter_open = 1.3, t_shutter_close = 1.3):
def __init__(self, id=0, ra=0., dec=0., img_pa=0., timestamp=1621915200, sat_x=0., sat_y=0., sat_z=0., sun_x=0., sun_y=0., sun_z=0., sat_vx=0., sat_vy=0., sat_vz=0., exp_time=150., pointing_type='SCI', pointing_type_code='101', pointing_id='00000001', obs_config_file=None, t_shutter_open=1.3, t_shutter_close=1.3):
self.id = id
self.ra = ra
self.dec = dec
......@@ -41,7 +42,6 @@ class Pointing(object):
if self.obs_param["obs_id"]:
self.obs_id = str(self.obs_param["obs_id"])
def get_full_depth_exptime(self, filter_type):
if self.survey_field_type == 'WIDE':
if filter_type in _util.SPEC_FILTERS:
......@@ -64,7 +64,6 @@ class Pointing(object):
else:
return max(150., self.exp_time) # [TODO] for FGS
def read_pointing_columns(self, columns, id=0, t=1621915200, pointing_type='SCI'):
self.id = id
col_len = len(columns)
......@@ -108,7 +107,8 @@ class Pointing(object):
self.timestamp = t
def make_output_pointing_dir(self, overall_config, copy_obs_config=False):
run_dir = os.path.join(overall_config["work_dir"], overall_config["run_name"])
run_dir = os.path.join(
overall_config["work_dir"], overall_config["run_name"])
if not os.path.exists(run_dir):
try:
os.makedirs(run_dir, exist_ok=True)
......@@ -119,7 +119,7 @@ class Pointing(object):
project_cycle=overall_config["project_cycle"],
run_counter=overall_config["run_counter"],
pointing_id=self.obs_id,
pointing_type_code = self.pointing_type_code)
pointing_type_code=self.pointing_type_code)
self.output_dir = os.path.join(run_dir, self.output_prefix)
if not os.path.exists(self.output_dir):
try:
......@@ -127,10 +127,10 @@ class Pointing(object):
except OSError:
pass
if copy_obs_config and self.obs_config_file:
obs_config_output_path = os.path.join(self.output_dir, os.path.basename(self.obs_config_file))
obs_config_output_path = os.path.join(
self.output_dir, os.path.basename(self.obs_config_file))
if not os.path.exists(obs_config_output_path):
try:
shutil.copy(self.obs_config_file, self.output_dir)
except OSError:
pass
def get_obs_id(img_type='SCI', project_cycle=6, run_counter=0, pointing_id='00000001',pointing_type_code='101'):
def get_obs_id(img_type='SCI', project_cycle=6, run_counter=0, pointing_id='00000001', pointing_type_code='101'):
# obs_type = {'SCI': '01', 'BIAS': '03', 'DARK': '07', 'FLAT': '11', 'CRS': '98', 'CRD': '99'}
# obs_type = {'SCIE': '01', 'BIAS': '03', 'DARK': '07', 'FLAT': '11', 'CRS': '98', 'CRD': '99', 'CAL': '01'}
obs_id = pointing_type_code + str(int(project_cycle)).rjust(2, '0') + str(int(run_counter)) + pointing_id
obs_id = pointing_type_code + \
str(int(project_cycle)).rjust(2, '0') + \
str(int(run_counter)) + pointing_id
return obs_id
# def get_obs_id(img_type='SCI', project_cycle=6, run_counter=0, pointing_num=0):
# # obs_type = {'SCI': '01', 'BIAS': '03', 'DARK': '07', 'FLAT': '11', 'CRS': '98', 'CRD': '99'}
# obs_type = {'SCIE': '01', 'BIAS': '03', 'DARK': '07', 'FLAT': '11', 'CRS': '98', 'CRD': '99', 'CAL': '01'}
# obs_id = '1'+ obs_type[img_type] + str(int(project_cycle)).rjust(2, '0') + str(int(run_counter)) + str(pointing_num).rjust(8,'0')
# return obs_id
def get_file_type(img_type='SCI'):
file_type = {'SCI':'SCI', 'BIAS':'BIAS', 'DARK':'DARK', 'FLAT':'FLAT', 'CRS':'CRS', 'CRD':'CRD','CALS':'CALS','CALF':'CALF'}
file_type = {'SCI': 'SCI', 'BIAS': 'BIAS', 'DARK': 'DARK', 'FLAT': 'FLAT',
'CRS': 'CRS', 'CRD': 'CRD', 'CALS': 'CALS', 'CALF': 'CALF'}
return file_type[img_type]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment