diff --git a/db.sqlite3 b/db.sqlite3 index 84a7f50e08912e8476c470186a338b42043db3fe..49efc9c42bba66b81ac13a41bfbcfffeeaa2429c 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/imagedb/models.py b/imagedb/models.py index a2a487e9023793342c7e6fa5ccf81f4502005292..06cc9da57a5d5be7ae38c6e44d1c8a87f7b91717 100644 --- a/imagedb/models.py +++ b/imagedb/models.py @@ -75,6 +75,9 @@ class ImageBaseFrame(models.Model): class Instrument(models.Model): instrumentName = models.CharField(max_length=100) telescopeName = models.CharField(max_length=100) + + class Meta: + unique_together = (('instrumentName', 'telescopeName')) class Pointing(CompositeField): @@ -114,6 +117,8 @@ class NispDetector(models.Model): rawFrame = models.ForeignKey('NispRawFrame', related_name='detectors', on_delete=models.CASCADE) + class Meta: + unique_together = (('detectorId', 'rawFrame')) WCS_COORDINATE_TYPE = ( diff --git a/imagedb_objects.ipynb b/imagedb_objects.ipynb index 6dff79e4a64000ab7faa3ed81efac85ab24ccfa5..2a2f3ea0aa0825d1fa5138260c90677098f04bdb 100644 --- a/imagedb_objects.ipynb +++ b/imagedb_objects.ipynb @@ -1,14 +1,12 @@ { "cells": [ { - "cell_type": "code", - "execution_count": 1, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "from imagedb.models import Instrument\n", + "## Data insertion and retrieval with Django models\n", "\n", - "instrument = Instrument.objects.get(instrumentName='NISP')\n" + "In the following we show some examples in order to perform insertions and retrievals of metadata " ] }, { @@ -20,24 +18,37 @@ "name": "stdout", "output_type": "stream", "text": [ - "NISP\n" + "Euclid\n" ] } ], "source": [ - "print(instrument.instrumentName)" + "from imagedb.models import Instrument\n", + "\n", + "instrument = Instrument.objects.get(instrumentName='NISP')\n", + "\n", + "print(instrument.telescopeName)\n" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ - "from imagedb.models import ImageType, Pointing, NispDetector, NispRawFrame\n", + "from imagedb.models import ImageType, Pointing, NispDetector, DataContainer, NispRawFrame\n", "\n", "from datetime import datetime\n", - " \n", + "\n", + "dataFile = DataContainer(\n", + " fileFormat = 'fits',\n", + " formatIdentifier = 'le1.nisprawframe',\n", + " formatVersion = '1.0',\n", + " url = \"http://ia2-ownclud.oats.inaf.it/fake/7ff2f203/data/EUC_LE1_NISP_53892-Y-1_20170712T155430.1Z_00.00.fits\"\n", + ")\n", + "\n", + "# We have to save the data container to the DB before assigning it to a NispRawFrame\n", + "dataFile.save()\n", "\n", "image = NispRawFrame(exposureTime = 105,\n", " imgNumber = 16,\n", @@ -48,72 +59,121 @@ " 'secondType':'STD'},\n", " observationDateTime = datetime.strptime(\"2025-06-21T18:27:23.000001\", \n", " \"%Y-%m-%dT%H:%M:%S.%f\"),\n", + " observationId = 53892,\n", + " ditherNumber = 1,\n", " instrument = instrument,\n", " commandedPointing = {'rightAscension':8.48223045516,\n", " 'declination':8.48223045516,\n", - " 'pointingAngle':64.8793517547},\n", + " 'orientation':64.8793517547},\n", " filterWheelPosition = \"Y\",\n", " grismWheelPosition = \"OPEN\"\n", - " )\n" + " )\n", + "\n", + "\n", + "\n", + "image.frameFile = dataFile" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 19, "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "None\n", + "3\n" + ] + } + ], + "source": [ + "print(image.id)\n", + "image.save()\n", + "print(image.id)" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": { + "scrolled": true + }, "outputs": [ { "data": { "text/plain": [ - "Pointing(rightAscension=8.48223045516, declination=8.48223045516, pointingAngle=64.8793517547)" + "<NispDetector: NispDetector object (4)>" ] }, - "execution_count": 4, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "image.commandedPointing" + "# We can start creating a detector\n", + "\n", + "d11 = NispDetector(detectorId = \"11\", gain = 1.0, readoutNoise = 0.0, rawFrame = image)\n", + "d11.save()\n", + "\n", + "# or we can create the detector starting from the NispRawFrame, using the reversed relationship.\n", + "# No need to save the detector in this case. It is done automatically\n", + "\n", + "image.detectors.create(\n", + " detectorId = \"12\",\n", + " gain = 1.0,\n", + " readoutNoise = 0.0\n", + ")" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "8.48223045516" + "<QuerySet [<NispDetector: NispDetector object (1)>, <NispDetector: NispDetector object (2)>]>" ] }, - "execution_count": 5, + "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "image.commandedPointing.rightAscension" + "image.detectors.all()" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 27, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "<QuerySet [<NispDetector: NispDetector object (1)>]>" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "image = NispRawFrame.objects.filter(commandedPointing_rightAscension__lte=8.48223045516)[0]" + "image.detectors.all()" ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, "outputs": [], - "source": [ - "d = NispDetector(detectorId = \"11\", gain = 1.0, readoutNoise = 0.0, rawFrame = image)" - ] + "source": [] } ], "metadata": { @@ -132,7 +192,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.3" + "version": "3.7.0" } }, "nbformat": 4, diff --git a/orm_example/settings.py b/orm_example/settings.py index c651d61c07f8e7dbba34a9a3e2e716f1efbed291..d9fde8da3999e3f28da647394078cff9d88a94b9 100644 --- a/orm_example/settings.py +++ b/orm_example/settings.py @@ -121,7 +121,7 @@ USE_I18N = True USE_L10N = True -USE_TZ = True +USE_TZ = False # Static files (CSS, JavaScript, Images)