diff --git a/docs/source/database.rst b/docs/source/database.rst index 28c96b7a3..0469952af 100644 --- a/docs/source/database.rst +++ b/docs/source/database.rst @@ -12,4 +12,4 @@ reset_database.py ----------------- .. automodule:: jwql.database.reset_database :members: - :undoc-members: \ No newline at end of file + :undoc-members: diff --git a/docs/source/website.rst b/docs/source/website.rst index 6f0da9b31..3825fa2ae 100644 --- a/docs/source/website.rst +++ b/docs/source/website.rst @@ -44,6 +44,12 @@ monitor_views.py :members: :undoc-members: +monitor_models +-------------- +.. automodule:: jwql.website.apps.jwql.monitor_models.common + :members: + :undoc-members: + settings.py ----------- .. automodule:: jwql.website.jwql_proj.settings @@ -60,4 +66,4 @@ views.py -------- .. automodule:: jwql.website.apps.jwql.views :members: - :undoc-members: \ No newline at end of file + :undoc-members: diff --git a/jwql/instrument_monitors/common_monitors/readnoise_monitor.py b/jwql/instrument_monitors/common_monitors/readnoise_monitor.py index 10fc82237..9401ce3b4 100755 --- a/jwql/instrument_monitors/common_monitors/readnoise_monitor.py +++ b/jwql/instrument_monitors/common_monitors/readnoise_monitor.py @@ -47,14 +47,26 @@ import matplotlib.pyplot as plt # noqa: E348 (comparison to true) import numpy as np # noqa: E348 (comparison to true) from pysiaf import Siaf # noqa: E348 (comparison to true) -from sqlalchemy.sql.expression import and_ # noqa: E348 (comparison to true) - -from jwql.database.database_interface import FGSReadnoiseQueryHistory, FGSReadnoiseStats # noqa: E348 (comparison to true) -from jwql.database.database_interface import MIRIReadnoiseQueryHistory, MIRIReadnoiseStats # noqa: E348 (comparison to true) -from jwql.database.database_interface import NIRCamReadnoiseQueryHistory, NIRCamReadnoiseStats # noqa: E348 (comparison to true) -from jwql.database.database_interface import NIRISSReadnoiseQueryHistory, NIRISSReadnoiseStats # noqa: E348 (comparison to true) -from jwql.database.database_interface import NIRSpecReadnoiseQueryHistory, NIRSpecReadnoiseStats # noqa: E348 (comparison to true) -from jwql.database.database_interface import session, engine # noqa: E348 (comparison to true) + +# astroquery.mast import that depends on value of auth_mast +# this import has to be made before any other import of astroquery.mast +ON_GITHUB_ACTIONS = '/home/runner' in os.path.expanduser('~') or '/Users/runner' in os.path.expanduser('~') + +# Determine if the code is being run as part of a Readthedocs build +ON_READTHEDOCS = False +if 'READTHEDOCS' in os.environ: # pragma: no cover + ON_READTHEDOCS = os.environ['READTHEDOCS'] + +if not ON_GITHUB_ACTIONS and not ON_READTHEDOCS: + # Need to set up django apps before we can access the models + import django # noqa: E402 (module level import not at top of file) + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "jwql.website.jwql_proj.settings") + django.setup() + + # Import * is okay here because this module specifically only contains database models + # for this monitor + from jwql.website.apps.jwql.monitor_models.readnoise import * # noqa: E402 (module level import not at top of file) + from jwql.shared_tasks.shared_tasks import only_one, run_pipeline, run_parallel_pipeline # noqa: E348 (comparison to true) from jwql.instrument_monitors import pipeline_tools # noqa: E348 (comparison to true) from jwql.utils import instrument_properties, monitor_utils # noqa: E348 (comparison to true) @@ -149,17 +161,8 @@ def file_exists_in_database(self, filename): file_exists : bool ``True`` if filename exists in the readnoise stats database. """ - - query = session.query(self.stats_table) - results = query.filter(self.stats_table.uncal_filename == filename).all() - - if len(results) != 0: - file_exists = True - else: - file_exists = False - - session.close() - return file_exists + results = self.stats_table.objects.filter(uncal_filename__iexact=filename).values() + return (len(results) != 0) def get_amp_stats(self, image, amps): """Calculates the sigma-clipped mean and stddev, as well as the @@ -385,17 +388,18 @@ def most_recent_search(self): Date (in MJD) of the ending range of the previous MAST query where the readnoise monitor was run. """ - - query = session.query(self.query_table).filter(and_(self.query_table.aperture == self.aperture, - self.query_table.run_monitor == True)).order_by(self.query_table.end_time_mjd).all() # noqa: E712 (comparison to True) + filter_kwargs = { + 'aperture__iexact': self.aperture, + 'run_monitor__exact': True + } + query = self.query_table.objects.filter(**filter_kwargs).order_by("-end_time_mjd").all() if len(query) == 0: query_result = 59607.0 # a.k.a. Jan 28, 2022 == First JWST images (MIRI) logging.info(('\tNo query history for {}. Beginning search date will be set to {}.'.format(self.aperture, query_result))) else: - query_result = query[-1].end_time_mjd + query_result = query[0].end_time_mjd - session.close() return query_result def process(self, file_list): @@ -512,24 +516,24 @@ def process(self, file_list): 'readnoise_filename': os.path.basename(readnoise_outfile), 'full_image_mean': float(full_image_mean), 'full_image_stddev': float(full_image_stddev), - 'full_image_n': full_image_n.astype(float), - 'full_image_bin_centers': full_image_bin_centers.astype(float), + 'full_image_n': list(full_image_n.astype(float)), + 'full_image_bin_centers': list(full_image_bin_centers.astype(float)), 'readnoise_diff_image': os.path.basename(readnoise_diff_png), 'diff_image_mean': float(diff_image_mean), 'diff_image_stddev': float(diff_image_stddev), - 'diff_image_n': diff_image_n.astype(float), - 'diff_image_bin_centers': diff_image_bin_centers.astype(float), + 'diff_image_n': list(diff_image_n.astype(float)), + 'diff_image_bin_centers': list(diff_image_bin_centers.astype(float)), 'entry_date': datetime.datetime.now() } for key in amp_stats.keys(): if isinstance(amp_stats[key], (int, float)): readnoise_db_entry[key] = float(amp_stats[key]) else: - readnoise_db_entry[key] = amp_stats[key].astype(float) + readnoise_db_entry[key] = list(amp_stats[key].astype(float)) # Add this new entry to the readnoise database table - with engine.begin() as connection: - connection.execute(self.stats_table.__table__.insert(), readnoise_db_entry) + entry = self.stats_table(**readnoise_db_entry) + entry.save() logging.info('\tNew entry added to readnoise database table') # Remove the raw and calibrated files to save memory space @@ -658,8 +662,8 @@ def run(self): 'files_found': len(new_files), 'run_monitor': monitor_run, 'entry_date': datetime.datetime.now()} - with engine.begin() as connection: - connection.execute(self.query_table.__table__.insert(), new_entry) + stats_entry = self.query_table(**new_entry) + stats_entry.save() logging.info('\tUpdated the query history table') logging.info('Readnoise Monitor completed successfully.') diff --git a/jwql/tests/test_bad_pixel_monitor.py b/jwql/tests/test_bad_pixel_monitor.py index 6446570b6..4bc5c9d92 100644 --- a/jwql/tests/test_bad_pixel_monitor.py +++ b/jwql/tests/test_bad_pixel_monitor.py @@ -163,6 +163,7 @@ def test_get_possible_apertures(instrument, expected_list): assert ap_list == expected_list +@pytest.mark.skipif(ON_GITHUB_ACTIONS, reason='Requires access to central storage.') def test_identify_tables(): """Be sure the correct database tables are identified """ diff --git a/jwql/tests/test_bias_monitor.py b/jwql/tests/test_bias_monitor.py index 8becc2558..6e73a0c01 100644 --- a/jwql/tests/test_bias_monitor.py +++ b/jwql/tests/test_bias_monitor.py @@ -65,7 +65,7 @@ def test_extract_zeroth_group(): # Extract the zeroth group using the bias monitor # nosec comment added to ignore bandit security check output_filename = monitor.extract_zeroth_group(filename) - os.chmod(output_filename, 508) # nosec + os.chmod(output_filename, 508) # nosec data = fits.getdata(output_filename, 'SCI')[0, 0, :, :] # Remove the copied test file and its zeroth group file so this test can be properly repeated @@ -96,6 +96,7 @@ def test_get_amp_medians(): assert amp_medians == amp_medians_truth +@pytest.mark.skipif(ON_GITHUB_ACTIONS, reason='Requires access to central storage.') def test_identify_tables(): """Be sure the correct database tables are identified""" diff --git a/jwql/tests/test_readnoise_monitor.py b/jwql/tests/test_readnoise_monitor.py index d00607dd5..f27a193ba 100644 --- a/jwql/tests/test_readnoise_monitor.py +++ b/jwql/tests/test_readnoise_monitor.py @@ -92,6 +92,7 @@ def test_get_metadata(): assert monitor.expstart == '2016-01-18T04:35:14.523' +@pytest.mark.skipif(ON_GITHUB_ACTIONS, reason='Requires access to central storage.') def test_identify_tables(): """Be sure the correct database tables are identified""" diff --git a/jwql/website/apps/jwql/monitor_models/bad_pixel.py b/jwql/website/apps/jwql/monitor_models/bad_pixel.py index d99c9a502..151aa39ff 100644 --- a/jwql/website/apps/jwql/monitor_models/bad_pixel.py +++ b/jwql/website/apps/jwql/monitor_models/bad_pixel.py @@ -27,9 +27,10 @@ # This is an auto-generated Django model module. # Feel free to rename the models, but don't rename db_table values or field names. from django.db import models +from django.contrib.postgres.fields import ArrayField -class FgsBadPixelQueryHistory(models.Model): +class FGSBadPixelQueryHistory(models.Model): entry_date = models.DateTimeField(unique=True) instrument = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) @@ -50,11 +51,11 @@ class Meta: app_label = 'monitors' -class FgsBadPixelStats(models.Model): +class FGSBadPixelStats(models.Model): entry_date = models.DateTimeField(unique=True) detector = models.CharField(blank=True, null=True) - x_coord = models.TextField(blank=True, null=True) # This field type is a guess. - y_coord = models.TextField(blank=True, null=True) # This field type is a guess. + x_coord = ArrayField(models.IntegerField()) + y_coord = ArrayField(models.IntegerField()) type = models.CharField(blank=True, null=True) source_files = models.TextField(blank=True, null=True) # This field type is a guess. obs_start_time = models.DateTimeField(blank=True, null=True) @@ -69,7 +70,7 @@ class Meta: app_label = 'monitors' -class MiriBadPixelQueryHistory(models.Model): +class MIRIBadPixelQueryHistory(models.Model): entry_date = models.DateTimeField(unique=True) instrument = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) @@ -90,11 +91,11 @@ class Meta: app_label = 'monitors' -class MiriBadPixelStats(models.Model): +class MIRIBadPixelStats(models.Model): entry_date = models.DateTimeField(unique=True) detector = models.CharField(blank=True, null=True) - x_coord = models.TextField(blank=True, null=True) # This field type is a guess. - y_coord = models.TextField(blank=True, null=True) # This field type is a guess. + x_coord = ArrayField(models.IntegerField()) + y_coord = ArrayField(models.IntegerField()) type = models.CharField(blank=True, null=True) source_files = models.TextField(blank=True, null=True) # This field type is a guess. obs_start_time = models.DateTimeField(blank=True, null=True) @@ -109,7 +110,7 @@ class Meta: app_label = 'monitors' -class NircamBadPixelQueryHistory(models.Model): +class NIRCamBadPixelQueryHistory(models.Model): entry_date = models.DateTimeField(unique=True) instrument = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) @@ -130,11 +131,11 @@ class Meta: app_label = 'monitors' -class NircamBadPixelStats(models.Model): +class NIRCamBadPixelStats(models.Model): entry_date = models.DateTimeField(unique=True) detector = models.CharField(blank=True, null=True) - x_coord = models.TextField(blank=True, null=True) # This field type is a guess. - y_coord = models.TextField(blank=True, null=True) # This field type is a guess. + x_coord = ArrayField(models.IntegerField()) + y_coord = ArrayField(models.IntegerField()) type = models.CharField(blank=True, null=True) source_files = models.TextField(blank=True, null=True) # This field type is a guess. obs_start_time = models.DateTimeField(blank=True, null=True) @@ -149,7 +150,7 @@ class Meta: app_label = 'monitors' -class NirissBadPixelQueryHistory(models.Model): +class NIRISSBadPixelQueryHistory(models.Model): entry_date = models.DateTimeField(unique=True) instrument = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) @@ -170,11 +171,11 @@ class Meta: app_label = 'monitors' -class NirissBadPixelStats(models.Model): +class NIRISSBadPixelStats(models.Model): entry_date = models.DateTimeField(unique=True) detector = models.CharField(blank=True, null=True) - x_coord = models.TextField(blank=True, null=True) # This field type is a guess. - y_coord = models.TextField(blank=True, null=True) # This field type is a guess. + x_coord = ArrayField(models.IntegerField()) + y_coord = ArrayField(models.IntegerField()) type = models.CharField(blank=True, null=True) source_files = models.TextField(blank=True, null=True) # This field type is a guess. obs_start_time = models.DateTimeField(blank=True, null=True) @@ -189,7 +190,7 @@ class Meta: app_label = 'monitors' -class NirspecBadPixelQueryHistory(models.Model): +class NIRSpecBadPixelQueryHistory(models.Model): entry_date = models.DateTimeField(unique=True) instrument = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) @@ -210,11 +211,11 @@ class Meta: app_label = 'monitors' -class NirspecBadPixelStats(models.Model): +class NIRSpecBadPixelStats(models.Model): entry_date = models.DateTimeField(unique=True) detector = models.CharField(blank=True, null=True) - x_coord = models.TextField(blank=True, null=True) # This field type is a guess. - y_coord = models.TextField(blank=True, null=True) # This field type is a guess. + x_coord = ArrayField(models.IntegerField()) + y_coord = ArrayField(models.IntegerField()) type = models.CharField(blank=True, null=True) source_files = models.TextField(blank=True, null=True) # This field type is a guess. obs_start_time = models.DateTimeField(blank=True, null=True) diff --git a/jwql/website/apps/jwql/monitor_models/bias.py b/jwql/website/apps/jwql/monitor_models/bias.py index 9882382e9..306ef3b29 100644 --- a/jwql/website/apps/jwql/monitor_models/bias.py +++ b/jwql/website/apps/jwql/monitor_models/bias.py @@ -27,9 +27,10 @@ # This is an auto-generated Django model module. # Feel free to rename the models, but don't rename db_table values or field names. from django.db import models +from django.contrib.postgres.fields import ArrayField -class NircamBiasQueryHistory(models.Model): +class NIRCamBiasQueryHistory(models.Model): instrument = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) start_time_mjd = models.FloatField(blank=True, null=True) @@ -46,7 +47,7 @@ class Meta: app_label = 'monitors' -class NircamBiasStats(models.Model): +class NIRCamBiasStats(models.Model): aperture = models.CharField(blank=True, null=True) uncal_filename = models.CharField(blank=True, null=True) cal_filename = models.CharField(blank=True, null=True) @@ -55,10 +56,10 @@ class NircamBiasStats(models.Model): mean = models.FloatField(blank=True, null=True) median = models.FloatField(blank=True, null=True) stddev = models.FloatField(blank=True, null=True) - collapsed_rows = models.TextField(blank=True, null=True) # This field type is a guess. - collapsed_columns = models.TextField(blank=True, null=True) # This field type is a guess. - counts = models.TextField(blank=True, null=True) # This field type is a guess. - bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + collapsed_rows = ArrayField(models.FloatField()) + collapsed_columns = ArrayField(models.FloatField()) + counts = ArrayField(models.FloatField()) + bin_centers = ArrayField(models.FloatField()) amp1_even_med = models.FloatField(blank=True, null=True) amp1_odd_med = models.FloatField(blank=True, null=True) amp2_even_med = models.FloatField(blank=True, null=True) @@ -76,7 +77,7 @@ class Meta: app_label = 'monitors' -class NirissBiasQueryHistory(models.Model): +class NIRISSBiasQueryHistory(models.Model): instrument = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) start_time_mjd = models.FloatField(blank=True, null=True) @@ -93,7 +94,7 @@ class Meta: app_label = 'monitors' -class NirissBiasStats(models.Model): +class NIRISSBiasStats(models.Model): aperture = models.CharField(blank=True, null=True) uncal_filename = models.CharField(blank=True, null=True) cal_filename = models.CharField(blank=True, null=True) @@ -102,10 +103,10 @@ class NirissBiasStats(models.Model): mean = models.FloatField(blank=True, null=True) median = models.FloatField(blank=True, null=True) stddev = models.FloatField(blank=True, null=True) - collapsed_rows = models.TextField(blank=True, null=True) # This field type is a guess. - collapsed_columns = models.TextField(blank=True, null=True) # This field type is a guess. - counts = models.TextField(blank=True, null=True) # This field type is a guess. - bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + collapsed_rows = ArrayField(models.FloatField()) + collapsed_columns = ArrayField(models.FloatField()) + counts = ArrayField(models.FloatField()) + bin_centers = ArrayField(models.FloatField()) amp1_even_med = models.FloatField(blank=True, null=True) amp1_odd_med = models.FloatField(blank=True, null=True) amp2_even_med = models.FloatField(blank=True, null=True) @@ -123,7 +124,7 @@ class Meta: app_label = 'monitors' -class NirspecBiasQueryHistory(models.Model): +class NIRSpecBiasQueryHistory(models.Model): instrument = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) start_time_mjd = models.FloatField(blank=True, null=True) @@ -140,7 +141,7 @@ class Meta: app_label = 'monitors' -class NirspecBiasStats(models.Model): +class NIRSpecBiasStats(models.Model): aperture = models.CharField(blank=True, null=True) uncal_filename = models.CharField(blank=True, null=True) cal_filename = models.CharField(blank=True, null=True) @@ -149,10 +150,10 @@ class NirspecBiasStats(models.Model): mean = models.FloatField(blank=True, null=True) median = models.FloatField(blank=True, null=True) stddev = models.FloatField(blank=True, null=True) - collapsed_rows = models.TextField(blank=True, null=True) # This field type is a guess. - collapsed_columns = models.TextField(blank=True, null=True) # This field type is a guess. - counts = models.TextField(blank=True, null=True) # This field type is a guess. - bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + collapsed_rows = ArrayField(models.FloatField()) + collapsed_columns = ArrayField(models.FloatField()) + counts = ArrayField(models.FloatField()) + bin_centers = ArrayField(models.FloatField()) amp1_even_med = models.FloatField(blank=True, null=True) amp1_odd_med = models.FloatField(blank=True, null=True) amp2_even_med = models.FloatField(blank=True, null=True) diff --git a/jwql/website/apps/jwql/monitor_models/claw.py b/jwql/website/apps/jwql/monitor_models/claw.py index 2bfab4176..90ea407d4 100644 --- a/jwql/website/apps/jwql/monitor_models/claw.py +++ b/jwql/website/apps/jwql/monitor_models/claw.py @@ -27,9 +27,10 @@ # This is an auto-generated Django model module. # Feel free to rename the models, but don't rename db_table values or field names. from django.db import models +from django.contrib.postgres.fields import ArrayField -class NircamClawQueryHistory(models.Model): +class NIRCamClawQueryHistory(models.Model): entry_date = models.DateTimeField(blank=True, null=True) instrument = models.CharField(blank=True, null=True) start_time_mjd = models.FloatField(blank=True, null=True) @@ -43,7 +44,7 @@ class Meta: app_label = 'monitors' -class NircamClawStats(models.Model): +class NIRCamClawStats(models.Model): entry_date = models.DateTimeField(blank=True, null=True) filename = models.CharField(blank=True, null=True) proposal = models.CharField(blank=True, null=True) diff --git a/jwql/website/apps/jwql/monitor_models/common.py b/jwql/website/apps/jwql/monitor_models/common.py index 98668951b..c521e5631 100644 --- a/jwql/website/apps/jwql/monitor_models/common.py +++ b/jwql/website/apps/jwql/monitor_models/common.py @@ -8,6 +8,141 @@ a data table. This module defines models that are used to store data related to the JWQL monitors. +Usage +----- + +JWQL uses the django database models for creating tables, updating table fields, adding +new data to tables, and retrieving data from tables. For instrument monitors, in particular, +there are a number of issues that may be relevant. + +In general, django model documentation can be found +`on the django website `_. +Unfortunately, finding a particular bit of documentation in django can be a challenge, so +a few quick-reference notes are provided below. + +Retrieving Data +--------------- + +Django retrieves data directly from its model tables. So, for example, if you want to +select data from the `MIRIMyMonitorStats` table, you must first import the relevant +object: + +.. code-block:: python + + from jwql.website.apps.jwql.monitor_models.my_monitor import MIRIMyMonitorStats + +Then, you would access the database contents via the `objects` member of the class. For +example, to search the `MIRIMyMonitorStats` table for all entries matching a given +aperture, and to sort them with the most recent date at the top, you might do a query like +the following: + +.. code-block:: python + + aperture = "my_miri_aperture" + + records = MIRIMyMonitorStats.objects.filter(aperture__iexact=aperture).order_by("-mjd_end").all() + +In the above code, + +* The `filter()` function selects matching records from the full table. You can use + multiple filter statements, or a single filter function with multiple filters. `filter()` + statements are always combined with an implicit AND. +* If you have a long filter statement and want to separate it from the query statement, + you can create a dictionary and add it in with the `**` prepended. The dictionary + equivalent to the above would be `{'aperture__iexact': aperture}` +* The text before the double underscore is a field name, and the text afterwards describes + the type of comparison. `iexact` indicates "case-insensitive exact match". You can also + use a variety of standard SQL comparisons (`like`, `startswith`, `gte`, etc.) +* If you want to get only records that *don't* match a pattern, then you can use the + `exclude()` function, which otherwise operates exactly the same as `filter()`. +* In the `order_by()` function, the `-` at the start is used to reverse the sort order, + and the `mjd_end` is the name of the field to be sorted by. +* The `all()` statement indicates that you want all the values returned. `get()` returns + a single value and can be iterated on, `first()` returns only the first value, etc. + +As an example of multiple filters, the code below: + +.. code-block:: python + + records = MIRIMyMonitorStats.objects.filter(aperture__iexact=ap, mjd_end__gte=60000) + + filters = { + "aperture__iexact": ap, + "mjd_end__gte": 60000 + } + records = MIRIMyMonitorStats.objects.filter(**filters) + +show two different ways of combining a search for a particular aperture *and* only data +taken more recently than MJD=60000. + +Note that django executes queries lazily, meaning that it will only actually *do* the +query when it needs the results. The above statement, for example, will not actually +run the query. Instead, it will be run when you operate on it, such as + +* Getting the length of the result with e.g. `len(records)` +* Printing out any of the results +* Asking for the value of one of the fields (e.g. `records[3].aperture`) + +Q Objects +========= + +In order to make more complex queries, Django supplies "Q Objects", which are essentially +encapsulated filters which can be combined using logical operators. For more on this, see +`the django Q object documentation `_. + +Storing Data +------------ + +Django also uses the model tables (and objects) directly for storing new data. For example, +if you have a monitor table defined as below: + +.. code-block:: python + + from django.db import models + from django.contrib.postgres.fields import ArrayField + + class NIRISSMyMonitorStats(models.Model): + aperture = models.CharField(blank=True, null=True) + mean = models.FloatField(blank=True, null=True) + median = models.FloatField(blank=True, null=True) + stddev = models.FloatField(blank=True, null=True) + counts = ArrayField(models.FloatField()) + entry_date = models.DateTimeField(blank=True, null=True) + + class Meta: + managed = True + db_table = 'niriss_my_monitor_stats' + unique_together = (('id', 'entry_date'),) + app_label = 'monitors' + +then you would create a new entry as follows: + +.. code-block:: python + + values = { + "aperture": "my_aperture", + "mean": float(mean), + "median": float(median), + "stddev": float(stddev), + "counts": list(counts.astype(float)), + "entry_date": datetime.datetime.now() + } + + entry = NIRISSMyMonitorStats(**values) + entry.save() + +There are (as usual) a few things to note above: + +* Django doesn't have a built-in array data type, so you need to import it from the + database-compatibility layers. The ArrayField takes, as a required argument, the type + of data that makes up the array. +* In the Meta sub-class of the monitor class, the `app_label = 'monitors'` statement is + required so that django knows that the model should be stored in the monitors table. +* The `float()` casts are required because the database interface doesn't understand + numpy data types. +* The `list()` cast is required because the database interface doesn't understand the + numpy `ndarray` data type + Authors ------- - Brian York @@ -27,6 +162,7 @@ # This is an auto-generated Django model module. # Feel free to rename the models, but don't rename db_table values or field names. from django.db import models +from django.contrib.postgres.fields import ArrayField class MonitorRouter: diff --git a/jwql/website/apps/jwql/monitor_models/cosmic_ray.py b/jwql/website/apps/jwql/monitor_models/cosmic_ray.py index ecb073403..f9084aa06 100644 --- a/jwql/website/apps/jwql/monitor_models/cosmic_ray.py +++ b/jwql/website/apps/jwql/monitor_models/cosmic_ray.py @@ -27,9 +27,10 @@ # This is an auto-generated Django model module. # Feel free to rename the models, but don't rename db_table values or field names. from django.db import models +from django.contrib.postgres.fields import ArrayField -class FgsCosmicRayQueryHistory(models.Model): +class FGSCosmicRayQueryHistory(models.Model): entry_date = models.DateTimeField(unique=True) instrument = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) @@ -45,7 +46,7 @@ class Meta: app_label = 'monitors' -class FgsCosmicRayStats(models.Model): +class FGSCosmicRayStats(models.Model): entry_date = models.DateTimeField(unique=True) aperture = models.CharField(blank=True, null=True) source_file = models.CharField(blank=True, null=True) @@ -63,7 +64,7 @@ class Meta: app_label = 'monitors' -class MiriCosmicRayQueryHistory(models.Model): +class MIRICosmicRayQueryHistory(models.Model): entry_date = models.DateTimeField(unique=True) instrument = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) @@ -79,7 +80,7 @@ class Meta: app_label = 'monitors' -class MiriCosmicRayStats(models.Model): +class MIRICosmicRayStats(models.Model): entry_date = models.DateTimeField(unique=True) aperture = models.CharField(blank=True, null=True) source_file = models.CharField(blank=True, null=True) @@ -97,7 +98,7 @@ class Meta: app_label = 'monitors' -class NircamCosmicRayQueryHistory(models.Model): +class NIRCamCosmicRayQueryHistory(models.Model): entry_date = models.DateTimeField(unique=True) instrument = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) @@ -113,7 +114,7 @@ class Meta: app_label = 'monitors' -class NircamCosmicRayStats(models.Model): +class NIRCamCosmicRayStats(models.Model): entry_date = models.DateTimeField(unique=True) aperture = models.CharField(blank=True, null=True) source_file = models.CharField(blank=True, null=True) @@ -131,7 +132,7 @@ class Meta: app_label = 'monitors' -class NirissCosmicRayQueryHistory(models.Model): +class NIRISSCosmicRayQueryHistory(models.Model): entry_date = models.DateTimeField(unique=True) instrument = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) @@ -147,7 +148,7 @@ class Meta: app_label = 'monitors' -class NirissCosmicRayStats(models.Model): +class NIRISSCosmicRayStats(models.Model): entry_date = models.DateTimeField(unique=True) aperture = models.CharField(blank=True, null=True) source_file = models.CharField(blank=True, null=True) @@ -165,7 +166,7 @@ class Meta: app_label = 'monitors' -class NirspecCosmicRayQueryHistory(models.Model): +class NIRSpecCosmicRayQueryHistory(models.Model): entry_date = models.DateTimeField(unique=True) instrument = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) @@ -181,7 +182,7 @@ class Meta: app_label = 'monitors' -class NirspecCosmicRayStats(models.Model): +class NIRSpecCosmicRayStats(models.Model): entry_date = models.DateTimeField(unique=True) aperture = models.CharField(blank=True, null=True) source_file = models.CharField(blank=True, null=True) diff --git a/jwql/website/apps/jwql/monitor_models/dark_current.py b/jwql/website/apps/jwql/monitor_models/dark_current.py index 1d68cf189..29d9a9523 100644 --- a/jwql/website/apps/jwql/monitor_models/dark_current.py +++ b/jwql/website/apps/jwql/monitor_models/dark_current.py @@ -27,9 +27,10 @@ # This is an auto-generated Django model module. # Feel free to rename the models, but don't rename db_table values or field names. from django.db import models +from django.contrib.postgres.fields import ArrayField -class FgsDarkDarkCurrent(models.Model): +class FGSDarkDarkCurrent(models.Model): entry_date = models.DateTimeField(unique=True) aperture = models.CharField(blank=True, null=True) amplifier = models.CharField(blank=True, null=True) @@ -40,20 +41,20 @@ class FgsDarkDarkCurrent(models.Model): obs_start_time = models.DateTimeField(blank=True, null=True) obs_mid_time = models.DateTimeField(blank=True, null=True) obs_end_time = models.DateTimeField(blank=True, null=True) - gauss_amplitude = models.TextField(blank=True, null=True) # This field type is a guess. - gauss_peak = models.TextField(blank=True, null=True) # This field type is a guess. - gauss_width = models.TextField(blank=True, null=True) # This field type is a guess. + gauss_amplitude = ArrayField(models.FloatField()) + gauss_peak = ArrayField(models.FloatField()) + gauss_width = ArrayField(models.FloatField()) gauss_chisq = models.FloatField(blank=True, null=True) - double_gauss_amplitude1 = models.TextField(blank=True, null=True) # This field type is a guess. - double_gauss_peak1 = models.TextField(blank=True, null=True) # This field type is a guess. - double_gauss_width1 = models.TextField(blank=True, null=True) # This field type is a guess. - double_gauss_amplitude2 = models.TextField(blank=True, null=True) # This field type is a guess. - double_gauss_peak2 = models.TextField(blank=True, null=True) # This field type is a guess. - double_gauss_width2 = models.TextField(blank=True, null=True) # This field type is a guess. + double_gauss_amplitude1 = ArrayField(models.FloatField()) + double_gauss_peak1 = ArrayField(models.FloatField()) + double_gauss_width1 = ArrayField(models.FloatField()) + double_gauss_amplitude2 = ArrayField(models.FloatField()) + double_gauss_peak2 = ArrayField(models.FloatField()) + double_gauss_width2 = ArrayField(models.FloatField()) double_gauss_chisq = models.FloatField(blank=True, null=True) mean_dark_image_file = models.CharField(blank=True, null=True) - hist_dark_values = models.TextField(blank=True, null=True) # This field type is a guess. - hist_amplitudes = models.TextField(blank=True, null=True) # This field type is a guess. + hist_dark_values = ArrayField(models.FloatField()) + hist_amplitudes = ArrayField(models.FloatField()) class Meta: managed = True @@ -62,11 +63,11 @@ class Meta: app_label = 'monitors' -class FgsDarkPixelStats(models.Model): +class FGSDarkPixelStats(models.Model): entry_date = models.DateTimeField(unique=True) detector = models.CharField(blank=True, null=True) - x_coord = models.TextField(blank=True, null=True) # This field type is a guess. - y_coord = models.TextField(blank=True, null=True) # This field type is a guess. + x_coord = ArrayField(models.IntegerField()) + y_coord = ArrayField(models.IntegerField()) type = models.CharField(blank=True, null=True) source_files = models.TextField(blank=True, null=True) # This field type is a guess. obs_start_time = models.DateTimeField(blank=True, null=True) @@ -82,7 +83,7 @@ class Meta: app_label = 'monitors' -class FgsDarkQueryHistory(models.Model): +class FGSDarkQueryHistory(models.Model): entry_date = models.DateTimeField(unique=True) instrument = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) @@ -99,7 +100,7 @@ class Meta: app_label = 'monitors' -class MiriDarkDarkCurrent(models.Model): +class MIRIDarkDarkCurrent(models.Model): entry_date = models.DateTimeField(unique=True) aperture = models.CharField(blank=True, null=True) amplifier = models.CharField(blank=True, null=True) @@ -110,20 +111,20 @@ class MiriDarkDarkCurrent(models.Model): obs_start_time = models.DateTimeField(blank=True, null=True) obs_mid_time = models.DateTimeField(blank=True, null=True) obs_end_time = models.DateTimeField(blank=True, null=True) - gauss_amplitude = models.TextField(blank=True, null=True) # This field type is a guess. - gauss_peak = models.TextField(blank=True, null=True) # This field type is a guess. - gauss_width = models.TextField(blank=True, null=True) # This field type is a guess. + gauss_amplitude = ArrayField(models.FloatField()) + gauss_peak = ArrayField(models.FloatField()) + gauss_width = ArrayField(models.FloatField()) gauss_chisq = models.FloatField(blank=True, null=True) - double_gauss_amplitude1 = models.TextField(blank=True, null=True) # This field type is a guess. - double_gauss_peak1 = models.TextField(blank=True, null=True) # This field type is a guess. - double_gauss_width1 = models.TextField(blank=True, null=True) # This field type is a guess. - double_gauss_amplitude2 = models.TextField(blank=True, null=True) # This field type is a guess. - double_gauss_peak2 = models.TextField(blank=True, null=True) # This field type is a guess. - double_gauss_width2 = models.TextField(blank=True, null=True) # This field type is a guess. + double_gauss_amplitude1 = ArrayField(models.FloatField()) + double_gauss_peak1 = ArrayField(models.FloatField()) + double_gauss_width1 = ArrayField(models.FloatField()) + double_gauss_amplitude2 = ArrayField(models.FloatField()) + double_gauss_peak2 = ArrayField(models.FloatField()) + double_gauss_width2 = ArrayField(models.FloatField()) double_gauss_chisq = models.FloatField(blank=True, null=True) mean_dark_image_file = models.CharField(blank=True, null=True) - hist_dark_values = models.TextField(blank=True, null=True) # This field type is a guess. - hist_amplitudes = models.TextField(blank=True, null=True) # This field type is a guess. + hist_dark_values = ArrayField(models.FloatField()) + hist_amplitudes = ArrayField(models.FloatField()) class Meta: managed = True @@ -132,11 +133,11 @@ class Meta: app_label = 'monitors' -class MiriDarkPixelStats(models.Model): +class MIRIDarkPixelStats(models.Model): entry_date = models.DateTimeField(unique=True) detector = models.CharField(blank=True, null=True) - x_coord = models.TextField(blank=True, null=True) # This field type is a guess. - y_coord = models.TextField(blank=True, null=True) # This field type is a guess. + x_coord = ArrayField(models.IntegerField()) + y_coord = ArrayField(models.IntegerField()) type = models.CharField(blank=True, null=True) source_files = models.TextField(blank=True, null=True) # This field type is a guess. obs_start_time = models.DateTimeField(blank=True, null=True) @@ -152,7 +153,7 @@ class Meta: app_label = 'monitors' -class MiriDarkQueryHistory(models.Model): +class MIRIDarkQueryHistory(models.Model): entry_date = models.DateTimeField(unique=True) instrument = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) @@ -169,7 +170,7 @@ class Meta: app_label = 'monitors' -class NircamDarkDarkCurrent(models.Model): +class NIRCamDarkDarkCurrent(models.Model): entry_date = models.DateTimeField(unique=True) aperture = models.CharField(blank=True, null=True) amplifier = models.CharField(blank=True, null=True) @@ -180,20 +181,20 @@ class NircamDarkDarkCurrent(models.Model): obs_start_time = models.DateTimeField(blank=True, null=True) obs_mid_time = models.DateTimeField(blank=True, null=True) obs_end_time = models.DateTimeField(blank=True, null=True) - gauss_amplitude = models.TextField(blank=True, null=True) # This field type is a guess. - gauss_peak = models.TextField(blank=True, null=True) # This field type is a guess. - gauss_width = models.TextField(blank=True, null=True) # This field type is a guess. + gauss_amplitude = ArrayField(models.FloatField()) + gauss_peak = ArrayField(models.FloatField()) + gauss_width = ArrayField(models.FloatField()) gauss_chisq = models.FloatField(blank=True, null=True) - double_gauss_amplitude1 = models.TextField(blank=True, null=True) # This field type is a guess. - double_gauss_peak1 = models.TextField(blank=True, null=True) # This field type is a guess. - double_gauss_width1 = models.TextField(blank=True, null=True) # This field type is a guess. - double_gauss_amplitude2 = models.TextField(blank=True, null=True) # This field type is a guess. - double_gauss_peak2 = models.TextField(blank=True, null=True) # This field type is a guess. - double_gauss_width2 = models.TextField(blank=True, null=True) # This field type is a guess. + double_gauss_amplitude1 = ArrayField(models.FloatField()) + double_gauss_peak1 = ArrayField(models.FloatField()) + double_gauss_width1 = ArrayField(models.FloatField()) + double_gauss_amplitude2 = ArrayField(models.FloatField()) + double_gauss_peak2 = ArrayField(models.FloatField()) + double_gauss_width2 = ArrayField(models.FloatField()) double_gauss_chisq = models.FloatField(blank=True, null=True) mean_dark_image_file = models.CharField(blank=True, null=True) - hist_dark_values = models.TextField(blank=True, null=True) # This field type is a guess. - hist_amplitudes = models.TextField(blank=True, null=True) # This field type is a guess. + hist_dark_values = ArrayField(models.FloatField()) + hist_amplitudes = ArrayField(models.FloatField()) class Meta: managed = True @@ -202,11 +203,11 @@ class Meta: app_label = 'monitors' -class NircamDarkPixelStats(models.Model): +class NIRCamDarkPixelStats(models.Model): entry_date = models.DateTimeField(unique=True) detector = models.CharField(blank=True, null=True) - x_coord = models.TextField(blank=True, null=True) # This field type is a guess. - y_coord = models.TextField(blank=True, null=True) # This field type is a guess. + x_coord = ArrayField(models.IntegerField()) + y_coord = ArrayField(models.IntegerField()) type = models.CharField(blank=True, null=True) source_files = models.TextField(blank=True, null=True) # This field type is a guess. obs_start_time = models.DateTimeField(blank=True, null=True) @@ -222,7 +223,7 @@ class Meta: app_label = 'monitors' -class NircamDarkQueryHistory(models.Model): +class NIRCamDarkQueryHistory(models.Model): entry_date = models.DateTimeField(unique=True) instrument = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) @@ -239,7 +240,7 @@ class Meta: app_label = 'monitors' -class NirissDarkDarkCurrent(models.Model): +class NIRISSDarkDarkCurrent(models.Model): entry_date = models.DateTimeField(unique=True) aperture = models.CharField(blank=True, null=True) amplifier = models.CharField(blank=True, null=True) @@ -250,20 +251,20 @@ class NirissDarkDarkCurrent(models.Model): obs_start_time = models.DateTimeField(blank=True, null=True) obs_mid_time = models.DateTimeField(blank=True, null=True) obs_end_time = models.DateTimeField(blank=True, null=True) - gauss_amplitude = models.TextField(blank=True, null=True) # This field type is a guess. - gauss_peak = models.TextField(blank=True, null=True) # This field type is a guess. - gauss_width = models.TextField(blank=True, null=True) # This field type is a guess. + gauss_amplitude = ArrayField(models.FloatField()) + gauss_peak = ArrayField(models.FloatField()) + gauss_width = ArrayField(models.FloatField()) gauss_chisq = models.FloatField(blank=True, null=True) - double_gauss_amplitude1 = models.TextField(blank=True, null=True) # This field type is a guess. - double_gauss_peak1 = models.TextField(blank=True, null=True) # This field type is a guess. - double_gauss_width1 = models.TextField(blank=True, null=True) # This field type is a guess. - double_gauss_amplitude2 = models.TextField(blank=True, null=True) # This field type is a guess. - double_gauss_peak2 = models.TextField(blank=True, null=True) # This field type is a guess. - double_gauss_width2 = models.TextField(blank=True, null=True) # This field type is a guess. + double_gauss_amplitude1 = ArrayField(models.FloatField()) + double_gauss_peak1 = ArrayField(models.FloatField()) + double_gauss_width1 = ArrayField(models.FloatField()) + double_gauss_amplitude2 = ArrayField(models.FloatField()) + double_gauss_peak2 = ArrayField(models.FloatField()) + double_gauss_width2 = ArrayField(models.FloatField()) double_gauss_chisq = models.FloatField(blank=True, null=True) mean_dark_image_file = models.CharField(blank=True, null=True) - hist_dark_values = models.TextField(blank=True, null=True) # This field type is a guess. - hist_amplitudes = models.TextField(blank=True, null=True) # This field type is a guess. + hist_dark_values = ArrayField(models.FloatField()) + hist_amplitudes = ArrayField(models.FloatField()) class Meta: managed = True @@ -272,11 +273,11 @@ class Meta: app_label = 'monitors' -class NirissDarkPixelStats(models.Model): +class NIRISSDarkPixelStats(models.Model): entry_date = models.DateTimeField(unique=True) detector = models.CharField(blank=True, null=True) - x_coord = models.TextField(blank=True, null=True) # This field type is a guess. - y_coord = models.TextField(blank=True, null=True) # This field type is a guess. + x_coord = ArrayField(models.IntegerField()) + y_coord = ArrayField(models.IntegerField()) type = models.CharField(blank=True, null=True) source_files = models.TextField(blank=True, null=True) # This field type is a guess. obs_start_time = models.DateTimeField(blank=True, null=True) @@ -292,7 +293,7 @@ class Meta: app_label = 'monitors' -class NirissDarkQueryHistory(models.Model): +class NIRISSDarkQueryHistory(models.Model): entry_date = models.DateTimeField(unique=True) instrument = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) @@ -309,7 +310,7 @@ class Meta: app_label = 'monitors' -class NirspecDarkDarkCurrent(models.Model): +class NIRSpecDarkDarkCurrent(models.Model): entry_date = models.DateTimeField(unique=True) aperture = models.CharField(blank=True, null=True) amplifier = models.CharField(blank=True, null=True) @@ -320,20 +321,20 @@ class NirspecDarkDarkCurrent(models.Model): obs_start_time = models.DateTimeField(blank=True, null=True) obs_mid_time = models.DateTimeField(blank=True, null=True) obs_end_time = models.DateTimeField(blank=True, null=True) - gauss_amplitude = models.TextField(blank=True, null=True) # This field type is a guess. - gauss_peak = models.TextField(blank=True, null=True) # This field type is a guess. - gauss_width = models.TextField(blank=True, null=True) # This field type is a guess. + gauss_amplitude = ArrayField(models.FloatField()) + gauss_peak = ArrayField(models.FloatField()) + gauss_width = ArrayField(models.FloatField()) gauss_chisq = models.FloatField(blank=True, null=True) - double_gauss_amplitude1 = models.TextField(blank=True, null=True) # This field type is a guess. - double_gauss_peak1 = models.TextField(blank=True, null=True) # This field type is a guess. - double_gauss_width1 = models.TextField(blank=True, null=True) # This field type is a guess. - double_gauss_amplitude2 = models.TextField(blank=True, null=True) # This field type is a guess. - double_gauss_peak2 = models.TextField(blank=True, null=True) # This field type is a guess. - double_gauss_width2 = models.TextField(blank=True, null=True) # This field type is a guess. + double_gauss_amplitude1 = ArrayField(models.FloatField()) + double_gauss_peak1 = ArrayField(models.FloatField()) + double_gauss_width1 = ArrayField(models.FloatField()) + double_gauss_amplitude2 = ArrayField(models.FloatField()) + double_gauss_peak2 = ArrayField(models.FloatField()) + double_gauss_width2 = ArrayField(models.FloatField()) double_gauss_chisq = models.FloatField(blank=True, null=True) mean_dark_image_file = models.CharField(blank=True, null=True) - hist_dark_values = models.TextField(blank=True, null=True) # This field type is a guess. - hist_amplitudes = models.TextField(blank=True, null=True) # This field type is a guess. + hist_dark_values = ArrayField(models.FloatField()) + hist_amplitudes = ArrayField(models.FloatField()) class Meta: managed = True @@ -342,11 +343,11 @@ class Meta: app_label = 'monitors' -class NirspecDarkPixelStats(models.Model): +class NIRSpecDarkPixelStats(models.Model): entry_date = models.DateTimeField(unique=True) detector = models.CharField(blank=True, null=True) - x_coord = models.TextField(blank=True, null=True) # This field type is a guess. - y_coord = models.TextField(blank=True, null=True) # This field type is a guess. + x_coord = ArrayField(models.IntegerField()) + y_coord = ArrayField(models.IntegerField()) type = models.CharField(blank=True, null=True) source_files = models.TextField(blank=True, null=True) # This field type is a guess. obs_start_time = models.DateTimeField(blank=True, null=True) @@ -362,7 +363,7 @@ class Meta: app_label = 'monitors' -class NirspecDarkQueryHistory(models.Model): +class NIRSpecDarkQueryHistory(models.Model): entry_date = models.DateTimeField(unique=True) instrument = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) diff --git a/jwql/website/apps/jwql/monitor_models/edb.py b/jwql/website/apps/jwql/monitor_models/edb.py index fa6c04057..cc9d8ec82 100644 --- a/jwql/website/apps/jwql/monitor_models/edb.py +++ b/jwql/website/apps/jwql/monitor_models/edb.py @@ -27,17 +27,18 @@ # This is an auto-generated Django model module. # Feel free to rename the models, but don't rename db_table values or field names. from django.db import models +from django.contrib.postgres.fields import ArrayField -class FgsEdbBlocksStats(models.Model): +class FGSEdbBlocksStats(models.Model): mnemonic = models.CharField(blank=True, null=True) latest_query = models.DateTimeField(blank=True, null=True) - times = models.TextField(blank=True, null=True) # This field type is a guess. - data = models.TextField(blank=True, null=True) # This field type is a guess. - stdev = models.TextField(blank=True, null=True) # This field type is a guess. - median = models.TextField(blank=True, null=True) # This field type is a guess. - max = models.TextField(blank=True, null=True) # This field type is a guess. - min = models.TextField(blank=True, null=True) # This field type is a guess. + times = ArrayField(models.DateTimeField()) + data = ArrayField(models.FloatField()) + stdev = ArrayField(models.FloatField()) + median = ArrayField(models.FloatField()) + max = ArrayField(models.FloatField()) + min = ArrayField(models.FloatField()) entry_date = models.DateTimeField(blank=True, null=True) class Meta: @@ -47,15 +48,15 @@ class Meta: app_label = 'monitors' -class FgsEdbDailyStats(models.Model): +class FGSEdbDailyStats(models.Model): mnemonic = models.CharField(blank=True, null=True) latest_query = models.DateTimeField(blank=True, null=True) - times = models.TextField(blank=True, null=True) # This field type is a guess. - data = models.TextField(blank=True, null=True) # This field type is a guess. - stdev = models.TextField(blank=True, null=True) # This field type is a guess. - median = models.TextField(blank=True, null=True) # This field type is a guess. - max = models.TextField(blank=True, null=True) # This field type is a guess. - min = models.TextField(blank=True, null=True) # This field type is a guess. + times = ArrayField(models.DateTimeField()) + data = ArrayField(models.FloatField()) + stdev = ArrayField(models.FloatField()) + median = ArrayField(models.FloatField()) + max = ArrayField(models.FloatField()) + min = ArrayField(models.FloatField()) entry_date = models.DateTimeField(blank=True, null=True) class Meta: @@ -65,11 +66,11 @@ class Meta: app_label = 'monitors' -class FgsEdbEveryChangeStats(models.Model): +class FGSEdbEveryChangeStats(models.Model): mnemonic = models.CharField(blank=True, null=True) latest_query = models.DateTimeField(blank=True, null=True) - time = models.TextField(blank=True, null=True) # This field type is a guess. - mnemonic_value = models.TextField(blank=True, null=True) # This field type is a guess. + time = ArrayField(models.DateTimeField()) + mnemonic_value = ArrayField(models.FloatField()) median = models.FloatField(blank=True, null=True) stdev = models.FloatField(blank=True, null=True) dependency_mnemonic = models.CharField(blank=True, null=True) @@ -83,15 +84,15 @@ class Meta: app_label = 'monitors' -class FgsEdbTimeIntervalStats(models.Model): +class FGSEdbTimeIntervalStats(models.Model): mnemonic = models.CharField(blank=True, null=True) latest_query = models.DateTimeField(blank=True, null=True) - times = models.TextField(blank=True, null=True) # This field type is a guess. - data = models.TextField(blank=True, null=True) # This field type is a guess. - stdev = models.TextField(blank=True, null=True) # This field type is a guess. - median = models.TextField(blank=True, null=True) # This field type is a guess. - max = models.TextField(blank=True, null=True) # This field type is a guess. - min = models.TextField(blank=True, null=True) # This field type is a guess. + times = ArrayField(models.DateTimeField()) + data = ArrayField(models.FloatField()) + stdev = ArrayField(models.FloatField()) + median = ArrayField(models.FloatField()) + max = ArrayField(models.FloatField()) + min = ArrayField(models.FloatField()) entry_date = models.DateTimeField(blank=True, null=True) class Meta: @@ -101,12 +102,12 @@ class Meta: app_label = 'monitors' -class FgsEdbTimeStats(models.Model): +class FGSEdbTimeStats(models.Model): mnemonic = models.CharField(blank=True, null=True) latest_query = models.DateTimeField(blank=True, null=True) - times = models.TextField(blank=True, null=True) # This field type is a guess. - data = models.TextField(blank=True, null=True) # This field type is a guess. - stdev = models.TextField(blank=True, null=True) # This field type is a guess. + times = ArrayField(models.DateTimeField()) + data = ArrayField(models.FloatField()) + stdev = ArrayField(models.FloatField()) entry_date = models.DateTimeField(blank=True, null=True) class Meta: @@ -116,15 +117,15 @@ class Meta: app_label = 'monitors' -class MiriEdbBlocksStats(models.Model): +class MIRIEdbBlocksStats(models.Model): mnemonic = models.CharField(blank=True, null=True) latest_query = models.DateTimeField(blank=True, null=True) - times = models.TextField(blank=True, null=True) # This field type is a guess. - data = models.TextField(blank=True, null=True) # This field type is a guess. - stdev = models.TextField(blank=True, null=True) # This field type is a guess. - median = models.TextField(blank=True, null=True) # This field type is a guess. - max = models.TextField(blank=True, null=True) # This field type is a guess. - min = models.TextField(blank=True, null=True) # This field type is a guess. + times = ArrayField(models.DateTimeField()) + data = ArrayField(models.FloatField()) + stdev = ArrayField(models.FloatField()) + median = ArrayField(models.FloatField()) + max = ArrayField(models.FloatField()) + min = ArrayField(models.FloatField()) entry_date = models.DateTimeField(blank=True, null=True) class Meta: @@ -134,15 +135,15 @@ class Meta: app_label = 'monitors' -class MiriEdbDailyStats(models.Model): +class MIRIEdbDailyStats(models.Model): mnemonic = models.CharField(blank=True, null=True) latest_query = models.DateTimeField(blank=True, null=True) - times = models.TextField(blank=True, null=True) # This field type is a guess. - data = models.TextField(blank=True, null=True) # This field type is a guess. - stdev = models.TextField(blank=True, null=True) # This field type is a guess. - median = models.TextField(blank=True, null=True) # This field type is a guess. - max = models.TextField(blank=True, null=True) # This field type is a guess. - min = models.TextField(blank=True, null=True) # This field type is a guess. + times = ArrayField(models.DateTimeField()) + data = ArrayField(models.FloatField()) + stdev = ArrayField(models.FloatField()) + median = ArrayField(models.FloatField()) + max = ArrayField(models.FloatField()) + min = ArrayField(models.FloatField()) entry_date = models.DateTimeField(blank=True, null=True) class Meta: @@ -152,11 +153,11 @@ class Meta: app_label = 'monitors' -class MiriEdbEveryChangeStats(models.Model): +class MIRIEdbEveryChangeStats(models.Model): mnemonic = models.CharField(blank=True, null=True) latest_query = models.DateTimeField(blank=True, null=True) - time = models.TextField(blank=True, null=True) # This field type is a guess. - mnemonic_value = models.TextField(blank=True, null=True) # This field type is a guess. + time = ArrayField(models.DateTimeField()) + mnemonic_value = ArrayField(models.FloatField()) median = models.FloatField(blank=True, null=True) stdev = models.FloatField(blank=True, null=True) dependency_mnemonic = models.CharField(blank=True, null=True) @@ -170,15 +171,15 @@ class Meta: app_label = 'monitors' -class MiriEdbTimeIntervalStats(models.Model): +class MIRIEdbTimeIntervalStats(models.Model): mnemonic = models.CharField(blank=True, null=True) latest_query = models.DateTimeField(blank=True, null=True) - times = models.TextField(blank=True, null=True) # This field type is a guess. - data = models.TextField(blank=True, null=True) # This field type is a guess. - stdev = models.TextField(blank=True, null=True) # This field type is a guess. - median = models.TextField(blank=True, null=True) # This field type is a guess. - max = models.TextField(blank=True, null=True) # This field type is a guess. - min = models.TextField(blank=True, null=True) # This field type is a guess. + times = ArrayField(models.DateTimeField()) + data = ArrayField(models.FloatField()) + stdev = ArrayField(models.FloatField()) + median = ArrayField(models.FloatField()) + max = ArrayField(models.FloatField()) + min = ArrayField(models.FloatField()) entry_date = models.DateTimeField(blank=True, null=True) class Meta: @@ -188,12 +189,12 @@ class Meta: app_label = 'monitors' -class MiriEdbTimeStats(models.Model): +class MIRIEdbTimeStats(models.Model): mnemonic = models.CharField(blank=True, null=True) latest_query = models.DateTimeField(blank=True, null=True) - times = models.TextField(blank=True, null=True) # This field type is a guess. - data = models.TextField(blank=True, null=True) # This field type is a guess. - stdev = models.TextField(blank=True, null=True) # This field type is a guess. + times = ArrayField(models.DateTimeField()) + data = ArrayField(models.FloatField()) + stdev = ArrayField(models.FloatField()) entry_date = models.DateTimeField(blank=True, null=True) class Meta: @@ -203,15 +204,15 @@ class Meta: app_label = 'monitors' -class NircamEdbBlocksStats(models.Model): +class NIRCamEdbBlocksStats(models.Model): mnemonic = models.CharField(blank=True, null=True) latest_query = models.DateTimeField(blank=True, null=True) - times = models.TextField(blank=True, null=True) # This field type is a guess. - data = models.TextField(blank=True, null=True) # This field type is a guess. - stdev = models.TextField(blank=True, null=True) # This field type is a guess. - median = models.TextField(blank=True, null=True) # This field type is a guess. - max = models.TextField(blank=True, null=True) # This field type is a guess. - min = models.TextField(blank=True, null=True) # This field type is a guess. + times = ArrayField(models.DateTimeField()) + data = ArrayField(models.FloatField()) + stdev = ArrayField(models.FloatField()) + median = ArrayField(models.FloatField()) + max = ArrayField(models.FloatField()) + min = ArrayField(models.FloatField()) entry_date = models.DateTimeField(blank=True, null=True) class Meta: @@ -221,15 +222,15 @@ class Meta: app_label = 'monitors' -class NircamEdbDailyStats(models.Model): +class NIRCamEdbDailyStats(models.Model): mnemonic = models.CharField(blank=True, null=True) latest_query = models.DateTimeField(blank=True, null=True) - times = models.TextField(blank=True, null=True) # This field type is a guess. - data = models.TextField(blank=True, null=True) # This field type is a guess. - stdev = models.TextField(blank=True, null=True) # This field type is a guess. - median = models.TextField(blank=True, null=True) # This field type is a guess. - max = models.TextField(blank=True, null=True) # This field type is a guess. - min = models.TextField(blank=True, null=True) # This field type is a guess. + times = ArrayField(models.DateTimeField()) + data = ArrayField(models.FloatField()) + stdev = ArrayField(models.FloatField()) + median = ArrayField(models.FloatField()) + max = ArrayField(models.FloatField()) + min = ArrayField(models.FloatField()) entry_date = models.DateTimeField(blank=True, null=True) class Meta: @@ -239,11 +240,11 @@ class Meta: app_label = 'monitors' -class NircamEdbEveryChangeStats(models.Model): +class NIRCamEdbEveryChangeStats(models.Model): mnemonic = models.CharField(blank=True, null=True) latest_query = models.DateTimeField(blank=True, null=True) - time = models.TextField(blank=True, null=True) # This field type is a guess. - mnemonic_value = models.TextField(blank=True, null=True) # This field type is a guess. + time = ArrayField(models.DateTimeField()) + mnemonic_value = ArrayField(models.FloatField()) median = models.FloatField(blank=True, null=True) stdev = models.FloatField(blank=True, null=True) dependency_mnemonic = models.CharField(blank=True, null=True) @@ -257,15 +258,15 @@ class Meta: app_label = 'monitors' -class NircamEdbTimeIntervalStats(models.Model): +class NIRCamEdbTimeIntervalStats(models.Model): mnemonic = models.CharField(blank=True, null=True) latest_query = models.DateTimeField(blank=True, null=True) - times = models.TextField(blank=True, null=True) # This field type is a guess. - data = models.TextField(blank=True, null=True) # This field type is a guess. - stdev = models.TextField(blank=True, null=True) # This field type is a guess. - median = models.TextField(blank=True, null=True) # This field type is a guess. - max = models.TextField(blank=True, null=True) # This field type is a guess. - min = models.TextField(blank=True, null=True) # This field type is a guess. + times = ArrayField(models.DateTimeField()) + data = ArrayField(models.FloatField()) + stdev = ArrayField(models.FloatField()) + median = ArrayField(models.FloatField()) + max = ArrayField(models.FloatField()) + min = ArrayField(models.FloatField()) entry_date = models.DateTimeField(blank=True, null=True) class Meta: @@ -275,12 +276,12 @@ class Meta: app_label = 'monitors' -class NircamEdbTimeStats(models.Model): +class NIRCamEdbTimeStats(models.Model): mnemonic = models.CharField(blank=True, null=True) latest_query = models.DateTimeField(blank=True, null=True) - times = models.TextField(blank=True, null=True) # This field type is a guess. - data = models.TextField(blank=True, null=True) # This field type is a guess. - stdev = models.TextField(blank=True, null=True) # This field type is a guess. + times = ArrayField(models.DateTimeField()) + data = ArrayField(models.FloatField()) + stdev = ArrayField(models.FloatField()) entry_date = models.DateTimeField(blank=True, null=True) class Meta: @@ -290,15 +291,15 @@ class Meta: app_label = 'monitors' -class NirissEdbBlocksStats(models.Model): +class NIRISSEdbBlocksStats(models.Model): mnemonic = models.CharField(blank=True, null=True) latest_query = models.DateTimeField(blank=True, null=True) - times = models.TextField(blank=True, null=True) # This field type is a guess. - data = models.TextField(blank=True, null=True) # This field type is a guess. - stdev = models.TextField(blank=True, null=True) # This field type is a guess. - median = models.TextField(blank=True, null=True) # This field type is a guess. - max = models.TextField(blank=True, null=True) # This field type is a guess. - min = models.TextField(blank=True, null=True) # This field type is a guess. + times = ArrayField(models.DateTimeField()) + data = ArrayField(models.FloatField()) + stdev = ArrayField(models.FloatField()) + median = ArrayField(models.FloatField()) + max = ArrayField(models.FloatField()) + min = ArrayField(models.FloatField()) entry_date = models.DateTimeField(blank=True, null=True) class Meta: @@ -308,15 +309,15 @@ class Meta: app_label = 'monitors' -class NirissEdbDailyStats(models.Model): +class NIRISSEdbDailyStats(models.Model): mnemonic = models.CharField(blank=True, null=True) latest_query = models.DateTimeField(blank=True, null=True) - times = models.TextField(blank=True, null=True) # This field type is a guess. - data = models.TextField(blank=True, null=True) # This field type is a guess. - stdev = models.TextField(blank=True, null=True) # This field type is a guess. - median = models.TextField(blank=True, null=True) # This field type is a guess. - max = models.TextField(blank=True, null=True) # This field type is a guess. - min = models.TextField(blank=True, null=True) # This field type is a guess. + times = ArrayField(models.DateTimeField()) + data = ArrayField(models.FloatField()) + stdev = ArrayField(models.FloatField()) + median = ArrayField(models.FloatField()) + max = ArrayField(models.FloatField()) + min = ArrayField(models.FloatField()) entry_date = models.DateTimeField(blank=True, null=True) class Meta: @@ -326,11 +327,11 @@ class Meta: app_label = 'monitors' -class NirissEdbEveryChangeStats(models.Model): +class NIRISSEdbEveryChangeStats(models.Model): mnemonic = models.CharField(blank=True, null=True) latest_query = models.DateTimeField(blank=True, null=True) - time = models.TextField(blank=True, null=True) # This field type is a guess. - mnemonic_value = models.TextField(blank=True, null=True) # This field type is a guess. + time = ArrayField(models.DateTimeField()) + mnemonic_value = ArrayField(models.FloatField()) median = models.FloatField(blank=True, null=True) stdev = models.FloatField(blank=True, null=True) dependency_mnemonic = models.CharField(blank=True, null=True) @@ -344,15 +345,15 @@ class Meta: app_label = 'monitors' -class NirissEdbTimeIntervalStats(models.Model): +class NIRISSEdbTimeIntervalStats(models.Model): mnemonic = models.CharField(blank=True, null=True) latest_query = models.DateTimeField(blank=True, null=True) - times = models.TextField(blank=True, null=True) # This field type is a guess. - data = models.TextField(blank=True, null=True) # This field type is a guess. - stdev = models.TextField(blank=True, null=True) # This field type is a guess. - median = models.TextField(blank=True, null=True) # This field type is a guess. - max = models.TextField(blank=True, null=True) # This field type is a guess. - min = models.TextField(blank=True, null=True) # This field type is a guess. + times = ArrayField(models.DateTimeField()) + data = ArrayField(models.FloatField()) + stdev = ArrayField(models.FloatField()) + median = ArrayField(models.FloatField()) + max = ArrayField(models.FloatField()) + min = ArrayField(models.FloatField()) entry_date = models.DateTimeField(blank=True, null=True) class Meta: @@ -362,12 +363,12 @@ class Meta: app_label = 'monitors' -class NirissEdbTimeStats(models.Model): +class NIRISSEdbTimeStats(models.Model): mnemonic = models.CharField(blank=True, null=True) latest_query = models.DateTimeField(blank=True, null=True) - times = models.TextField(blank=True, null=True) # This field type is a guess. - data = models.TextField(blank=True, null=True) # This field type is a guess. - stdev = models.TextField(blank=True, null=True) # This field type is a guess. + times = ArrayField(models.DateTimeField()) + data = ArrayField(models.FloatField()) + stdev = ArrayField(models.FloatField()) entry_date = models.DateTimeField(blank=True, null=True) class Meta: @@ -377,15 +378,15 @@ class Meta: app_label = 'monitors' -class NirspecEdbBlocksStats(models.Model): +class NIRSpecEdbBlocksStats(models.Model): mnemonic = models.CharField(blank=True, null=True) latest_query = models.DateTimeField(blank=True, null=True) - times = models.TextField(blank=True, null=True) # This field type is a guess. - data = models.TextField(blank=True, null=True) # This field type is a guess. - stdev = models.TextField(blank=True, null=True) # This field type is a guess. - median = models.TextField(blank=True, null=True) # This field type is a guess. - max = models.TextField(blank=True, null=True) # This field type is a guess. - min = models.TextField(blank=True, null=True) # This field type is a guess. + times = ArrayField(models.DateTimeField()) + data = ArrayField(models.FloatField()) + stdev = ArrayField(models.FloatField()) + median = ArrayField(models.FloatField()) + max = ArrayField(models.FloatField()) + min = ArrayField(models.FloatField()) entry_date = models.DateTimeField(blank=True, null=True) class Meta: @@ -395,15 +396,15 @@ class Meta: app_label = 'monitors' -class NirspecEdbDailyStats(models.Model): +class NIRSpecEdbDailyStats(models.Model): mnemonic = models.CharField(blank=True, null=True) latest_query = models.DateTimeField(blank=True, null=True) - times = models.TextField(blank=True, null=True) # This field type is a guess. - data = models.TextField(blank=True, null=True) # This field type is a guess. - stdev = models.TextField(blank=True, null=True) # This field type is a guess. - median = models.TextField(blank=True, null=True) # This field type is a guess. - max = models.TextField(blank=True, null=True) # This field type is a guess. - min = models.TextField(blank=True, null=True) # This field type is a guess. + times = ArrayField(models.DateTimeField()) + data = ArrayField(models.FloatField()) + stdev = ArrayField(models.FloatField()) + median = ArrayField(models.FloatField()) + max = ArrayField(models.FloatField()) + min = ArrayField(models.FloatField()) entry_date = models.DateTimeField(blank=True, null=True) class Meta: @@ -413,11 +414,11 @@ class Meta: app_label = 'monitors' -class NirspecEdbEveryChangeStats(models.Model): +class NIRSpecEdbEveryChangeStats(models.Model): mnemonic = models.CharField(blank=True, null=True) latest_query = models.DateTimeField(blank=True, null=True) - time = models.TextField(blank=True, null=True) # This field type is a guess. - mnemonic_value = models.TextField(blank=True, null=True) # This field type is a guess. + time = ArrayField(models.DateTimeField()) + mnemonic_value = ArrayField(models.FloatField()) median = models.FloatField(blank=True, null=True) stdev = models.FloatField(blank=True, null=True) dependency_mnemonic = models.CharField(blank=True, null=True) @@ -431,15 +432,15 @@ class Meta: app_label = 'monitors' -class NirspecEdbTimeIntervalStats(models.Model): +class NIRSpecEdbTimeIntervalStats(models.Model): mnemonic = models.CharField(blank=True, null=True) latest_query = models.DateTimeField(blank=True, null=True) - times = models.TextField(blank=True, null=True) # This field type is a guess. - data = models.TextField(blank=True, null=True) # This field type is a guess. - stdev = models.TextField(blank=True, null=True) # This field type is a guess. - median = models.TextField(blank=True, null=True) # This field type is a guess. - max = models.TextField(blank=True, null=True) # This field type is a guess. - min = models.TextField(blank=True, null=True) # This field type is a guess. + times = ArrayField(models.DateTimeField()) + data = ArrayField(models.FloatField()) + stdev = ArrayField(models.FloatField()) + median = ArrayField(models.FloatField()) + max = ArrayField(models.FloatField()) + min = ArrayField(models.FloatField()) entry_date = models.DateTimeField(blank=True, null=True) class Meta: @@ -449,12 +450,12 @@ class Meta: app_label = 'monitors' -class NirspecEdbTimeStats(models.Model): +class NIRSpecEdbTimeStats(models.Model): mnemonic = models.CharField(blank=True, null=True) latest_query = models.DateTimeField(blank=True, null=True) - times = models.TextField(blank=True, null=True) # This field type is a guess. - data = models.TextField(blank=True, null=True) # This field type is a guess. - stdev = models.TextField(blank=True, null=True) # This field type is a guess. + times = ArrayField(models.DateTimeField()) + data = ArrayField(models.FloatField()) + stdev = ArrayField(models.FloatField()) entry_date = models.DateTimeField(blank=True, null=True) class Meta: diff --git a/jwql/website/apps/jwql/monitor_models/grating.py b/jwql/website/apps/jwql/monitor_models/grating.py index 73dd6b726..9e4268879 100644 --- a/jwql/website/apps/jwql/monitor_models/grating.py +++ b/jwql/website/apps/jwql/monitor_models/grating.py @@ -27,9 +27,10 @@ # This is an auto-generated Django model module. # Feel free to rename the models, but don't rename db_table values or field names. from django.db import models +from django.contrib.postgres.fields import ArrayField -class NirspecGratingQueryHistory(models.Model): +class NIRSpecGratingQueryHistory(models.Model): start_time_mjd = models.FloatField(blank=True, null=True) end_time_mjd = models.FloatField(blank=True, null=True) run_monitor = models.BooleanField(blank=True, null=True) @@ -42,7 +43,7 @@ class Meta: app_label = 'monitors' -class NirspecGratingStats(models.Model): +class NIRSpecGratingStats(models.Model): entry_date = models.DateTimeField(unique=True) time = models.CharField(blank=True, null=True) inrsh_gwa_adcmgain = models.FloatField(blank=True, null=True) diff --git a/jwql/website/apps/jwql/monitor_models/readnoise.py b/jwql/website/apps/jwql/monitor_models/readnoise.py index 6f59da49a..5a500c709 100644 --- a/jwql/website/apps/jwql/monitor_models/readnoise.py +++ b/jwql/website/apps/jwql/monitor_models/readnoise.py @@ -27,9 +27,10 @@ # This is an auto-generated Django model module. # Feel free to rename the models, but don't rename db_table values or field names. from django.db import models +from django.contrib.postgres.fields import ArrayField -class FgsReadnoiseQueryHistory(models.Model): +class FGSReadnoiseQueryHistory(models.Model): instrument = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) start_time_mjd = models.FloatField(blank=True, null=True) @@ -46,7 +47,7 @@ class Meta: app_label = 'monitors' -class FgsReadnoiseStats(models.Model): +class FGSReadnoiseStats(models.Model): uncal_filename = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) detector = models.CharField(blank=True, null=True) @@ -58,30 +59,30 @@ class FgsReadnoiseStats(models.Model): readnoise_filename = models.CharField(blank=True, null=True) full_image_mean = models.FloatField(blank=True, null=True) full_image_stddev = models.FloatField(blank=True, null=True) - full_image_n = models.TextField(blank=True, null=True) # This field type is a guess. - full_image_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + full_image_n = ArrayField(models.FloatField()) + full_image_bin_centers = ArrayField(models.FloatField()) readnoise_diff_image = models.CharField(blank=True, null=True) diff_image_mean = models.FloatField(blank=True, null=True) diff_image_stddev = models.FloatField(blank=True, null=True) - diff_image_n = models.TextField(blank=True, null=True) # This field type is a guess. - diff_image_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + diff_image_n = ArrayField(models.FloatField()) + diff_image_bin_centers = ArrayField(models.FloatField()) entry_date = models.DateTimeField(blank=True, null=True) amp1_mean = models.FloatField(blank=True, null=True) amp1_stddev = models.FloatField(blank=True, null=True) - amp1_n = models.TextField(blank=True, null=True) # This field type is a guess. - amp1_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + amp1_n = ArrayField(models.FloatField()) + amp1_bin_centers = ArrayField(models.FloatField()) amp2_mean = models.FloatField(blank=True, null=True) amp2_stddev = models.FloatField(blank=True, null=True) - amp2_n = models.TextField(blank=True, null=True) # This field type is a guess. - amp2_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + amp2_n = ArrayField(models.FloatField()) + amp2_bin_centers = ArrayField(models.FloatField()) amp3_mean = models.FloatField(blank=True, null=True) amp3_stddev = models.FloatField(blank=True, null=True) - amp3_n = models.TextField(blank=True, null=True) # This field type is a guess. - amp3_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + amp3_n = ArrayField(models.FloatField()) + amp3_bin_centers = ArrayField(models.FloatField()) amp4_mean = models.FloatField(blank=True, null=True) amp4_stddev = models.FloatField(blank=True, null=True) - amp4_n = models.TextField(blank=True, null=True) # This field type is a guess. - amp4_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + amp4_n = ArrayField(models.FloatField()) + amp4_bin_centers = ArrayField(models.FloatField()) class Meta: managed = True @@ -90,7 +91,7 @@ class Meta: app_label = 'monitors' -class MiriReadnoiseQueryHistory(models.Model): +class MIRIReadnoiseQueryHistory(models.Model): instrument = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) start_time_mjd = models.FloatField(blank=True, null=True) @@ -107,7 +108,7 @@ class Meta: app_label = 'monitors' -class MiriReadnoiseStats(models.Model): +class MIRIReadnoiseStats(models.Model): uncal_filename = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) detector = models.CharField(blank=True, null=True) @@ -119,30 +120,30 @@ class MiriReadnoiseStats(models.Model): readnoise_filename = models.CharField(blank=True, null=True) full_image_mean = models.FloatField(blank=True, null=True) full_image_stddev = models.FloatField(blank=True, null=True) - full_image_n = models.TextField(blank=True, null=True) # This field type is a guess. - full_image_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + full_image_n = ArrayField(models.FloatField()) + full_image_bin_centers = ArrayField(models.FloatField()) readnoise_diff_image = models.CharField(blank=True, null=True) diff_image_mean = models.FloatField(blank=True, null=True) diff_image_stddev = models.FloatField(blank=True, null=True) - diff_image_n = models.TextField(blank=True, null=True) # This field type is a guess. - diff_image_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + diff_image_n = ArrayField(models.FloatField()) + diff_image_bin_centers = ArrayField(models.FloatField()) entry_date = models.DateTimeField(blank=True, null=True) amp1_mean = models.FloatField(blank=True, null=True) amp1_stddev = models.FloatField(blank=True, null=True) - amp1_n = models.TextField(blank=True, null=True) # This field type is a guess. - amp1_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + amp1_n = ArrayField(models.FloatField()) + amp1_bin_centers = ArrayField(models.FloatField()) amp2_mean = models.FloatField(blank=True, null=True) amp2_stddev = models.FloatField(blank=True, null=True) - amp2_n = models.TextField(blank=True, null=True) # This field type is a guess. - amp2_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + amp2_n = ArrayField(models.FloatField()) + amp2_bin_centers = ArrayField(models.FloatField()) amp3_mean = models.FloatField(blank=True, null=True) amp3_stddev = models.FloatField(blank=True, null=True) - amp3_n = models.TextField(blank=True, null=True) # This field type is a guess. - amp3_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + amp3_n = ArrayField(models.FloatField()) + amp3_bin_centers = ArrayField(models.FloatField()) amp4_mean = models.FloatField(blank=True, null=True) amp4_stddev = models.FloatField(blank=True, null=True) - amp4_n = models.TextField(blank=True, null=True) # This field type is a guess. - amp4_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + amp4_n = ArrayField(models.FloatField()) + amp4_bin_centers = ArrayField(models.FloatField()) class Meta: managed = True @@ -151,7 +152,7 @@ class Meta: app_label = 'monitors' -class NircamReadnoiseQueryHistory(models.Model): +class NIRCamReadnoiseQueryHistory(models.Model): instrument = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) start_time_mjd = models.FloatField(blank=True, null=True) @@ -168,7 +169,7 @@ class Meta: app_label = 'monitors' -class NircamReadnoiseStats(models.Model): +class NIRCamReadnoiseStats(models.Model): uncal_filename = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) detector = models.CharField(blank=True, null=True) @@ -180,30 +181,30 @@ class NircamReadnoiseStats(models.Model): readnoise_filename = models.CharField(blank=True, null=True) full_image_mean = models.FloatField(blank=True, null=True) full_image_stddev = models.FloatField(blank=True, null=True) - full_image_n = models.TextField(blank=True, null=True) # This field type is a guess. - full_image_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + full_image_n = ArrayField(models.FloatField()) + full_image_bin_centers = ArrayField(models.FloatField()) readnoise_diff_image = models.CharField(blank=True, null=True) diff_image_mean = models.FloatField(blank=True, null=True) diff_image_stddev = models.FloatField(blank=True, null=True) - diff_image_n = models.TextField(blank=True, null=True) # This field type is a guess. - diff_image_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + diff_image_n = ArrayField(models.FloatField()) + diff_image_bin_centers = ArrayField(models.FloatField()) entry_date = models.DateTimeField(blank=True, null=True) amp1_mean = models.FloatField(blank=True, null=True) amp1_stddev = models.FloatField(blank=True, null=True) - amp1_n = models.TextField(blank=True, null=True) # This field type is a guess. - amp1_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + amp1_n = ArrayField(models.FloatField()) + amp1_bin_centers = ArrayField(models.FloatField()) amp2_mean = models.FloatField(blank=True, null=True) amp2_stddev = models.FloatField(blank=True, null=True) - amp2_n = models.TextField(blank=True, null=True) # This field type is a guess. - amp2_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + amp2_n = ArrayField(models.FloatField()) + amp2_bin_centers = ArrayField(models.FloatField()) amp3_mean = models.FloatField(blank=True, null=True) amp3_stddev = models.FloatField(blank=True, null=True) - amp3_n = models.TextField(blank=True, null=True) # This field type is a guess. - amp3_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + amp3_n = ArrayField(models.FloatField()) + amp3_bin_centers = ArrayField(models.FloatField()) amp4_mean = models.FloatField(blank=True, null=True) amp4_stddev = models.FloatField(blank=True, null=True) - amp4_n = models.TextField(blank=True, null=True) # This field type is a guess. - amp4_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + amp4_n = ArrayField(models.FloatField()) + amp4_bin_centers = ArrayField(models.FloatField()) class Meta: managed = True @@ -212,7 +213,7 @@ class Meta: app_label = 'monitors' -class NirissReadnoiseQueryHistory(models.Model): +class NIRISSReadnoiseQueryHistory(models.Model): instrument = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) start_time_mjd = models.FloatField(blank=True, null=True) @@ -229,7 +230,7 @@ class Meta: app_label = 'monitors' -class NirissReadnoiseStats(models.Model): +class NIRISSReadnoiseStats(models.Model): uncal_filename = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) detector = models.CharField(blank=True, null=True) @@ -241,30 +242,30 @@ class NirissReadnoiseStats(models.Model): readnoise_filename = models.CharField(blank=True, null=True) full_image_mean = models.FloatField(blank=True, null=True) full_image_stddev = models.FloatField(blank=True, null=True) - full_image_n = models.TextField(blank=True, null=True) # This field type is a guess. - full_image_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + full_image_n = ArrayField(models.FloatField()) + full_image_bin_centers = ArrayField(models.FloatField()) readnoise_diff_image = models.CharField(blank=True, null=True) diff_image_mean = models.FloatField(blank=True, null=True) diff_image_stddev = models.FloatField(blank=True, null=True) - diff_image_n = models.TextField(blank=True, null=True) # This field type is a guess. - diff_image_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + diff_image_n = ArrayField(models.FloatField()) + diff_image_bin_centers = ArrayField(models.FloatField()) entry_date = models.DateTimeField(blank=True, null=True) amp1_mean = models.FloatField(blank=True, null=True) amp1_stddev = models.FloatField(blank=True, null=True) - amp1_n = models.TextField(blank=True, null=True) # This field type is a guess. - amp1_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + amp1_n = ArrayField(models.FloatField()) + amp1_bin_centers = ArrayField(models.FloatField()) amp2_mean = models.FloatField(blank=True, null=True) amp2_stddev = models.FloatField(blank=True, null=True) - amp2_n = models.TextField(blank=True, null=True) # This field type is a guess. - amp2_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + amp2_n = ArrayField(models.FloatField()) + amp2_bin_centers = ArrayField(models.FloatField()) amp3_mean = models.FloatField(blank=True, null=True) amp3_stddev = models.FloatField(blank=True, null=True) - amp3_n = models.TextField(blank=True, null=True) # This field type is a guess. - amp3_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + amp3_n = ArrayField(models.FloatField()) + amp3_bin_centers = ArrayField(models.FloatField()) amp4_mean = models.FloatField(blank=True, null=True) amp4_stddev = models.FloatField(blank=True, null=True) - amp4_n = models.TextField(blank=True, null=True) # This field type is a guess. - amp4_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + amp4_n = ArrayField(models.FloatField()) + amp4_bin_centers = ArrayField(models.FloatField()) class Meta: managed = True @@ -273,7 +274,7 @@ class Meta: app_label = 'monitors' -class NirspecReadnoiseQueryHistory(models.Model): +class NIRSpecReadnoiseQueryHistory(models.Model): instrument = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) start_time_mjd = models.FloatField(blank=True, null=True) @@ -290,7 +291,7 @@ class Meta: app_label = 'monitors' -class NirspecReadnoiseStats(models.Model): +class NIRSpecReadnoiseStats(models.Model): uncal_filename = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) detector = models.CharField(blank=True, null=True) @@ -302,30 +303,30 @@ class NirspecReadnoiseStats(models.Model): readnoise_filename = models.CharField(blank=True, null=True) full_image_mean = models.FloatField(blank=True, null=True) full_image_stddev = models.FloatField(blank=True, null=True) - full_image_n = models.TextField(blank=True, null=True) # This field type is a guess. - full_image_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + full_image_n = ArrayField(models.FloatField()) + full_image_bin_centers = ArrayField(models.FloatField()) readnoise_diff_image = models.CharField(blank=True, null=True) diff_image_mean = models.FloatField(blank=True, null=True) diff_image_stddev = models.FloatField(blank=True, null=True) - diff_image_n = models.TextField(blank=True, null=True) # This field type is a guess. - diff_image_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + diff_image_n = ArrayField(models.FloatField()) + diff_image_bin_centers = ArrayField(models.FloatField()) entry_date = models.DateTimeField(blank=True, null=True) amp1_mean = models.FloatField(blank=True, null=True) amp1_stddev = models.FloatField(blank=True, null=True) - amp1_n = models.TextField(blank=True, null=True) # This field type is a guess. - amp1_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + amp1_n = ArrayField(models.FloatField()) + amp1_bin_centers = ArrayField(models.FloatField()) amp2_mean = models.FloatField(blank=True, null=True) amp2_stddev = models.FloatField(blank=True, null=True) - amp2_n = models.TextField(blank=True, null=True) # This field type is a guess. - amp2_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + amp2_n = ArrayField(models.FloatField()) + amp2_bin_centers = ArrayField(models.FloatField()) amp3_mean = models.FloatField(blank=True, null=True) amp3_stddev = models.FloatField(blank=True, null=True) - amp3_n = models.TextField(blank=True, null=True) # This field type is a guess. - amp3_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + amp3_n = ArrayField(models.FloatField()) + amp3_bin_centers = ArrayField(models.FloatField()) amp4_mean = models.FloatField(blank=True, null=True) amp4_stddev = models.FloatField(blank=True, null=True) - amp4_n = models.TextField(blank=True, null=True) # This field type is a guess. - amp4_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + amp4_n = ArrayField(models.FloatField()) + amp4_bin_centers = ArrayField(models.FloatField()) class Meta: managed = True diff --git a/jwql/website/apps/jwql/monitor_models/ta.py b/jwql/website/apps/jwql/monitor_models/ta.py index b732582a5..e48433dee 100644 --- a/jwql/website/apps/jwql/monitor_models/ta.py +++ b/jwql/website/apps/jwql/monitor_models/ta.py @@ -27,9 +27,10 @@ # This is an auto-generated Django model module. # Feel free to rename the models, but don't rename db_table values or field names. from django.db import models +from django.contrib.postgres.fields import ArrayField -class MiriTaQueryHistory(models.Model): +class MIRITaQueryHistory(models.Model): instrument = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) start_time_mjd = models.FloatField(blank=True, null=True) @@ -46,7 +47,7 @@ class Meta: app_label = 'monitors' -class MiriTaStats(models.Model): +class MIRITaStats(models.Model): entry_date = models.DateTimeField(unique=True) cal_file_name = models.CharField(blank=True, null=True) obs_end_time = models.DateTimeField(blank=True, null=True) @@ -65,7 +66,7 @@ class Meta: app_label = 'monitors' -class NirspecTaQueryHistory(models.Model): +class NIRSpecTaQueryHistory(models.Model): instrument = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) start_time_mjd = models.FloatField(blank=True, null=True) @@ -82,7 +83,7 @@ class Meta: app_label = 'monitors' -class NirspecTaStats(models.Model): +class NIRSpecTaStats(models.Model): entry_date = models.DateTimeField(blank=True, null=True) uncal_filename = models.CharField(blank=True, null=True) aperture = models.CharField(blank=True, null=True) @@ -94,28 +95,28 @@ class NirspecTaStats(models.Model): expstart = models.CharField(blank=True, null=True) full_image_mean = models.FloatField(blank=True, null=True) full_image_stddev = models.FloatField(blank=True, null=True) - full_image_n = models.TextField(blank=True, null=True) # This field type is a guess. - full_image_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + full_image_n = ArrayField(models.FloatField()) + full_image_bin_centers = ArrayField(models.FloatField()) diff_image_mean = models.FloatField(blank=True, null=True) diff_image_stddev = models.FloatField(blank=True, null=True) - diff_image_n = models.TextField(blank=True, null=True) # This field type is a guess. - diff_image_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + diff_image_n = ArrayField(models.FloatField()) + diff_image_bin_centers = ArrayField(models.FloatField()) amp1_mean = models.FloatField(blank=True, null=True) amp1_stddev = models.FloatField(blank=True, null=True) - amp1_n = models.TextField(blank=True, null=True) # This field type is a guess. - amp1_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + amp1_n = ArrayField(models.FloatField()) + amp1_bin_centers = ArrayField(models.FloatField()) amp2_mean = models.FloatField(blank=True, null=True) amp2_stddev = models.FloatField(blank=True, null=True) - amp2_n = models.TextField(blank=True, null=True) # This field type is a guess. - amp2_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + amp2_n = ArrayField(models.FloatField()) + amp2_bin_centers = ArrayField(models.FloatField()) amp3_mean = models.FloatField(blank=True, null=True) amp3_stddev = models.FloatField(blank=True, null=True) - amp3_n = models.TextField(blank=True, null=True) # This field type is a guess. - amp3_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + amp3_n = ArrayField(models.FloatField()) + amp3_bin_centers = ArrayField(models.FloatField()) amp4_mean = models.FloatField(blank=True, null=True) amp4_stddev = models.FloatField(blank=True, null=True) - amp4_n = models.TextField(blank=True, null=True) # This field type is a guess. - amp4_bin_centers = models.TextField(blank=True, null=True) # This field type is a guess. + amp4_n = ArrayField(models.FloatField()) + amp4_bin_centers = ArrayField(models.FloatField()) class Meta: managed = True diff --git a/jwql/website/apps/jwql/monitor_pages/monitor_readnoise_bokeh.py b/jwql/website/apps/jwql/monitor_pages/monitor_readnoise_bokeh.py index a84c9d2ca..d78e64de5 100644 --- a/jwql/website/apps/jwql/monitor_pages/monitor_readnoise_bokeh.py +++ b/jwql/website/apps/jwql/monitor_pages/monitor_readnoise_bokeh.py @@ -28,8 +28,10 @@ from django.templatetags.static import static import numpy as np -from jwql.database.database_interface import session -from jwql.database.database_interface import FGSReadnoiseStats, MIRIReadnoiseStats, NIRCamReadnoiseStats, NIRISSReadnoiseStats, NIRSpecReadnoiseStats +# PEP8 will undoubtedly complain, but the file is specifically designed so that everything +# importable is a monitor class. +from jwql.website.apps.jwql.monitor_models.readnoise import * + from jwql.utils.constants import FULL_FRAME_APERTURES, JWST_INSTRUMENT_NAMES_MIXEDCASE from jwql.utils.utils import get_config @@ -79,14 +81,7 @@ def load_data(self): # Determine which database tables are needed based on instrument self.identify_tables() - # Query database for all data in readnoise stats with a matching aperture, - # and sort the data by exposure start time. - self.query_results = session.query(self.stats_table) \ - .filter(self.stats_table.aperture == self.aperture) \ - .order_by(self.stats_table.expstart) \ - .all() - - session.close() + self.query_results = list(self.stats_table.objects.filter(aperture__iexact=self.aperture).order_by("expstart").all()) class ReadNoiseFigure(): @@ -122,9 +117,9 @@ def __init__(self, instrument, aperture): self.plot_readnoise_histogram() self.tab = TabPanel(child=column(row(*self.amp_plots), - self.diff_image_plot, - self.readnoise_histogram), - title=self.aperture) + self.diff_image_plot, + self.readnoise_histogram), + title=self.aperture) def plot_readnoise_amplifers(self): """Class to create readnoise scatter plots per amplifier. diff --git a/jwql/website/jwql_proj/settings.py b/jwql/website/jwql_proj/settings.py index a6a838803..c0e72240f 100644 --- a/jwql/website/jwql_proj/settings.py +++ b/jwql/website/jwql_proj/settings.py @@ -111,6 +111,7 @@ 'default': get_config()['django_databases']['default'], 'monitors': get_config()['django_databases']['monitors'] } +DATABASE_ROUTERS = ["jwql.website.apps.jwql.monitor_models.common.MonitorRouter"] # Password validation # https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators