diff --git a/db.sqlite3 b/db.sqlite3 index 49efc9c42bba66b81ac13a41bfbcfffeeaa2429c..396bf98f364c1d2fce4b692e8f49ccc4577c5401 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/imagedb/models.py b/imagedb/models.py index 06cc9da57a5d5be7ae38c6e44d1c8a87f7b91717..3c72de582a2eb5cd906be16a3e7df4b6b752dcc7 100644 --- a/imagedb/models.py +++ b/imagedb/models.py @@ -149,7 +149,7 @@ class CtypeWcs(CompositeField): class Astrometry(models.Model): - ctpye1 = CtypeWcs() + ctype1 = CtypeWcs() ctype2 = CtypeWcs() crval1 = models.FloatField() crval2 = models.FloatField() diff --git a/imagedb_objects.ipynb b/imagedb_objects.ipynb index 2a2f3ea0aa0825d1fa5138260c90677098f04bdb..f50c8d3a219d21a96d8b1164b959b0acd56c91b2 100644 --- a/imagedb_objects.ipynb +++ b/imagedb_objects.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Data insertion and retrieval with Django models\n", + "# Data insertion and retrieval with Django models\n", "\n", "In the following we show some examples in order to perform insertions and retrievals of metadata " ] @@ -30,9 +30,20 @@ "print(instrument.telescopeName)\n" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Creating new objects\n", + "\n", + "In the following we will create a NispRawFrame object. Since the NispRawFrame must have also a DataCotainer (i.e. a file to reference to), we first create a DataContainer instance.\n", + "\n", + "We can see also that the fields that we have defined as composite fields provide some synctactic sugar when we initialize them with simple dictionaries." + ] + }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -44,7 +55,7 @@ " 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", + " url = \"http://ia2-owncloud.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", @@ -74,9 +85,16 @@ "image.frameFile = dataFile" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Before saving an object, its surrogate key is still empty, i.e. equal to None" + ] + }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -84,7 +102,7 @@ "output_type": "stream", "text": [ "None\n", - "3\n" + "2\n" ] } ], @@ -96,7 +114,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 5, "metadata": { "scrolled": true }, @@ -107,7 +125,7 @@ "<NispDetector: NispDetector object (4)>" ] }, - "execution_count": 30, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -118,11 +136,14 @@ "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", + "# Or we can use the create() in order to create and save immediately the new object\n", + "NispDetector.objects.create(detectorId = \"12\", gain = 1.0, readoutNoise = 0.0, rawFrame = image)\n", + "\n", + "# or we can create the detector starting from the NispRawFrame, using the reversed relationship,\n", + "# using again the create method\n", "\n", "image.detectors.create(\n", - " detectorId = \"12\",\n", + " detectorId = \"13\",\n", " gain = 1.0,\n", " readoutNoise = 0.0\n", ")" @@ -130,16 +151,16 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "<QuerySet [<NispDetector: NispDetector object (1)>, <NispDetector: NispDetector object (2)>]>" + "<QuerySet [<NispDetector: NispDetector object (2)>, <NispDetector: NispDetector object (3)>, <NispDetector: NispDetector object (4)>]>" ] }, - "execution_count": 29, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -147,33 +168,6 @@ "source": [ "image.detectors.all()" ] - }, - { - "cell_type": "code", - "execution_count": 27, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "<QuerySet [<NispDetector: NispDetector object (1)>]>" - ] - }, - "execution_count": 27, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "image.detectors.all()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": {