{"action":"created","issue":{"url":"https://api.github.com/repos/lsst/sims_catUtils/issues/3","labels_url":"https://api.github.com/repos/lsst/sims_catUtils/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/lsst/sims_catUtils/issues/3/comments","events_url":"https://api.github.com/repos/lsst/sims_catUtils/issues/3/events","html_url":"https://github.com/lsst/sims_catUtils/issues/3","id":75382005,"number":3,"title":"Quick Question Regarding OpSim3_61DBObject Queries","user":{"login":"JPGlaser","id":11276213,"avatar_url":"https://avatars.githubusercontent.com/u/11276213?v=3","gravatar_id":"","url":"https://api.github.com/users/JPGlaser","html_url":"https://github.com/JPGlaser","followers_url":"https://api.github.com/users/JPGlaser/followers","following_url":"https://api.github.com/users/JPGlaser/following{/other_user}","gists_url":"https://api.github.com/users/JPGlaser/gists{/gist_id}","starred_url":"https://api.github.com/users/JPGlaser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JPGlaser/subscriptions","organizations_url":"https://api.github.com/users/JPGlaser/orgs","repos_url":"https://api.github.com/users/JPGlaser/repos","events_url":"https://api.github.com/users/JPGlaser/events{/privacy}","received_events_url":"https://api.github.com/users/JPGlaser/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":33,"created_at":"2015-05-11T22:35:12Z","updated_at":"2015-07-20T19:40:00Z","closed_at":null,"body":"Hello Everyone (@danielsf & @SimonKrughoff),\r\n\r\nI have been working with the ObSim, CatSim, and PhoSims lately in an effort to generate test data for our AGN survey group here at Drexel. As such, I am currently investigating the ObSim integration in master-gce0eaba1be version of sims_catUtils.\r\n\r\nEssentially, I'd like to do a double query of the ObSim 3.61 database, first filtering out airmass values that aren't in a specified range and then filtering out pointings that don't use a specific set of filters (say the r & g filters). Is this currently possible? From looking into the python classes, it seems that obsMD.executeConstrainedQuery only accepts a singular constraint ...\r\n\r\nIn addition, can someone clear up the exact nature of the output of these queries? It seems that it basically returns a trimmed array of matching ObsHistID's and so my script (attached below) would generate a catalog for the first matching pointing. Is this a correct understanding of the data structure?\r\n\r\nThanks in advance!\r\n\r\n~ Joe G.\r\n\r\n``` python\r\n\"\"\"\r\nThis script creates an instance catalog of Galaxies and AGN for use in PhoSim,\r\nsubject to certain pre-defined constraints.\r\n\r\n\"\"\"\r\n\r\nfrom __future__ import with_statement\r\nfrom lsst.sims.catalogs.measures.instance import InstanceCatalog\r\nfrom lsst.sims.catalogs.generation.db import ObservationMetaData, CatalogDBObject\r\nfrom lsst.sims.catUtils.baseCatalogModels import OpSim3_61DBObject\r\nfrom lsst.sims.catUtils.exampleCatalogDefinitions.phoSimCatalogExamples import \\\r\n        PhoSimCatalogPoint, PhoSimCatalogSersic2D, PhoSimCatalogZPoint\r\nfrom lsst.sims.catUtils.baseCatalogModels import *\r\n\r\n# Define File Name\r\nfileName = \"InstCat_GalAGN_r2deg.txt\"\r\n\r\n# Define Desired Observing Parameters\r\nra = 1.5\r\ndec = -1.5\r\ntol = 2.0\r\nradiusDeg = 1.0\r\n\r\n# Loads in the OpSim 3.61 database\r\nobsMD = OpSim3_61DBObject()\r\n\r\n# Prepares to find the Spatial Bounds of the night sky.\r\nskyBounds = SpatialBounds.getSpatialBounds('box', ra, dec, tol)\r\n\r\n# Sets the SQL query constraint, in this case a specific airmass.\r\nqueryConstraint = \"airmass = 1.1\"\r\n\r\n# Generates the constrained query on the Opsim 3.61 database.\r\nquery = obsMD.executeConstrainedQuery(skyBounds, constraint=queryConstraint)\r\n    \r\n# Converts the query into observation meta data for use in a catalog.\r\nobsMetaData = obsMD.getObservationMetaData(query['Opsim_obshistid'][0],\r\n radiusDeg, makeCircBounds=True)\r\n\r\n# Load in Galaxy Bulge objects, create their 2D sersic profiles, and append them\r\n# to our output file subject to our observational meta-data.\r\ngals = CatalogDBObject.from_objid('galaxyBulge')\r\ngalaxy_phoSim = PhoSimCatalogSersic2D(gals, obs_metadata=obs_metadata)\r\ngalaxy_phoSim.write_catalog(\"phoSim_example.txt\",write_mode='a',write_header=True,chunk_size=20000)\r\n\r\n# Load in Galaxy Disk objects, create their 2D sersic profiles, and append them\r\n# to our output file subject to our observational meta-data.\r\ngals = CatalogDBObject.from_objid('galaxyDisk')\r\ngalaxy_phoSim = PhoSimCatalogSersic2D(gals, obs_metadata=obs_metadata)\r\ngalaxy_phoSim.write_catalog(\"phoSim_example.txt\",write_mode='a',write_header=False,chunk_size=20000)\r\n\r\n# Load in Galaxy AGN objects, create their extragalatic point source profiles, and\r\n# append them to our output file subject to our observational meta-data.\r\ngals = CatalogDBObject.from_objid('galaxyAgn')\r\ngalaxy_phoSim = PhoSimCatalogZPoint(gals, obs_metadata=obs_metadata)\r\ngalaxy_phoSim.write_catalog(\"phoSim_example.txt\",write_mode='a',write_header=False,chunk_size=20000)\r\n```"},"comment":{"url":"https://api.github.com/repos/lsst/sims_catUtils/issues/comments/123002323","html_url":"https://github.com/lsst/sims_catUtils/issues/3#issuecomment-123002323","issue_url":"https://api.github.com/repos/lsst/sims_catUtils/issues/3","id":123002323,"user":{"login":"danielsf","id":1682854,"avatar_url":"https://avatars.githubusercontent.com/u/1682854?v=3","gravatar_id":"","url":"https://api.github.com/users/danielsf","html_url":"https://github.com/danielsf","followers_url":"https://api.github.com/users/danielsf/followers","following_url":"https://api.github.com/users/danielsf/following{/other_user}","gists_url":"https://api.github.com/users/danielsf/gists{/gist_id}","starred_url":"https://api.github.com/users/danielsf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielsf/subscriptions","organizations_url":"https://api.github.com/users/danielsf/orgs","repos_url":"https://api.github.com/users/danielsf/repos","events_url":"https://api.github.com/users/danielsf/events{/privacy}","received_events_url":"https://api.github.com/users/danielsf/received_events","type":"User","site_admin":false},"created_at":"2015-07-20T19:40:00Z","updated_at":"2015-07-20T19:40:00Z","body":"I don't think that is possible.  Most of the ways to impose constraints on the contents of catalogs happen at the SQL level, and variable magnitudes are not stored on the database.\r\n\r\nOne thing you could do (this will not save you any time, but I do not think it will slow you down) is define a column \"filtered_magnitude\".  The getter for this could look something like\r\n\r\n```\r\ndef get_filtered_magnitude(self):\r\n    raw_magnitude = self.column_by_name('uAgn')\r\n    some code that converts all magntiudes in raw_magnitude gerater than 24 to None\r\n    return raw_magnitude\r\n```\r\n\r\nand then have cannot_be_null = ['filtered_magnitude']"}}