diff --git a/skycatalogs/catalog_creator.py b/skycatalogs/catalog_creator.py index fe653318..8be6c640 100644 --- a/skycatalogs/catalog_creator.py +++ b/skycatalogs/catalog_creator.py @@ -424,9 +424,9 @@ def create(self, catalog_type): if not self._no_flux: self.create_pointsource_flux_catalog() elif catalog_type == ('sso'): - if not self._flux_only: + if not self._no_main: self._sso_creator.create_sso_catalog() - if not self._main_only: + if not self._no_flux: self._sso_creator.create_sso_flux_catalog() else: diff --git a/skycatalogs/objects/sso_object.py b/skycatalogs/objects/sso_object.py index 041e9d46..0e422327 100644 --- a/skycatalogs/objects/sso_object.py +++ b/skycatalogs/objects/sso_object.py @@ -1,6 +1,7 @@ from collections.abc import Iterable import itertools import numpy as np +import math import galsim from .base_object import BaseObject, ObjectCollection from lsst.sphgeom import UnitVector3d, LonLat @@ -58,9 +59,8 @@ def get_gsobject_components(self, gsparams=None, rng=None, dec = self.dec # Convert from (arc?)degrees/day to degrees/sec ra_rate = self.get_native_attribute('ra_rate')/SECONDS_PER_DAY - # Take out factor of cos(dec). - ra_rate_raw = ra_rate/np.cos(dec) - # ra_rate = self.get_native_attribute('ra_rate')/24.0 + # Take out factor of cos(dec). np.cos expects radians + ra_rate_raw = ra_rate/np.cos(math.radians(dec)) dec_rate = self.get_native_attribute('dec_rate')/SECONDS_PER_DAY # ra_final is approximate since really ra_rate is a function # of dec, but average dec_rate is small so @@ -74,8 +74,7 @@ def get_gsobject_components(self, gsparams=None, rng=None, # now rotate to direction of (ra_rate, dec_rate) # angle_rad = galsim.Angle(np.arctan2(dec_rate, (ra_rate * np.cos(dec))), galsim.radians) - # NOTE: Probably cos(dec) has already been applied, in which - # case we want + # NOTE: cos(dec) has already been applied, so we want angle_rad = galsim.Angle(np.arctan2(dec_rate, ra_rate), galsim.radians) diff --git a/skycatalogs/sso_catalog_creator.py b/skycatalogs/sso_catalog_creator.py index c95511fa..7d59be0b 100644 --- a/skycatalogs/sso_catalog_creator.py +++ b/skycatalogs/sso_catalog_creator.py @@ -1,7 +1,6 @@ import os import sys from multiprocessing import Process, Pipe -import numpy as np import sqlite3 import pandas as pd import pyarrow as pa @@ -56,11 +55,13 @@ def _do_sso_flux_chunk(send_conn, sso_collection, instrument_needed, class SsoCatalogCreator: - _sso_truth = '/sdf/home/j/jrb/rubin-user/sso/input/20feb2024' + # _sso_truth = '/sdf/home/j/jrb/rubin-user/sso/input/20feb2024' + _sso_truth = '/sdf/data/rubin/shared/ops-rehearsals/ops-rehearsal-4/imSim_catalogs/inputs/sso' _sso_sed = '/sdf/home/j/jrb/rubin-user/sso/sed/solar_sed.db' + _sso_db_tbl = 'results' def __init__(self, catalog_creator, output_dir, - sso_truth=None, sso_sed=None): + sso_truth=None, sso_sed=None, sso_db_tbl=None): ''' Parameters ---------- @@ -79,16 +80,21 @@ def __init__(self, catalog_creator, output_dir, if sso_sed is None: # use default path self._sso_sed = SsoCatalogCreator._sso_sed + self._sso_db_tbl = sso_db_tbl + if sso_db_tbl is None: + # correct for default input file + self._sso_db_tbl = SsoCatalogCreator._sso_db_tbl + self._row_group_size = _DEFAULT_ROW_GROUP_SIZE - tbl = 'pp_results' - mjd_c = 'FieldMJD_TAI' + tbl = self._sso_db_tbl + mjd_c = 'fieldMJD_TAI' self._mjd_q = f'select min({mjd_c}), max({mjd_c}), count({mjd_c}) from {tbl}' self._dfhp_query = f'''select ObjID as id, {mjd_c} as mjd, - "AstRA(deg)" as ra, "AstDec(deg)" as dec, - "AstRARate(deg/day)" as ra_rate, - "AstDecRate(deg/day)" as dec_rate, - TrailedSourceMag as trailed_source_mag from {tbl} + "RA_deg" as ra, "Dec_deg" as dec, + "RARateCosDec_deg_day" as ra_rate, + "DecRate_deg_day" as dec_rate, + trailedSourceMag as trailed_source_mag from {tbl} where healpix = (?) order by mjd, ObjID''' @@ -127,8 +133,8 @@ def _create_flux_schema(self): def _get_hps(self, filepath): - with sqlite3.connect(filepath) as conn: - df = pd.read_sql_query('select distinct healpix from pp_results', + with sqlite3.connect(f'file:{filepath}?mode=ro', uri=True) as conn: + df = pd.read_sql_query(f'select distinct healpix from {self._sso_db_tbl}', conn) return set(df['healpix']) @@ -136,7 +142,7 @@ def _write_hp(self, hp, hps_by_file, arrow_schema): df_list = [] for f in hps_by_file: if hp in hps_by_file[f]: - conn = sqlite3.connect(f) + conn = sqlite3.connect(f'file:{f}?mode=ro', uri=True) one_df = pd.read_sql_query(self._dfhp_query, conn, params=(hp,)) df_list.append(one_df) @@ -189,7 +195,7 @@ def _create_sso_flux_pixel(self, pixel, arrow_schema): None ''' - global _sso_collection + # global _sso_collection output_filename = f'sso_flux_{pixel}.parquet' output_path = os.path.join(self._catalog_creator._output_dir, output_filename)