Skip to content
Snippets Groups Projects
a832fcb74a8c_add_std_cms_imaging_templates.py 6.42 KiB
Newer Older
"""add std_cms_imaging templates

Revision ID: a832fcb74a8c
Revises: 6ce7b4b8a9ea
Create Date: 2021-06-28 15:51:12.733523

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "a832fcb74a8c"
down_revision = "6ce7b4b8a9ea"
branch_labels = None
depends_on = None

condor_content = """executable = std_cms_imaging.sh
arguments = metadata.json PPR.xml

output = imaging.out
error = imaging.err
log = condor.log

SBIN_PATH = /lustre/aoc/cluster/pipeline/$ENV(CAPO_PROFILE)/workspaces/sbin
CMS_PATH = /lustre/aoc/cluster/pipeline/$ENV(CAPO_PROFILE)/workspaces/spool/{{relative_path}}/working
should_transfer_files = yes
transfer_input_files = $(SBIN_PATH)/.matplotlib, $(SBIN_PATH)/pycapo, $(SBIN_PATH)/framework.sh, $(SBIN_PATH)/productfetcher,
 $(SBIN_PATH)/casa_envoy, $(SBIN_PATH)/vela, $(SBIN_PATH)/conveyor, ./PPR.xml, ./metadata.json, $(CMS_PATH)/{{cms_name}}

request_memory = {{ramInGb}}
getenv = True
environment = "CAPO_PATH=/home/casa/capo"

queue

"""

script_content = """#!/bin/sh

export HOME=$TMPDIR

./framework.sh -d .
chmod 770 .
mv {{cms_name}} ./rawdata
./casa_envoy --standard-cmsimage $1 $2
./conveyor --deliver-image $1

"""

metadata_content = """{
  "fileSetIds": "{{sdmId}}",
  "workflowName": "std_cms_imaging",
  "systemId": "{{request_id}}",
  "productLocator": "{{product_locator}}",
  "projectMetadata": {
    "projectCode": "{{projectCode}}",
    "title": "{{title}}",
    "startTime": "{{startTime}}",
    "observer": "{{observer}}"
  },
  "destinationDirectory": "{{root_directory}}/{{relative_path}}"
  "calibrationSourceDirectory":"{{cal_directory}}"
}
"""

ppr_content = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:SciPipeRequest xmlns:ns2="Common/pipelinescience/SciPipeRequest">
    <ProjectSummary>
        <ProposalCode>VLA/null</ProposalCode>
        <Observatory>NRAO</Observatory>
        <Telescope>VLA</Telescope>
        <ProcessingSite>Socorro</ProcessingSite>
        <Operator>vlapipe</Operator>
        <Mode>SCIENCE</Mode>
        <Version>NGRH-ALMA-10_8</Version>
        <CreationTime>{{created_at}}</CreationTime>
    </ProjectSummary>
    <ProjectStructure>TBD</ProjectStructure>
    <ProcessingRequests>
        <RootDirectory>{{root_directory}}</RootDirectory>
        <ProcessingRequest>
            <ProcessingIntents>
                <Intents>
                    <Keyword>VLA_INTERFEROMETRY_STANDARD_OBSERVING_MODE</Keyword>
                    <Value>Undefined</Value>
                </Intents>
            </ProcessingIntents>
            <ProcessingProcedure>
                <ProcedureTitle>hifv_contimage</ProcedureTitle>
                <ProcessingCommand>
                    <Command xmlns="">hifv_importdata</Command>
                    <ParameterSet>
                    </ParameterSet>
                </ProcessingCommand>
                <ProcessingCommand>
                    <Command xmlns="">hif_mstransform</Command>
                    <ParameterSet>
                    </ParameterSet>
                </ProcessingCommand>
                <ProcessingCommand>
                    <Command xmlns="">hif_checkproductsize</Command>
                    <ParameterSet>
                        <Parameter>
                            <Keyword xmlns="">maximsize</Keyword>
                            <Value xmlns="">16384</Value>
                        </Parameter>
                    </ParameterSet>
                </ProcessingCommand>
                <ProcessingCommand>
                    <Command xmlns="">hif_makeimlist</Command>
                    <ParameterSet>
                        <Parameter>
                            <Keyword xmlns="">specmode</Keyword>
                            <Value xmlns="">cont</Value>
                        </Parameter>
                    </ParameterSet>
                </ProcessingCommand>
                <ProcessingCommand>
                    <Command xmlns="">hif_makeimages</Command>
                    <ParameterSet>
                        <Parameter>
                            <Keyword xmlns="">hm_masking</Keyword>
                            <Value xmlns="">none</Value>
                        </Parameter>
                        <Parameter>
                            <Keyword xmlns="">hm_cyclefactor</Keyword>
                            <Value xmlns="">3.0</Value>
                        </Parameter>
                    </ParameterSet>
                </ProcessingCommand>
                <ProcessingCommand>
                    <Command xmlns="">hifv_exportdata</Command>
                    <ParameterSet>
                        <Parameter>
                            <Keyword xmlns="">imaging_products_only</Keyword>
                            <Value xmlns="">True</Value>
                        </Parameter>
                    </ParameterSet>
                </ProcessingCommand>
            </ProcessingProcedure>
            <DataSet>
                <RelativePath>{{relative_path}}</RelativePath>
                <SdmIdentifier>{{sdmId}}.ms</SdmIdentifier>
                <DataType>asdm</DataType>
            </DataSet>
        </ProcessingRequest>0
    </ProcessingRequests>
    <ResultsProcessing>
        <ArchiveResults>false</ArchiveResults>
        <CleanUpDisk>false</CleanUpDisk>
        <UpdateProjectLifeCycle>false</UpdateProjectLifeCycle>
        <NotifyOperatorWhenDone>false</NotifyOperatorWhenDone>
        <SDMall>false</SDMall>
        <SDMonly>false</SDMonly>
        <PipelineOperatorAddress>Unknown</PipelineOperatorAddress>
    </ResultsProcessing>
</ns2:SciPipeRequest>

"""


def upgrade():
    op.execute(
        f"""
        INSERT INTO workflow_templates (filename, content, workflow_name) 
        VALUES('std_cms_imaging.condor', E'{condor_content}', 'std_cms_imaging') 
        """
    )
    op.execute(
        f"""
        INSERT INTO workflow_templates (filename, content, workflow_name) 
        VALUES ('std_cms_imaging.sh', E'{script_content}', 'std_cms_imaging') 
        """
    )
    op.execute(
        f"""
        INSERT INTO workflow_templates (filename, content, workflow_name) 
        VALUES ('metadata.json', E'{metadata_content}', 'std_cms_imaging') 
        """
    )
    op.execute(
        f"""
        INSERT INTO workflow_templates (filename, content, workflow_name) 
        VALUES ('PPR.xml', E'{ppr_content}', 'std_cms_imaging') 
        """
    )


def downgrade():
    op.execute(
        """
        DELETE FROM workflow_templates WHERE workflow_name='std_cms_imaging'
        """
    )