From 34ff7ada39bba95a1f513420fc2bee4369cda107 Mon Sep 17 00:00:00 2001
From: Marco Frailis <marco.frailis@inaf.it>
Date: Sun, 14 Oct 2018 18:45:19 +0200
Subject: [PATCH] Fixing Astrometry typo

---
 db.sqlite3            | Bin 188416 -> 188416 bytes
 imagedb/models.py     |   2 +-
 imagedb_objects.ipynb |  74 +++++++++++++++++++-----------------------
 3 files changed, 35 insertions(+), 41 deletions(-)

diff --git a/db.sqlite3 b/db.sqlite3
index 49efc9c42bba66b81ac13a41bfbcfffeeaa2429c..396bf98f364c1d2fce4b692e8f49ccc4577c5401 100644
GIT binary patch
delta 418
zcmZoTz};|wdxM~iyorLLnU#sLm9eFsnW?3rshJT!D}%JEV`gq*dTL72<c0F0g2-x2
zEDX%dCWpybAd8w>ni-fHPo6Jhjv{JdXkctG`MHb@il~{1sgc=a6Imk^QDbvUOXJDq
zvc{;QCI%+vlXuG+qKFz=ni&~S{wr&OB5Gi2X<{(hNzM{k)Wp)rz`$&B51Ocjfr*9L
z<ZE(P0!V%{F*P-`n5-agEQ>5?WNvC<X~4|NAg=0|n39{BhaMy*hK82L=98z%D<E5J
zY-wg;U_AM_yauur#^z=QM$P}_+yBcmZvQXOq-M-iSukBam`R(ZvLMxP`i5X8jqP>8
HOieuiqwHjJ

delta 418
zcmZoTz};|wdxM~iys?6jft885m4ShtnURH=k+~5+D}%JEV`gq*dTL72<c0F0g2-wN
zO%2S9CWpybAd8w>7+9DZPM$Agjv{JmX=-6K`MHb@im0)HiG|T*6Imk^QA0yBQ<KT%
zvc@Q)24=<<hLd;88X}9Dm>U@wTTcEfYl0$bY-V9%I@w9i5=GR=(AdOuau1rQfw`r*
z`Q&SIRsu+VGd4FgvYf0SZ!C)}Xl!n7WN5(5${?=ln3$5AnTH-E#)ig*MkbS|$txgR
zY-DL}X>2z6xV#3k6-H*}Cg#om<=g+uGj9Jc&!lF|R8ToxJ(x+GrJyp^aQcQ|CXMZN
I!Awm(0MDvpg8%>k

diff --git a/imagedb/models.py b/imagedb/models.py
index 06cc9da..3c72de5 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 2a2f3ea..f50c8d3 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": {
-- 
GitLab