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

Workaround for bad flux values #722

Merged
merged 8 commits into from Nov 13, 2018
Merged

Workaround for bad flux values #722

merged 8 commits into from Nov 13, 2018

Conversation

weaverba137
Copy link
Member

This PR is a workaround for desihub/desitarget#397.

Do not merge yet. I also need to review changes to the data model (for example, the target table has added about 60 columns).

@weaverba137 weaverba137 self-assigned this Nov 12, 2018
Copy link
Contributor

@sbailey sbailey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine (though I haven't tested it myself).

@weaverba137 weaverba137 added bug WIP Work in Progress labels Nov 13, 2018
@weaverba137 weaverba137 removed the WIP Work in Progress label Nov 13, 2018
@weaverba137
Copy link
Member Author

I think this is ready to merge. I tested this with the redshift-database tutorial, which itself needed updates for 18.11++.

@sbailey
Copy link
Contributor

sbailey commented Nov 13, 2018

This fixes the bad flux values, but I'm still getting a crash from loading a full minitest production:

basedir = '/global/cscratch1/sd/sjbailey/desi/dev/end2end'
targetdir = '/global/cscratch1/sd/sjbailey/desi/dev/end2end/targets'
reduxdir = '/global/cscratch1/sd/sjbailey/desi/dev/end2end/spectro/redux/mini'
fibassigndir = '/global/cscratch1/sd/sjbailey/desi/dev/end2end/fiberassign'
expfile = '/global/cscratch1/sd/sjbailey/desi/dev/end2end/survey/exposures.fits'

from argparse import Namespace
from desispec.database.redshift import (setup_db, dbSession, load_file, ObsList, Target, Truth, ZCat, FiberAssign,
                                        load_fiberassign)
options = Namespace(overwrite=True, dbfile=os.path.join(os.getenv('SCRATCH'), 'minitest.db'), hostname=None, maxrows=0,
                    chunksize=50000, schema=None, username=None, verbose=False, datapath=basedir)
# We'll be using a SQLite database, ignore the return value of setup_db
postgresql = setup_db(options)
load_file(expfile, ObsList, hdu='EXPOSURES', expand={'PASS': 'passnum'})
load_file(os.path.join(targetdir, 'truth.fits'), Truth, hdu='TRUTH')
load_file(os.path.join(targetdir, 'targets.fits'), Target, hdu="TARGETS")
load_file(os.path.join(reduxdir, 'zcatalog-mini.fits'), ZCat, hdu='ZCATALOG',
          expand={'COEFF': ('coeff_0', 'coeff_1', 'coeff_2', 'coeff_3', 'coeff_4',
                            'coeff_5', 'coeff_6', 'coeff_7', 'coeff_8', 'coeff_9',)},
          rowfilter=lambda x: ((x['TARGETID'] != 0) & (x['TARGETID'] != -1)))
load_fiberassign(fibassigndir)

Results in

INFO:redshift.py:810:setup_db: Begin creating tables.
INFO:redshift.py:814:setup_db: Finished creating tables.
INFO:redshift.py:365:load_file: Read data from /global/cscratch1/sd/sjbailey/desi/dev/end2end/survey/exposures.fits.
INFO:redshift.py:383:load_file: Integrity check complete on obslist.
INFO:redshift.py:391:load_file: Initial column conversion complete on obslist.
INFO:redshift.py:413:load_file: Column expansion complete on obslist.
INFO:redshift.py:419:load_file: Column conversion complete on obslist.
INFO:redshift.py:426:load_file: Converted columns into rows on obslist.
INFO:redshift.py:433:load_file: Inserted 41 rows in obslist.
INFO:redshift.py:365:load_file: Read data from /global/cscratch1/sd/sjbailey/desi/dev/end2end/targets/truth.fits.
WARNING:redshift.py:376:load_file: 4 rows of bad data detected in column FLUX_R of /global/cscratch1/sd/sjbailey/desi/dev/end2end/targets/truth.fits.
INFO:redshift.py:383:load_file: Integrity check complete on truth.
INFO:redshift.py:391:load_file: Initial column conversion complete on truth.
INFO:redshift.py:413:load_file: Column expansion complete on truth.
INFO:redshift.py:419:load_file: Column conversion complete on truth.
INFO:redshift.py:426:load_file: Converted columns into rows on truth.
INFO:redshift.py:433:load_file: Inserted 50000 rows in truth.
INFO:redshift.py:433:load_file: Inserted 100000 rows in truth.
INFO:redshift.py:433:load_file: Inserted 150000 rows in truth.
INFO:redshift.py:433:load_file: Inserted 200000 rows in truth.
INFO:redshift.py:433:load_file: Inserted 224266 rows in truth.
INFO:redshift.py:365:load_file: Read data from /global/cscratch1/sd/sjbailey/desi/dev/end2end/targets/targets.fits.
WARNING:redshift.py:376:load_file: 4 rows of bad data detected in column FLUX_R of /global/cscratch1/sd/sjbailey/desi/dev/end2end/targets/targets.fits.
WARNING:redshift.py:376:load_file: 4 rows of bad data detected in column FIBERFLUX_R of /global/cscratch1/sd/sjbailey/desi/dev/end2end/targets/targets.fits.
WARNING:redshift.py:376:load_file: 4 rows of bad data detected in column FIBERTOTFLUX_R of /global/cscratch1/sd/sjbailey/desi/dev/end2end/targets/targets.fits.
INFO:redshift.py:383:load_file: Integrity check complete on target.
INFO:redshift.py:391:load_file: Initial column conversion complete on target.
INFO:redshift.py:413:load_file: Column expansion complete on target.
INFO:redshift.py:419:load_file: Column conversion complete on target.
INFO:redshift.py:426:load_file: Converted columns into rows on target.
---------------------------------------------------------------------------
IntegrityError                            Traceback (most recent call last)
/global/common/software/desi/cori/desiconda/20180709-1.2.6-spec/conda/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _execute_context(self, dialect, constructor, statement, parameters, *args)
   1169                         parameters,
-> 1170                         context)
   1171             elif not parameters and context.no_parameters:

/global/common/software/desi/cori/desiconda/20180709-1.2.6-spec/conda/lib/python3.6/site-packages/sqlalchemy/engine/default.py in do_executemany(self, cursor, statement, parameters, context)
    504     def do_executemany(self, cursor, statement, parameters, context=None):
--> 505         cursor.executemany(statement, parameters)
    506 

IntegrityError: NOT NULL constraint failed: target.dchisq_psf

The above exception was the direct cause of the following exception:

IntegrityError                            Traceback (most recent call last)
<ipython-input-3-0895a53ef0da> in <module>()
      8 load_file(expfile, ObsList, hdu='EXPOSURES', expand={'PASS': 'passnum'})
      9 load_file(os.path.join(targetdir, 'truth.fits'), Truth, hdu='TRUTH')
---> 10 load_file(os.path.join(targetdir, 'targets.fits'), Target, hdu="TARGETS")
     11 load_file(os.path.join(reduxdir, 'zcatalog-mini.fits'), ZCat, hdu='ZCATALOG',
     12           expand={'COEFF': ('coeff_0', 'coeff_1', 'coeff_2', 'coeff_3', 'coeff_4',

/global/cscratch1/sd/sjbailey/desi/code/desispec/py/desispec/database/redshift.py in load_file(filepath, tcls, hdu, expand, convert, index, rowfilter, q3c, chunksize, maxrows)
    429                       for row in data_rows[k*chunksize:(k+1)*chunksize]]
    430         if len(data_chunk) > 0:
--> 431             engine.execute(tcls.__table__.insert(), data_chunk)
    432             log.info("Inserted %d rows in %s.",
    433                      min((k+1)*chunksize, finalrows), tn)

/global/common/software/desi/cori/desiconda/20180709-1.2.6-spec/conda/lib/python3.6/site-packages/sqlalchemy/engine/base.py in execute(self, statement, *multiparams, **params)
   2073 
   2074         connection = self.contextual_connect(close_with_result=True)
-> 2075         return connection.execute(statement, *multiparams, **params)
   2076 
   2077     def scalar(self, statement, *multiparams, **params):

/global/common/software/desi/cori/desiconda/20180709-1.2.6-spec/conda/lib/python3.6/site-packages/sqlalchemy/engine/base.py in execute(self, object, *multiparams, **params)
    946             raise exc.ObjectNotExecutableError(object)
    947         else:
--> 948             return meth(self, multiparams, params)
    949 
    950     def _execute_function(self, func, multiparams, params):

/global/common/software/desi/cori/desiconda/20180709-1.2.6-spec/conda/lib/python3.6/site-packages/sqlalchemy/sql/elements.py in _execute_on_connection(self, connection, multiparams, params)
    267     def _execute_on_connection(self, connection, multiparams, params):
    268         if self.supports_execution:
--> 269             return connection._execute_clauseelement(self, multiparams, params)
    270         else:
    271             raise exc.ObjectNotExecutableError(self)

/global/common/software/desi/cori/desiconda/20180709-1.2.6-spec/conda/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _execute_clauseelement(self, elem, multiparams, params)
   1058             compiled_sql,
   1059             distilled_params,
-> 1060             compiled_sql, distilled_params
   1061         )
   1062         if self._has_events or self.engine._has_events:

/global/common/software/desi/cori/desiconda/20180709-1.2.6-spec/conda/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _execute_context(self, dialect, constructor, statement, parameters, *args)
   1198                 parameters,
   1199                 cursor,
-> 1200                 context)
   1201 
   1202         if self._has_events or self.engine._has_events:

