def build_a_plane_position(plane): from astropy.io import fits from astropy.wcs import wcs from caom2 import SegmentType, Point, Vertex, Position, shape logging.error('do i get here?') try: z = fits.open('/usr/src/app/draogmims2caom2/draogmims2caom2/tests' '/data/gmims_HBN_Fan.fits') w = wcs.WCS(z[0].header) points = [] vertices = [] segment_type = SegmentType['MOVE'] for x, y in ([0, 0], [1, 0], [1, 1], [0, 1]): v = w.all_pix2world(x * z[0].header['naxis1'], y * z[0].header['naxis2'], 1, 1) points.append(Point(float(v[0]), float(v[1]))) vertices.append(Vertex(float(v[0]), float(v[1]), segment_type)) segment_type = SegmentType['LINE'] vertices.append( Vertex(points[0].cval1, points[0].cval2, SegmentType['CLOSE'])) polygon = shape.Polygon(points=points, samples=shape.MultiPolygon(vertices)) position = Position(time_dependent=False, bounds=polygon) plane.position = position except Exception as e: logging.error('wtf {}'.format(e))
def _validate_move(self, vertex): if self._open_loop: raise AssertionError( 'invalid polygon: MOVE vertex when loop open') self._lines = 0 self._open_loop = True self._polygon.points.append(Point(vertex.cval1, vertex.cval2))
def _validate_close(self, vertex): # close the polygon if not self._open_loop: raise AssertionError( 'invalid polygon: CLOSE vertex when loop close') if self._lines < 2: raise AssertionError('invalid polygon: minimum 2 lines required') self._open_loop = False # SphericalPolygon requires point[0] == point[-1] point = self._polygon.points[0] self._polygon.points.append(Point(point.cval1, point.cval2)) # validate the polygons in the multipolygon validate_polygon(self._polygon) # instantiate a new Polygon for the next iteration self._polygon = Polygon()
def test_plane_level_position(self): # special handling, because nan == nan is False p1 = [ Point(cval1=float('nan'), cval2=float('nan')), Point(cval1=100.25, cval2=-30.5), Point(cval1=100.25, cval2=30.0), Point(cval1=float('nan'), cval2=float('nan')) ] p2 = [ Point(cval1=float('nan'), cval2=float('nan')), Point(cval1=100.25, cval2=-30.5), Point(cval1=100.25, cval2=30.0), Point(cval1=float('nan'), cval2=float('nan')) ] v1 = [ Vertex(p1[0].cval1, p1[0].cval2, SegmentType.MOVE), Vertex(p1[1].cval1, p1[1].cval2, SegmentType.LINE), Vertex(p1[2].cval1, p1[2].cval2, SegmentType.LINE), Vertex(p1[3].cval1, p1[3].cval2, SegmentType.LINE), Vertex(p1[0].cval1, p1[0].cval2, SegmentType.CLOSE) ] v2 = [ Vertex(p2[0].cval1, p2[0].cval2, SegmentType.MOVE), Vertex(p2[1].cval1, p2[1].cval2, SegmentType.LINE), Vertex(p2[2].cval1, p2[2].cval2, SegmentType.LINE), Vertex(p2[3].cval1, p2[3].cval2, SegmentType.LINE), Vertex(p2[0].cval1, p2[0].cval2, SegmentType.CLOSE) ] poly1 = shape.Polygon(points=p1, samples=shape.MultiPolygon(v1)) poly2 = shape.Polygon(points=p2, samples=shape.MultiPolygon(v2)) o1 = Position(time_dependent=False, bounds=poly1) o2 = Position(time_dependent=False, bounds=poly2) report = diff.get_differences(o1, o2, 'caom test instances') assert report is None, 'NaN comparison failure'
def _validate_line(self, vertex): if not self._open_loop: raise AssertionError( 'invalid polygon: LINE vertex when loop close') self._lines += 1 self._polygon.points.append(Point(vertex.cval1, vertex.cval2))
def _build_obs(override, db_content, fqn, index, almaca_name, md_name): obs_date = db_content['Observation date'][index] if obs_date is None: raise mc.CadcException('No observation date for {}'.format(fqn)) else: obs_date = time.Time(obs_date).to_datetime() # of_site('alma') # 2225015.30883296, -5440016.41799762, -2481631.27428014 # size = db_content['Array'][index] telescope = Telescope(name="ALMA-{}".format(size), geo_location_x=2225142.18, geo_location_y=-5440307.37, geo_location_z=-2481029.852) instrument = Instrument(name=_get_band_name(override)) # HK - 14-08-19 # target: this should be the science target / science fieldname and # not the calibrator fieldname, as it is presently (i.e., should be # J1851+0035, not J1924-2914). Or, we may need to continue to leave # that field blank at this level. A single calibrated measurement set # may contain multiple science target names, which would not be # properly captured at this level. [For the raw data, the target # field is left blank] target = Target(name=override.get('field'), standard=False, moving=False, target_type=TargetType.OBJECT) # HK - 07-02-20 # Since we've changed what the base level observation is and can now list # a target name in the 'Derived Observation' base plane, I believe that # means we can also include that target's position under targetPosition. # You've already pulled this info out for the subsequent levels of the # hierarchy under 'position', so it's presumably fairly straightforward to # include the same info here. result_ra, result_dec = _get_ra_dec(md_name) point = Point(result_ra, result_dec) target_position = TargetPosition( coordinates=point, coordsys='ICRS', # from listobs output equinox=2000.0) # a guess by google # db_content as votable: # >>> t.colnames # ['Project_code', 'Source_name', 'RA', 'Dec', 'Galactic_longitude', # 'Galactic_latitude', 'Band', 'Spatial_resolution', # 'Frequency_resolution', 'Array', 'Mosaic', 'Integration', # 'Release_date', 'Frequency_support', 'Velocity_resolution', # 'Pol_products', 'Observation_date', 'PI_name', 'SB_name', # 'Proposal_authors', 'Line_sensitivity__10_km_s_', # 'Continuum_sensitivity', 'PWV', 'Group_ous_id', 'Member_ous_id', # 'Asdm_uid', 'Project_title', 'Project_type', 'Scan_intent', # 'Field_of_view', 'Largest_angular_scale', 'QA2_Status', 'COUNT', # 'Science_keyword', 'Scientific_category', 'ASA_PROJECT_CODE'] # # db_content.colnames as html: # # ['Project code', 'Source name', 'RA', 'Dec', 'Galactic longitude', # 'Galactic latitude', 'Band', 'Spatial resolution', # 'Frequency resolution', 'Array', 'Mosaic', 'Integration', # 'Release date', 'Frequency support', 'Velocity resolution', # 'Pol products', 'Observation date', 'PI name', 'SB name', # 'Proposal authors', 'Line sensitivity (10 km/s)', # 'Continuum sensitivity', 'PWV', 'Group ous id', 'Member ous id', # 'Asdm uid', 'Project title', 'Project type', 'Scan intent', # 'Field of view', 'Largest angular scale', 'QA2 Status', 'COUNT', # 'Science keyword', 'Scientific category', 'ASA_PROJECT_CODE'] # HK - 14-08-19 # can we include the project code, and not just the observation UID # somewhere in here? For the raw data, it looks like the project # code was included as 'proposal: ID', whereas for the calibrated # measurement set, proposal: ID is now set to the UID and the project # code (2016.1.00010.S) is not captured anywhere. Could the 'project' # field, currently set as 'null' be used for this? proposal = Proposal(id=db_content['Project code'][index], project=override.get('project'), pi_name=db_content['PI name'][index], title=db_content['Project title'][index]) keywords = db_content['Science keyword'][index] if keywords is not None: proposal.keywords = set(keywords.split()) environment = Environment() environment.tau = db_content['PWV'][index] / 0.935 + 0.35 environment.wavelength_tau = 350 * units.um.to(units.meter) intent = (ObservationIntentType.SCIENCE if almaca_name.intent is ProductType.SCIENCE else ObservationIntentType.CALIBRATION) algorithm = Algorithm(name='single band split') # # PD, SG 15-08-19 # make it a composite, algorithm name something like # 'target splitting' # observation = DerivedObservation(collection=ARCHIVE, observation_id=almaca_name.obs_id, sequence_number=None, intent=intent, type="OBJECT", proposal=proposal, telescope=telescope, instrument=instrument, target=target, meta_release=obs_date, algorithm=algorithm, environment=environment, target_position=target_position) observation.members.add( ObservationURI( mc.CaomName.make_obs_uri_from_obs_id('ALMA', 'A001_X88b_X23'))) return observation