Package: ocs-archive
OCS Archive LibraryA base library for the Science Archive and Ingester library to support generalized input file types, generalized data stores, and shared configuration items. This library is configurable via environment variables, but more customization is possible by subclassing theDataFileclass for a specific file type, or subclassing theFileStoreclass for a specific file storage scheme.PrerequisitesOptional prerequisites may be skipped for reduced functionality.Python >= 3.8UsageThis library is used with the OCSScience Archiveand OCSIngester library. It has built in support for .fits files, compressed .fits files, or custom files if the metadata is supplied separately. It is critical that the Header Mapping environment variables below are set up to map to the proper .fits header keys in your data product definition, so that the information can be automatically extracted and stored in the Science Archive. The FileStore environment variables also need to be set for whichever file storage system you are targetting (S3 preferred). The DataFile environment variables aid in the extracting and ingestion of header values from data. For more information on how to customize your OCS Science Archive, please review thedata flow documentation.InstallationIt is highly recommended that you install and run your python code inside a dedicated pythonvirtual environment.Add theocs_archivepackage to your python environment:(venv)$pipinstallocs_archiveConfigurationEnvironment VariablesGroupVariableDescriptionDefaultFileStoreFILESTORE_TYPEType of filestorage to use. Options aredummy,local, ors3.dummyFILESYSTEM_STORAGE_ROOT_DIRIf usinglocalfile storage, this is the directory on the local filesystem to use as the root of the storage directoriesempty stringFILESYSTEM_STORAGE_BASE_URLIf usinglocalfile storage, this is the base URL at which those files will be hosted fromhttp://0.0.0.0/Observation PortalOBSERVATION_PORTAL_BASE_URLBase URL for the Observation Portalempty stringOBSERVATION_PORTAL_API_TOKENAPI Token used to authenticate with the Observation Portalempty stringAWSBUCKETIf usings3file storage; AWS S3 Bucket NametestbucketAWS_ACCESS_KEY_IDIf usings3file storage; AWS Access Key with write access to the S3 bucketempty stringAWS_SECRET_ACCESS_KEYIf usings3file storage; AWS Secret Access Keyempty stringAWS_DEFAULT_REGIONIf usings3file storage; AWS S3 Default Regionempty stringS3_ADDRESSING_STYLEIf usings3file storage; Sets the addressing_style for generated s3 paths. Can be one ofvirtual,path, orauto.virtualS3_ENDPOINT_URLIf usings3file storage; Endpoint url for connecting to s3. This can be modified to connect to a local instance of s3."http://s3.us-west-2.amazonaws.com"S3_DAYS_TO_IA_STORAGEIf usings3file storage, this is the age in days after which data will be ingested directly to Infrequent Access (IA) storage vs normal storage.60DataFileFILETYPE_MAPPING_OVERRIDESA string literal representation of a python dictionary containing a mapping of file extensions to dotpaths to python Classes which subclass the DataFile class. This appends and overrides the default list in the FileFactory class."{}"HEADER_BLACKLISTComma delimited string list of header values that should be removed from the data before storage in the archive. This can be overriden when instantiating a DataFile as well as via environment variable.HISTORY,COMMENTREQUIRED_HEADERSComma delimited string list of header values that must be present in the DataFile. This can be overriden when instantiating a DataFile as well as via environment variableNULL_HEADER_VALUESComma delimited string list of header values that should be turned intoNoneor empty keys. This only applies to the FitsFile class.N/A,UNSPECIFIED,UNKNOWNCALIBRATION_TYPESComma delimited string list of configuration types which represent calibration images. This is used to automatically set calibration images public date to be the observation date if it is not presentBIAS,DARK,SKYFLAT,EXPERIMENTALPUBLIC_PROPOSAL_TAGSA comma delimited string list of Observation Portal proposal tags to denote data from this proposal as public. If public, the public date will be set to the observation date. The ocs_archive will fall back to the list ofPUBLIC_PROPOSALSif any of a proposal's tags are not found in this list.publicPRIVATE_PROPOSAL_TAGSA comma delimited string list of Observation Portal proposal tags to denote data from this proposal as private. If private, the public date will be set to 999 years in the future. The ocs_archive will fall back to the list ofPRIVATE_PROPOSALSif any of a proposal's tags are not found in this list.private,internalPUBLIC_PROPOSALSComma delimited string list of proposal IDs which represent public proposals. This is used to set the public date of observations under those proposals to the observation date if it is not present. The matching is based on if each character group appears anywhere within the proposal IDEPO,calib,standard,pointingPRIVATE_PROPOSALSA comma delimited string list of proposal IDs which represent private proposals. This is used to set the public date of the observations under those proposals to be 999 years in the future. The matching is based on if each character group appears anywhere within the proposal IDLCOEngineeringDAYS_UNTIL_PUBLICThe number of days until user data becomes public by default. This is added onto the observation date to get the public date if one is not specifed with the data365PRIVATE_FILE_TYPESA comma delimited string list of fragments of the file name which denote a private data file. If any of the fragments are found within the filename, the public date will be set 999 years in the future for this file-t00,-x00Header MappingOBSERVATION_DATE_KEYThe key in which to find an iso formatted observation date within the header dataDATE-OBSOBSERVATION_DAY_KEYThe key in which to find an iso formatted observation day within the header dataDAY-OBSOBSERVATION_END_TIME_KEYThe key in which to find an iso formatted observation end date within the header dataUTSTOPREDUCTION_LEVEL_KEYThe key in which to find a numeric reduction level within the header data. Raw is 0, while anything non-zero is some form of processingRLEVELEXPOSURE_TIME_KEYThe key in which to find the exposure time in fractional seconds in the header dataEXPTIMEINSTRUMENT_ID_KEYThe key in which to find the instrument ID in the header dataINSTRUMESITE_ID_KEYThe key in which to find the site ID in the header dataSITEIDTELESCOPE_ID_KEYThe key in which to find the telescope ID in the header dataTELIDOBSERVATION_ID_KEYThe key in which to find the observation ID in the header dataBLKUIDCONFIGURATION_ID_KEYThe key in which to find the configuration ID in the header dataMOLUIDPRIMARY_OPTICAL_ELEMENT_KEYThe key in which to find the primary filter value in the header dataFILTERTARGET_NAME_KEYThe key in which to find the target object's name in the header dataOBJECTREQUEST_ID_KEYThe key in which to find the request ID in the header dataREQNUMREQUESTGROUP_ID_KEYThe key in which to find the request group ID in the header dataTRACKNUMCONFIGURATION_TYPE_KEYThe key in which to find the configuration type in the header dataOBSTYPEPROPOSAL_ID_KEYThe key in which to find the proposal ID in the header dataPROPIDCATALOG_TARGET_FRAME_KEYThe key in which to find the base filename of the catalog file for the target of this observation in the header dataL1IDCATPUBLIC_DATE_KEYThe key in which to find the iso formatted date in which this data should become available to the public in the header dataL1PUBDATRELATED_FRAME_KEYSA comma delimited list of keys in the header data to look for related frame base filenames for this observationL1IDBIAS,L1IDDARK,L1IDFLAT,L1IDSHUT,L1IDMASK,L1IDFRNG,L1IDCAT,L1IDARC,L1ID1D,L1ID2D,L1IDSUM,TARFILE,ORIGNAME,ARCFILE,FLATFILE,GUIDETARRADIUS_KEYThe key in which to find FOV radius for a circular FOV, used to calculate WCS polygon if specified. Unit of arcsecondsRADIUSRA_KEYThe key in which to find FOV center RA for a circular FOV, used to calculate WCS polygon if specified. Unit of hour angleRADEC_KEYThe key in which to find FOV center DEC for a circular FOV, used to calculate WCS polygon if specified. Unit of decimal degreesDECInput File Format ConfigurationThe library is designed to be configured mostly through environment variables, but customDataFilesubclasses can be included and specified via an environment variable in order to support new and more complicated data formats. All data files must contain the minimum set of metadata in order to ingested into the archive. This metadata is used to provide filtering and querying support within the archive. The pieces of file metadata that should be specified have their mappings defined in the Header Data section of the environment variables below. TheFitsFileclass provided will work for normal or funpacked fits files, provided you set up the Header Data environment variables with the correct mapping of observation concepts to header keys in your data format.File Storage Format ConfigurationThe library supports three types of file storage by default, that can be selected via environment variable. Thedummytype is just used for testing and development and doesn't actually store any file. Thelocalstorage just saves the files into a locally mounted directory. It requires you to run a separate file server on that directory so it knows how to direct links to download the files. This can be accomplished as simply as runningpython -m http.server --directory=/my/root/dir. It could alternatively be served using any other file server, like node's http-server. The third option iss3, and expects to connect to Amazon's S3 or something with that same interface like minio. S3 file storage requiresBUCKET,AWS_*, andS3_*environment variables to be set. More storage types can be added via forking the library and subclassing theFileStoreclass. S3 storage is the preferred method for a production and public-facing archive, since it is the only option to support versioning and secure data access by generating presigned data URLs.DevelopmentPoetryWe use Poetry for package management. If you already have Poetry installed, you
can skip this section.You can install Poetry using one of the many options listed athttps://python-poetry.org/docs/#installation.
One simple option is using Pipx:python3 -m pip install --user pipx
python3 -m pipx ensurepath
pipx install poetryInstallInstall the project and its Python dependencies:poetry installThis will install the project in a Poetry managed virtual environment. To run
commands in that environment either usepoetry run ...or start a shell in
that environment withpoetry shellTestpoetry run pytest