<commit_before>#!/usr/bin/env python
"""
Module for working with survey fields.
"""
import os
import copy
from collections import OrderedDict as odict
import logging

import numpy as np

from obztak import __version__
from obztak.utils import constants
from obztak.utils import fileio

# Default field array values
DEFAULTS = odict([
    ('HEX',       dict(dtype=int,value=0)),
    ('RA',        dict(dtype=float,value=None)),
    ('DEC',       dict(dtype=float,value=None)),
    ('FILTER',    dict(dtype='S1',value='')),
    ('EXPTIME',   dict(dtype=float,value=90)),
    ('TILING',    dict(dtype=int,value=0)),
    ('PRIORITY',  dict(dtype=int,value=1)),
    ('DATE',      dict(dtype='S30',value='')),
    ('AIRMASS',   dict(dtype=float,value=-1.0)),
    ('SLEW',      dict(dtype=float,value=-1.0)),
    ('MOONANGLE', dict(dtype=float,value=-1.0)),
    ('HOURANGLE', dict(dtype=float,value=-1.0)),
])
DTYPES = odict([(k,v['dtype']) for k,v in DEFAULTS.items()])
VALUES = odict([(k,v['value']) for k,v in DEFAULTS.items()])

SEP = ':'
#OBJECT_FMT = 'MAGLITES field' + SEP + ' %s'
#SEQID_FMT  = 'MAGLITES scheduled' + SEP + ' %(DATE)s'
#PROGRAM = 'maglites'
#PROPID  = '2016A-0366'


# Default sispi dictionary
SISPI_DICT = odict([
    ("object",  None),
    ("seqnum",  None), # 1-indexed
    ("seqtot",  2),
    ("seqid",   None),
    ("expTime", 90),
    ("RA",      None),
    ("dec",     None),
    ("filter",  None),
    ("count",   1),
    ("expType", "object"),
    #("program", PROGRAM),
    ("program", None),
    ("wait",    "False"),
    #("propid",  PROPID),
    ("propid",  None),
    ("comment", ""),
])

# Mapping between sispi dict keys and field array columns
SISPI_MAP = odict([
    ('expTime','EXPTIME'),
    ('RA','RA'),
    ('dec','DEC'),
    ('filter','FILTER'),
])

class FieldArray(np.recarray):
    """ Array for holding observation fields. """
    PROGRAM = 'maglites'
    PROPID  = '2016A-0366'

    SISPI_DICT = copy.deepcopy(SISPI_DICT)
    SISPI_DICT['program'] = PROGRAM
    SISPI_DICT['propid'] = PROPID
    #OBJECT_FMT = 'OBZTAK field'+SEP+' %s'
    #SEQID_FMT  = 'OBZTAK scheduled'+SEP+' %(DATE)s'
    OBJECT_FMT = 'MAGLITES field'+SEP+' %s'
    SEQID_FMT  = 'MAGLITES scheduled'+SEP+' %(DATE)s'

    BANDS = constants.BANDS

    def __new__(cls,shape=0):
        # Need to do it this way so that array can be resized...
        dtype = DTYPES.items()
        self = np.recarray(shape,dtype=dtype).view(cls)
        values = VALUES.items()
        for k,v in values: self[k].fill(v)
        return self

    def __add__(self, other):
        return np.concatenate([self,other]).view(self.__class__)

    def __getitem__(self,key):
        if isinstance(key,basestring) and key == 'ID':<commit_msg>copying fields correctly<commit_after>#!/usr/bin/env python
"""
Module for working with survey fields.
"""
import os
import copy
from collections import OrderedDict as odict
import logging

import numpy as np

from obztak import __version__
from obztak.utils import constants
from obztak.utils import fileio

# Default field array values
DEFAULTS = odict([
    ('HEX',       dict(dtype=int,value=0)),
    ('RA',        dict(dtype=float,value=None)),
    ('DEC',       dict(dtype=float,value=None)),
    ('FILTER',    dict(dtype='S1',value='')),
    ('EXPTIME',   dict(dtype=float,value=90)),
    ('TILING',    dict(dtype=int,value=0)),
    ('PRIORITY',  dict(dtype=int,value=1)),
    ('DATE',      dict(dtype='S30',value='')),
    ('AIRMASS',   dict(dtype=float,value=-1.0)),
    ('SLEW',      dict(dtype=float,value=-1.0)),
    ('MOONANGLE', dict(dtype=float,value=-1.0)),
    ('HOURANGLE', dict(dtype=float,value=-1.0)),
])
DTYPES = odict([(k,v['dtype']) for k,v in DEFAULTS.items()])
VALUES = odict([(k,v['value']) for k,v in DEFAULTS.items()])

SEP = ':'
#OBJECT_FMT = 'MAGLITES field' + SEP + ' %s'
#SEQID_FMT  = 'MAGLITES scheduled' + SEP + ' %(DATE)s'
#PROGRAM = 'maglites'
#PROPID  = '2016A-0366'


# Default sispi dictionary
SISPI_DICT = odict([
    ("object",  None),
    ("seqnum",  None), # 1-indexed
    ("seqtot",  2),
    ("seqid",   None),
    ("expTime", 90),
    ("RA",      None),
    ("dec",     None),
    ("filter",  None),
    ("count",   1),
    ("expType", "object"),
    #("program", PROGRAM),
    ("program", None),
    ("wait",    "False"),
    #("propid",  PROPID),
    ("propid",  None),
    ("comment", ""),
])

# Mapping between sispi dict keys and field array columns
SISPI_MAP = odict([
    ('expTime','EXPTIME'),
    ('RA','RA'),
    ('dec','DEC'),
    ('filter','FILTER'),
])

class FieldArray(np.recarray):
    """ Array for holding observation fields. """
    PROGRAM = 'maglites'
    PROPID  = '2016A-0366'

    SISPI_DICT = copy.deepcopy(SISPI_DICT)
    SISPI_DICT['program'] = PROGRAM
    SISPI_DICT['propid'] = PROPID
    #OBJECT_FMT = 'OBZTAK field'+SEP+' %s'
    #SEQID_FMT  = 'OBZTAK scheduled'+SEP+' %(DATE)s'
    OBJECT_FMT = 'MAGLITES field'+SEP+' %s'
    SEQID_FMT  = 'MAGLITES scheduled'+SEP+' %(DATE)s'

    BANDS = constants.BANDS

    def __new__(cls,shape=0):
        # Need to do it this way so that array can be resized...
        dtype = DTYPES.items()
        self = np.recarray(shape,dtype=dtype).view(cls)
        values = VALUES.items()
        for k,v in values: self[k].fill(v)
        return self
    
    #def __array_finalize__(self,obj):
    #    print('In array_finalize:')
    #    print('   self type is %s' % type(self))
    #    print('   obj type is %s' % type(obj))

    #def __array_wrap__(self, out_arr, context=None):
    #    print('In __array_wrap__:')
    #    print('   self is %s' % repr(self))
    #    print('   arr is %s' % repr(out_arr))

    def __add__(self, other):
        return np.concatenate([self,other]).view(self.__class__)

    def __getitem__(self,key):
        if isinstance(key,basestring) and key == 'ID':
{'fraction_non_alphanumeric': 0.18739294278862625, 'fraction_numerical': 0.01301815690304899, 'mean_word_length': 3.3028739867354457, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4390956', 'n_tokens_mistral': 2207, 'n_tokens_neox': 2193, 'n_words': 471}