Commit 34ff7ada authored by Marco Frailis's avatar Marco Frailis
Browse files

Fixing Astrometry typo

parent 1f65921b
Loading
Loading
Loading
Loading
(184 KiB)

File changed.

No diff preview for this file type.

+1 −1
Original line number Diff line number Diff line
@@ -149,7 +149,7 @@ class CtypeWcs(CompositeField):


class Astrometry(models.Model):
  ctpye1 = CtypeWcs()
  ctype1 = CtypeWcs()
  ctype2 = CtypeWcs()
  crval1 = models.FloatField()
  crval2 = models.FloatField()
+22 −22
Original line number Diff line number Diff line
%% Cell type:markdown id: tags:

## Data insertion and retrieval with Django models
# 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')

print(instrument.telescopeName)
```

%% Output

    Euclid

%% Cell type:markdown id: tags:

## Creating new objects

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.

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 id: tags:

``` python
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"
  url = "http://ia2-owncloud.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,
                                          'orientation':64.8793517547},
                     filterWheelPosition = "Y",
                     grismWheelPosition = "OPEN"
                    )



image.frameFile = dataFile
```

%% Cell type:markdown id: tags:

Before saving an object, its surrogate key is still empty, i.e. equal to None

%% Cell type:code id: tags:

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

%% Output

    None
    3
    2

%% Cell type:code id: tags:

``` python
# 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
# Or we can use the create() in order to create and save immediately the new object
NispDetector.objects.create(detectorId = "12", gain = 1.0, readoutNoise = 0.0, rawFrame = image)

# or we can create the detector starting from the NispRawFrame, using the reversed relationship,
# using again the create method

image.detectors.create(
  detectorId = "12",
  detectorId = "13",
  gain = 1.0,
  readoutNoise = 0.0
)
```

%% Output

    <NispDetector: NispDetector object (4)>

%% Cell type:code id: tags:

``` python
image.detectors.all()
```

%% Output

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

%% Cell type:code id: tags:

``` python
image.detectors.all()
```

%% Output

    <QuerySet [<NispDetector: NispDetector object (1)>]>

%% Cell type:code id: tags:

``` python
```
    <QuerySet [<NispDetector: NispDetector object (2)>, <NispDetector: NispDetector object (3)>, <NispDetector: NispDetector object (4)>]>