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

U/jrbogart/sso ops4 #108

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions skycatalogs/catalog_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 4 additions & 5 deletions skycatalogs/objects/sso_object.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)

Expand Down
32 changes: 19 additions & 13 deletions skycatalogs/sso_catalog_creator.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
----------
Expand All @@ -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'''

Expand Down Expand Up @@ -127,16 +133,16 @@ 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'])

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)
Expand Down Expand Up @@ -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)
Expand Down