/global/common/software/desi/cori/desiconda/20180709-1.2.6-spec/conda/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _handle_dbapi_exception(self, e, statement, parameters, cursor, context)
   1411                 util.raise_from_cause(
   1412                     sqlalchemy_exception,
-> 1413                     exc_info
   1414                 )
   1415             else:

/global/common/software/desi/cori/desiconda/20180709-1.2.6-spec/conda/lib/python3.6/site-packages/sqlalchemy/util/compat.py in raise_from_cause(exception, exc_info)
    201     exc_type, exc_value, exc_tb = exc_info
    202     cause = exc_value if exc_value is not exception else None
--> 203     reraise(type(exception), exception, tb=exc_tb, cause=cause)
    204 
    205 if py3k:

/global/common/software/desi/cori/desiconda/20180709-1.2.6-spec/conda/lib/python3.6/site-packages/sqlalchemy/util/compat.py in reraise(tp, value, tb, cause)
    184             value.__cause__ = cause
    185         if value.__traceback__ is not tb:
--> 186             raise value.with_traceback(tb)
    187         raise value
    188 

/global/common/software/desi/cori/desiconda/20180709-1.2.6-spec/conda/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _execute_context(self, dialect, constructor, statement, parameters, *args)
   1168                         statement,
   1169                         parameters,
-> 1170                         context)
   1171             elif not parameters and context.no_parameters:
   1172                 if self.dialect._has_events:

/global/common/software/desi/cori/desiconda/20180709-1.2.6-spec/conda/lib/python3.6/site-packages/sqlalchemy/engine/default.py in do_executemany(self, cursor, statement, parameters, context)
    503 
    504     def do_executemany(self, cursor, statement, parameters, context=None):
--> 505         cursor.executemany(statement, parameters)
    506 
    507     def do_execute(self, cursor, statement, parameters, context=None):

IntegrityError: (sqlite3.IntegrityError) NOT NULL constraint failed: target.dchisq_psf [SQL: 'INSERT INTO target (release, brickid, brickname, brick_objid, morphtype, ra, dec, ra_ivar, dec_ivar, flux_g, flux_r, flux_z, flux_w1, flux_w2, flux_ivar_g, flux_ivar_r, flux_ivar_z, flux_ivar_w1, flux_ivar_w2, mw_transmission_g, mw_transmission_r, mw_transmission_z, mw_transmission_w1, mw_transmission_w2, nobs_g, nobs_r, nobs_z, fracflux_g, fracflux_r, fracflux_z, fracmasked_g, fracmasked_r, fracmasked_z, fracin_g, fracin_r, fracin_z, allmask_g, allmask_r, allmask_z, psfdepth_g, psfdepth_r, psfdepth_z, galdepth_g, galdepth_r, galdepth_z, fracdev, fracdev_ivar, shapedev_r, shapedev_r_ivar, shapedev_e1, shapedev_e1_ivar, shapedev_e2, shapedev_e2_ivar, shapeexp_r, shapeexp_r_ivar, shapeexp_e1, shapeexp_e1_ivar, shapeexp_e2, shapeexp_e2_ivar, fiberflux_g, fiberflux_r, fiberflux_z, fibertotflux_g, fibertotflux_r, fibertotflux_z, ref_id, gaia_phot_g_mean_mag, gaia_phot_g_mean_flux_over_error, gaia_phot_bp_mean_mag, gaia_phot_bp_mean_flux_over_error, gaia_phot_rp_mean_mag, gaia_phot_rp_mean_flux_over_error, gaia_astrometric_excess_noise, gaia_duplicated_source, parallax, parallax_ivar, pmra, pmra_ivar, pmdec, pmdec_ivar, brightstarinblob, ebv, photsys, targetid, desi_target, bgs_target, mws_target, priority, subpriority, numobs, hpxpixel) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'] [parameters: ((9999, 488659, '1526p285', 0, 'EXP ', 152.4978485107422, 28.408809661865234, 100000000.0, 100000000.0, 16.09772300720215, 28.7934513092041, 42.85902786254883, 33.36859130859375, 25.591564178466797, 1438.599853515625, 329.5641784667969, 62.79716110229492, 0.7545953392982483, 0.29916098713874817, 0.9354498982429504, 0.9560464024543762, 0.9749687314033508, 0.996187150478363, 0.9976567029953003, 2, 2, 2, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 52.48074722290039, 7.726805686950684, 1.8706821203231812, 57.54399490356445, 13.182567596435547, 2.5118863582611084, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.9714908599853516, 52018.12109375, 0.3237842321395874, 2.4894924091765555e+17, 0.10086371749639511, 166199.734375, 1.695696473121643, 3.098234176635742, 4.726201057434082, 1.695696473121643, 3.098234176635742, 4.726201057434082, -1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0, 0.022541597485542297, 'S', 288230398217945088, 1152921504606846976, 131586, 0, 2100, 0.3568103559416339, 1, 5261), (9999, 488658, '1523p285', 1, 'DEV ', 152.40225219726562, 28.43646240234375, 100000000.0, 100000000.0, 90.11798858642578, 184.66262817382812, 301.1165771484375, 270.7568664550781, 192.89874267578125, 1438.599853515625, 329.5641784667969, 62.79716110229492, 0.7545765042304993, 0.29915371537208557, 0.9321490526199341, 0.9537726640701294, 0.9736603498458862, 0.9959855675697327, 0.9975327253341675, 2, 2, 2, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 52.48074722290039, 7.726805686950684, 1.8706821203231812, 57.54399490356445, 13.182567596435547, 2.5118863582611084, 1.0, 0.0, 3.1728429794311523, 96601.546875, 0.05746058002114296, 2.8273491148297103e+20, 0.13335759937763214, 1376962.125, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 8.10999584197998, 17.16741371154785, 29.049846649169922, 8.10999584197998, 17.16741371154785, 29.049846649169922, -1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0, 0.023735709488391876, 'S', 288230398217945089, 1152921504606846976, 131586, 0, 2100, 0.568604199296773, 1, 5261), (9999, 488658, '1523p285', 2, 'REX ', 152.38270568847656, 28.428730010986328, 100000000.0, 100000000.0, 10.246813774108887, 21.87872314453125, 33.94467544555664, 29.530611038208008, 20.334270477294922, 1438.599853515625, 329.5641784667969, 62.79716110229492, 0.7545267939567566, 0.2991345226764679, 0.9310829043388367, 0.953037679195404, 0.9732370972633362, 0.9959203600883484, 0.9974925518035889, 2, 2, 2, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 52.48074722290039, 7.726805686950684, 1.8706821203231812, 57.54399490356445, 13.182567596435547, 2.5118863582611084, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.6344906091690063, 13692.08203125, 0.0, 0.0, 0.0, 0.0, 1.3950544595718384, 3.052152156829834, 4.869853496551514, 1.3950544595718384, 3.052152156829834, 4.869853496551514, -1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0, 0.02412230521440506, 'S', 288230398217945090, 1152921504606846976, 131586, 0, 2100, 0.9329254586401731, 1, 5261), (9999, 487390, '1526p282', 3, 'REX ', 152.7200164794922, 28.32263946533203, 100000000.0, 100000000.0, 4.866122722625732, 11.972004890441895, 20.438461303710938, 20.707250595092773, 17.912580490112305, 1438.599853515625, 329.5641784667969, 62.79716110229492, 0.754564642906189, 0.29914912581443787, 0.9302952885627747, 0.9524945616722107, 0.9729242920875549, 0.9958720803260803, 0.9974628686904907, 2, 2, 2, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 52.48074722290039, 7.726805686950684, 1.8706821203231812, 57.54399490356445, 13.182567596435547, 2.5118863582611084, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.6859385371208191, 60716.265625, 0.0, 0.0, 0.0, 0.0, 1.6744358539581299, 4.290088653564453, 7.6673784255981445, 1.6744358539581299, 4.290088653564453, 7.6673784255981445, -1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0, 0.02440819889307022, 'S', 288230398217945091, 1152921504606846976, 65793, 0, 2000, 0.5880792227876986, 1, 5261), (9999, 487390, '1526p282', 4, 'REX ', 152.75033569335938, 28.370037078857422, 100000000.0, 100000000.0, 6.632730007171631, 15.018413543701172, 24.129465103149414, 19.661819458007812, 12.702428817749023, 1438.599853515625, 329.5641784667969, 62.79716110229492, 0.754763662815094, 0.29922589659690857, 0.9296985864639282, 0.9520829916000366, 0.9726871252059937, 0.9958354830741882, 0.9974403977394104, 2, 2, 2, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 52.48074722290039, 7.726805686950684, 1.8706821203231812, 57.54399490356445, 13.182567596435547, 2.5118863582611084, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5423256754875183, 57870.56640625, 0.0, 0.0, 0.0, 0.0, 2.7036244869232178, 6.4018683433532715, 10.816449165344238, 2.7036244869232178, 6.4018683433532715, 10.816449165344238, -1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0, 0.02462494559586048, 'S', 288230398217945092, 1152921504606846976, 65793, 0, 2000, 0.17543431523839492, 1, 5261), (9999, 486117, '1524p280', 5, 'EXP ', 152.55130004882812, 28.12346839904785, 100000000.0, 100000000.0, 4.090408802032471, 14.306994438171387, 29.584917068481445, 45.93244934082031, 38.651702880859375, 1438.599853515625, 329.5641784667969, 62.79716110229492, 0.7536880373954773, 0.29881104826927185, 0.9203853011131287, 0.9456477761268616, 0.9689738750457764, 0.9952616691589355, 0.9970873594284058, 2, 2, 2, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 52.48074722290039, 7.726805686950684, 1.8706821203231812, 57.54399490356445, 13.182567596435547, 2.5118863582611084, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.203531265258789, 4171.45166015625, 0.03928520530462265, 1867774842372096.0, 0.35615596175193787, 30481.431640625, 0.3576124906539917, 1.27470862865448, 2.6941983699798584, 0.3576124906539917, 1.27470862865448, 2.6941983699798584, -1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0, 0.028026076033711433, 'S', 288230398217945093, 1152921504606846976, 65793, 0, 2000, 0.3655313045016235, 1, 5261), (9999, 487390, '1526p282', 6, 'DEV ', 152.6802978515625, 28.179832458496094, 100000000.0, 100000000.0, 8.717318534851074, 26.65909194946289, 52.678157806396484, 68.17051696777344, 51.3319091796875, 1438.599853515625, 329.5641784667969, 62.79716110229492, 0.7540304064750671, 0.29894310235977173, 0.9222020506858826, 0.9469047784805298, 0.969700038433075, 0.9953740239143372, 0.9971565008163452, 2, 2, 2, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 52.48074722290039, 7.726805686950684, 1.8706821203231812, 57.54399490356445, 13.182567596435547, 2.5118863582611084, 1.0, 0.0, 0.8572824597358704, 20022.142578125, 0.10677320510149002, 333073673617408.0, 0.12159992754459381, 18184.173828125, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.5458266735076904, 8.146329879760742, 16.937957763671875, 2.5458266735076904, 8.146329879760742, 16.937957763671875, -1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0, 0.02735993079841137, 'S', 288230398217945094, 1152921504606846976, 131586, 0, 2100, 0.9511830621245244, 1, 5261), (9999, 487390, '1526p282', 7, 'REX ', 152.7872314453125, 28.192785263061523, 100000000.0, 100000000.0, 3.7336440086364746, 12.043473243713379, 25.54196548461914, 41.78341293334961, 31.527860641479492, 1438.599853515625, 329.5641784667969, 62.79716110229492, 0.7542009949684143, 0.29900890588760376, 0.9211333990097046, 0.9461655020713806, 0.969273030757904, 0.995307981967926, 0.9971158504486084, 2, 2, 2, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 52.48074722290039, 7.726805686950684, 1.8706821203231812, 57.54399490356445, 13.182567596435547, 2.5118863582611084, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.7476310729980469, 29394.662109375, 0.0, 0.0, 0.0, 0.0, 0.4648111164569855, 1.534567952156067, 3.3427071571350098, 0.4648111164569855, 1.534567952156067, 3.3427071571350098, -1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0, 0.027751604095101357, 'S', 288230398217945095, 1152921504606846976, 65793, 0, 2000, 0.16704683354563044, 1, 5261)  ... displaying 10 of 50000 total bound parameter sets ...  (9999, 489918, '1505p287', 73, 'EXP ', 150.62860107421875, 28.846633911132812, 100000000.0, 100000000.0, 33.038124084472656, 83.62114715576172, 151.85191345214844, 156.5404815673828, 105.21444702148438, 1438.599853515625, 329.5641784667969, 62.79716110229492, 0.753903865814209, 0.2988942861557007, 0.9454969167709351, 0.9629511833190918, 0.9789336919784546, 0.9967966079711914, 0.998031497001648, 2, 2, 2, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 52.48074722290039, 7.726805686950684, 1.8706821203231812, 57.54399490356445, 13.182567596435547, 2.5118863582611084, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.448697805404663, 234034.375, -0.007581037934869528, 1.389766079226239e+23, 0.02925814688205719, 935237.875, 2.263221502304077, 5.815425395965576, 10.74710464477539, 2.263221502304077, 5.815425395965576, 10.74710464477539, -1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0, 0.018932709470391273, 'S', 288230398314414153, 1152921504606846976, 131586, 0, 2100, 0.20038828049405466, 1, 5284), (9999, 491182, '1507p290', 74, 'REX ', 150.66876220703125, 28.931087493896484, 100000000.0, 100000000.0, 3.9731950759887695, 10.705737113952637, 17.48809051513672, 28.678274154663086, 22.746755599975586, 1438.599853515625, 329.5641784667969, 62.79716110229492, 0.7542377710342407, 0.2990230619907379, 0.9514783024787903, 0.9670504927635193, 0.9812817573547363, 0.99715656042099, 0.998252809047699, 2, 2, 2, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 52.48074722290039, 7.726805686950684, 1.8706821203231812, 57.54399490356445, 13.182567596435547, 2.5118863582611084, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.2529327869415283, 18379.90625, 0.0, 0.0, 0.0, 0.0, 0.7542810440063477, 2.0925073623657227, 3.5339815616607666, 0.7542810440063477, 2.0925073623657227, 3.5339815616607666, -1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0, 0.016802361235022545, 'S', 288230398314414154, 1152921504606846976, 65793, 0, 2000, 0.49559071659276355, 1, 5284))] (Background on this error at: http://sqlalche.me/e/gkpj)

@weaverba137
Copy link
Member Author

@sbailey, you need to look at the redshift-database tutorial to see how to change the loading sequence.

@sbailey
Copy link
Contributor

sbailey commented Nov 13, 2018

@weaverba137 got it. For the record, this worked. I'll merge now and update the minitest notebook.

from argparse import Namespace
from desispec.database.redshift import (setup_db, dbSession, load_file, ObsList, Target, Truth, ZCat, FiberAssign,
                                        load_fiberassign, update_truth)
options = Namespace(overwrite=True, dbfile=os.path.join(basedir, 'minitest.db'), hostname=None, maxrows=0,
                    chunksize=50000, schema=None, username=None, verbose=False, datapath=basedir)
# We'll be using a SQLite database, ignore the return value of setup_db
postgresql = setup_db(options)

print('--- Loading exposure list')
load_file(expfile, ObsList, hdu='EXPOSURES', expand={'PASS': 'passnum'})

print('--- Loading truth tables')
load_file(os.path.join(targetdir, 'truth.fits'), Truth, hdu='TRUTH')
for h in ('BGS', 'ELG', 'LRG', 'QSO', 'STAR', 'WD'):
    update_truth(os.path.join(targetdir, 'truth.fits'), 'TRUTH_' + h)

print('--- Loading targets')
load_file(os.path.join(targetdir, 'targets.fits'), Target, hdu='TARGETS',
          expand={'DCHISQ': ('dchisq_psf', 'dchisq_rex', 'dchisq_dev', 'dchisq_exp', 'dchisq_comp',)})

print('--- loading redshift catalog')
load_file(os.path.join(reduxdir, 'zcatalog-mini.fits'), ZCat, hdu='ZCATALOG',
          expand={'COEFF': ('coeff_0', 'coeff_1', 'coeff_2', 'coeff_3', 'coeff_4',
                            'coeff_5', 'coeff_6', 'coeff_7', 'coeff_8', 'coeff_9',)},
          rowfilter=lambda x: ((x['TARGETID'] != 0) & (x['TARGETID'] != -1)))

print('--- loading fiber assignments')
load_fiberassign(fibassigndir)

print('--- done')

@sbailey sbailey merged commit 50ff10a into master Nov 13, 2018
@weaverba137 weaverba137 deleted the workaround-bad-flux branch November 13, 2018 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants