Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
orm_example
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
odmc
orm_example
Commits
1f65921b
Commit
1f65921b
authored
6 years ago
by
Marco Frailis
Browse files
Options
Downloads
Patches
Plain Diff
Fixing some constraints
parent
cc9fc1f1
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
db.sqlite3
+0
-0
0 additions, 0 deletions
db.sqlite3
imagedb/models.py
+5
-0
5 additions, 0 deletions
imagedb/models.py
imagedb_objects.ipynb
+88
-28
88 additions, 28 deletions
imagedb_objects.ipynb
orm_example/settings.py
+1
-1
1 addition, 1 deletion
orm_example/settings.py
with
94 additions
and
29 deletions
db.sqlite3
+
0
−
0
View file @
1f65921b
No preview for this file type
This diff is collapsed.
Click to expand it.
imagedb/models.py
+
5
−
0
View file @
1f65921b
...
...
@@ -76,6 +76,9 @@ 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
):
rightAscension
=
models
.
FloatField
()
...
...
@@ -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
=
(
...
...
This diff is collapsed.
Click to expand it.
imagedb_objects.ipynb
+
88
−
28
View file @
1f65921b
{
"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",
"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,
...
...
%% Cell type:markdown id: tags:
## Data insertion and retrieval with Django models
In the following we show some examples in order to perform insertions and retrievals of metadata
%% Cell type:code id: tags:
```
python
from
imagedb.models
import
Instrument
instrument
=
Instrument
.
objects
.
get
(
instrumentName
=
'
NISP
'
)
```
%% Cell type:code id: tags:
```
python
print
(
instrument
.
instrumentName
)
print
(
instrument
.
telescopeName
)
```
%% Output
NISP
Euclid
%% Cell type:code id: tags:
```
python
from
imagedb.models
import
ImageType
,
Pointing
,
NispDetector
,
NispRawFrame
from
imagedb.models
import
ImageType
,
Pointing
,
NispDetector
,
DataContainer
,
NispRawFrame
from
datetime
import
datetime
dataFile
=
DataContainer
(
fileFormat
=
'
fits
'
,
formatIdentifier
=
'
le1.nisprawframe
'
,
formatVersion
=
'
1.0
'
,
url
=
"
http://ia2-ownclud.oats.inaf.it/fake/7ff2f203/data/EUC_LE1_NISP_53892-Y-1_20170712T155430.1Z_00.00.fits
"
)
# We have to save the data container to the DB before assigning it to a NispRawFrame
dataFile
.
save
()
image
=
NispRawFrame
(
exposureTime
=
105
,
imgNumber
=
16
,
naxis1
=
2040
,
naxis2
=
2040
,
imageType
=
{
'
category
'
:
'
SCIENCE
'
,
'
firstType
'
:
'
OBJECT
'
,
'
secondType
'
:
'
STD
'
},
observationDateTime
=
datetime
.
strptime
(
"
2025-06-21T18:27:23.000001
"
,
"
%Y-%m-%dT%H:%M:%S.%f
"
),
observationId
=
53892
,
ditherNumber
=
1
,
instrument
=
instrument
,
commandedPointing
=
{
'
rightAscension
'
:
8.48223045516
,
'
declination
'
:
8.48223045516
,
'
pointingAngle
'
:
64.8793517547
},
'
orientation
'
:
64.8793517547
},
filterWheelPosition
=
"
Y
"
,
grismWheelPosition
=
"
OPEN
"
)
image
.
frameFile
=
dataFile
```
%% Cell type:code id: tags:
```
python
image
.
commandedPointing
print
(
image
.
id
)
image
.
save
()
print
(
image
.
id
)
```
%% Output
Pointing(rightAscension=8.48223045516, declination=8.48223045516, pointingAngle=64.8793517547)
None
3
%% Cell type:code id: tags:
```
python
image
.
commandedPointing
.
rightAscension
# We can start creating a detector
d11
=
NispDetector
(
detectorId
=
"
11
"
,
gain
=
1.0
,
readoutNoise
=
0.0
,
rawFrame
=
image
)
d11
.
save
()
# or we can create the detector starting from the NispRawFrame, using the reversed relationship.
# No need to save the detector in this case. It is done automatically
image
.
detectors
.
create
(
detectorId
=
"
12
"
,
gain
=
1.0
,
readoutNoise
=
0.0
)
```
%% Output
<NispDetector: NispDetector object (4)>
%% Cell type:code id: tags:
```
python
image
.
detectors
.
all
()
```
%% Output
8.48223045516
<QuerySet [<NispDetector: NispDetector object (1)>, <NispDetector: NispDetector object (2)>]>
%% Cell type:code id: tags:
```
python
image
=
NispRawFrame
.
objects
.
filter
(
commandedPointing_rightAscension__lte
=
8.48223045516
)[
0
]
image
.
detectors
.
all
()
```
%% Output
<QuerySet [<NispDetector: NispDetector object (1)>]>
%% Cell type:code id: tags:
```
python
d
=
NispDetector
(
detectorId
=
"
11
"
,
gain
=
1.0
,
readoutNoise
=
0.0
,
rawFrame
=
image
)
```
...
...
This diff is collapsed.
Click to expand it.
orm_example/settings.py
+
1
−
1
View file @
1f65921b
...
...
@@ -121,7 +121,7 @@ USE_I18N = True
USE_L10N
=
True
USE_TZ
=
Tru
e
USE_TZ
=
Fals
e
# Static files (CSS, JavaScript, Images)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment