Skip to content
Snippets Groups Projects
Commit 1f65921b authored by Marco Frailis's avatar Marco Frailis
Browse files

Fixing some constraints

parent cc9fc1f1
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -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 = (
......
%% 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)
```
......
......@@ -121,7 +121,7 @@ USE_I18N = True
USE_L10N = True
USE_TZ = True
USE_TZ = False
# Static files (CSS, JavaScript, Images)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment