Commit 1f65921b authored by Marco Frailis's avatar Marco Frailis
Browse files

Fixing some constraints

parent cc9fc1f1
Loading
Loading
Loading
Loading
+8 KiB (184 KiB)

File changed.

No diff preview for this file type.

+5 −0
Original line number Original line Diff line number Diff line
@@ -76,6 +76,9 @@ class Instrument(models.Model):
  instrumentName = models.CharField(max_length=100)
  instrumentName = models.CharField(max_length=100)
  telescopeName = models.CharField(max_length=100)
  telescopeName = models.CharField(max_length=100)
  
  
  class Meta:
    unique_together = (('instrumentName', 'telescopeName'))



class Pointing(CompositeField):
class Pointing(CompositeField):
  rightAscension = models.FloatField()
  rightAscension = models.FloatField()
@@ -114,6 +117,8 @@ class NispDetector(models.Model):
  rawFrame = models.ForeignKey('NispRawFrame',
  rawFrame = models.ForeignKey('NispRawFrame',
                               related_name='detectors',
                               related_name='detectors',
                               on_delete=models.CASCADE)
                               on_delete=models.CASCADE)
  class Meta:
    unique_together = (('detectorId', 'rawFrame'))




WCS_COORDINATE_TYPE = (
WCS_COORDINATE_TYPE = (
+59 −14
Original line number Original line Diff line number Diff line
%% 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:
%% Cell type:code id: tags:


``` python
``` python
from imagedb.models import Instrument
from imagedb.models import Instrument


instrument = Instrument.objects.get(instrumentName='NISP')
instrument = Instrument.objects.get(instrumentName='NISP')
```


%% Cell type:code id: tags:
print(instrument.telescopeName)

``` python
print(instrument.instrumentName)
```
```


%% Output
%% Output


    NISP
    Euclid


%% Cell type:code id: tags:
%% Cell type:code id: tags:


``` python
``` python
from imagedb.models import ImageType, Pointing, NispDetector, NispRawFrame
from imagedb.models import ImageType, Pointing, NispDetector, DataContainer, NispRawFrame


from datetime import datetime
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,
image = NispRawFrame(exposureTime = 105,
                     imgNumber = 16,
                     imgNumber = 16,
                     naxis1 = 2040,
                     naxis1 = 2040,
                     naxis2 = 2040,
                     naxis2 = 2040,
                     imageType = {'category':'SCIENCE',
                     imageType = {'category':'SCIENCE',
                                  'firstType':'OBJECT',
                                  'firstType':'OBJECT',
                                  'secondType':'STD'},
                                  'secondType':'STD'},
                     observationDateTime = datetime.strptime("2025-06-21T18:27:23.000001",
                     observationDateTime = datetime.strptime("2025-06-21T18:27:23.000001",
                                                             "%Y-%m-%dT%H:%M:%S.%f"),
                                                             "%Y-%m-%dT%H:%M:%S.%f"),
                     observationId = 53892,
                     ditherNumber = 1,
                     instrument = instrument,
                     instrument = instrument,
                     commandedPointing = {'rightAscension':8.48223045516,
                     commandedPointing = {'rightAscension':8.48223045516,
                                          'declination':8.48223045516,
                                          'declination':8.48223045516,
                                          'pointingAngle':64.8793517547},
                                          'orientation':64.8793517547},
                     filterWheelPosition = "Y",
                     filterWheelPosition = "Y",
                     grismWheelPosition = "OPEN"
                     grismWheelPosition = "OPEN"
                    )
                    )



image.frameFile = dataFile
```
```


%% Cell type:code id: tags:
%% Cell type:code id: tags:


``` python
``` python
image.commandedPointing
print(image.id)
image.save()
print(image.id)
```
```


%% Output
%% Output


    Pointing(rightAscension=8.48223045516, declination=8.48223045516, pointingAngle=64.8793517547)
    None
    3


%% Cell type:code id: tags:
%% Cell type:code id: tags:


``` python
``` 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
%% Output


    8.48223045516
    <QuerySet [<NispDetector: NispDetector object (1)>, <NispDetector: NispDetector object (2)>]>


%% Cell type:code id: tags:
%% Cell type:code id: tags:


``` python
``` 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:
%% Cell type:code id: tags:


``` python
``` python
d = NispDetector(detectorId = "11", gain = 1.0, readoutNoise = 0.0, rawFrame = image)
```
```
+1 −1
Original line number Original line Diff line number Diff line
@@ -121,7 +121,7 @@ USE_I18N = True


USE_L10N = True
USE_L10N = True


USE_TZ = True
USE_TZ = False




# Static files (CSS, JavaScript, Images)
# Static files (CSS, JavaScript, Images)